aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorJimmy Hu <jimmy.hu@dexon.org>2018-12-08 16:33:42 +0800
committerGitHub <noreply@github.com>2018-12-08 16:33:42 +0800
commit7654e95f94f4902eb624bcdae1e6c8ebbf38e289 (patch)
tree5c50289fe6305507d71d72d96abbfe2d4b584d0a /core
parent1b352d9e52839c8b6c316c2601d08c91c995d8f0 (diff)
downloaddexon-consensus-7654e95f94f4902eb624bcdae1e6c8ebbf38e289.tar
dexon-consensus-7654e95f94f4902eb624bcdae1e6c8ebbf38e289.tar.gz
dexon-consensus-7654e95f94f4902eb624bcdae1e6c8ebbf38e289.tar.bz2
dexon-consensus-7654e95f94f4902eb624bcdae1e6c8ebbf38e289.tar.lz
dexon-consensus-7654e95f94f4902eb624bcdae1e6c8ebbf38e289.tar.xz
dexon-consensus-7654e95f94f4902eb624bcdae1e6c8ebbf38e289.tar.zst
dexon-consensus-7654e95f94f4902eb624bcdae1e6c8ebbf38e289.zip
ci: Add TravisCI setting. (#363)
* Update Gopkg.lock * Fix test * Add travisCI setting * Print log using fmt * Update GNUmakefile * Use single go rountine for consensus_test
Diffstat (limited to 'core')
-rw-r--r--core/configuration-chain_test.go96
-rw-r--r--core/consensus_test.go72
2 files changed, 122 insertions, 46 deletions
diff --git a/core/configuration-chain_test.go b/core/configuration-chain_test.go
index 3a7f729..2e75b7f 100644
--- a/core/configuration-chain_test.go
+++ b/core/configuration-chain_test.go
@@ -19,6 +19,7 @@ package core
import (
"encoding/json"
+ "errors"
"sync"
"testing"
"time"
@@ -61,16 +62,24 @@ func newTestCCReceiver(
func (r *testCCReceiver) ProposeDKGComplaint(complaint *typesDKG.Complaint) {
prvKey, exist := r.s.prvKeys[complaint.ProposerID]
- r.s.Require().True(exist)
+ if !exist {
+ panic(errors.New("should exist"))
+ }
var err error
complaint.Signature, err = prvKey.Sign(hashDKGComplaint(complaint))
- r.s.Require().NoError(err)
+ if err != nil {
+ panic(err)
+ }
for _, gov := range r.govs {
// Use Marshal/Unmarshal to do deep copy.
data, err := json.Marshal(complaint)
- r.s.Require().NoError(err)
+ if err != nil {
+ panic(err)
+ }
complaintCopy := &typesDKG.Complaint{}
- r.s.Require().NoError(json.Unmarshal(data, complaintCopy))
+ if err := json.Unmarshal(data, complaintCopy); err != nil {
+ panic(err)
+ }
gov.AddDKGComplaint(complaintCopy.Round, complaintCopy)
}
}
@@ -78,16 +87,24 @@ func (r *testCCReceiver) ProposeDKGComplaint(complaint *typesDKG.Complaint) {
func (r *testCCReceiver) ProposeDKGMasterPublicKey(
mpk *typesDKG.MasterPublicKey) {
prvKey, exist := r.s.prvKeys[mpk.ProposerID]
- r.s.Require().True(exist)
+ if !exist {
+ panic(errors.New("should exist"))
+ }
var err error
mpk.Signature, err = prvKey.Sign(hashDKGMasterPublicKey(mpk))
- r.s.Require().NoError(err)
+ if err != nil {
+ panic(err)
+ }
for _, gov := range r.govs {
// Use Marshal/Unmarshal to do deep copy.
data, err := json.Marshal(mpk)
- r.s.Require().NoError(err)
+ if err != nil {
+ panic(err)
+ }
mpkCopy := typesDKG.NewMasterPublicKey()
- r.s.Require().NoError(json.Unmarshal(data, mpkCopy))
+ if err := json.Unmarshal(data, mpkCopy); err != nil {
+ panic(err)
+ }
gov.AddDKGMasterPublicKey(mpkCopy.Round, mpkCopy)
}
}
@@ -96,14 +113,22 @@ func (r *testCCReceiver) ProposeDKGPrivateShare(
prv *typesDKG.PrivateShare) {
go func() {
prvKey, exist := r.s.prvKeys[prv.ProposerID]
- r.s.Require().True(exist)
+ if !exist {
+ panic(errors.New("should exist"))
+ }
var err error
prv.Signature, err = prvKey.Sign(hashDKGPrivateShare(prv))
- r.s.Require().NoError(err)
+ if err != nil {
+ panic(err)
+ }
receiver, exist := r.nodes[prv.ReceiverID]
- r.s.Require().True(exist)
+ if !exist {
+ panic(errors.New("should exist"))
+ }
err = receiver.processPrivateShare(prv)
- r.s.Require().NoError(err)
+ if err != nil {
+ panic(err)
+ }
}()
}
@@ -111,34 +136,52 @@ func (r *testCCReceiver) ProposeDKGAntiNackComplaint(
prv *typesDKG.PrivateShare) {
go func() {
prvKey, exist := r.s.prvKeys[prv.ProposerID]
- r.s.Require().True(exist)
+ if !exist {
+ panic(errors.New("should exist"))
+ }
var err error
prv.Signature, err = prvKey.Sign(hashDKGPrivateShare(prv))
- r.s.Require().NoError(err)
+ if err != nil {
+ panic(err)
+ }
for _, cc := range r.nodes {
// Use Marshal/Unmarshal to do deep copy.
data, err := json.Marshal(prv)
- r.s.Require().NoError(err)
+ if err != nil {
+ panic(err)
+ }
prvCopy := &typesDKG.PrivateShare{}
- r.s.Require().NoError(json.Unmarshal(data, prvCopy))
+ if err := json.Unmarshal(data, prvCopy); err != nil {
+ panic(err)
+ }
err = cc.processPrivateShare(prvCopy)
- r.s.Require().NoError(err)
+ if err != nil {
+ panic(err)
+ }
}
}()
}
func (r *testCCReceiver) ProposeDKGFinalize(final *typesDKG.Finalize) {
prvKey, exist := r.s.prvKeys[final.ProposerID]
- r.s.Require().True(exist)
+ if !exist {
+ panic(errors.New("should exist"))
+ }
var err error
final.Signature, err = prvKey.Sign(hashDKGFinalize(final))
- r.s.Require().NoError(err)
+ if err != nil {
+ panic(err)
+ }
for _, gov := range r.govs {
// Use Marshal/Unmarshal to do deep copy.
data, err := json.Marshal(final)
- r.s.Require().NoError(err)
+ if err != nil {
+ panic(err)
+ }
finalCopy := &typesDKG.Finalize{}
- r.s.Require().NoError(json.Unmarshal(data, finalCopy))
+ if err := json.Unmarshal(data, finalCopy); err != nil {
+ panic(err)
+ }
gov.AddDKGFinalize(finalCopy.Round, finalCopy)
}
}
@@ -174,7 +217,7 @@ func (s *ConfigurationChainTestSuite) runDKG(
for _, nID := range s.nIDs {
gov, err := test.NewGovernance(test.NewState(
- pks, 50*time.Millisecond, &common.NullLogger{}, true), ConfigRoundShift)
+ pks, 100*time.Millisecond, &common.NullLogger{}, true), ConfigRoundShift)
s.Require().NoError(err)
cache := utils.NewNodeSetCache(gov)
cfgChains[nID] = newConfigurationChain(
@@ -214,6 +257,9 @@ func (s *ConfigurationChainTestSuite) preparePartialSignature(
psigs []*typesDKG.PartialSignature) {
psigs = make([]*typesDKG.PartialSignature, 0, len(cfgChains))
for nID, cc := range cfgChains {
+ if _, exist := cc.gpk[round]; !exist {
+ continue
+ }
if _, exist := cc.gpk[round].qualifyNodeIDs[nID]; !exist {
continue
}
@@ -245,6 +291,9 @@ func (s *ConfigurationChainTestSuite) TestConfigurationChain() {
errs := make(chan error, n)
tsigChan := make(chan crypto.Signature, n)
for nID, cc := range cfgChains {
+ if _, exist := cc.gpk[round]; !exist {
+ continue
+ }
if _, exist := cc.gpk[round].qualifyNodeIDs[nID]; !exist {
continue
}
@@ -260,6 +309,9 @@ func (s *ConfigurationChainTestSuite) TestConfigurationChain() {
}
}
for nID, cc := range cfgChains {
+ if _, exist := cc.gpk[round]; !exist {
+ s.FailNow("Should be qualifyied")
+ }
if _, exist := cc.gpk[round].qualifyNodeIDs[nID]; !exist {
s.FailNow("Should be qualifyied")
}
diff --git a/core/consensus_test.go b/core/consensus_test.go
index 9234512..65f4e36 100644
--- a/core/consensus_test.go
+++ b/core/consensus_test.go
@@ -18,17 +18,19 @@
package core
import (
+ "encoding/json"
"sort"
"testing"
"time"
+ "github.com/stretchr/testify/suite"
+
"github.com/dexon-foundation/dexon-consensus/common"
"github.com/dexon-foundation/dexon-consensus/core/blockdb"
"github.com/dexon-foundation/dexon-consensus/core/crypto"
"github.com/dexon-foundation/dexon-consensus/core/test"
"github.com/dexon-foundation/dexon-consensus/core/types"
typesDKG "github.com/dexon-foundation/dexon-consensus/core/types/dkg"
- "github.com/stretchr/testify/suite"
)
// network implements core.Network.
@@ -101,37 +103,33 @@ func (nc *networkConnection) broadcast(from types.NodeID, msg interface{}) {
}
func (nc *networkConnection) send(to types.NodeID, msg interface{}) {
- con, exist := nc.cons[to]
+ ch, exist := nc.cons[to]
if !exist {
return
}
- go func() {
- var err error
- // Testify package does not support concurrent call.
- // Use panic() to detact error.
- switch val := msg.(type) {
- case *types.Block:
- err = con.preProcessBlock(val)
- case *types.Vote:
- err = con.ProcessVote(val)
- case *types.AgreementResult:
- err = con.ProcessAgreementResult(val)
- case *types.BlockRandomnessResult:
- err = con.ProcessBlockRandomnessResult(val)
- case *typesDKG.PrivateShare:
- err = con.cfgModule.processPrivateShare(val)
- case *typesDKG.PartialSignature:
- err = con.cfgModule.processPartialSignature(val)
- }
+ msgCopy := msg
+ // Clone msg if necessary.
+ switch val := msg.(type) {
+ case *types.Block:
+ msgCopy = val.Clone()
+ case *typesDKG.PrivateShare:
+ // Use Marshal/Unmarshal to do deep copy.
+ data, err := json.Marshal(val)
if err != nil {
panic(err)
}
- }()
+ valCopy := &typesDKG.PrivateShare{}
+ if err := json.Unmarshal(data, valCopy); err != nil {
+ panic(err)
+ }
+ msgCopy = valCopy
+ }
+ ch <- msgCopy
}
type networkConnection struct {
s *ConsensusTestSuite
- cons map[types.NodeID]*Consensus
+ cons map[types.NodeID]chan interface{}
}
func (nc *networkConnection) newNetwork(nID types.NodeID) *network {
@@ -142,7 +140,33 @@ func (nc *networkConnection) newNetwork(nID types.NodeID) *network {
}
func (nc *networkConnection) setCon(nID types.NodeID, con *Consensus) {
- nc.cons[nID] = con
+ ch := make(chan interface{}, 1000)
+ go func() {
+ for {
+ msg := <-ch
+ var err error
+ // Testify package does not support concurrent call.
+ // Use panic() to detact error.
+ switch val := msg.(type) {
+ case *types.Block:
+ err = con.preProcessBlock(val)
+ case *types.Vote:
+ err = con.ProcessVote(val)
+ case *types.AgreementResult:
+ err = con.ProcessAgreementResult(val)
+ case *types.BlockRandomnessResult:
+ err = con.ProcessBlockRandomnessResult(val)
+ case *typesDKG.PrivateShare:
+ err = con.cfgModule.processPrivateShare(val)
+ case *typesDKG.PartialSignature:
+ err = con.cfgModule.processPartialSignature(val)
+ }
+ if err != nil {
+ panic(err)
+ }
+ }
+ }()
+ nc.cons[nID] = ch
}
type ConsensusTestSuite struct {
@@ -153,7 +177,7 @@ type ConsensusTestSuite struct {
func (s *ConsensusTestSuite) newNetworkConnection() *networkConnection {
return &networkConnection{
s: s,
- cons: make(map[types.NodeID]*Consensus),
+ cons: make(map[types.NodeID]chan interface{}),
}
}