Skip to content

Commit

Permalink
Adds test for DeriveRoot function in trie (#691)
Browse files Browse the repository at this point in the history
* Adds test for DeriveRoot function in trie

* Fix linter error
  • Loading branch information
ahasikos authored Apr 22, 2024
1 parent 88c7c86 commit bbec4a2
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions trie/derive_root_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package trie

import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/vechain/thor/v2/thor"
)

type MockDerivableList struct {
Elements [][]byte
}

func (m *MockDerivableList) Len() int {
return len(m.Elements)
}

func (m *MockDerivableList) GetRlp(i int) []byte {
if i >= len(m.Elements) {
return nil
}
return m.Elements[i]
}

func TestDeriveRoot(t *testing.T) {
mockList := &MockDerivableList{
Elements: [][]byte{
{1, 2, 3, 4},
{1, 2, 3, 4, 5, 6},
},
}

root := DeriveRoot(mockList)

assert.Equal(t, "0x154227caf1172839284ce29cd6eaaee115af0993d5a5a4a08d9bb19ed18edae7", root.String())
assert.NotEqual(t, thor.Bytes32{}, root, "The root hash should not be empty")
}

0 comments on commit bbec4a2

Please sign in to comment.