Merge pull request #31 from getamis/test/gossip-network-test
test: TFS-07-01 add gossip network test
This commit is contained in:
commit
dd4da1b579
|
@ -34,7 +34,7 @@ import (
|
|||
type Blockchain interface {
|
||||
AddValidators(numOfValidators int) ([]Ethereum, error)
|
||||
EnsureConsensusWorking(geths []Ethereum, t time.Duration) error
|
||||
Start() error
|
||||
Start(bool) error
|
||||
Stop(bool) error
|
||||
Validators() []Ethereum
|
||||
Finalize()
|
||||
|
@ -82,7 +82,7 @@ func (bc *blockchain) AddValidators(numOfValidators int) ([]Ethereum, error) {
|
|||
}
|
||||
}
|
||||
|
||||
if err := bc.connectAll(); err != nil {
|
||||
if err := bc.connectAll(true); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return newValidators, nil
|
||||
|
@ -109,11 +109,11 @@ func (bc *blockchain) EnsureConsensusWorking(geths []Ethereum, t time.Duration)
|
|||
return err
|
||||
}
|
||||
|
||||
func (bc *blockchain) Start() error {
|
||||
func (bc *blockchain) Start(strong bool) error {
|
||||
if err := bc.start(bc.validators); err != nil {
|
||||
return err
|
||||
}
|
||||
return bc.connectAll()
|
||||
return bc.connectAll(strong)
|
||||
}
|
||||
|
||||
func (bc *blockchain) Stop(force bool) error {
|
||||
|
@ -143,16 +143,15 @@ func (bc *blockchain) addValidators(numOfValidators int) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (bc *blockchain) connectAll() error {
|
||||
func (bc *blockchain) connectAll(strong bool) error {
|
||||
for i, v := range bc.validators {
|
||||
istClient := v.NewIstanbulClient()
|
||||
for j, v := range bc.validators {
|
||||
if i == j {
|
||||
continue
|
||||
}
|
||||
err := istClient.AddPeer(context.Background(), v.NodeAddress())
|
||||
if err != nil {
|
||||
return err
|
||||
if (strong && j > i) || (!strong && j == i+1) {
|
||||
err := istClient.AddPeer(context.Background(), v.NodeAddress())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ func TestEthereumBlockchain(t *testing.T) {
|
|||
)
|
||||
defer chain.Finalize()
|
||||
|
||||
err := chain.Start()
|
||||
err := chain.Start(true)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
|
|
@ -66,6 +66,15 @@ func (ic *Client) AdminPeers(ctx context.Context) ([]*p2p.PeerInfo, error) {
|
|||
return r, err
|
||||
}
|
||||
|
||||
func (ic *Client) NodeInfo(ctx context.Context) (*p2p.PeerInfo, error) {
|
||||
var r *p2p.PeerInfo
|
||||
err := ic.c.CallContext(ctx, &r, "admin_nodeInfo")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return r, err
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
func (ic *Client) BlockNumber(ctx context.Context) (*big.Int, error) {
|
||||
var r string
|
||||
|
|
|
@ -51,7 +51,7 @@ var _ = Describe("Dynamic validators addition/removal testing", func() {
|
|||
container.Logging(true),
|
||||
)
|
||||
|
||||
Expect(blockchain.Start()).To(BeNil())
|
||||
Expect(blockchain.Start(true)).To(BeNil())
|
||||
})
|
||||
|
||||
AfterEach(func() {
|
||||
|
|
|
@ -52,7 +52,7 @@ var _ = Describe("TFS-01: General consensus", func() {
|
|||
container.Logging(false),
|
||||
)
|
||||
|
||||
Expect(blockchain.Start()).To(BeNil())
|
||||
Expect(blockchain.Start(true)).To(BeNil())
|
||||
})
|
||||
|
||||
AfterEach(func() {
|
||||
|
|
|
@ -0,0 +1,88 @@
|
|||
// 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/>.
|
||||
|
||||
package tests
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
|
||||
"github.com/getamis/istanbul-tools/container"
|
||||
)
|
||||
|
||||
var _ = Describe("TFS-07: Gossip Network", func() {
|
||||
const (
|
||||
numberOfValidators = 4
|
||||
)
|
||||
var (
|
||||
blockchain container.Blockchain
|
||||
)
|
||||
|
||||
BeforeEach(func() {
|
||||
blockchain = container.NewBlockchain(
|
||||
numberOfValidators,
|
||||
container.ImageRepository("quay.io/amis/geth"),
|
||||
container.ImageTag("istanbul_develop"),
|
||||
container.DataDir("/data"),
|
||||
container.WebSocket(),
|
||||
container.WebSocketAddress("0.0.0.0"),
|
||||
container.WebSocketAPI("admin,eth,net,web3,personal,miner"),
|
||||
container.WebSocketOrigin("*"),
|
||||
container.NAT("any"),
|
||||
container.NoDiscover(),
|
||||
container.Etherbase("1a9afb711302c5f83b5902843d1c007a1a137632"),
|
||||
container.Mine(),
|
||||
container.Logging(false),
|
||||
)
|
||||
|
||||
Expect(blockchain.Start(false)).To(BeNil())
|
||||
})
|
||||
|
||||
AfterEach(func() {
|
||||
Expect(blockchain.Stop(false)).To(BeNil())
|
||||
blockchain.Finalize()
|
||||
})
|
||||
|
||||
It("TFS-07-01: Gossip Network", func(done Done) {
|
||||
By("Check peer count", func() {
|
||||
for _, geth := range blockchain.Validators() {
|
||||
c := geth.NewIstanbulClient()
|
||||
peers, e := c.AdminPeers(context.Background())
|
||||
Expect(e).To(BeNil())
|
||||
Ω(len(peers)).Should(BeNumerically("<=", 2))
|
||||
}
|
||||
})
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
})
|
||||
close(done)
|
||||
}, 240)
|
||||
})
|
|
@ -53,7 +53,7 @@ var _ = Describe("4 validators Istanbul", func() {
|
|||
container.Logging(true),
|
||||
)
|
||||
|
||||
Expect(blockchain.Start()).To(BeNil())
|
||||
Expect(blockchain.Start(true)).To(BeNil())
|
||||
})
|
||||
|
||||
AfterEach(func() {
|
||||
|
|
|
@ -26,7 +26,7 @@ import (
|
|||
"github.com/getamis/istanbul-tools/container"
|
||||
)
|
||||
|
||||
var _ = Describe("TSU-04: Non-Byzantine Faulty", func() {
|
||||
var _ = Describe("TFS-04: Non-Byzantine Faulty", func() {
|
||||
const (
|
||||
numberOfValidators = 4
|
||||
)
|
||||
|
@ -51,7 +51,7 @@ var _ = Describe("TSU-04: Non-Byzantine Faulty", func() {
|
|||
container.Logging(false),
|
||||
)
|
||||
|
||||
Expect(blockchain.Start()).To(BeNil())
|
||||
Expect(blockchain.Start(true)).To(BeNil())
|
||||
})
|
||||
|
||||
AfterEach(func() {
|
||||
|
@ -59,50 +59,52 @@ var _ = Describe("TSU-04: Non-Byzantine Faulty", func() {
|
|||
blockchain.Finalize()
|
||||
})
|
||||
|
||||
It("TSU-04-01: Stop F validators", func(done Done) {
|
||||
|
||||
By("Generating blocks")
|
||||
It("TFS-04-01: Stop F validators", func(done Done) {
|
||||
v0 := blockchain.Validators()[0]
|
||||
c0 := v0.NewIstanbulClient()
|
||||
ticker := time.NewTicker(time.Millisecond * 100)
|
||||
for _ = range ticker.C {
|
||||
n, e := c0.BlockNumber(context.Background())
|
||||
Expect(e).To(BeNil())
|
||||
// Check if new blocks are getting generated
|
||||
if n.Int64() > 1 {
|
||||
ticker.Stop()
|
||||
break
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
By("Stopping validator 0")
|
||||
e := v0.Stop()
|
||||
Expect(e).To(BeNil())
|
||||
})
|
||||
|
||||
ticker = time.NewTicker(time.Millisecond * 100)
|
||||
for _ = range ticker.C {
|
||||
By("Stopping validator 0", func() {
|
||||
e := v0.Stop()
|
||||
// Wait for e to be non-nil to make sure the container is down
|
||||
if e != nil {
|
||||
ticker.Stop()
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
By("Checking blockchain progress")
|
||||
v1 := blockchain.Validators()[1]
|
||||
c1 := v1.NewIstanbulClient()
|
||||
n1, e := c1.BlockNumber(context.Background())
|
||||
Expect(e).To(BeNil())
|
||||
ticker = time.NewTicker(time.Millisecond * 100)
|
||||
for _ = range ticker.C {
|
||||
newN1, e := c1.BlockNumber(context.Background())
|
||||
Expect(e).To(BeNil())
|
||||
if newN1.Int64() > n1.Int64() {
|
||||
ticker.Stop()
|
||||
break
|
||||
ticker := time.NewTicker(time.Millisecond * 100)
|
||||
for _ = range ticker.C {
|
||||
e := v0.Stop()
|
||||
// Wait for e to be non-nil to make sure the container is down
|
||||
if e != nil {
|
||||
ticker.Stop()
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
close(done)
|
||||
}, 60)
|
||||
}, 120)
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue