update mainnet blocks test
This commit is contained in:
parent
2ad905ff75
commit
ea9a8feb81
@ -414,13 +414,6 @@ var (
|
|||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
type arguments struct {
|
|
||||||
oldStateRoot common.Hash
|
|
||||||
newStateRoot common.Hash
|
|
||||||
blockNumber *big.Int
|
|
||||||
blockHash common.Hash
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
db = rawdb.NewMemoryDatabase()
|
db = rawdb.NewMemoryDatabase()
|
||||||
genesisBlock = core.DefaultGenesisBlock().MustCommit(db)
|
genesisBlock = core.DefaultGenesisBlock().MustCommit(db)
|
||||||
@ -476,39 +469,29 @@ func TestBuilderOnMainnetBlocks(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
config := statediff.Config{
|
params := statediff.Params{
|
||||||
IntermediateNodes: true,
|
IntermediateStateNodes: true,
|
||||||
}
|
}
|
||||||
builder = statediff.NewBuilder(chain, config)
|
builder = statediff.NewBuilder(chain.StateCache())
|
||||||
|
|
||||||
var tests = []struct {
|
var tests = []struct {
|
||||||
name string
|
name string
|
||||||
startingArguments arguments
|
startingArguments statediff.Args
|
||||||
expected *statediff.StateDiff
|
expected *statediff.StateDiff
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
"testBlock1",
|
"testBlock1",
|
||||||
//10000 transferred from testBankAddress to account1Addr
|
//10000 transferred from testBankAddress to account1Addr
|
||||||
arguments{
|
statediff.Args{
|
||||||
oldStateRoot: block0.Root(),
|
OldStateRoot: block0.Root(),
|
||||||
newStateRoot: block1.Root(),
|
NewStateRoot: block1.Root(),
|
||||||
blockNumber: block1.Number(),
|
BlockNumber: block1.Number(),
|
||||||
blockHash: block1.Hash(),
|
BlockHash: block1.Hash(),
|
||||||
},
|
},
|
||||||
&statediff.StateDiff{
|
&statediff.StateDiff{
|
||||||
BlockNumber: block1.Number(),
|
BlockNumber: block1.Number(),
|
||||||
BlockHash: block1.Hash(),
|
BlockHash: block1.Hash(),
|
||||||
CreatedNodes: []statediff.StateNode{
|
Nodes: []statediff.StateNode{
|
||||||
{
|
|
||||||
Path: []byte{'\x04', '\x0b', '\x0e'},
|
|
||||||
NodeType: statediff.Leaf,
|
|
||||||
LeafKey: block1CoinbaseHash.Bytes(),
|
|
||||||
NodeValue: block1CoinbaseLeafNode,
|
|
||||||
StorageDiffs: emptyStorage,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
DeletedNodes: emptyAccounts,
|
|
||||||
UpdatedNodes: []statediff.StateNode{
|
|
||||||
{
|
{
|
||||||
Path: []byte{},
|
Path: []byte{},
|
||||||
NodeType: statediff.Branch,
|
NodeType: statediff.Branch,
|
||||||
@ -527,6 +510,13 @@ func TestBuilderOnMainnetBlocks(t *testing.T) {
|
|||||||
StorageDiffs: emptyStorage,
|
StorageDiffs: emptyStorage,
|
||||||
NodeValue: block1x040bBranchNode,
|
NodeValue: block1x040bBranchNode,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Path: []byte{'\x04', '\x0b', '\x0e'},
|
||||||
|
NodeType: statediff.Leaf,
|
||||||
|
LeafKey: block1CoinbaseHash.Bytes(),
|
||||||
|
NodeValue: block1CoinbaseLeafNode,
|
||||||
|
StorageDiffs: emptyStorage,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -535,36 +525,16 @@ func TestBuilderOnMainnetBlocks(t *testing.T) {
|
|||||||
// 1000 transferred from testBankAddress to account1Addr
|
// 1000 transferred from testBankAddress to account1Addr
|
||||||
// 1000 transferred from account1Addr to account2Addr
|
// 1000 transferred from account1Addr to account2Addr
|
||||||
// account1addr creates a new contract
|
// account1addr creates a new contract
|
||||||
arguments{
|
statediff.Args{
|
||||||
oldStateRoot: block1.Root(),
|
OldStateRoot: block1.Root(),
|
||||||
newStateRoot: block2.Root(),
|
NewStateRoot: block2.Root(),
|
||||||
blockNumber: block2.Number(),
|
BlockNumber: block2.Number(),
|
||||||
blockHash: block2.Hash(),
|
BlockHash: block2.Hash(),
|
||||||
},
|
},
|
||||||
&statediff.StateDiff{
|
&statediff.StateDiff{
|
||||||
BlockNumber: block2.Number(),
|
BlockNumber: block2.Number(),
|
||||||
BlockHash: block2.Hash(),
|
BlockHash: block2.Hash(),
|
||||||
CreatedNodes: []statediff.StateNode{
|
Nodes: []statediff.StateNode{
|
||||||
// this new leaf at x00 x08 x0d x00 was "created" when a premine account (leaf) was moved from path x00 x08 x0d
|
|
||||||
// this occurred because of the creation of the new coinbase receiving account (leaf) at x00 x08 x0d x04
|
|
||||||
// which necessitates we create a branch at x00 x08 x0d (as shown in the below UpdateAccounts)
|
|
||||||
{
|
|
||||||
Path: []byte{'\x00', '\x08', '\x0d', '\x00'},
|
|
||||||
NodeType: statediff.Leaf,
|
|
||||||
StorageDiffs: emptyStorage,
|
|
||||||
LeafKey: common.HexToHash("08d0f2e24db7943eab4415f99e109698863b0fecca1cf9ffc500f38cefbbe29e").Bytes(),
|
|
||||||
NodeValue: block2MovedPremineLeafNode,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Path: []byte{'\x00', '\x08', '\x0d', '\x04'},
|
|
||||||
NodeType: statediff.Leaf,
|
|
||||||
StorageDiffs: emptyStorage,
|
|
||||||
LeafKey: block2CoinbaseHash.Bytes(),
|
|
||||||
NodeValue: block2CoinbaseLeafNode,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
DeletedNodes: emptyAccounts,
|
|
||||||
UpdatedNodes: []statediff.StateNode{
|
|
||||||
{
|
{
|
||||||
Path: []byte{},
|
Path: []byte{},
|
||||||
NodeType: statediff.Branch,
|
NodeType: statediff.Branch,
|
||||||
@ -589,6 +559,23 @@ func TestBuilderOnMainnetBlocks(t *testing.T) {
|
|||||||
StorageDiffs: emptyStorage,
|
StorageDiffs: emptyStorage,
|
||||||
NodeValue: block2x00080dBranchNode,
|
NodeValue: block2x00080dBranchNode,
|
||||||
},
|
},
|
||||||
|
// this new leaf at x00 x08 x0d x00 was "created" when a premine account (leaf) was moved from path x00 x08 x0d
|
||||||
|
// this occurred because of the creation of the new coinbase receiving account (leaf) at x00 x08 x0d x04
|
||||||
|
// which necessitates we create a branch at x00 x08 x0d (as shown in the below UpdateAccounts)
|
||||||
|
{
|
||||||
|
Path: []byte{'\x00', '\x08', '\x0d', '\x00'},
|
||||||
|
NodeType: statediff.Leaf,
|
||||||
|
StorageDiffs: emptyStorage,
|
||||||
|
LeafKey: common.HexToHash("08d0f2e24db7943eab4415f99e109698863b0fecca1cf9ffc500f38cefbbe29e").Bytes(),
|
||||||
|
NodeValue: block2MovedPremineLeafNode,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Path: []byte{'\x00', '\x08', '\x0d', '\x04'},
|
||||||
|
NodeType: statediff.Leaf,
|
||||||
|
StorageDiffs: emptyStorage,
|
||||||
|
LeafKey: block2CoinbaseHash.Bytes(),
|
||||||
|
NodeValue: block2CoinbaseLeafNode,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -596,40 +583,16 @@ func TestBuilderOnMainnetBlocks(t *testing.T) {
|
|||||||
"testBlock3",
|
"testBlock3",
|
||||||
//the contract's storage is changed
|
//the contract's storage is changed
|
||||||
//and the block is mined by account 2
|
//and the block is mined by account 2
|
||||||
arguments{
|
statediff.Args{
|
||||||
oldStateRoot: block2.Root(),
|
OldStateRoot: block2.Root(),
|
||||||
newStateRoot: block3.Root(),
|
NewStateRoot: block3.Root(),
|
||||||
blockNumber: block3.Number(),
|
BlockNumber: block3.Number(),
|
||||||
blockHash: block3.Hash(),
|
BlockHash: block3.Hash(),
|
||||||
},
|
},
|
||||||
&statediff.StateDiff{
|
&statediff.StateDiff{
|
||||||
BlockNumber: block3.Number(),
|
BlockNumber: block3.Number(),
|
||||||
BlockHash: block3.Hash(),
|
BlockHash: block3.Hash(),
|
||||||
CreatedNodes: []statediff.StateNode{
|
Nodes: []statediff.StateNode{
|
||||||
{ // How was this account created???
|
|
||||||
Path: []byte{'\x0c', '\x0e', '\x05', '\x07', '\x03'},
|
|
||||||
NodeType: statediff.Leaf,
|
|
||||||
StorageDiffs: emptyStorage,
|
|
||||||
LeafKey: common.HexToHash("ce573ced93917e658d10e2d9009470dad72b63c898d173721194a12f2ae5e190").Bytes(),
|
|
||||||
NodeValue: block3MovedPremineLeafNode1,
|
|
||||||
},
|
|
||||||
{ // This account (leaf) used to be at 0c 0e 05 07, not sure why it moves...
|
|
||||||
Path: []byte{'\x0c', '\x0e', '\x05', '\x07', '\x08'},
|
|
||||||
NodeType: statediff.Leaf,
|
|
||||||
StorageDiffs: emptyStorage,
|
|
||||||
LeafKey: common.HexToHash("ce5783bc1e69eedf90f402e11f6862da14ed8e50156635a04d6393bbae154012").Bytes(),
|
|
||||||
NodeValue: block3MovedPremineLeafNode2,
|
|
||||||
},
|
|
||||||
{ // this is the new account created due to the coinbase mining a block, it's creation shouldn't affect 0x 0e 05 07
|
|
||||||
Path: []byte{'\x06', '\x0e', '\x0f'},
|
|
||||||
NodeType: statediff.Leaf,
|
|
||||||
StorageDiffs: emptyStorage,
|
|
||||||
LeafKey: block3CoinbaseHash.Bytes(),
|
|
||||||
NodeValue: block3CoinbaseLeafNode,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
DeletedNodes: emptyAccounts,
|
|
||||||
UpdatedNodes: []statediff.StateNode{
|
|
||||||
{
|
{
|
||||||
Path: []byte{},
|
Path: []byte{},
|
||||||
NodeType: statediff.Branch,
|
NodeType: statediff.Branch,
|
||||||
@ -672,14 +635,34 @@ func TestBuilderOnMainnetBlocks(t *testing.T) {
|
|||||||
StorageDiffs: emptyStorage,
|
StorageDiffs: emptyStorage,
|
||||||
NodeValue: block3x0c0e0507BranchNode,
|
NodeValue: block3x0c0e0507BranchNode,
|
||||||
},
|
},
|
||||||
|
{ // How was this account created???
|
||||||
|
Path: []byte{'\x0c', '\x0e', '\x05', '\x07', '\x03'},
|
||||||
|
NodeType: statediff.Leaf,
|
||||||
|
StorageDiffs: emptyStorage,
|
||||||
|
LeafKey: common.HexToHash("ce573ced93917e658d10e2d9009470dad72b63c898d173721194a12f2ae5e190").Bytes(),
|
||||||
|
NodeValue: block3MovedPremineLeafNode1,
|
||||||
|
},
|
||||||
|
{ // This account (leaf) used to be at 0c 0e 05 07, likely moves because of the new account above
|
||||||
|
Path: []byte{'\x0c', '\x0e', '\x05', '\x07', '\x08'},
|
||||||
|
NodeType: statediff.Leaf,
|
||||||
|
StorageDiffs: emptyStorage,
|
||||||
|
LeafKey: common.HexToHash("ce5783bc1e69eedf90f402e11f6862da14ed8e50156635a04d6393bbae154012").Bytes(),
|
||||||
|
NodeValue: block3MovedPremineLeafNode2,
|
||||||
|
},
|
||||||
|
{ // this is the new account created due to the coinbase mining a block, it's creation shouldn't affect 0x 0e 05 07
|
||||||
|
Path: []byte{'\x06', '\x0e', '\x0f'},
|
||||||
|
NodeType: statediff.Leaf,
|
||||||
|
StorageDiffs: emptyStorage,
|
||||||
|
LeafKey: block3CoinbaseHash.Bytes(),
|
||||||
|
NodeValue: block3CoinbaseLeafNode,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
arguments := test.startingArguments
|
diff, err := builder.BuildStateDiff(test.startingArguments, params)
|
||||||
diff, err := builder.BuildStateDiff(arguments.oldStateRoot, arguments.newStateRoot, arguments.blockNumber, arguments.blockHash)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user