client, container, tests/*: integrate ethclient with Istanbul client

This commit is contained in:
Alan Chen 2017-09-07 11:30:30 +08:00
parent de7b73ea4d
commit 0ac6064088
14 changed files with 268 additions and 84 deletions

View File

@ -14,7 +14,7 @@
// 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 istclient
package client
import (
"context"
@ -27,10 +27,12 @@ import (
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/p2p"
"github.com/ethereum/go-ethereum/rpc"
"github.com/getamis/go-ethereum/ethclient"
)
type Client struct {
c *rpc.Client
c *rpc.Client
ethClient *ethclient.Client
}
func Dial(rawurl string) (*Client, error) {
@ -38,7 +40,10 @@ func Dial(rawurl string) (*Client, error) {
if err != nil {
return nil, err
}
return &Client{c}, nil
return &Client{
c: c,
ethClient: ethclient.NewClient(c),
}, nil
}
func (c *Client) Close() {

View File

@ -14,7 +14,7 @@
// 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 istclient
package client
import (
"context"

200
client/ethclient.go Normal file
View File

@ -0,0 +1,200 @@
// 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 client
import (
"context"
"math/big"
ethereum "github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
)
// Blockchain Access
// BlockByHash returns the given full block.
//
// Note that loading full blocks requires two requests. Use HeaderByHash
// if you don't need all transactions or uncle headers.
func (c *Client) BlockByHash(ctx context.Context, hash common.Hash) (*types.Block, error) {
return c.ethClient.BlockByHash(ctx, hash)
}
// BlockByNumber returns a block from the current canonical chain. If number is nil, the
// latest known block is returned.
//
// Note that loading full blocks requires two requests. Use HeaderByNumber
// if you don't need all transactions or uncle headers.
func (c *Client) BlockByNumber(ctx context.Context, number *big.Int) (*types.Block, error) {
return c.ethClient.BlockByNumber(ctx, number)
}
// HeaderByHash returns the block header with the given hash.
func (c *Client) HeaderByHash(ctx context.Context, hash common.Hash) (*types.Header, error) {
return c.ethClient.HeaderByHash(ctx, hash)
}
// HeaderByNumber returns a block header from the current canonical chain. If number is
// nil, the latest known header is returned.
func (c *Client) HeaderByNumber(ctx context.Context, number *big.Int) (*types.Header, error) {
return c.ethClient.HeaderByNumber(ctx, number)
}
// TransactionByHash returns the transaction with the given hash.
func (c *Client) TransactionByHash(ctx context.Context, hash common.Hash) (tx *types.Transaction, isPending bool, err error) {
return c.ethClient.TransactionByHash(ctx, hash)
}
// TransactionCount returns the total number of transactions in the given block.
func (c *Client) TransactionCount(ctx context.Context, blockHash common.Hash) (uint, error) {
return c.ethClient.TransactionCount(ctx, blockHash)
}
// TransactionInBlock returns a single transaction at index in the given block.
func (c *Client) TransactionInBlock(ctx context.Context, blockHash common.Hash, index uint) (*types.Transaction, error) {
return c.ethClient.TransactionInBlock(ctx, blockHash, index)
}
// TransactionReceipt returns the receipt of a transaction by transaction hash.
// Note that the receipt is not available for pending transactions.
func (c *Client) TransactionReceipt(ctx context.Context, txHash common.Hash) (*types.Receipt, error) {
return c.ethClient.TransactionReceipt(ctx, txHash)
}
// SyncProgress retrieves the current progress of the sync algorithm. If there's
// no sync currently running, it returns nil.
func (c *Client) SyncProgress(ctx context.Context) (*ethereum.SyncProgress, error) {
return c.ethClient.SyncProgress(ctx)
}
// SubscribeNewHead subscribes to notifications about the current blockchain head
// on the given channel.
func (c *Client) SubscribeNewHead(ctx context.Context, ch chan<- *types.Header) (ethereum.Subscription, error) {
return c.ethClient.SubscribeNewHead(ctx, ch)
}
// State Access
// NetworkID returns the network ID (also known as the chain ID) for this chain.
func (c *Client) NetworkID(ctx context.Context) (*big.Int, error) {
return c.ethClient.NetworkID(ctx)
}
// BalanceAt returns the wei balance of the given account.
// The block number can be nil, in which case the balance is taken from the latest known block.
func (c *Client) BalanceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (*big.Int, error) {
return c.ethClient.BalanceAt(ctx, account, blockNumber)
}
// StorageAt returns the value of key in the contract storage of the given account.
// The block number can be nil, in which case the value is taken from the latest known block.
func (c *Client) StorageAt(ctx context.Context, account common.Address, key common.Hash, blockNumber *big.Int) ([]byte, error) {
return c.ethClient.StorageAt(ctx, account, key, blockNumber)
}
// CodeAt returns the contract code of the given account.
// The block number can be nil, in which case the code is taken from the latest known block.
func (c *Client) CodeAt(ctx context.Context, account common.Address, blockNumber *big.Int) ([]byte, error) {
return c.ethClient.CodeAt(ctx, account, blockNumber)
}
// NonceAt returns the account nonce of the given account.
// The block number can be nil, in which case the nonce is taken from the latest known block.
func (c *Client) NonceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (uint64, error) {
return c.ethClient.NonceAt(ctx, account, blockNumber)
}
// Filters
// FilterLogs executes a filter query.
func (c *Client) FilterLogs(ctx context.Context, q ethereum.FilterQuery) ([]types.Log, error) {
return c.ethClient.FilterLogs(ctx, q)
}
// SubscribeFilterLogs subscribes to the results of a streaming filter query.
func (c *Client) SubscribeFilterLogs(ctx context.Context, q ethereum.FilterQuery, ch chan<- types.Log) (ethereum.Subscription, error) {
return c.ethClient.SubscribeFilterLogs(ctx, q, ch)
}
// Pending State
// PendingBalanceAt returns the wei balance of the given account in the pending state.
func (c *Client) PendingBalanceAt(ctx context.Context, account common.Address) (*big.Int, error) {
return c.ethClient.PendingBalanceAt(ctx, account)
}
// PendingStorageAt returns the value of key in the contract storage of the given account in the pending state.
func (c *Client) PendingStorageAt(ctx context.Context, account common.Address, key common.Hash) ([]byte, error) {
return c.ethClient.PendingStorageAt(ctx, account, key)
}
// PendingCodeAt returns the contract code of the given account in the pending state.
func (c *Client) PendingCodeAt(ctx context.Context, account common.Address) ([]byte, error) {
return c.ethClient.PendingCodeAt(ctx, account)
}
// PendingNonceAt returns the account nonce of the given account in the pending state.
// This is the nonce that should be used for the next transaction.
func (c *Client) PendingNonceAt(ctx context.Context, account common.Address) (uint64, error) {
return c.ethClient.PendingNonceAt(ctx, account)
}
// PendingTransactionCount returns the total number of transactions in the pending state.
func (c *Client) PendingTransactionCount(ctx context.Context) (uint, error) {
return c.ethClient.PendingTransactionCount(ctx)
}
// Contract Calling
// CallContract executes a message call transaction, which is directly executed in the VM
// of the node, but never mined into the blockchain.
//
// blockNumber selects the block height at which the call runs. It can be nil, in which
// case the code is taken from the latest known block. Note that state from very old
// blocks might not be available.
func (c *Client) CallContract(ctx context.Context, msg ethereum.CallMsg, blockNumber *big.Int) ([]byte, error) {
return c.ethClient.CallContract(ctx, msg, blockNumber)
}
// PendingCallContract executes a message call transaction using the EVM.
// The state seen by the contract call is the pending state.
func (c *Client) PendingCallContract(ctx context.Context, msg ethereum.CallMsg) ([]byte, error) {
return c.ethClient.PendingCallContract(ctx, msg)
}
// SuggestGasPrice retrieves the currently suggested gas price to allow a timely
// execution of a transaction.
func (c *Client) SuggestGasPrice(ctx context.Context) (*big.Int, error) {
return c.ethClient.SuggestGasPrice(ctx)
}
// EstimateGas tries to estimate the gas needed to execute a specific transaction based on
// the current pending state of the backend blockchain. There is no guarantee that this is
// the true gas limit requirement as other transactions may be added or removed by miners,
// but it should provide a basis for setting a reasonable default.
func (c *Client) EstimateGas(ctx context.Context, msg ethereum.CallMsg) (*big.Int, error) {
return c.ethClient.EstimateGas(ctx, msg)
}
// SendTransaction injects a signed transaction into the pending pool for execution.
//
// If the transaction was a contract creation use the TransactionReceipt method to get the
// contract address after the transaction has been mined.
func (c *Client) SendTransaction(ctx context.Context, tx *types.Transaction) error {
return c.ethClient.SendTransaction(ctx, tx)
}

View File

@ -220,7 +220,7 @@ func (bc *blockchain) AddValidators(numOfValidators int) ([]Ethereum, error) {
// propose new validators as validator in consensus
for _, v := range bc.validators[:lastLen] {
istClient := v.NewIstanbulClient()
istClient := v.NewClient()
for _, newV := range newValidators {
if err := istClient.ProposeValidator(context.Background(), newV.Address(), true); err != nil {
return nil, err
@ -259,7 +259,7 @@ func (bc *blockchain) RemoveValidators(candidates []Ethereum, processingTime tim
var newValidators []Ethereum
for _, v := range bc.validators {
istClient := v.NewIstanbulClient()
istClient := v.NewClient()
isFound := false
for _, c := range candidates {
if err := istClient.ProposeValidator(context.Background(), c.Address(), false); err != nil {

View File

@ -35,7 +35,7 @@ func (eth *ethereum) ContainerID() string {
func (eth *ethereum) Host() string {
var host string
daemonHost := eth.client.DaemonHost()
daemonHost := eth.dockerClient.DaemonHost()
url, err := url.Parse(daemonHost)
if err != nil {
log.Printf("Failed to parse daemon host, err: %v", err)

View File

@ -34,18 +34,17 @@ import (
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/filters"
"github.com/docker/docker/api/types/network"
"github.com/docker/docker/client"
docker "github.com/docker/docker/client"
"github.com/docker/go-connections/nat"
"github.com/ethereum/go-ethereum/cmd/utils"
"github.com/ethereum/go-ethereum/common"
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/client"
istcommon "github.com/getamis/istanbul-tools/common"
"github.com/getamis/istanbul-tools/genesis"
"github.com/getamis/istanbul-tools/istclient"
)
const (
@ -68,8 +67,7 @@ type Ethereum interface {
ContainerID() string
Host() string
NewClient() *ethclient.Client
NewIstanbulClient() *istclient.Client
NewClient() *client.Client
ConsensusMonitor(err chan<- error, quit chan struct{})
WaitForProposed(expectedAddress common.Address, t time.Duration) error
@ -88,9 +86,9 @@ type Ethereum interface {
DockerBinds() []string
}
func NewEthereum(c *client.Client, options ...Option) *ethereum {
func NewEthereum(c *docker.Client, options ...Option) *ethereum {
eth := &ethereum{
client: c,
dockerClient: c,
}
for _, opt := range options {
@ -105,7 +103,7 @@ func NewEthereum(c *client.Client, options ...Option) *ethereum {
})
if len(images) == 0 || err != nil {
out, err := eth.client.ImagePull(context.Background(), eth.Image(), types.ImagePullOptions{})
out, err := eth.dockerClient.ImagePull(context.Background(), eth.Image(), types.ImagePullOptions{})
if err != nil {
log.Printf("Cannot pull %s, err: %v", eth.Image(), err)
return nil
@ -141,9 +139,9 @@ type ethereum struct {
imageTag string
dockerNetworkName string
key *ecdsa.PrivateKey
logging bool
client *client.Client
key *ecdsa.PrivateKey
logging bool
dockerClient *docker.Client
}
func (eth *ethereum) Init(genesisFile string) error {
@ -159,7 +157,7 @@ func (eth *ethereum) Init(genesisFile string) error {
binds = append(binds, eth.dataDir+":"+utils.DataDirFlag.Value.Value)
}
resp, err := eth.client.ContainerCreate(context.Background(),
resp, err := eth.dockerClient.ContainerCreate(context.Background(),
&container.Config{
Image: eth.Image(),
Cmd: []string{
@ -179,12 +177,12 @@ func (eth *ethereum) Init(genesisFile string) error {
id := resp.ID
if err := eth.client.ContainerStart(context.Background(), id, types.ContainerStartOptions{}); err != nil {
if err := eth.dockerClient.ContainerStart(context.Background(), id, types.ContainerStartOptions{}); err != nil {
log.Printf("Failed to start container, err: %v", err)
return err
}
resC, errC := eth.client.ContainerWait(context.Background(), id, container.WaitConditionNotRunning)
resC, errC := eth.dockerClient.ContainerWait(context.Background(), id, container.WaitConditionNotRunning)
select {
case <-resC:
case <-errC:
@ -196,7 +194,7 @@ func (eth *ethereum) Init(genesisFile string) error {
eth.showLog(context.Background())
}
return eth.client.ContainerRemove(context.Background(), id, types.ContainerRemoveOptions{Force: true})
return eth.dockerClient.ContainerRemove(context.Background(), id, types.ContainerRemoveOptions{Force: true})
}
func (eth *ethereum) Start() error {
@ -250,7 +248,7 @@ func (eth *ethereum) Start() error {
}
}
resp, err := eth.client.ContainerCreate(context.Background(),
resp, err := eth.dockerClient.ContainerCreate(context.Background(),
&container.Config{
Hostname: "geth-" + eth.hostName,
Image: eth.Image(),
@ -269,7 +267,7 @@ func (eth *ethereum) Start() error {
eth.containerID = resp.ID
err = eth.client.ContainerStart(context.Background(), eth.containerID, types.ContainerStartOptions{})
err = eth.dockerClient.ContainerStart(context.Background(), eth.containerID, types.ContainerStartOptions{})
if err != nil {
log.Printf("Failed to start container, err: %v, ip:%v", err, eth.ip)
return err
@ -297,7 +295,7 @@ func (eth *ethereum) Start() error {
containerIP := eth.ip
if containerIP == "" {
containerJSON, err := eth.client.ContainerInspect(context.Background(), eth.containerID)
containerJSON, err := eth.dockerClient.ContainerInspect(context.Background(), eth.containerID)
if err != nil {
log.Print("Failed to inspect container,", err)
return err
@ -317,7 +315,7 @@ func (eth *ethereum) Start() error {
}
func (eth *ethereum) Stop() error {
err := eth.client.ContainerStop(context.Background(), eth.containerID, nil)
err := eth.dockerClient.ContainerStop(context.Background(), eth.containerID, nil)
if err != nil {
fmt.Printf("error on stop container:%v", err)
return err
@ -325,7 +323,7 @@ func (eth *ethereum) Stop() error {
defer os.RemoveAll(eth.dataDir)
return eth.client.ContainerRemove(context.Background(), eth.containerID,
return eth.dockerClient.ContainerRemove(context.Background(), eth.containerID,
types.ContainerRemoveOptions{
Force: true,
})
@ -334,12 +332,12 @@ func (eth *ethereum) Stop() error {
func (eth *ethereum) Wait(t time.Duration) error {
ctx, cancel := context.WithTimeout(context.Background(), t)
defer cancel()
_, errCh := eth.client.ContainerWait(ctx, eth.containerID, "")
_, errCh := eth.dockerClient.ContainerWait(ctx, eth.containerID, "")
return <-errCh
}
func (eth *ethereum) Running() bool {
containers, err := eth.client.ContainerList(context.Background(), types.ContainerListOptions{})
containers, err := eth.dockerClient.ContainerList(context.Background(), types.ContainerListOptions{})
if err != nil {
log.Printf("Failed to list containers, err: %v", err)
return false
@ -354,7 +352,7 @@ func (eth *ethereum) Running() bool {
return false
}
func (eth *ethereum) NewClient() *ethclient.Client {
func (eth *ethereum) NewClient() *client.Client {
var scheme, port string
if eth.rpcPort != "" {
@ -365,26 +363,7 @@ func (eth *ethereum) NewClient() *ethclient.Client {
scheme = "ws://"
port = eth.wsPort
}
client, err := ethclient.Dial(scheme + eth.Host() + ":" + port)
if err != nil {
log.Printf("Failed to dial eth client, err: %v\n", err)
return nil
}
return client
}
func (eth *ethereum) NewIstanbulClient() *istclient.Client {
var scheme, port string
if eth.rpcPort != "" {
scheme = "http://"
port = eth.rpcPort
}
if eth.wsPort != "" {
scheme = "ws://"
port = eth.wsPort
}
client, err := istclient.Dial(scheme + eth.Host() + ":" + port)
client, err := client.Dial(scheme + eth.Host() + ":" + port)
if err != nil {
return nil
}
@ -477,7 +456,7 @@ func (eth *ethereum) WaitForProposed(expectedAddress common.Address, timeout tim
}
func (eth *ethereum) WaitForPeersConnected(expectedPeercount int) error {
client := eth.NewIstanbulClient()
client := eth.NewClient()
if client == nil {
return errors.New("failed to retrieve client")
}
@ -503,7 +482,7 @@ func (eth *ethereum) WaitForPeersConnected(expectedPeercount int) error {
func (eth *ethereum) WaitForBlocks(num int, waitingTime ...time.Duration) error {
var first *big.Int
client := eth.NewIstanbulClient()
client := eth.NewClient()
if client == nil {
return errors.New("failed to retrieve client")
}
@ -542,7 +521,7 @@ func (eth *ethereum) WaitForBlocks(num int, waitingTime ...time.Duration) error
}
func (eth *ethereum) WaitForBlockHeight(num int) error {
client := eth.NewIstanbulClient()
client := eth.NewClient()
if client == nil {
return errors.New("failed to retrieve client")
}
@ -566,7 +545,7 @@ func (eth *ethereum) WaitForBlockHeight(num int) error {
func (eth *ethereum) WaitForNoBlocks(num int, duration time.Duration) error {
var first *big.Int
client := eth.NewIstanbulClient()
client := eth.NewClient()
if client == nil {
return errors.New("failed to retrieve client")
}
@ -595,7 +574,7 @@ func (eth *ethereum) WaitForNoBlocks(num int, duration time.Duration) error {
}
func (eth *ethereum) AddPeer(address string) error {
client := eth.NewIstanbulClient()
client := eth.NewClient()
if client == nil {
return errors.New("failed to retrieve client")
}
@ -605,7 +584,7 @@ func (eth *ethereum) AddPeer(address string) error {
}
func (eth *ethereum) StartMining() error {
client := eth.NewIstanbulClient()
client := eth.NewClient()
if client == nil {
return errors.New("failed to retrieve client")
}
@ -615,7 +594,7 @@ func (eth *ethereum) StartMining() error {
}
func (eth *ethereum) StopMining() error {
client := eth.NewIstanbulClient()
client := eth.NewClient()
if client == nil {
return errors.New("failed to retrieve client")
}
@ -635,7 +614,7 @@ func (eth *ethereum) DockerBinds() []string {
// ----------------------------------------------------------------------------
func (eth *ethereum) showLog(context context.Context) {
if readCloser, err := eth.client.ContainerLogs(context, eth.containerID,
if readCloser, err := eth.dockerClient.ContainerLogs(context, eth.containerID,
types.ContainerLogsOptions{ShowStderr: true, Follow: true}); err == nil {
defer readCloser.Close()
_, err = io.Copy(os.Stdout, readCloser)

View File

@ -108,7 +108,7 @@ var _ = Describe("Block synchronization testing", func() {
By("Stop consensus", func() {
for _, v := range blockchain.Validators() {
client := v.NewIstanbulClient()
client := v.NewClient()
Expect(client).NotTo(BeNil())
err := client.StopMining(context.Background())
Expect(err).To(BeNil())

View File

@ -52,7 +52,7 @@ var _ = Describe("TFS-02: Dynamic validators addition/removal testing", func() {
By("Ensure the number of validators is correct", func() {
for _, v := range blockchain.Validators() {
client := v.NewIstanbulClient()
client := v.NewClient()
validators, err := client.GetValidators(context.Background(), nil)
Expect(err).Should(BeNil())
Expect(len(validators)).Should(BeNumerically("==", numberOfValidators))
@ -73,7 +73,7 @@ var _ = Describe("TFS-02: Dynamic validators addition/removal testing", func() {
By("Ensure the number of validators is correct", func() {
for _, v := range blockchain.Validators() {
client := v.NewIstanbulClient()
client := v.NewClient()
validators, err := client.GetValidators(context.Background(), nil)
Expect(err).Should(BeNil())
Expect(len(validators)).Should(BeNumerically("==", numberOfValidators+testValidators))
@ -98,7 +98,7 @@ var _ = Describe("TFS-02: Dynamic validators addition/removal testing", func() {
By("Ensure that numbers of validator is equal to $numberOfValidators", func() {
for _, v := range blockchain.Validators() {
client := v.NewIstanbulClient()
client := v.NewClient()
validators, err := client.GetValidators(context.Background(), nil)
Expect(err).Should(BeNil())
Expect(len(validators)).Should(BeNumerically("==", numberOfValidators))
@ -116,7 +116,7 @@ var _ = Describe("TFS-02: Dynamic validators addition/removal testing", func() {
By("Check if the number of validators is correct", func() {
for _, v := range blockchain.Validators() {
client := v.NewIstanbulClient()
client := v.NewClient()
validators, err := client.GetValidators(context.Background(), nil)
Expect(err).Should(BeNil())
Expect(len(validators)).Should(BeNumerically("==", numberOfValidators+numOfCandidates))
@ -136,7 +136,7 @@ var _ = Describe("TFS-02: Dynamic validators addition/removal testing", func() {
By("Check if the number of validators is correct", func() {
for _, v := range blockchain.Validators() {
client := v.NewIstanbulClient()
client := v.NewClient()
validators, err := client.GetValidators(context.Background(), nil)
Expect(err).Should(BeNil())
Expect(len(validators)).Should(BeNumerically("==", numberOfValidators))
@ -160,14 +160,14 @@ var _ = Describe("TFS-02: Dynamic validators addition/removal testing", func() {
// stop validators [3]
stopCandidates := blockchain.Validators()[numberOfValidators-1:]
for _, candidates := range stopCandidates {
c := candidates.NewIstanbulClient()
c := candidates.NewClient()
Expect(c.StopMining(context.Background())).Should(BeNil())
}
})
By("Verify number of validators", func() {
for _, v := range blockchain.Validators() {
client := v.NewIstanbulClient()
client := v.NewClient()
validators, err := client.GetValidators(context.Background(), nil)
Expect(err).Should(BeNil())
Expect(len(validators)).Should(BeNumerically("==", numberOfValidators))
@ -194,14 +194,14 @@ var _ = Describe("TFS-02: Dynamic validators addition/removal testing", func() {
stopCandidates := blockchain.Validators()[numberOfValidators-2:]
// stop validators [3,4]
for _, candidates := range stopCandidates {
c := candidates.NewIstanbulClient()
c := candidates.NewClient()
Expect(c.StopMining(context.Background())).Should(BeNil())
}
})
By("Verify number of validators", func() {
for _, v := range blockchain.Validators() {
client := v.NewIstanbulClient()
client := v.NewClient()
validators, err := client.GetValidators(context.Background(), nil)
Expect(err).Should(BeNil())
Expect(len(validators)).Should(BeNumerically("==", numberOfValidators))

View File

@ -87,7 +87,7 @@ var _ = Describe("TFS-01: General consensus", func() {
}
// 2. Check validator set
istClient := geth.NewIstanbulClient()
istClient := geth.NewClient()
vals, err := istClient.GetValidators(context.Background(), big.NewInt(0))
if err != nil {
errc <- err
@ -191,7 +191,7 @@ var _ = Describe("TFS-01: General consensus", func() {
for _, geth := range blockchain.Validators() {
go func(geth container.Ethereum) {
c := geth.NewClient()
istClient := geth.NewIstanbulClient()
istClient := geth.NewClient()
// get initial validator set
vals, err := istClient.GetValidators(context.Background(), big.NewInt(0))

View File

@ -48,7 +48,7 @@ var _ = Describe("TFS-07: Gossip Network", func() {
It("TFS-07-01: Gossip Network", func(done Done) {
By("Check peer count", func() {
for _, geth := range blockchain.Validators() {
c := geth.NewIstanbulClient()
c := geth.NewClient()
peers, e := c.AdminPeers(context.Background())
Expect(e).To(BeNil())
Ω(len(peers)).Should(BeNumerically("<=", 2))

View File

@ -113,7 +113,7 @@ var _ = Describe("Block synchronization testing", func() {
By("Stop consensus", func() {
for _, v := range blockchain.Validators() {
client := v.NewIstanbulClient()
client := v.NewClient()
Expect(client).NotTo(BeNil())
err := client.StopMining(context.Background())
Expect(err).To(BeNil())

View File

@ -57,7 +57,7 @@ var _ = Describe("QFS-02: Dynamic validators addition/removal testing", func() {
By("Ensure the number of validators is correct", func() {
for _, v := range blockchain.Validators() {
client := v.NewIstanbulClient()
client := v.NewClient()
validators, err := client.GetValidators(context.Background(), nil)
Expect(err).Should(BeNil())
Expect(len(validators)).Should(BeNumerically("==", numberOfValidators))
@ -78,7 +78,7 @@ var _ = Describe("QFS-02: Dynamic validators addition/removal testing", func() {
By("Ensure the number of validators is correct", func() {
for _, v := range blockchain.Validators() {
client := v.NewIstanbulClient()
client := v.NewClient()
validators, err := client.GetValidators(context.Background(), nil)
Expect(err).Should(BeNil())
Expect(len(validators)).Should(BeNumerically("==", numberOfValidators+testValidators))
@ -103,7 +103,7 @@ var _ = Describe("QFS-02: Dynamic validators addition/removal testing", func() {
By("Ensure that numbers of validator is equal to $numberOfValidators", func() {
for _, v := range blockchain.Validators() {
client := v.NewIstanbulClient()
client := v.NewClient()
validators, err := client.GetValidators(context.Background(), nil)
Expect(err).Should(BeNil())
Expect(len(validators)).Should(BeNumerically("==", numberOfValidators))
@ -121,7 +121,7 @@ var _ = Describe("QFS-02: Dynamic validators addition/removal testing", func() {
By("Check if the number of validators is correct", func() {
for _, v := range blockchain.Validators() {
client := v.NewIstanbulClient()
client := v.NewClient()
validators, err := client.GetValidators(context.Background(), nil)
Expect(err).Should(BeNil())
Expect(len(validators)).Should(BeNumerically("==", numberOfValidators+numOfCandidates))
@ -141,7 +141,7 @@ var _ = Describe("QFS-02: Dynamic validators addition/removal testing", func() {
By("Check if the number of validators is correct", func() {
for _, v := range blockchain.Validators() {
client := v.NewIstanbulClient()
client := v.NewClient()
validators, err := client.GetValidators(context.Background(), nil)
Expect(err).Should(BeNil())
Expect(len(validators)).Should(BeNumerically("==", numberOfValidators))
@ -165,14 +165,14 @@ var _ = Describe("QFS-02: Dynamic validators addition/removal testing", func() {
// stop validators [3]
stopCandidates := blockchain.Validators()[numberOfValidators-1:]
for _, candidates := range stopCandidates {
c := candidates.NewIstanbulClient()
c := candidates.NewClient()
Expect(c.StopMining(context.Background())).Should(BeNil())
}
})
By("Verify number of validators", func() {
for _, v := range blockchain.Validators() {
client := v.NewIstanbulClient()
client := v.NewClient()
validators, err := client.GetValidators(context.Background(), nil)
Expect(err).Should(BeNil())
Expect(len(validators)).Should(BeNumerically("==", numberOfValidators))
@ -199,14 +199,14 @@ var _ = Describe("QFS-02: Dynamic validators addition/removal testing", func() {
stopCandidates := blockchain.Validators()[numberOfValidators-2:]
// stop validators [3,4]
for _, candidates := range stopCandidates {
c := candidates.NewIstanbulClient()
c := candidates.NewClient()
Expect(c.StopMining(context.Background())).Should(BeNil())
}
})
By("Verify number of validators", func() {
for _, v := range blockchain.Validators() {
client := v.NewIstanbulClient()
client := v.NewClient()
validators, err := client.GetValidators(context.Background(), nil)
Expect(err).Should(BeNil())
Expect(len(validators)).Should(BeNumerically("==", numberOfValidators))

View File

@ -92,7 +92,7 @@ var _ = Describe("QFS-01: General consensus", func() {
}
// 2. Check validator set
istClient := geth.NewIstanbulClient()
istClient := geth.NewClient()
vals, err := istClient.GetValidators(context.Background(), big.NewInt(0))
if err != nil {
errc <- err
@ -195,7 +195,7 @@ var _ = Describe("QFS-01: General consensus", func() {
for _, geth := range blockchain.Validators() {
go func(geth container.Ethereum) {
c := geth.NewClient()
istClient := geth.NewIstanbulClient()
istClient := geth.NewClient()
// get initial validator set
vals, err := istClient.GetValidators(context.Background(), big.NewInt(0))

View File

@ -53,7 +53,7 @@ var _ = Describe("QFS-07: Gossip Network", func() {
It("QFS-07-01: Gossip Network", func(done Done) {
By("Check peer count", func() {
for _, geth := range blockchain.Validators() {
c := geth.NewIstanbulClient()
c := geth.NewClient()
peers, e := c.AdminPeers(context.Background())
Expect(e).To(BeNil())
Ω(len(peers)).Should(BeNumerically("<=", 2))