Concurrent statediff iteration #12
@ -566,7 +566,9 @@ func TestBuilderOnMainnetBlocks(t *testing.T) {
|
||||
},
|
||||
StorageDiff: emptyStorage,
|
||||
},
|
||||
{ // this is the new account created due to the coinbase mining a block, it's creation shouldn't affect 0x 0e 05 07
|
||||
{
|
||||
// this is the new account created due to the coinbase mining a block, its
|
||||
// creation shouldn't affect 0x 0e 05 07
|
||||
Removed: false,
|
||||
AccountWrapper: sdtypes.AccountWrapper{
|
||||
Account: block3CoinbaseAccount,
|
||||
|
@ -3,12 +3,14 @@ package test_helpers
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"math/big"
|
||||
"sort"
|
||||
"testing"
|
||||
|
||||
statediff "github.com/cerc-io/plugeth-statediff"
|
||||
"github.com/cerc-io/plugeth-statediff/adapt"
|
||||
sdtypes "github.com/cerc-io/plugeth-statediff/types"
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/core/state"
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
@ -23,6 +25,14 @@ type TestCase struct {
|
||||
|
||||
type CheckedRoots map[*types.Block][]byte
|
||||
|
||||
// Recapitulates the statediff object, but indexes nodes by CID
|
||||
type normalizedStateDiff struct {
|
||||
BlockNumber *big.Int
|
||||
BlockHash common.Hash
|
||||
Nodes map[string]sdtypes.StateLeafNode
|
||||
IPLDs map[string]sdtypes.IPLD
|
||||
}
|
||||
|
||||
func RunBuilderTests(
|
||||
t *testing.T,
|
||||
sdb state.Database,
|
||||
@ -39,10 +49,10 @@ func RunBuilderTests(
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
normalize(test.Expected)
|
||||
normalize(&diff)
|
||||
require.Equal(t, *test.Expected, diff)
|
||||
require.Equal(t,
|
||||
normalize(test.Expected),
|
||||
normalize(&diff),
|
||||
)
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -56,17 +66,13 @@ func (roots CheckedRoots) Check(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// Sorts contained state nodes, storage nodes, and IPLDs
|
||||
func normalize(diff *sdtypes.StateObject) {
|
||||
sort.Slice(diff.IPLDs, func(i, j int) bool {
|
||||
return diff.IPLDs[i].CID < diff.IPLDs[j].CID
|
||||
})
|
||||
sort.Slice(diff.Nodes, func(i, j int) bool {
|
||||
return bytes.Compare(
|
||||
diff.Nodes[i].AccountWrapper.LeafKey,
|
||||
diff.Nodes[j].AccountWrapper.LeafKey,
|
||||
) < 0
|
||||
})
|
||||
func normalize(diff *sdtypes.StateObject) normalizedStateDiff {
|
||||
norm := normalizedStateDiff{
|
||||
BlockNumber: diff.BlockNumber,
|
||||
BlockHash: diff.BlockHash,
|
||||
Nodes: make(map[string]sdtypes.StateLeafNode),
|
||||
IPLDs: make(map[string]sdtypes.IPLD),
|
||||
}
|
||||
for _, node := range diff.Nodes {
|
||||
sort.Slice(node.StorageDiff, func(i, j int) bool {
|
||||
return bytes.Compare(
|
||||
@ -74,5 +80,10 @@ func normalize(diff *sdtypes.StateObject) {
|
||||
node.StorageDiff[j].LeafKey,
|
||||
) < 0
|
||||
})
|
||||
norm.Nodes[node.AccountWrapper.CID] = node
|
||||
}
|
||||
for _, ipld := range diff.IPLDs {
|
||||
norm.IPLDs[ipld.CID] = ipld
|
||||
}
|
||||
return norm
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user