From 63ec08550932ff2e01973c69bbffd70dfc953042 Mon Sep 17 00:00:00 2001 From: Edwin Date: Thu, 24 Aug 2017 15:04:45 +0800 Subject: [PATCH] tests: reduce validator network size to less than 2F+1 --- tests/dynamic_test.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/tests/dynamic_test.go b/tests/dynamic_test.go index 2daf789d..e5e9142f 100644 --- a/tests/dynamic_test.go +++ b/tests/dynamic_test.go @@ -149,4 +149,36 @@ var _ = Describe("Dynamic validators addition/removal testing", func() { }) }) }) + + It("TFS-02-05 Reduce validator network size below 2F+1", func() { + By("Ensure that blocks are generated by validators", func() { + waitFor(blockchain.Validators(), func(geth container.Ethereum, wg *sync.WaitGroup) { + Expect(geth.WaitForBlocks(5)).To(BeNil()) + wg.Done() + }) + }) + + By("Reduce validator network size to less than 2F+1", func() { + stopCandidates := blockchain.Validators()[numberOfValidators-2:] + // stop validators [3,4] + for _, candidates := range stopCandidates { + c := candidates.NewIstanbulClient() + Expect(c.StopMining(context.Background())).Should(BeNil()) + } + }) + + By("Verify number of validators", 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("No block generated", func() { + // REMARK: ErrNoBlock will return if validators not generate block after 10 second. + Expect(blockchain.EnsureConsensusWorking(blockchain.Validators(), 11*time.Second)).Should(Equal(container.ErrNoBlock)) + }) + }) })