Skip to content

Commit

Permalink
Test coverage
Browse files Browse the repository at this point in the history
Signed-off-by: Jim Zhang <[email protected]>
  • Loading branch information
jimthematrix committed Sep 17, 2024
1 parent 8c35ca2 commit 690278b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
8 changes: 0 additions & 8 deletions go-sdk/internal/log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,6 @@ func InitConfig() {
logrus.SetFormatter(formatter)
}

func IsDebugEnabled() bool {
return logrus.IsLevelEnabled(logrus.DebugLevel)
}

func IsTraceEnabled() bool {
return logrus.IsLevelEnabled(logrus.TraceLevel)
}

func ensureInit() {
// Called at a couple of strategic points to check we get log initialize in things like unit tests
// However NOT guaranteed to be called because we can't afford to do atomic load on every log line
Expand Down
26 changes: 26 additions & 0 deletions go-sdk/internal/sparse-merkle-tree/smt/smt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,32 @@ func (s *MerkleTreeTestSuite) TestAddNode() {
assert.Equal(s.T(), "abacf46f5217552ee28fe50b8fd7ca6aa46daeb9acf9f60928654c3b1a472f23", mt2.Root().Hex())
}

func (s *MerkleTreeTestSuite) TestAddNodeFailExistingKey() {
mt, err := NewMerkleTree(s.db, 10)
assert.NoError(s.T(), err)

x, _ := new(big.Int).SetString("9198063289874244593808956064764348354864043212453245695133881114917754098693", 10)
y, _ := new(big.Int).SetString("3600411115173311692823743444460566395943576560299970643507632418781961416843", 10)
alice := &babyjub.PublicKey{
X: x,
Y: y,
}
salt1, _ := new(big.Int).SetString("43c49e8ba68a9b8a6bb5c230a734d8271a83d2f63722e7651272ebeef5446e", 16)
utxo1 := node.NewFungible(big.NewInt(10), alice, salt1)
idx1, err := utxo1.CalculateIndex()
assert.NoError(s.T(), err)
assert.Equal(s.T(), "11a22e32f5010d3658d1da9c93f26b77afe7a84346f49eae3d1d4fc6cd0a36fd", idx1.BigInt().Text(16))

n1, err := node.NewLeafNode(utxo1)
assert.NoError(s.T(), err)
err = mt.AddLeaf(n1)
assert.NoError(s.T(), err)
assert.Equal(s.T(), "525b60b382630ee7825bea84fb8808c13ede1fb827fe683cd5b14d76f6ac6d0b", mt.Root().Hex())

err = mt.AddLeaf(n1)
assert.EqualError(s.T(), err, "key already exists")
}

func (s *MerkleTreeTestSuite) TestGenerateProof() {
const levels = 10
mt, _ := NewMerkleTree(s.db, levels)
Expand Down

0 comments on commit 690278b

Please sign in to comment.