Skip to content

Commit

Permalink
Generate takes []byte instead of common.Hash to match Verify sign…
Browse files Browse the repository at this point in the history
…ature
  • Loading branch information
qdm12 committed Jun 15, 2022
1 parent 8d58fdf commit 08dcfb3
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions internal/trie/proof/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ type Database interface {
// corresponding to the root hash given, and for the (Little Endian)
// full key given. The database given is used to load the trie
// using the root hash given.
func Generate(rootHash common.Hash, fullKey []byte, database Database) (
func Generate(rootHash []byte, fullKey []byte, database Database) (
encodedProofNodes [][]byte, err error) {
trie := trie.NewEmptyTrie()
if err := trie.Load(database, rootHash); err != nil {
if err := trie.Load(database, common.BytesToHash(rootHash)); err != nil {
return nil, fmt.Errorf("cannot load trie: %w", err)
}

Expand Down
10 changes: 5 additions & 5 deletions internal/trie/proof/generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ func Test_Generate(t *testing.T) {
errTest := errors.New("test error")

testCases := map[string]struct {
rootHash common.Hash
rootHash []byte
fullKey []byte // nibbles
databaseBuilder func(ctrl *gomock.Controller) Database
encodedProofNodes [][]byte
errWrapped error
errMessage string
}{
"failed loading trie": {
rootHash: common.Hash{1},
rootHash: []byte{1},
databaseBuilder: func(ctrl *gomock.Controller) Database {
mockDatabase := NewMockDatabase(ctrl)
mockDatabase.EXPECT().Get(common.Hash{1}.ToBytes()).
Expand All @@ -41,7 +41,7 @@ func Test_Generate(t *testing.T) {
"test error",
},
"walk error": {
rootHash: common.Hash{1},
rootHash: []byte{1},
databaseBuilder: func(ctrl *gomock.Controller) Database {
mockDatabase := NewMockDatabase(ctrl)
encodedRoot := encodeNode(t, node.Node{
Expand All @@ -57,7 +57,7 @@ func Test_Generate(t *testing.T) {
errMessage: "cannot find node at key 0x01 in trie: key not found",
},
"leaf root": {
rootHash: common.Hash{1},
rootHash: []byte{1},
databaseBuilder: func(ctrl *gomock.Controller) Database {
mockDatabase := NewMockDatabase(ctrl)
encodedRoot := encodeNode(t, node.Node{
Expand All @@ -76,7 +76,7 @@ func Test_Generate(t *testing.T) {
},
},
"branch root": {
rootHash: common.Hash{1},
rootHash: []byte{1},
databaseBuilder: func(ctrl *gomock.Controller) Database {
mockDatabase := NewMockDatabase(ctrl)
encodedRoot := encodeNode(t, node.Node{
Expand Down
2 changes: 1 addition & 1 deletion internal/trie/proof/proof_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func Test_Generate_Verify(t *testing.T) {
require.NoError(t, err)

for i, key := range keys {
proof, err := Generate(rootHash, []byte(key), database)
proof, err := Generate(rootHash.ToBytes(), []byte(key), database)
require.NoError(t, err)

expectedValue := fmt.Sprintf("%x-%d", key, i)
Expand Down
2 changes: 1 addition & 1 deletion lib/runtime/wasmer/imports_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1794,7 +1794,7 @@ func Test_ext_trie_blake2_256_verify_proof_version_1(t *testing.T) {

var allProofs [][]byte
for _, key := range keys {
singleProof, err := proof.Generate(hash, key, memdb)
singleProof, err := proof.Generate(root, key, memdb)
require.NoError(t, err)
allProofs = append(allProofs, singleProof...)
}
Expand Down
2 changes: 1 addition & 1 deletion lib/trie/database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func Test_Trie_WriteDirty_Delete(t *testing.T) {
func Test_Trie_WriteDirty_ClearPrefix(t *testing.T) {
t.Parallel()

const size = 2000
const size = 15000
trie, keyValues := makeSeededTrie(t, size)

generator := newGenerator()
Expand Down

0 comments on commit 08dcfb3

Please sign in to comment.