Updated unit tests for changes in builder

This commit is contained in:
nabarun 2022-03-15 19:22:09 +05:30 committed by prathamesh0
parent 4855d9304e
commit a14745dac5
2 changed files with 124 additions and 40 deletions

View File

@ -113,7 +113,7 @@ var (
Nonce: 1, Nonce: 1,
Balance: big.NewInt(0), Balance: big.NewInt(0),
CodeHash: common.HexToHash("0xaaea5efba4fd7b45d7ec03918ac5d8b31aa93b48986af0e6b591f0f087c80127").Bytes(), CodeHash: common.HexToHash("0xaaea5efba4fd7b45d7ec03918ac5d8b31aa93b48986af0e6b591f0f087c80127").Bytes(),
Root: crypto.Keccak256Hash(slot0StorageLeafRootNode), Root: crypto.Keccak256Hash(block5StorageBranchRootNode),
}) })
contractAccountAtBlock5LeafNode, _ = rlp.EncodeToBytes([]interface{}{ contractAccountAtBlock5LeafNode, _ = rlp.EncodeToBytes([]interface{}{
common.Hex2Bytes("3114658a74d9cc9f7acf2c5cd696c3494d7c344d78bfec3add0d91ec4e8d1c45"), common.Hex2Bytes("3114658a74d9cc9f7acf2c5cd696c3494d7c344d78bfec3add0d91ec4e8d1c45"),
@ -163,7 +163,7 @@ var (
}) })
account1AtBlock5, _ = rlp.EncodeToBytes(types.StateAccount{ account1AtBlock5, _ = rlp.EncodeToBytes(types.StateAccount{
Nonce: 2, Nonce: 2,
Balance: big.NewInt(2999566008847709960), Balance: big.NewInt(2999586469962854280),
CodeHash: test_helpers.NullCodeHash.Bytes(), CodeHash: test_helpers.NullCodeHash.Bytes(),
Root: test_helpers.EmptyContractRoot, Root: test_helpers.EmptyContractRoot,
}) })
@ -173,7 +173,7 @@ var (
}) })
account1AtBlock6, _ = rlp.EncodeToBytes(types.StateAccount{ account1AtBlock6, _ = rlp.EncodeToBytes(types.StateAccount{
Nonce: 3, Nonce: 3,
Balance: big.NewInt(2999537516847709960), Balance: big.NewInt(2999557977962854280),
CodeHash: test_helpers.NullCodeHash.Bytes(), CodeHash: test_helpers.NullCodeHash.Bytes(),
Root: test_helpers.EmptyContractRoot, Root: test_helpers.EmptyContractRoot,
}) })
@ -214,7 +214,7 @@ var (
}) })
account2AtBlock6, _ = rlp.EncodeToBytes(types.StateAccount{ account2AtBlock6, _ = rlp.EncodeToBytes(types.StateAccount{
Nonce: 0, Nonce: 0,
Balance: big.NewInt(6000063293259748636), Balance: big.NewInt(6000063258066544204),
CodeHash: test_helpers.NullCodeHash.Bytes(), CodeHash: test_helpers.NullCodeHash.Bytes(),
Root: test_helpers.EmptyContractRoot, Root: test_helpers.EmptyContractRoot,
}) })
@ -278,8 +278,8 @@ var (
bankAccountAtBlock4, bankAccountAtBlock4,
}) })
bankAccountAtBlock5, _ = rlp.EncodeToBytes(types.StateAccount{ bankAccountAtBlock5, _ = rlp.EncodeToBytes(types.StateAccount{
Nonce: 7, Nonce: 8,
Balance: big.NewInt(999805027999990000), Balance: big.NewInt(999761283999990000),
CodeHash: test_helpers.NullCodeHash.Bytes(), CodeHash: test_helpers.NullCodeHash.Bytes(),
Root: test_helpers.EmptyContractRoot, Root: test_helpers.EmptyContractRoot,
}) })
@ -460,6 +460,25 @@ var (
[]byte{}, []byte{},
[]byte{}, []byte{},
}) })
block5StorageBranchRootNode, _ = rlp.EncodeToBytes([]interface{}{
[]byte{},
[]byte{},
crypto.Keccak256(slot0StorageLeafNode),
[]byte{},
[]byte{},
[]byte{},
[]byte{},
[]byte{},
[]byte{},
[]byte{},
[]byte{},
[]byte{},
crypto.Keccak256(slot3StorageLeafNode),
[]byte{},
[]byte{},
[]byte{},
[]byte{},
})
) )
func init() { func init() {
@ -1272,15 +1291,14 @@ func TestBuilderWithRemovedAccountAndStorage(t *testing.T) {
StorageNodes: []types2.StorageNode{ StorageNodes: []types2.StorageNode{
{ {
Path: []byte{}, Path: []byte{},
NodeType: types2.Leaf, NodeType: types2.Branch,
NodeValue: slot0StorageLeafRootNode, NodeValue: block5StorageBranchRootNode,
LeafKey: slot0StorageKey.Bytes(),
}, },
{ {
Path: []byte{'\x02'}, Path: []byte{'\x0c'},
NodeType: types2.Removed, NodeType: types2.Leaf,
LeafKey: slot0StorageKey.Bytes(), LeafKey: slot3StorageKey.Bytes(),
NodeValue: []byte{}, NodeValue: slot3StorageLeafNode,
}, },
{ {
Path: []byte{'\x04'}, Path: []byte{'\x04'},
@ -1323,7 +1341,25 @@ func TestBuilderWithRemovedAccountAndStorage(t *testing.T) {
NodeType: types2.Removed, NodeType: types2.Removed,
LeafKey: contractLeafKey, LeafKey: contractLeafKey,
NodeValue: []byte{}, NodeValue: []byte{},
StorageNodes: emptyStorage, StorageNodes: []types2.StorageNode{
{
Path: []byte{},
NodeType: types2.Removed,
NodeValue: []byte{},
},
{
Path: []byte{'\x02'},
NodeType: types2.Removed,
LeafKey: slot0StorageKey.Bytes(),
NodeValue: []byte{},
},
{
Path: []byte{'\x0c'},
NodeType: types2.Removed,
LeafKey: slot3StorageKey.Bytes(),
NodeValue: []byte{},
},
},
}, },
{ {
Path: []byte{'\x0c'}, Path: []byte{'\x0c'},
@ -1467,16 +1503,10 @@ func TestBuilderWithRemovedAccountAndStorageWithoutIntermediateNodes(t *testing.
NodeValue: contractAccountAtBlock5LeafNode, NodeValue: contractAccountAtBlock5LeafNode,
StorageNodes: []types2.StorageNode{ StorageNodes: []types2.StorageNode{
{ {
Path: []byte{}, Path: []byte{'\x0c'},
NodeType: types2.Leaf, NodeType: types2.Leaf,
LeafKey: slot0StorageKey.Bytes(), LeafKey: slot3StorageKey.Bytes(),
NodeValue: slot0StorageLeafRootNode, NodeValue: slot3StorageLeafNode,
},
{
Path: []byte{'\x02'},
NodeType: types2.Removed,
LeafKey: slot0StorageKey.Bytes(),
NodeValue: []byte{},
}, },
{ {
Path: []byte{'\x04'}, Path: []byte{'\x04'},
@ -1513,6 +1543,20 @@ func TestBuilderWithRemovedAccountAndStorageWithoutIntermediateNodes(t *testing.
NodeType: types2.Removed, NodeType: types2.Removed,
LeafKey: contractLeafKey, LeafKey: contractLeafKey,
NodeValue: []byte{}, NodeValue: []byte{},
StorageNodes: []types2.StorageNode{
{
Path: []byte{'\x02'},
NodeType: types2.Removed,
LeafKey: slot0StorageKey.Bytes(),
NodeValue: []byte{},
},
{
Path: []byte{'\x0c'},
NodeType: types2.Removed,
LeafKey: slot3StorageKey.Bytes(),
NodeValue: []byte{},
},
},
}, },
{ {
Path: []byte{'\x0c'}, Path: []byte{'\x0c'},
@ -1754,16 +1798,10 @@ func TestBuilderWithRemovedWatchedAccount(t *testing.T) {
NodeValue: contractAccountAtBlock5LeafNode, NodeValue: contractAccountAtBlock5LeafNode,
StorageNodes: []types2.StorageNode{ StorageNodes: []types2.StorageNode{
{ {
Path: []byte{}, Path: []byte{'\x0c'},
NodeType: types2.Leaf, NodeType: types2.Leaf,
LeafKey: slot0StorageKey.Bytes(), LeafKey: slot3StorageKey.Bytes(),
NodeValue: slot0StorageLeafRootNode, NodeValue: slot3StorageLeafNode,
},
{
Path: []byte{'\x02'},
NodeType: types2.Removed,
LeafKey: slot0StorageKey.Bytes(),
NodeValue: []byte{},
}, },
{ {
Path: []byte{'\x04'}, Path: []byte{'\x04'},
@ -1800,6 +1838,20 @@ func TestBuilderWithRemovedWatchedAccount(t *testing.T) {
NodeType: types2.Removed, NodeType: types2.Removed,
LeafKey: contractLeafKey, LeafKey: contractLeafKey,
NodeValue: []byte{}, NodeValue: []byte{},
StorageNodes: []types2.StorageNode{
{
Path: []byte{'\x02'},
NodeType: types2.Removed,
LeafKey: slot0StorageKey.Bytes(),
NodeValue: []byte{},
},
{
Path: []byte{'\x0c'},
NodeType: types2.Removed,
LeafKey: slot3StorageKey.Bytes(),
NodeValue: []byte{},
},
},
}, },
{ {
Path: []byte{'\x0e'}, Path: []byte{'\x0e'},
@ -2019,6 +2071,22 @@ func TestBuilderWithMovedAccount(t *testing.T) {
NodeType: types2.Removed, NodeType: types2.Removed,
LeafKey: contractLeafKey, LeafKey: contractLeafKey,
NodeValue: []byte{}, NodeValue: []byte{},
StorageNodes: []types2.StorageNode{
{
Path: []byte{},
NodeType: types2.Removed,
},
{
Path: []byte{'\x02'},
NodeType: types2.Removed,
LeafKey: slot0StorageKey.Bytes(),
},
{
Path: []byte{'\x0b'},
NodeType: types2.Removed,
LeafKey: slot1StorageKey.Bytes(),
},
},
}, },
{ {
Path: []byte{'\x00'}, Path: []byte{'\x00'},
@ -2144,6 +2212,18 @@ func TestBuilderWithMovedAccountOnlyLeafs(t *testing.T) {
NodeType: types2.Removed, NodeType: types2.Removed,
LeafKey: contractLeafKey, LeafKey: contractLeafKey,
NodeValue: []byte{}, NodeValue: []byte{},
StorageNodes: []types2.StorageNode{
{
Path: []byte{'\x02'},
NodeType: types2.Removed,
LeafKey: slot0StorageKey.Bytes(),
},
{
Path: []byte{'\x0b'},
NodeType: types2.Removed,
LeafKey: slot1StorageKey.Bytes(),
},
},
}, },
{ {
Path: []byte{'\x00'}, Path: []byte{'\x00'},

View File

@ -106,13 +106,17 @@ func TestChainGen(i int, block *core.BlockGen) {
block.AddTx(tx3) block.AddTx(tx3)
case 4: case 4:
// Block 5 has one tx from bankAccount to the contract, that transfers no value // Block 5 has one tx from bankAccount to the contract, that transfers no value
// It sets the remaining storage value to zero // It sets the one storage value to zero and the other to new value.
// Block 5 is mined by Account1Addr // Block 5 is mined by Account1Addr
block.SetCoinbase(Account1Addr) block.SetCoinbase(Account1Addr)
data := common.Hex2Bytes("C16431B900000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000") data1 := common.Hex2Bytes("C16431B900000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000")
data2 := common.Hex2Bytes("C16431B900000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000003")
nonce := block.TxNonce(TestBankAddress) nonce := block.TxNonce(TestBankAddress)
tx, _ := types.SignTx(types.NewTransaction(nonce, ContractAddr, big.NewInt(0), 100000, big.NewInt(params.InitialBaseFee), data), signer, TestBankKey) tx1, _ := types.SignTx(types.NewTransaction(nonce, ContractAddr, big.NewInt(0), 100000, big.NewInt(params.InitialBaseFee), data1), signer, TestBankKey)
block.AddTx(tx) nonce++
tx2, _ := types.SignTx(types.NewTransaction(nonce, ContractAddr, big.NewInt(0), 100000, big.NewInt(params.InitialBaseFee), data2), signer, TestBankKey)
block.AddTx(tx1)
block.AddTx(tx2)
case 5: case 5:
// Block 6 has a tx from Account1Key which self-destructs the contract, it transfers no value // Block 6 has a tx from Account1Key which self-destructs the contract, it transfers no value
// Block 6 is mined by Account2Addr // Block 6 is mined by Account2Addr