aboutsummaryrefslogtreecommitdiffstats
path: root/core/configuration-chain_test.go
diff options
context:
space:
mode:
authorMission Liao <mission.liao@dexon.org>2018-12-16 14:44:15 +0800
committerGitHub <noreply@github.com>2018-12-16 14:44:15 +0800
commit99d72382687196fb15ea6ab0fcf297b9ab10ac46 (patch)
tree2fc321a32c9cb1d72933dbbdb0c259d6ae4f6aa3 /core/configuration-chain_test.go
parent5f32dc8d27564e1f3a105fd1dacf02130b08621a (diff)
downloaddexon-consensus-99d72382687196fb15ea6ab0fcf297b9ab10ac46.tar
dexon-consensus-99d72382687196fb15ea6ab0fcf297b9ab10ac46.tar.gz
dexon-consensus-99d72382687196fb15ea6ab0fcf297b9ab10ac46.tar.bz2
dexon-consensus-99d72382687196fb15ea6ab0fcf297b9ab10ac46.tar.lz
dexon-consensus-99d72382687196fb15ea6ab0fcf297b9ab10ac46.tar.xz
dexon-consensus-99d72382687196fb15ea6ab0fcf297b9ab10ac46.tar.zst
dexon-consensus-99d72382687196fb15ea6ab0fcf297b9ab10ac46.zip
core: cache dkg's private key in db (#371)
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))
}