2017-08-24 01:09:59 -07:00
|
|
|
// Copyright 2017 AMIS Technologies
|
|
|
|
// This file is part of the go-ethereum library.
|
|
|
|
//
|
|
|
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2017-08-31 20:26:54 -07:00
|
|
|
package functional
|
2017-08-24 01:09:59 -07:00
|
|
|
|
|
|
|
import (
|
|
|
|
"sync"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
. "github.com/onsi/ginkgo"
|
|
|
|
. "github.com/onsi/gomega"
|
|
|
|
|
|
|
|
"github.com/getamis/istanbul-tools/container"
|
2017-08-31 20:26:54 -07:00
|
|
|
"github.com/getamis/istanbul-tools/tests"
|
2017-08-24 01:09:59 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
var _ = Describe("TFS-05: Byzantine Faulty", func() {
|
|
|
|
|
|
|
|
Context("TFS-05-01: F faulty validators", func() {
|
|
|
|
const (
|
|
|
|
numberOfNormal = 3
|
|
|
|
numberOfFaulty = 1
|
|
|
|
)
|
|
|
|
var (
|
|
|
|
blockchain container.Blockchain
|
|
|
|
)
|
|
|
|
BeforeEach(func() {
|
2017-09-01 01:52:08 -07:00
|
|
|
blockchain = container.NewDefaultBlockchainWithFaulty(dockerNetwork, numberOfNormal, numberOfFaulty)
|
2017-08-24 01:09:59 -07:00
|
|
|
Expect(blockchain.Start(true)).To(BeNil())
|
|
|
|
})
|
|
|
|
|
|
|
|
AfterEach(func() {
|
|
|
|
Expect(blockchain.Stop(false)).To(BeNil())
|
|
|
|
blockchain.Finalize()
|
|
|
|
})
|
|
|
|
|
|
|
|
It("Should generate blocks", func(done Done) {
|
|
|
|
|
|
|
|
By("Wait for p2p connection", func() {
|
2017-08-31 20:26:54 -07:00
|
|
|
tests.WaitFor(blockchain.Validators(), func(geth container.Ethereum, wg *sync.WaitGroup) {
|
2017-08-24 01:09:59 -07:00
|
|
|
Expect(geth.WaitForPeersConnected(numberOfNormal + numberOfFaulty - 1)).To(BeNil())
|
|
|
|
wg.Done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
By("Wait for blocks", func() {
|
|
|
|
const targetBlockHeight = 3
|
2017-08-31 20:26:54 -07:00
|
|
|
tests.WaitFor(blockchain.Validators()[:1], func(geth container.Ethereum, wg *sync.WaitGroup) {
|
2017-08-24 01:09:59 -07:00
|
|
|
Expect(geth.WaitForBlocks(targetBlockHeight)).To(BeNil())
|
|
|
|
wg.Done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
close(done)
|
|
|
|
}, 60)
|
|
|
|
})
|
|
|
|
|
|
|
|
Context("TFS-05-01: F+1 faulty validators", func() {
|
|
|
|
const (
|
|
|
|
numberOfNormal = 2
|
|
|
|
numberOfFaulty = 2
|
|
|
|
)
|
|
|
|
var (
|
|
|
|
blockchain container.Blockchain
|
|
|
|
)
|
|
|
|
BeforeEach(func() {
|
2017-09-01 01:52:08 -07:00
|
|
|
blockchain = container.NewDefaultBlockchainWithFaulty(dockerNetwork, numberOfNormal, numberOfFaulty)
|
2017-08-24 01:09:59 -07:00
|
|
|
Expect(blockchain.Start(true)).To(BeNil())
|
|
|
|
})
|
|
|
|
|
|
|
|
AfterEach(func() {
|
|
|
|
Expect(blockchain.Stop(false)).To(BeNil())
|
|
|
|
blockchain.Finalize()
|
|
|
|
})
|
|
|
|
|
|
|
|
It("Should not generate blocks", func(done Done) {
|
|
|
|
By("Wait for p2p connection", func() {
|
2017-08-31 20:26:54 -07:00
|
|
|
tests.WaitFor(blockchain.Validators(), func(geth container.Ethereum, wg *sync.WaitGroup) {
|
2017-08-24 01:09:59 -07:00
|
|
|
Expect(geth.WaitForPeersConnected(numberOfNormal + numberOfFaulty - 1)).To(BeNil())
|
|
|
|
wg.Done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
By("Wait for blocks", func() {
|
|
|
|
// Only check normal validators
|
2017-08-31 20:26:54 -07:00
|
|
|
tests.WaitFor(blockchain.Validators()[:2], func(geth container.Ethereum, wg *sync.WaitGroup) {
|
2017-08-24 01:09:59 -07:00
|
|
|
Expect(geth.WaitForNoBlocks(0, time.Second*30)).To(BeNil())
|
|
|
|
wg.Done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
close(done)
|
|
|
|
}, 60)
|
|
|
|
})
|
|
|
|
|
|
|
|
})
|