-
Notifications
You must be signed in to change notification settings - Fork 21.5k
add node.go unit test file node_test.go #20028
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| package trie | ||
|
|
||
| import ( | ||
| "bytes" | ||
| "testing" | ||
|
|
||
| "github.com/ethereum/go-ethereum/rlp" | ||
| ) | ||
|
|
||
| func newFullNode(v []byte) []interface{} { | ||
|
||
| fullNodeData := []interface{}{} | ||
| for i := 0; i < 16; i++ { | ||
| k := bytes.Repeat([]byte{byte(i + 1)}, 32) | ||
| fullNodeData = append(fullNodeData, k) | ||
| } | ||
| fullNodeData = append(fullNodeData, []byte("value1")) | ||
| return fullNodeData | ||
| } | ||
|
|
||
| func TestDecodeNestedNode(t *testing.T) { | ||
| fullNodeData := newFullNode([]byte("fullnode")) | ||
|
|
||
| data := [][]byte{} | ||
| for i := 0; i < 16; i++ { | ||
| data = append(data, nil) | ||
| } | ||
| data = append(data, []byte("subnode")) | ||
| fullNodeData[15] = data | ||
|
|
||
| buf := bytes.NewBuffer([]byte{}) | ||
| rlp.Encode(buf, fullNodeData) | ||
|
|
||
| if _, err := decodeNode([]byte("testdecode"), buf.Bytes()); err != nil { | ||
| t.Fatalf("decode nested full node err: %v", err) | ||
| } | ||
| } | ||
|
|
||
| func TestDecodeFullNodeWrongSizeChild(t *testing.T) { | ||
| fullNodeData := newFullNode([]byte("wrongsizechild")) | ||
| fullNodeData[0] = []byte("00") | ||
| buf := bytes.NewBuffer([]byte{}) | ||
| rlp.Encode(buf, fullNodeData) | ||
|
|
||
| _, err := decodeNode([]byte("testdecode"), buf.Bytes()) | ||
| if _, ok := err.(*decodeError); !ok { | ||
| t.Fatalf("decodeNode returned wrong err: %v", err) | ||
| } | ||
| } | ||
|
|
||
| func TestDecodeFullNodeWrongNestedFullNode(t *testing.T) { | ||
| fullNodeData := newFullNode([]byte("fullnode")) | ||
|
|
||
| data := [][]byte{} | ||
| for i := 0; i < 16; i++ { | ||
| data = append(data, []byte("123456")) | ||
| } | ||
| data = append(data, []byte("subnode")) | ||
| fullNodeData[15] = data | ||
|
|
||
| buf := bytes.NewBuffer([]byte{}) | ||
| rlp.Encode(buf, fullNodeData) | ||
|
|
||
| _, err := decodeNode([]byte("testdecode"), buf.Bytes()) | ||
| if _, ok := err.(*decodeError); !ok { | ||
| t.Fatalf("decodeNode returned wrong err: %v", err) | ||
| } | ||
| } | ||
|
|
||
| func TestDecodeNode(t *testing.T) { | ||
| fullNodeData := newFullNode([]byte("decodefullnode")) | ||
| buf := bytes.NewBuffer([]byte{}) | ||
| rlp.Encode(buf, fullNodeData) | ||
|
|
||
| _, err := decodeNode([]byte("testdecode"), buf.Bytes()) | ||
| if err != nil { | ||
| t.Fatalf("decode full node err: %v", err) | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -546,16 +546,3 @@ func updateString(trie *Trie, k, v string) { | |
| func deleteString(trie *Trie, k string) { | ||
| trie.Delete([]byte(k)) | ||
| } | ||
|
|
||
| func TestDecodeNode(t *testing.T) { | ||
| t.Parallel() | ||
| var ( | ||
| hash = make([]byte, 20) | ||
| elems = make([]byte, 20) | ||
| ) | ||
| for i := 0; i < 5000000; i++ { | ||
| rand.Read(hash) | ||
| rand.Read(elems) | ||
| decodeNode(hash, elems) | ||
| } | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why delete this one?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this test seems useless, and it tests nothing, so i decide to delete it. already rollback. |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+license
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done