-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
95.7% test coverage for
internal/trie/node
- Loading branch information
Showing
12 changed files
with
980 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
// Copyright 2021 ChainSafe Systems (ON) | ||
// SPDX-License-Identifier: LGPL-3.0-only | ||
|
||
package node | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func Test_NewBranch(t *testing.T) { | ||
t.Parallel() | ||
|
||
key := []byte{1, 2} | ||
value := []byte{3, 4} | ||
const dirty = true | ||
const generation = 9 | ||
|
||
branch := NewBranch(key, value, dirty, generation) | ||
|
||
expectedBranch := &Branch{ | ||
Key: key, | ||
Value: value, | ||
dirty: dirty, | ||
generation: generation, | ||
} | ||
assert.Equal(t, expectedBranch, branch) | ||
|
||
// Check modifying passed slice modifies branch slices | ||
key[0] = 11 | ||
value[0] = 13 | ||
assert.Equal(t, expectedBranch, branch) | ||
} | ||
|
||
func Test_Branch_String(t *testing.T) { | ||
t.Parallel() | ||
|
||
testCases := map[string]struct { | ||
branch *Branch | ||
s string | ||
}{ | ||
"empty branch": { | ||
branch: &Branch{}, | ||
s: "branch key=0x childrenBitmap=0 value=0x dirty=false", | ||
}, | ||
"branch with value smaller than 1024": { | ||
branch: &Branch{ | ||
Key: []byte{1, 2}, | ||
Value: []byte{3, 4}, | ||
dirty: true, | ||
Children: [16]Node{ | ||
nil, nil, nil, | ||
&Leaf{}, | ||
nil, nil, nil, | ||
&Branch{}, | ||
nil, nil, nil, | ||
&Leaf{}, | ||
nil, nil, nil, nil, | ||
}, | ||
}, | ||
s: "branch key=0x0102 childrenBitmap=100010001000 value=0x0304 dirty=true", | ||
}, | ||
"branch with value higher than 1024": { | ||
branch: &Branch{ | ||
Key: []byte{1, 2}, | ||
Value: make([]byte, 1025), | ||
dirty: true, | ||
Children: [16]Node{ | ||
nil, nil, nil, | ||
&Leaf{}, | ||
nil, nil, nil, | ||
&Branch{}, | ||
nil, nil, nil, | ||
&Leaf{}, | ||
nil, nil, nil, nil, | ||
}, | ||
}, | ||
s: "branch key=0x0102 childrenBitmap=100010001000 " + | ||
"value (hashed)=0x307861663233363133353361303538646238383034626337353735323831663131663735313265326331346336373032393864306232336630396538386266333066 " + //nolint:lll | ||
"dirty=true", | ||
}, | ||
} | ||
|
||
for name, testCase := range testCases { | ||
testCase := testCase | ||
t.Run(name, func(t *testing.T) { | ||
t.Parallel() | ||
|
||
s := testCase.branch.String() | ||
|
||
assert.Equal(t, testCase.s, s) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
// Copyright 2021 ChainSafe Systems (ON) | ||
// SPDX-License-Identifier: LGPL-3.0-only | ||
|
||
package node | ||
|
||
import ( | ||
|
Oops, something went wrong.