container: connect all validators
This commit is contained in:
parent
9c0fa56cfc
commit
28ac722bb2
|
@ -82,7 +82,7 @@ func (bc *blockchain) Start() error {
|
|||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
return bc.connectAll()
|
||||
}
|
||||
|
||||
func (bc *blockchain) Stop() error {
|
||||
|
@ -167,3 +167,19 @@ func (bc *blockchain) setupValidators(keys []*ecdsa.PrivateKey, options ...Optio
|
|||
bc.validators = append(bc.validators, geth)
|
||||
}
|
||||
}
|
||||
|
||||
func (bc *blockchain) connectAll() 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
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ func TestEthereumBlockchain(t *testing.T) {
|
|||
DataDir("/data"),
|
||||
WebSocket(),
|
||||
WebSocketAddress("0.0.0.0"),
|
||||
WebSocketAPI("eth,net,web3,personal"),
|
||||
WebSocketAPI("admin,eth,net,web3,personal"),
|
||||
WebSocketOrigin("*"),
|
||||
NoDiscover(),
|
||||
Logging(true),
|
||||
|
|
|
@ -40,6 +40,7 @@ import (
|
|||
"github.com/ethereum/go-ethereum/p2p/discover"
|
||||
|
||||
"github.com/getamis/istanbul-tools/genesis"
|
||||
"github.com/getamis/istanbul-tools/istclient"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -57,6 +58,7 @@ type Ethereum interface {
|
|||
ContainerID() string
|
||||
Host() string
|
||||
NewClient() *ethclient.Client
|
||||
NewIstanbulClient() *istclient.Client
|
||||
}
|
||||
|
||||
func NewEthereum(c *client.Client, options ...Option) *ethereum {
|
||||
|
@ -331,6 +333,24 @@ func (eth *ethereum) NewClient() *ethclient.Client {
|
|||
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)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
return client
|
||||
}
|
||||
|
||||
func (eth *ethereum) NodeAddress() string {
|
||||
if eth.node != nil {
|
||||
return eth.node.String()
|
||||
|
|
|
@ -37,7 +37,7 @@ func TestEthereumContainer(t *testing.T) {
|
|||
HostPort(freeport.GetPort()),
|
||||
WebSocket(),
|
||||
WebSocketAddress("0.0.0.0"),
|
||||
WebSocketAPI("eth,net,web3,personal"),
|
||||
WebSocketAPI("admin,eth,net,web3,personal"),
|
||||
HostWebSocketPort(freeport.GetPort()),
|
||||
WebSocketOrigin("*"),
|
||||
NoDiscover(),
|
||||
|
|
|
@ -43,7 +43,7 @@ var _ = Describe("4 validators Istanbul", func() {
|
|||
container.DataDir("/data"),
|
||||
container.WebSocket(),
|
||||
container.WebSocketAddress("0.0.0.0"),
|
||||
container.WebSocketAPI("eth,net,web3,personal,miner"),
|
||||
container.WebSocketAPI("admin,eth,net,web3,personal,miner"),
|
||||
container.WebSocketOrigin("*"),
|
||||
container.NAT("any"),
|
||||
container.NoDiscover(),
|
||||
|
|
Loading…
Reference in New Issue