tests: watch few block and see if the newly added validator has been picked as proposer at least once.
This commit is contained in:
parent
e48e2dad3b
commit
10be446832
|
@ -37,11 +37,13 @@ import (
|
|||
"github.com/docker/go-connections/nat"
|
||||
"github.com/ethereum/go-ethereum/cmd/utils"
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/consensus/istanbul"
|
||||
ethtypes "github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
"github.com/ethereum/go-ethereum/ethclient"
|
||||
"github.com/ethereum/go-ethereum/p2p/discover"
|
||||
|
||||
"github.com/getamis/istanbul-tools/cmd/istanbul/extradata"
|
||||
"github.com/getamis/istanbul-tools/genesis"
|
||||
"github.com/getamis/istanbul-tools/istclient"
|
||||
)
|
||||
|
@ -70,6 +72,7 @@ type Ethereum interface {
|
|||
NewIstanbulClient() *istclient.Client
|
||||
ConsensusMonitor(err chan<- error, quit chan struct{})
|
||||
|
||||
WaitForProposed(expectedAddress common.Address, t time.Duration) error
|
||||
WaitForPeersConnected(int) error
|
||||
WaitForBlocks(int) error
|
||||
WaitForBlockHeight(int) error
|
||||
|
@ -401,7 +404,7 @@ func (eth *ethereum) ConsensusMonitor(errCh chan<- error, quit chan struct{}) {
|
|||
log.Printf("Connection lost: %v", err)
|
||||
errCh <- err
|
||||
return
|
||||
case <-timer.C:
|
||||
case <-timer.C: // FIXME: this event may be missed
|
||||
if blockNumber == 0 {
|
||||
errCh <- ErrNoBlock
|
||||
} else {
|
||||
|
@ -423,6 +426,42 @@ func (eth *ethereum) ConsensusMonitor(errCh chan<- error, quit chan struct{}) {
|
|||
}
|
||||
}
|
||||
|
||||
// TODO: refactor with ConsensusMonitor
|
||||
func (eth *ethereum) WaitForProposed(expectedAddress common.Address, timeout time.Duration) error {
|
||||
cli := eth.NewClient()
|
||||
|
||||
subCh := make(chan *ethtypes.Header)
|
||||
|
||||
sub, err := cli.SubscribeNewHead(context.Background(), subCh)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer sub.Unsubscribe()
|
||||
|
||||
timer := time.NewTimer(timeout)
|
||||
for {
|
||||
select {
|
||||
case err := <-sub.Err():
|
||||
return err
|
||||
case <-timer.C: // FIXME: this event may be missed
|
||||
return errors.New("no result")
|
||||
case head := <-subCh:
|
||||
_, istanbulExtra, err := extradata.Decode(common.ToHex(head.Extra))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
addr, err := istanbul.GetSignatureAddress(sigHash(head).Bytes(), istanbulExtra.Seal)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if addr.String() == expectedAddress.String() {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (eth *ethereum) WaitForPeersConnected(expectedPeercount int) error {
|
||||
client := eth.NewIstanbulClient()
|
||||
if client == nil {
|
||||
|
|
|
@ -24,7 +24,10 @@ import (
|
|||
"path/filepath"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
"github.com/ethereum/go-ethereum/crypto/sha3"
|
||||
"github.com/ethereum/go-ethereum/rlp"
|
||||
uuid "github.com/satori/go.uuid"
|
||||
)
|
||||
|
||||
|
@ -78,3 +81,12 @@ func saveNodeKey(key *ecdsa.PrivateKey, dataDir string) error {
|
|||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func sigHash(header *types.Header) (hash common.Hash) {
|
||||
hasher := sha3.NewKeccak256()
|
||||
|
||||
// Clean seal is required for calculating proposer seal.
|
||||
rlp.Encode(hasher, types.IstanbulFilteredHeader(header, false))
|
||||
hasher.Sum(hash[:0])
|
||||
return hash
|
||||
}
|
||||
|
|
|
@ -72,6 +72,18 @@ var _ = Describe("Dynamic validators addition/removal testing", func() {
|
|||
}
|
||||
})
|
||||
|
||||
It("TFS-02-02 New validators consensus participation", func() {
|
||||
testValidator := 1
|
||||
|
||||
newValidators, err := blockchain.AddValidators(testValidator)
|
||||
Expect(err).Should(BeNil())
|
||||
|
||||
waitFor(blockchain.Validators()[numberOfValidators:], func(eth container.Ethereum, wg *sync.WaitGroup) {
|
||||
Expect(eth.WaitForProposed(newValidators[0].Address(), 100*time.Second)).Should(BeNil())
|
||||
wg.Done()
|
||||
})
|
||||
})
|
||||
|
||||
It("TFS-02-03 Remove validators", func() {
|
||||
numOfCandidates := 3
|
||||
|
||||
|
|
Loading…
Reference in New Issue