diff options
Diffstat (limited to 'core/db/memory_test.go')
-rw-r--r-- | core/db/memory_test.go | 25 |
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)) } |