mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-22 20:56:42 +00:00
fix some of the failing tests
This commit is contained in:
parent
e94d14cfe5
commit
8704f12349
4 changed files with 77 additions and 5 deletions
|
|
@ -147,7 +147,6 @@ var (
|
|||
t8ntool.OutputBasedir,
|
||||
t8ntool.OutputAllocFlag,
|
||||
t8ntool.OutputBTFlag,
|
||||
t8ntool.OutputWitnessFlag,
|
||||
t8ntool.OutputResultFlag,
|
||||
t8ntool.OutputBodyFlag,
|
||||
t8ntool.InputAllocFlag,
|
||||
|
|
|
|||
|
|
@ -308,7 +308,7 @@ func TestVerkleGenesisCommit(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
expected := common.FromHex("018d20eebb130b5e2b796465fe36aafab650650729a92435aec071bf2386f080")
|
||||
expected := common.FromHex("19056b480530799a4fdaa9fd9407043b965a3a5c37b4d2a1a9a4f3395a327561")
|
||||
got := genesis.ToBlock().Root().Bytes()
|
||||
if !bytes.Equal(got, expected) {
|
||||
t.Fatalf("invalid genesis state root, expected %x, got %x", expected, got)
|
||||
|
|
|
|||
|
|
@ -53,6 +53,10 @@ func (h HashedNode) InsertValuesAtStem(stem []byte, values [][]byte, resolver No
|
|||
return nil, fmt.Errorf("InsertValuesAtStem path generation error: %w", err)
|
||||
}
|
||||
|
||||
if resolver == nil {
|
||||
return nil, errors.New("InsertValuesAtStem resolve error: resolver is nil")
|
||||
}
|
||||
|
||||
// Step 2: Resolve the hashed node to get the actual node data
|
||||
data, err := resolver(path, common.Hash(h))
|
||||
if err != nil {
|
||||
|
|
@ -77,7 +81,7 @@ func (h HashedNode) toDot(parent string, path string) string {
|
|||
}
|
||||
|
||||
func (h HashedNode) CollectNodes([]byte, NodeFlushFn) error {
|
||||
return errors.New("collectNodes not implemented for hashed node")
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h HashedNode) GetHeight() int {
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@
|
|||
package bintrie
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"testing"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
|
|
@ -94,14 +95,82 @@ func TestHashedNodeInsertValuesAtStem(t *testing.T) {
|
|||
stem := make([]byte, StemSize)
|
||||
values := make([][]byte, StemNodeWidth)
|
||||
|
||||
// Test 1: nil resolver should return an error
|
||||
_, err := node.InsertValuesAtStem(stem, values, nil, 0)
|
||||
if err == nil {
|
||||
t.Fatal("Expected error for InsertValuesAtStem on HashedNode")
|
||||
t.Fatal("Expected error for InsertValuesAtStem on HashedNode with nil resolver")
|
||||
}
|
||||
|
||||
if err.Error() != "insertValuesAtStem not implemented for hashed node" {
|
||||
if err.Error() != "InsertValuesAtStem resolve error: resolver is nil" {
|
||||
t.Errorf("Unexpected error message: %v", err)
|
||||
}
|
||||
|
||||
// Test 2: mock resolver returning invalid data should return deserialization error
|
||||
mockResolver := func(path []byte, hash common.Hash) ([]byte, error) {
|
||||
// Return invalid/nonsense data that cannot be deserialized
|
||||
return []byte{0xff, 0xff, 0xff}, nil
|
||||
}
|
||||
|
||||
_, err = node.InsertValuesAtStem(stem, values, mockResolver, 0)
|
||||
if err == nil {
|
||||
t.Fatal("Expected error for InsertValuesAtStem on HashedNode with invalid resolver data")
|
||||
}
|
||||
|
||||
expectedPrefix := "InsertValuesAtStem node deserialization error:"
|
||||
if len(err.Error()) < len(expectedPrefix) || err.Error()[:len(expectedPrefix)] != expectedPrefix {
|
||||
t.Errorf("Expected deserialization error, got: %v", err)
|
||||
}
|
||||
|
||||
// Test 3: mock resolver returning valid serialized node should succeed
|
||||
stem = make([]byte, StemSize)
|
||||
stem[0] = 0xaa
|
||||
var originalValues [StemNodeWidth][]byte
|
||||
originalValues[0] = common.HexToHash("0x1111111111111111111111111111111111111111111111111111111111111111").Bytes()
|
||||
originalValues[1] = common.HexToHash("0x2222222222222222222222222222222222222222222222222222222222222222").Bytes()
|
||||
|
||||
originalNode := &StemNode{
|
||||
Stem: stem,
|
||||
Values: originalValues[:],
|
||||
depth: 0,
|
||||
}
|
||||
|
||||
// Serialize the node
|
||||
serialized := SerializeNode(originalNode)
|
||||
|
||||
// Create a mock resolver that returns the serialized node
|
||||
validResolver := func(path []byte, hash common.Hash) ([]byte, error) {
|
||||
return serialized, nil
|
||||
}
|
||||
|
||||
var newValues [StemNodeWidth][]byte
|
||||
newValues[2] = common.HexToHash("0x3333333333333333333333333333333333333333333333333333333333333333").Bytes()
|
||||
|
||||
resolvedNode, err := node.InsertValuesAtStem(stem, newValues[:], validResolver, 0)
|
||||
if err != nil {
|
||||
t.Fatalf("Expected successful resolution and insertion, got error: %v", err)
|
||||
}
|
||||
|
||||
resultStem, ok := resolvedNode.(*StemNode)
|
||||
if !ok {
|
||||
t.Fatalf("Expected resolved node to be *StemNode, got %T", resolvedNode)
|
||||
}
|
||||
|
||||
if !bytes.Equal(resultStem.Stem, stem) {
|
||||
t.Errorf("Stem mismatch: expected %x, got %x", stem, resultStem.Stem)
|
||||
}
|
||||
|
||||
// Verify the original values are preserved
|
||||
if !bytes.Equal(resultStem.Values[0], originalValues[0]) {
|
||||
t.Errorf("Original value at index 0 not preserved: expected %x, got %x", originalValues[0], resultStem.Values[0])
|
||||
}
|
||||
if !bytes.Equal(resultStem.Values[1], originalValues[1]) {
|
||||
t.Errorf("Original value at index 1 not preserved: expected %x, got %x", originalValues[1], resultStem.Values[1])
|
||||
}
|
||||
|
||||
// Verify the new value was inserted
|
||||
if !bytes.Equal(resultStem.Values[2], newValues[2]) {
|
||||
t.Errorf("New value at index 2 not inserted correctly: expected %x, got %x", newValues[2], resultStem.Values[2])
|
||||
}
|
||||
}
|
||||
|
||||
// TestHashedNodeToDot tests the toDot method for visualization
|
||||
|
|
|
|||
Loading…
Reference in a new issue