tests: test block refactoring and use wait methods
This commit is contained in:
parent
e48e2dad3b
commit
c6dac0d378
|
@ -96,13 +96,14 @@ var _ = Describe("Block synchronization testing", func() {
|
|||
It("TFS-06-02: Node synchronization", func(done Done) {
|
||||
const targetBlockHeight = 10
|
||||
|
||||
By("Wait for blocks")
|
||||
By("Wait for blocks", func() {
|
||||
waitFor(blockchain.Validators(), func(geth container.Ethereum, wg *sync.WaitGroup) {
|
||||
Expect(geth.WaitForBlocks(targetBlockHeight)).To(BeNil())
|
||||
wg.Done()
|
||||
})
|
||||
})
|
||||
|
||||
By("Stop consensus")
|
||||
By("Stop consensus", func() {
|
||||
for _, v := range blockchain.Validators() {
|
||||
client := v.NewIstanbulClient()
|
||||
Expect(client).NotTo(BeNil())
|
||||
|
@ -110,40 +111,44 @@ var _ = Describe("Block synchronization testing", func() {
|
|||
Expect(err).To(BeNil())
|
||||
client.Close()
|
||||
}
|
||||
})
|
||||
|
||||
By("Get target block")
|
||||
latestBlock, err := blockchain.Validators()[0].NewClient().BlockByNumber(context.Background(), big.NewInt(targetBlockHeight))
|
||||
Expect(err).To(BeNil())
|
||||
Expect(latestBlock).NotTo(BeNil())
|
||||
|
||||
By("Connect all nodes to the validators")
|
||||
By("Connect all nodes to the validators", func() {
|
||||
for _, n := range nodes {
|
||||
for _, v := range blockchain.Validators() {
|
||||
Expect(n.AddPeer(v.NodeAddress())).To(BeNil())
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
By("Wait for p2p connection")
|
||||
By("Wait for p2p connection", func() {
|
||||
waitFor(nodes, func(node container.Ethereum, wg *sync.WaitGroup) {
|
||||
Expect(node.WaitForPeersConnected(numberOfValidators)).To(BeNil())
|
||||
wg.Done()
|
||||
})
|
||||
})
|
||||
|
||||
By("Wait for block synchronization between nodes and validators")
|
||||
By("Wait for block synchronization between nodes and validators", func() {
|
||||
waitFor(nodes, func(geth container.Ethereum, wg *sync.WaitGroup) {
|
||||
Expect(geth.WaitForBlockHeight(targetBlockHeight)).To(BeNil())
|
||||
wg.Done()
|
||||
})
|
||||
})
|
||||
|
||||
By("Check target block hash of nodes")
|
||||
for i := 0; i < numberOfNodes; i++ {
|
||||
nodeClient := nodes[i].NewClient()
|
||||
By("Check target block hash of nodes", func() {
|
||||
expectedBlock, err := blockchain.Validators()[0].NewClient().BlockByNumber(context.Background(), big.NewInt(targetBlockHeight))
|
||||
Expect(err).To(BeNil())
|
||||
Expect(expectedBlock).NotTo(BeNil())
|
||||
|
||||
for _, n := range nodes {
|
||||
nodeClient := n.NewClient()
|
||||
block, err := nodeClient.BlockByNumber(context.Background(), big.NewInt(targetBlockHeight))
|
||||
|
||||
Expect(err).To(BeNil())
|
||||
Expect(block).NotTo(BeNil())
|
||||
Expect(latestBlock.Hash()).To(BeEquivalentTo(block.Hash()))
|
||||
Expect(expectedBlock.Hash()).To(BeEquivalentTo(block.Hash()))
|
||||
}
|
||||
})
|
||||
|
||||
close(done)
|
||||
}, 30)
|
||||
|
|
|
@ -47,9 +47,9 @@ var _ = Describe("Dynamic validators addition/removal testing", func() {
|
|||
})
|
||||
|
||||
It("TFS-02-01 Add validators", func() {
|
||||
testValidators := 3
|
||||
testValidators := 1
|
||||
|
||||
By("Ensure that numbers of validator is equal to $numberOfValidators", func() {
|
||||
By("Ensure the number of validators is correct", func() {
|
||||
for _, v := range blockchain.Validators() {
|
||||
client := v.NewIstanbulClient()
|
||||
validators, err := client.GetValidators(context.Background(), nil)
|
||||
|
@ -58,12 +58,19 @@ var _ = Describe("Dynamic validators addition/removal testing", func() {
|
|||
}
|
||||
})
|
||||
|
||||
By("Add validators", func() {
|
||||
_, err := blockchain.AddValidators(testValidators)
|
||||
Expect(err).Should(BeNil())
|
||||
|
||||
By("Ensure that consensus is working in 50 seconds", func() {
|
||||
Expect(blockchain.EnsureConsensusWorking(blockchain.Validators(), 50*time.Second)).Should(BeNil())
|
||||
})
|
||||
|
||||
By("Wait for several blocks", func() {
|
||||
waitFor(blockchain.Validators(), func(geth container.Ethereum, wg *sync.WaitGroup) {
|
||||
Expect(geth.WaitForBlocks(5)).To(BeNil())
|
||||
wg.Done()
|
||||
})
|
||||
})
|
||||
|
||||
By("Ensure the number of validators is correct", func() {
|
||||
for _, v := range blockchain.Validators() {
|
||||
client := v.NewIstanbulClient()
|
||||
validators, err := client.GetValidators(context.Background(), nil)
|
||||
|
@ -71,6 +78,7 @@ var _ = Describe("Dynamic validators addition/removal testing", func() {
|
|||
Expect(len(validators)).Should(BeNumerically("==", numberOfValidators+testValidators))
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
It("TFS-02-03 Remove validators", func() {
|
||||
numOfCandidates := 3
|
||||
|
@ -84,33 +92,44 @@ var _ = Describe("Dynamic validators addition/removal testing", func() {
|
|||
}
|
||||
})
|
||||
|
||||
By("Add validators", func() {
|
||||
_, err := blockchain.AddValidators(numOfCandidates)
|
||||
Expect(err).Should(BeNil())
|
||||
})
|
||||
|
||||
By("Ensure that consensus is working in 50 seconds", func() {
|
||||
Expect(blockchain.EnsureConsensusWorking(blockchain.Validators(), 50*time.Second)).Should(BeNil())
|
||||
})
|
||||
|
||||
By("Check if the number of validators is correct", func() {
|
||||
for _, v := range blockchain.Validators() {
|
||||
client := v.NewIstanbulClient()
|
||||
validators, err := client.GetValidators(context.Background(), nil)
|
||||
Expect(err).Should(BeNil())
|
||||
Expect(len(validators)).Should(BeNumerically("==", numberOfValidators+numOfCandidates))
|
||||
}
|
||||
})
|
||||
|
||||
// remove validators [1,2,3]
|
||||
By("Remove validators", func() {
|
||||
removalCandidates := blockchain.Validators()[:numOfCandidates]
|
||||
processingTime := time.Duration(math.Pow(2, float64(len(removalCandidates)))*7) * time.Second
|
||||
Expect(blockchain.RemoveValidators(removalCandidates, processingTime)).Should(BeNil())
|
||||
})
|
||||
|
||||
By("Ensure that consensus is working in 20 seconds", func() {
|
||||
Expect(blockchain.EnsureConsensusWorking(blockchain.Validators(), 20*time.Second)).Should(BeNil())
|
||||
})
|
||||
|
||||
By("Check if the number of validators is correct", func() {
|
||||
for _, v := range blockchain.Validators() {
|
||||
client := v.NewIstanbulClient()
|
||||
validators, err := client.GetValidators(context.Background(), nil)
|
||||
Expect(err).Should(BeNil())
|
||||
Expect(len(validators)).Should(BeNumerically("==", numberOfValidators))
|
||||
}
|
||||
})
|
||||
|
||||
By("Ensure that consensus is working in 30 seconds", func() {
|
||||
Expect(blockchain.EnsureConsensusWorking(blockchain.Validators(), 30*time.Second)).Should(BeNil())
|
||||
})
|
||||
|
|
|
@ -17,9 +17,7 @@
|
|||
package tests
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"time"
|
||||
"sync"
|
||||
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
|
@ -45,38 +43,13 @@ var _ = Describe("TFS-01: General consensus", func() {
|
|||
blockchain.Finalize()
|
||||
})
|
||||
|
||||
It("TFS-01-03: Peer connection", func() {
|
||||
|
||||
By("Check peer count")
|
||||
errc := make(chan error, numberOfValidators)
|
||||
for _, v := range blockchain.Validators() {
|
||||
go func(v container.Ethereum) {
|
||||
c := v.NewIstanbulClient()
|
||||
ticker := time.NewTicker(time.Millisecond * 100)
|
||||
timeout := time.NewTimer(time.Second * 10)
|
||||
expPeerCnt := numberOfValidators - 1
|
||||
for {
|
||||
select {
|
||||
case <-ticker.C:
|
||||
peers, err := c.AdminPeers(context.Background())
|
||||
Expect(err).To(BeNil())
|
||||
if len(peers) != expPeerCnt {
|
||||
continue
|
||||
} else {
|
||||
errc <- nil
|
||||
return
|
||||
}
|
||||
case <-timeout.C:
|
||||
errc <- errors.New("Check peer count timeout.")
|
||||
return
|
||||
}
|
||||
}
|
||||
}(v)
|
||||
}
|
||||
|
||||
for i := 0; i < numberOfValidators; i++ {
|
||||
err := <-errc
|
||||
Expect(err).To(BeNil())
|
||||
}
|
||||
It("TFS-01-03: Peer connection", func(done Done) {
|
||||
expectedPeerCount := len(blockchain.Validators()) - 1
|
||||
waitFor(blockchain.Validators(), func(v container.Ethereum, wg *sync.WaitGroup) {
|
||||
Expect(v.WaitForPeersConnected(expectedPeerCount)).To(BeNil())
|
||||
wg.Done()
|
||||
})
|
||||
|
||||
close(done)
|
||||
}, 20)
|
||||
})
|
||||
|
|
|
@ -18,7 +18,7 @@ package tests
|
|||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
"sync"
|
||||
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
|
@ -55,19 +55,12 @@ var _ = Describe("TFS-07: Gossip Network", func() {
|
|||
})
|
||||
|
||||
By("Checking blockchain progress", func() {
|
||||
v0 := blockchain.Validators()[0]
|
||||
c0 := v0.NewClient()
|
||||
ticker := time.NewTicker(time.Millisecond * 100)
|
||||
for _ = range ticker.C {
|
||||
b, e := c0.BlockByNumber(context.Background(), nil)
|
||||
Expect(e).To(BeNil())
|
||||
// Check if new blocks are getting generated
|
||||
if b.Number().Int64() > 1 {
|
||||
ticker.Stop()
|
||||
break
|
||||
}
|
||||
}
|
||||
waitFor(blockchain.Validators(), func(geth container.Ethereum, wg *sync.WaitGroup) {
|
||||
Expect(geth.WaitForBlocks(3)).To(BeNil())
|
||||
wg.Done()
|
||||
})
|
||||
})
|
||||
|
||||
close(done)
|
||||
}, 240)
|
||||
})
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
package tests
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
. "github.com/onsi/ginkgo"
|
||||
|
@ -45,22 +45,15 @@ var _ = Describe("TFS-04: Non-Byzantine Faulty", func() {
|
|||
})
|
||||
|
||||
It("TFS-04-01: Stop F validators", func(done Done) {
|
||||
v0 := blockchain.Validators()[0]
|
||||
By("Generating blockchain progress before stopping validator", func() {
|
||||
c0 := v0.NewClient()
|
||||
ticker := time.NewTicker(time.Millisecond * 100)
|
||||
for _ = range ticker.C {
|
||||
b, e := c0.BlockByNumber(context.Background(), nil)
|
||||
Expect(e).To(BeNil())
|
||||
// Check if new blocks are getting generated
|
||||
if b.Number().Int64() > 1 {
|
||||
ticker.Stop()
|
||||
break
|
||||
}
|
||||
}
|
||||
waitFor(blockchain.Validators(), func(geth container.Ethereum, wg *sync.WaitGroup) {
|
||||
Expect(geth.WaitForBlocks(3)).To(BeNil())
|
||||
wg.Done()
|
||||
})
|
||||
})
|
||||
|
||||
By("Stopping validator 0", func() {
|
||||
v0 := blockchain.Validators()[0]
|
||||
e := v0.Stop()
|
||||
Expect(e).To(BeNil())
|
||||
ticker := time.NewTicker(time.Millisecond * 100)
|
||||
|
@ -75,19 +68,10 @@ var _ = Describe("TFS-04: Non-Byzantine Faulty", func() {
|
|||
})
|
||||
|
||||
By("Checking blockchain progress after stopping validator", func() {
|
||||
v1 := blockchain.Validators()[1]
|
||||
c1 := v1.NewClient()
|
||||
b1, e := c1.BlockByNumber(context.Background(), nil)
|
||||
Expect(e).To(BeNil())
|
||||
ticker := time.NewTicker(time.Millisecond * 100)
|
||||
for _ = range ticker.C {
|
||||
newB1, e := c1.BlockByNumber(context.Background(), nil)
|
||||
Expect(e).To(BeNil())
|
||||
if newB1.Number().Int64() > b1.Number().Int64() {
|
||||
ticker.Stop()
|
||||
break
|
||||
}
|
||||
}
|
||||
waitFor(blockchain.Validators()[1:], func(geth container.Ethereum, wg *sync.WaitGroup) {
|
||||
Expect(geth.WaitForBlocks(3)).To(BeNil())
|
||||
wg.Done()
|
||||
})
|
||||
})
|
||||
|
||||
close(done)
|
||||
|
|
Loading…
Reference in New Issue