aboutsummaryrefslogtreecommitdiffstats
path: root/core/configuration-chain_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'core/configuration-chain_test.go')
-rw-r--r--core/configuration-chain_test.go35
1 files changed, 33 insertions, 2 deletions
diff --git a/core/configuration-chain_test.go b/core/configuration-chain_test.go
index 92b47c9..8214d6a 100644
--- a/core/configuration-chain_test.go
+++ b/core/configuration-chain_test.go
@@ -18,6 +18,7 @@
package core
import (
+ "bytes"
"encoding/json"
"errors"
"sync"
@@ -30,6 +31,7 @@ import (
"github.com/dexon-foundation/dexon-consensus/core/crypto"
"github.com/dexon-foundation/dexon-consensus/core/crypto/dkg"
"github.com/dexon-foundation/dexon-consensus/core/crypto/ecdsa"
+ "github.com/dexon-foundation/dexon-consensus/core/db"
"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"
@@ -220,8 +222,10 @@ func (s *ConfigurationChainTestSuite) runDKG(
pks, 100*time.Millisecond, &common.NullLogger{}, true), ConfigRoundShift)
s.Require().NoError(err)
cache := utils.NewNodeSetCache(gov)
+ dbInst, err := db.NewMemBackedDB()
+ s.Require().NoError(err)
cfgChains[nID] = newConfigurationChain(
- nID, recv, gov, cache, &common.NullLogger{})
+ nID, recv, gov, cache, dbInst, &common.NullLogger{})
recv.nodes[nID] = cfgChains[nID]
recv.govs[nID] = gov
}
@@ -346,8 +350,10 @@ func (s *ConfigurationChainTestSuite) TestDKGComplaintDelayAdd() {
s.Require().NoError(state.RequestChange(
test.StateChangeLambdaDKG, lambdaDKG))
cache := utils.NewNodeSetCache(gov)
+ dbInst, err := db.NewMemBackedDB()
+ s.Require().NoError(err)
cfgChains[nID] = newConfigurationChain(
- nID, recv, gov, cache, &common.NullLogger{})
+ nID, recv, gov, cache, dbInst, &common.NullLogger{})
recv.nodes[nID] = cfgChains[nID]
recv.govs[nID] = gov
}
@@ -499,6 +505,31 @@ func (s *ConfigurationChainTestSuite) TestTSigTimeout() {
}
}
+func (s *ConfigurationChainTestSuite) TestDKGSignerRecoverFromDB() {
+ k := 2
+ n := 7
+ round := uint64(0)
+ cfgChains := s.runDKG(k, n, round)
+ hash := crypto.Keccak256Hash([]byte("Hash1"))
+ // Make sure we have more than one configurationChain instance.
+ s.Require().True(len(cfgChains) > 0)
+ for _, cc := range cfgChains {
+ psig1, err := cc.preparePartialSignature(round, hash)
+ s.Require().NoError(err)
+ // Create a cloned configurationChain, we should be able to recover
+ // the DKG signer.
+ clonedCC := newConfigurationChain(
+ cc.ID, cc.recv, cc.gov, cc.cache, cc.db, cc.logger,
+ )
+ psig2, err := clonedCC.preparePartialSignature(round, hash)
+ s.Require().NoError(err)
+ // Make sure the signed signature are equal.
+ s.Require().Equal(bytes.Compare(
+ psig1.PartialSignature.Signature,
+ psig2.PartialSignature.Signature), 0)
+ }
+}
+
func TestConfigurationChain(t *testing.T) {
suite.Run(t, new(ConfigurationChainTestSuite))
}