aboutsummaryrefslogtreecommitdiffstats
path: root/core/db/memory_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/db/memory_test.go
parent5f32dc8d27564e1f3a105fd1dacf02130b08621a (diff)
downloadtangerine-consensus-99d72382687196fb15ea6ab0fcf297b9ab10ac46.tar.gz
tangerine-consensus-99d72382687196fb15ea6ab0fcf297b9ab10ac46.tar.zst
tangerine-consensus-99d72382687196fb15ea6ab0fcf297b9ab10ac46.zip
core: cache dkg's private key in db (#371)
Diffstat (limited to 'core/db/memory_test.go')
-rw-r--r--core/db/memory_test.go25
1 files changed, 25 insertions, 0 deletions
diff --git a/core/db/memory_test.go b/core/db/memory_test.go
index 7d18c3a..09f74bb 100644
--- a/core/db/memory_test.go
+++ b/core/db/memory_test.go
@@ -18,10 +18,12 @@
package db
import (
+ "bytes"
"os"
"testing"
"github.com/dexon-foundation/dexon-consensus/common"
+ "github.com/dexon-foundation/dexon-consensus/core/crypto/dkg"
"github.com/dexon-foundation/dexon-consensus/core/types"
"github.com/stretchr/testify/suite"
)
@@ -145,6 +147,29 @@ func (s *MemBackedDBTestSuite) TestCompactionChainTipInfo() {
s.Require().IsType(err, ErrInvalidCompactionChainTipHeight)
}
+func (s *MemBackedDBTestSuite) TestDKGPrivateKey() {
+ dbInst, err := NewMemBackedDB()
+ s.Require().NoError(err)
+ s.Require().NotNil(dbInst)
+ p := dkg.NewPrivateKey()
+ // Check existence.
+ exists, err := dbInst.HasDKGPrivateKey(1)
+ s.Require().NoError(err)
+ s.Require().False(exists)
+ // We should be unable to get it, too.
+ _, err = dbInst.GetDKGPrivateKey(1)
+ s.Require().IsType(err, ErrDKGPrivateKeyDoesNotExist)
+ // Put it.
+ s.Require().NoError(dbInst.PutDKGPrivateKey(1, *p))
+ // Put it again, should not success.
+ err = dbInst.PutDKGPrivateKey(1, *p)
+ s.Require().IsType(err, ErrDKGPrivateKeyExists)
+ // Get it back.
+ tmpPrv, err := dbInst.GetDKGPrivateKey(1)
+ s.Require().NoError(err)
+ s.Require().Equal(bytes.Compare(p.Bytes(), tmpPrv.Bytes()), 0)
+}
+
func TestMemBackedDB(t *testing.T) {
suite.Run(t, new(MemBackedDBTestSuite))
}