2020-10-21 19:54:40 +00:00
|
|
|
package node
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
2020-10-21 22:05:12 +00:00
|
|
|
"time"
|
2020-10-21 19:54:40 +00:00
|
|
|
|
|
|
|
"github.com/Secured-Finance/dione/config"
|
2020-10-21 20:36:05 +00:00
|
|
|
"github.com/sirupsen/logrus"
|
2020-10-21 19:54:40 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestConsensus(t *testing.T) {
|
2020-10-21 20:36:05 +00:00
|
|
|
logrus.SetLevel(logrus.DebugLevel)
|
2020-10-21 22:05:12 +00:00
|
|
|
//log.SetAllLoggers(log.LevelDebug)
|
2020-10-21 19:54:40 +00:00
|
|
|
|
|
|
|
cfg := &config.Config{
|
|
|
|
ListenPort: "1234",
|
2020-10-21 22:05:12 +00:00
|
|
|
ListenAddr: "0.0.0.0",
|
2020-10-21 19:54:40 +00:00
|
|
|
Bootstrap: true,
|
|
|
|
Rendezvous: "dione",
|
|
|
|
PubSub: config.PubSubConfig{
|
|
|
|
ProtocolID: "/test/1.0",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2020-10-21 22:05:12 +00:00
|
|
|
//cfg.BootstrapNodeMultiaddr = "/dnsaddr/bootstrap.libp2p.io/p2p/QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN"
|
|
|
|
|
2020-10-21 19:54:40 +00:00
|
|
|
// setup first node
|
|
|
|
privKey, err := generatePrivateKey()
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
ctx, ctxCancel := context.WithCancel(context.Background())
|
|
|
|
node1 := &Node{
|
|
|
|
OracleTopic: "dione",
|
|
|
|
Config: cfg,
|
|
|
|
GlobalCtx: ctx,
|
|
|
|
GlobalCtxCancel: ctxCancel,
|
|
|
|
}
|
|
|
|
node1.setupNode(ctx, privKey)
|
|
|
|
|
|
|
|
// setup second node
|
|
|
|
privKey, err = generatePrivateKey()
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
ctx, ctxCancel = context.WithCancel(context.Background())
|
|
|
|
cfg.ListenPort = "1235"
|
|
|
|
cfg.Bootstrap = false
|
2020-10-21 22:05:12 +00:00
|
|
|
cfg.BootstrapNodeMultiaddr = node1.Host.Addrs()[0].String() + fmt.Sprintf("/p2p/%s", node1.Host.ID().String())
|
|
|
|
|
2020-10-21 19:54:40 +00:00
|
|
|
node2 := &Node{
|
|
|
|
OracleTopic: "dione",
|
|
|
|
Config: cfg,
|
|
|
|
GlobalCtx: ctx,
|
|
|
|
GlobalCtxCancel: ctxCancel,
|
|
|
|
}
|
|
|
|
node2.setupNode(ctx, privKey)
|
|
|
|
|
|
|
|
// setup third node
|
|
|
|
privKey, err = generatePrivateKey()
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
ctx, ctxCancel = context.WithCancel(context.Background())
|
|
|
|
cfg.ListenPort = "1236"
|
|
|
|
node3 := &Node{
|
|
|
|
OracleTopic: "dione",
|
|
|
|
Config: cfg,
|
|
|
|
GlobalCtx: ctx,
|
|
|
|
GlobalCtxCancel: ctxCancel,
|
|
|
|
}
|
|
|
|
node3.setupNode(ctx, privKey)
|
|
|
|
|
2020-10-21 22:05:12 +00:00
|
|
|
|
|
|
|
time.Sleep(10 * time.Second)
|
|
|
|
go node2.ConsensusManager.NewTestConsensus("test", "123")
|
|
|
|
go node1.ConsensusManager.NewTestConsensus("test1", "123")
|
|
|
|
go node3.ConsensusManager.NewTestConsensus("test", "123")
|
|
|
|
select{}
|
|
|
|
}
|