From bc2280b654cbbc28bb2afb2b061045d2be5dce24 Mon Sep 17 00:00:00 2001 From: Arijit Das Date: Fri, 25 Jun 2021 09:28:00 +0530 Subject: [PATCH] Fix failing test. --- go.mod | 3 ++ go.sum | 9 ++++ statediff/builder_test.go | 47 +++++++++++---------- statediff/testhelpers/constant.go | 17 ++++++++ statediff/testhelpers/helpers.go | 24 +++++------ statediff/testhelpers/mocks/service_test.go | 6 ++- statediff/testhelpers/test_data.go | 3 +- 7 files changed, 71 insertions(+), 38 deletions(-) create mode 100644 statediff/testhelpers/constant.go diff --git a/go.mod b/go.mod index 158e6a897..db3018b1a 100644 --- a/go.mod +++ b/go.mod @@ -31,6 +31,7 @@ require ( github.com/go-stack/stack v1.8.0 github.com/golang/protobuf v1.4.3 github.com/golang/snappy v0.0.3 + github.com/google/go-cmp v0.5.4 // indirect github.com/google/gofuzz v1.1.1-0.20200604201612-c04b05f3adfa github.com/google/uuid v1.1.5 github.com/gorilla/websocket v1.4.2 @@ -61,8 +62,10 @@ require ( github.com/olekukonko/tablewriter v0.0.5 github.com/peterh/liner v1.1.1-0.20190123174540-a2c9a5303de7 github.com/prometheus/tsdb v0.7.1 + github.com/r3labs/diff/v2 v2.13.1 // indirect github.com/rjeczalik/notify v0.9.1 github.com/rs/cors v1.7.0 + github.com/sergi/go-diff v1.2.0 // indirect github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible github.com/status-im/keycard-go v0.0.0-20190316090335-8537d3370df4 github.com/stretchr/testify v1.7.0 diff --git a/go.sum b/go.sum index c73d3f9ce..8ccf7cbba 100644 --- a/go.sum +++ b/go.sum @@ -398,6 +398,8 @@ github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= github.com/prometheus/tsdb v0.7.1 h1:YZcsG11NqnK4czYLrWd9mpEuAJIHVQLwdrleYfszMAA= github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU= +github.com/r3labs/diff/v2 v2.13.1 h1:o0mlcYwUKTeL6jVblu42vCnXS7gfArPKYJCs4qkwOw8= +github.com/r3labs/diff/v2 v2.13.1/go.mod h1:I8noH9Fc2fjSaMxqF3G2lhDdC0b+JXCfyx85tWFM9kc= github.com/retailnext/hllpp v1.0.1-0.20180308014038-101a6d2f8b52/go.mod h1:RDpi1RftBQPUCDRw6SmxeaREsAaRKnOclghuzp/WRzc= github.com/rjeczalik/notify v0.9.1 h1:CLCKso/QK1snAlnhNR/CNvNiFU2saUtjV0bx3EwNeCE= github.com/rjeczalik/notify v0.9.1/go.mod h1:rKwnCoCGeuQnwBtTSPL9Dad03Vh2n40ePRrjvIXnJho= @@ -408,6 +410,8 @@ github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQD github.com/segmentio/kafka-go v0.1.0/go.mod h1:X6itGqS9L4jDletMsxZ7Dz+JFWxM6JHfPOCvTvk+EJo= github.com/segmentio/kafka-go v0.2.0/go.mod h1:X6itGqS9L4jDletMsxZ7Dz+JFWxM6JHfPOCvTvk+EJo= github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= +github.com/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ= +github.com/sergi/go-diff v1.2.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM= github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible h1:Bn1aCHHRnjv4Bl16T8rcaFjYSrGrIZvpiGO6P3Q4GpU= github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= @@ -428,6 +432,7 @@ github.com/stretchr/testify v1.2.0/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/syndtr/goleveldb v1.0.1-0.20210305035536-64b5b1c73954 h1:xQdMZ1WLrgkkvOZ/LDQxjVxMLdby7osSh4ZEVa5sIjs= @@ -440,6 +445,8 @@ github.com/tklauser/numcpus v0.2.2/go.mod h1:x3qojaO3uyYt0i56EW/VUYs7uBvdl2fkfZF github.com/tyler-smith/go-bip39 v1.0.1-0.20181017060643-dbb3b84ba2ef h1:wHSqTBrZW24CsNJDfeh9Ex6Pm0Rcpc7qrgKBiL44vF4= github.com/tyler-smith/go-bip39 v1.0.1-0.20181017060643-dbb3b84ba2ef/go.mod h1:sJ5fKU0s6JVwZjjcUEX2zFOnvq0ASQ2K9Zr6cf67kNs= github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI= +github.com/vmihailenco/msgpack v4.0.4+incompatible h1:dSLoQfGFAo3F6OoNhwUmLwVgaUXK79GlxNBwueZn0xI= +github.com/vmihailenco/msgpack v4.0.4+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk= github.com/whyrusleeping/go-logging v0.0.0-20170515211332-0457bb6b88fc h1:9lDbC6Rz4bwmou+oE6Dt4Cb2BGMur5eR/GYptkKUVHo= github.com/whyrusleeping/go-logging v0.0.0-20170515211332-0457bb6b88fc/go.mod h1:bopw91TMyo8J3tvftk8xmU2kPmlrt4nScJQZU2hE5EM= github.com/willf/bitset v1.1.3/go.mod h1:RjeCKbqT1RxIR/KWY6phxZiaY1IyutSBfGjNPySAYV4= @@ -636,6 +643,8 @@ google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7 google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= google.golang.org/appengine v1.6.1/go.mod h1:i06prIuMbXzDqacNJfV5OdTW448YApPu5ww/cMBSeb0= google.golang.org/appengine v1.6.5/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= +google.golang.org/appengine v1.6.6 h1:lMO5rYAqUxkmaj76jAkRUvt5JZgFymx/+Q5Mzfivuhc= +google.golang.org/appengine v1.6.6/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= google.golang.org/genproto v0.0.0-20190418145605-e7d98fc518a7/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= diff --git a/statediff/builder_test.go b/statediff/builder_test.go index 7ad49f565..6cbf8b313 100644 --- a/statediff/builder_test.go +++ b/statediff/builder_test.go @@ -44,12 +44,6 @@ var ( minerAddress = common.HexToAddress("0x0") minerLeafKey = testhelpers.AddressToLeafKey(minerAddress) - balanceChange10000 = int64(10000) - balanceChange1000 = int64(1000) - block1BankBalance = int64(99990000) - block1Account1Balance = int64(10000) - block2Account2Balance = int64(1000) - slot0 = common.HexToHash("0") slot1 = common.HexToHash("1") slot2 = common.HexToHash("2") @@ -129,7 +123,7 @@ var ( minerAccountAtBlock1, _ = rlp.EncodeToBytes(state.Account{ Nonce: 0, - Balance: big.NewInt(miningReward), + Balance: big.NewInt(2000002625000000000), CodeHash: testhelpers.NullCodeHash.Bytes(), Root: testhelpers.EmptyContractRoot, }) @@ -139,7 +133,7 @@ var ( }) minerAccountAtBlock2, _ = rlp.EncodeToBytes(state.Account{ Nonce: 0, - Balance: big.NewInt(miningReward + miningReward), + Balance: big.NewInt(4000111203461610525), CodeHash: testhelpers.NullCodeHash.Bytes(), Root: testhelpers.EmptyContractRoot, }) @@ -150,7 +144,7 @@ var ( account1AtBlock1, _ = rlp.EncodeToBytes(state.Account{ Nonce: 0, - Balance: big.NewInt(balanceChange10000), + Balance: testhelpers.Block1Account1Balance, CodeHash: testhelpers.NullCodeHash.Bytes(), Root: testhelpers.EmptyContractRoot, }) @@ -160,7 +154,7 @@ var ( }) account1AtBlock2, _ = rlp.EncodeToBytes(state.Account{ Nonce: 2, - Balance: big.NewInt(block1Account1Balance - balanceChange1000 + balanceChange1000), + Balance: big.NewInt(999555797000009000), CodeHash: testhelpers.NullCodeHash.Bytes(), Root: testhelpers.EmptyContractRoot, }) @@ -170,7 +164,7 @@ var ( }) account1AtBlock5, _ = rlp.EncodeToBytes(state.Account{ Nonce: 2, - Balance: big.NewInt(block1Account1Balance - balanceChange1000 + balanceChange1000 + miningReward), + Balance: big.NewInt(2999566008847709960), CodeHash: testhelpers.NullCodeHash.Bytes(), Root: testhelpers.EmptyContractRoot, }) @@ -180,7 +174,7 @@ var ( }) account1AtBlock6, _ = rlp.EncodeToBytes(state.Account{ Nonce: 3, - Balance: big.NewInt(block1Account1Balance - balanceChange1000 + balanceChange1000 + miningReward), + Balance: big.NewInt(2999537516847709960), CodeHash: testhelpers.NullCodeHash.Bytes(), Root: testhelpers.EmptyContractRoot, }) @@ -191,7 +185,7 @@ var ( account2AtBlock2, _ = rlp.EncodeToBytes(state.Account{ Nonce: 0, - Balance: big.NewInt(balanceChange1000), + Balance: big.NewInt(1000), CodeHash: testhelpers.NullCodeHash.Bytes(), Root: testhelpers.EmptyContractRoot, }) @@ -201,7 +195,7 @@ var ( }) account2AtBlock3, _ = rlp.EncodeToBytes(state.Account{ Nonce: 0, - Balance: big.NewInt(block2Account2Balance + miningReward), + Balance: big.NewInt(2000013574009435976), CodeHash: testhelpers.NullCodeHash.Bytes(), Root: testhelpers.EmptyContractRoot, }) @@ -211,7 +205,7 @@ var ( }) account2AtBlock4, _ = rlp.EncodeToBytes(state.Account{ Nonce: 0, - Balance: big.NewInt(block2Account2Balance + miningReward*2), + Balance: big.NewInt(4000048088163070348), CodeHash: testhelpers.NullCodeHash.Bytes(), Root: testhelpers.EmptyContractRoot, }) @@ -221,7 +215,7 @@ var ( }) account2AtBlock6, _ = rlp.EncodeToBytes(state.Account{ Nonce: 0, - Balance: big.NewInt(block2Account2Balance + miningReward*3), + Balance: big.NewInt(6000063293259748636), CodeHash: testhelpers.NullCodeHash.Bytes(), Root: testhelpers.EmptyContractRoot, }) @@ -240,9 +234,11 @@ var ( common.Hex2Bytes("2000bf49f440a1cd0527e4d06e2765654c0f56452257516d793a9b8d604dcfdf2a"), bankAccountAtBlock0, }) + + block1BankBalance = big.NewInt(testhelpers.TestBankFunds.Int64() - testhelpers.BalanceChange10000 - testhelpers.GasFees) bankAccountAtBlock1, _ = rlp.EncodeToBytes(state.Account{ Nonce: 1, - Balance: big.NewInt(testhelpers.TestBankFunds.Int64() - balanceChange10000), + Balance: block1BankBalance, CodeHash: testhelpers.NullCodeHash.Bytes(), Root: testhelpers.EmptyContractRoot, }) @@ -250,9 +246,11 @@ var ( common.Hex2Bytes("30bf49f440a1cd0527e4d06e2765654c0f56452257516d793a9b8d604dcfdf2a"), bankAccountAtBlock1, }) + + block2BankBalance = block1BankBalance.Int64() - testhelpers.BalanceChange1Ether - testhelpers.GasFees bankAccountAtBlock2, _ = rlp.EncodeToBytes(state.Account{ Nonce: 2, - Balance: big.NewInt(block1BankBalance - balanceChange1000), + Balance: big.NewInt(block2BankBalance), CodeHash: testhelpers.NullCodeHash.Bytes(), Root: testhelpers.EmptyContractRoot, }) @@ -262,7 +260,7 @@ var ( }) bankAccountAtBlock3, _ = rlp.EncodeToBytes(state.Account{ Nonce: 3, - Balance: big.NewInt(99989000), + Balance: big.NewInt(999914255999990000), CodeHash: testhelpers.NullCodeHash.Bytes(), Root: testhelpers.EmptyContractRoot, }) @@ -272,7 +270,7 @@ var ( }) bankAccountAtBlock4, _ = rlp.EncodeToBytes(state.Account{ Nonce: 6, - Balance: big.NewInt(99989000), + Balance: big.NewInt(999826859999990000), CodeHash: testhelpers.NullCodeHash.Bytes(), Root: testhelpers.EmptyContractRoot, }) @@ -282,7 +280,7 @@ var ( }) bankAccountAtBlock5, _ = rlp.EncodeToBytes(state.Account{ Nonce: 7, - Balance: big.NewInt(99989000), + Balance: big.NewInt(999805027999990000), CodeHash: testhelpers.NullCodeHash.Bytes(), Root: testhelpers.EmptyContractRoot, }) @@ -1706,10 +1704,12 @@ func TestBuilderWithRemovedAccountAndStorageWithoutIntermediateNodes(t *testing. if err != nil { t.Error(err) } + expectedStateDiffRlp, err := rlp.EncodeToBytes(test.expected) if err != nil { t.Error(err) } + sort.Slice(receivedStateDiffRlp, func(i, j int) bool { return receivedStateDiffRlp[i] < receivedStateDiffRlp[j] }) sort.Slice(expectedStateDiffRlp, func(i, j int) bool { return expectedStateDiffRlp[i] < expectedStateDiffRlp[j] }) if !bytes.Equal(receivedStateDiffRlp, expectedStateDiffRlp) { @@ -1740,7 +1740,7 @@ var ( bankAccountAtBlock01, _ = rlp.EncodeToBytes(state.Account{ Nonce: 1, - Balance: big.NewInt(testhelpers.TestBankFunds.Int64() + miningReward), + Balance: big.NewInt(3999629697375000000), CodeHash: testhelpers.NullCodeHash.Bytes(), Root: testhelpers.EmptyContractRoot, }) @@ -1750,7 +1750,7 @@ var ( }) bankAccountAtBlock02, _ = rlp.EncodeToBytes(state.Account{ Nonce: 2, - Balance: big.NewInt(testhelpers.TestBankFunds.Int64() + miningReward*2), + Balance: big.NewInt(5999607323457344852), CodeHash: testhelpers.NullCodeHash.Bytes(), Root: testhelpers.EmptyContractRoot, }) @@ -1926,6 +1926,7 @@ func TestBuilderWithMovedAccount(t *testing.T) { if err != nil { t.Error(err) } + sort.Slice(receivedStateDiffRlp, func(i, j int) bool { return receivedStateDiffRlp[i] < receivedStateDiffRlp[j] }) sort.Slice(expectedStateDiffRlp, func(i, j int) bool { return expectedStateDiffRlp[i] < expectedStateDiffRlp[j] }) if !bytes.Equal(receivedStateDiffRlp, expectedStateDiffRlp) { diff --git a/statediff/testhelpers/constant.go b/statediff/testhelpers/constant.go new file mode 100644 index 000000000..9788549e6 --- /dev/null +++ b/statediff/testhelpers/constant.go @@ -0,0 +1,17 @@ +package testhelpers + +import ( + "math/big" + + "github.com/ethereum/go-ethereum/params" +) + +var ( + BalanceChange1000 = int64(1000) + BalanceChange10000 = int64(10000) + BalanceChange1Ether = int64(params.Ether) + Block1Account1Balance = big.NewInt(BalanceChange10000) + Block2Account2Balance = big.NewInt(21000000000000) + GasFees = int64(params.GWei) * int64(params.TxGas) + ContractGasLimit = uint64(1000000) +) diff --git a/statediff/testhelpers/helpers.go b/statediff/testhelpers/helpers.go index 7fd320b25..168d770af 100644 --- a/statediff/testhelpers/helpers.go +++ b/statediff/testhelpers/helpers.go @@ -44,7 +44,7 @@ func TestSelfDestructChainGen(i int, block *core.BlockGen) { // Block 1 is mined by Account1Addr // Account1Addr creates a new contract block.SetCoinbase(TestBankAddress) - tx, _ := types.SignTx(types.NewContractCreation(0, big.NewInt(0), 1000000, big.NewInt(0), ContractCode), signer, TestBankKey) + tx, _ := types.SignTx(types.NewContractCreation(0, big.NewInt(0), 1000000, big.NewInt(params.GWei), ContractCode), signer, TestBankKey) ContractAddr = crypto.CreateAddress(TestBankAddress, 0) block.AddTx(tx) case 1: @@ -52,7 +52,7 @@ func TestSelfDestructChainGen(i int, block *core.BlockGen) { // Account1Addr self-destructs the contract block.SetCoinbase(TestBankAddress) data := common.Hex2Bytes("43D726D6") - tx, _ := types.SignTx(types.NewTransaction(1, ContractAddr, big.NewInt(0), 100000, nil, data), signer, TestBankKey) + tx, _ := types.SignTx(types.NewTransaction(1, ContractAddr, big.NewInt(0), 100000, big.NewInt(params.GWei), data), signer, TestBankKey) block.AddTx(tx) } } @@ -62,17 +62,17 @@ func TestChainGen(i int, block *core.BlockGen) { switch i { case 0: // In block 1, the test bank sends account #1 some ether. - tx, _ := types.SignTx(types.NewTransaction(block.TxNonce(TestBankAddress), Account1Addr, big.NewInt(10000), params.TxGas, nil, nil), signer, TestBankKey) + tx, _ := types.SignTx(types.NewTransaction(block.TxNonce(TestBankAddress), Account1Addr, big.NewInt(BalanceChange10000), params.TxGas, big.NewInt(params.GWei), nil), signer, TestBankKey) block.AddTx(tx) case 1: // In block 2, the test bank sends some more ether to account #1. // Account1Addr passes it on to account #2. // Account1Addr creates a test contract. - tx1, _ := types.SignTx(types.NewTransaction(block.TxNonce(TestBankAddress), Account1Addr, big.NewInt(1000), params.TxGas, nil, nil), signer, TestBankKey) + tx1, _ := types.SignTx(types.NewTransaction(block.TxNonce(TestBankAddress), Account1Addr, big.NewInt(BalanceChange1Ether), params.TxGas, big.NewInt(params.GWei), nil), signer, TestBankKey) nonce := block.TxNonce(Account1Addr) - tx2, _ := types.SignTx(types.NewTransaction(nonce, Account2Addr, big.NewInt(1000), params.TxGas, nil, nil), signer, Account1Key) + tx2, _ := types.SignTx(types.NewTransaction(nonce, Account2Addr, big.NewInt(BalanceChange1000), params.TxGas, big.NewInt(params.GWei), nil), signer, Account1Key) nonce++ - tx3, _ := types.SignTx(types.NewContractCreation(nonce, big.NewInt(0), 1000000, big.NewInt(0), ContractCode), signer, Account1Key) + tx3, _ := types.SignTx(types.NewContractCreation(nonce, big.NewInt(0), ContractGasLimit, big.NewInt(params.GWei), ContractCode), signer, Account1Key) ContractAddr = crypto.CreateAddress(Account1Addr, nonce) block.AddTx(tx1) block.AddTx(tx2) @@ -84,7 +84,7 @@ func TestChainGen(i int, block *core.BlockGen) { //put function: c16431b9 //close function: 43d726d6 data := common.Hex2Bytes("C16431B900000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000003") - tx, _ := types.SignTx(types.NewTransaction(block.TxNonce(TestBankAddress), ContractAddr, big.NewInt(0), 100000, nil, data), signer, TestBankKey) + tx, _ := types.SignTx(types.NewTransaction(block.TxNonce(TestBankAddress), ContractAddr, big.NewInt(0), params.TxGasContractCreation, big.NewInt(params.GWei), data), signer, TestBankKey) block.AddTx(tx) case 3: // Block 4 has three txs from bankAccount to the contract, that transfer no value @@ -96,11 +96,11 @@ func TestChainGen(i int, block *core.BlockGen) { data3 := common.Hex2Bytes("C16431B900000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000009") nonce := block.TxNonce(TestBankAddress) - tx1, _ := types.SignTx(types.NewTransaction(nonce, ContractAddr, big.NewInt(0), 100000, nil, data1), signer, TestBankKey) + tx1, _ := types.SignTx(types.NewTransaction(nonce, ContractAddr, big.NewInt(0), 100000, big.NewInt(params.InitialBaseFee), data1), signer, TestBankKey) nonce++ - tx2, _ := types.SignTx(types.NewTransaction(nonce, ContractAddr, big.NewInt(0), 100000, nil, data2), signer, TestBankKey) + tx2, _ := types.SignTx(types.NewTransaction(nonce, ContractAddr, big.NewInt(0), 100000, big.NewInt(params.InitialBaseFee), data2), signer, TestBankKey) nonce++ - tx3, _ := types.SignTx(types.NewTransaction(nonce, ContractAddr, big.NewInt(0), 100000, nil, data3), signer, TestBankKey) + tx3, _ := types.SignTx(types.NewTransaction(nonce, ContractAddr, big.NewInt(0), 100000, big.NewInt(params.InitialBaseFee), data3), signer, TestBankKey) block.AddTx(tx1) block.AddTx(tx2) block.AddTx(tx3) @@ -111,14 +111,14 @@ func TestChainGen(i int, block *core.BlockGen) { block.SetCoinbase(Account1Addr) data := common.Hex2Bytes("C16431B900000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000") nonce := block.TxNonce(TestBankAddress) - tx, _ := types.SignTx(types.NewTransaction(nonce, ContractAddr, big.NewInt(0), 100000, nil, data), signer, TestBankKey) + tx, _ := types.SignTx(types.NewTransaction(nonce, ContractAddr, big.NewInt(0), 100000, big.NewInt(params.InitialBaseFee), data), signer, TestBankKey) block.AddTx(tx) case 5: // Block 6 has a tx from Account1Key which self-destructs the contract, it transfers no value // Block 6 is mined by Account2Addr block.SetCoinbase(Account2Addr) data := common.Hex2Bytes("43D726D6") - tx, _ := types.SignTx(types.NewTransaction(block.TxNonce(Account1Addr), ContractAddr, big.NewInt(0), 100000, nil, data), signer, Account1Key) + tx, _ := types.SignTx(types.NewTransaction(block.TxNonce(Account1Addr), ContractAddr, big.NewInt(0), 100000, big.NewInt(params.InitialBaseFee), data), signer, Account1Key) block.AddTx(tx) } } diff --git a/statediff/testhelpers/mocks/service_test.go b/statediff/testhelpers/mocks/service_test.go index e618268fd..a4f2c0d49 100644 --- a/statediff/testhelpers/mocks/service_test.go +++ b/statediff/testhelpers/mocks/service_test.go @@ -51,7 +51,7 @@ var ( }) minerAccount, _ = rlp.EncodeToBytes(state.Account{ Nonce: uint64(0), - Balance: big.NewInt(2000000000000000000), + Balance: big.NewInt(2000002625000000000), CodeHash: common.HexToHash("0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470").Bytes(), Root: common.HexToHash("0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"), }) @@ -61,7 +61,7 @@ var ( }) bankAccount, _ = rlp.EncodeToBytes(state.Account{ Nonce: uint64(1), - Balance: big.NewInt(testhelpers.TestBankFunds.Int64() - 10000), + Balance: big.NewInt(1999978999999990000), CodeHash: common.HexToHash("0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470").Bytes(), Root: common.HexToHash("0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"), }) @@ -129,6 +129,7 @@ func testSubscriptionAPI(t *testing.T) { }, } expectedStateDiffBytes, _ := rlp.EncodeToBytes(expectedStateDiff) + blockChan := make(chan *types.Block) parentBlockChain := make(chan *types.Block) serviceQuitChan := make(chan bool) @@ -145,6 +146,7 @@ func testSubscriptionAPI(t *testing.T) { Subscriptions: make(map[common.Hash]map[rpc.ID]statediff.Subscription), SubscriptionTypes: make(map[common.Hash]statediff.Params), } + mockService.Start() id := rpc.NewID() payloadChan := make(chan statediff.Payload) diff --git a/statediff/testhelpers/test_data.go b/statediff/testhelpers/test_data.go index cc5374da9..73def50a4 100644 --- a/statediff/testhelpers/test_data.go +++ b/statediff/testhelpers/test_data.go @@ -24,6 +24,7 @@ import ( "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core/rawdb" "github.com/ethereum/go-ethereum/crypto" + "github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/rlp" ) @@ -54,7 +55,7 @@ var ( TestBankKey, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291") TestBankAddress = crypto.PubkeyToAddress(TestBankKey.PublicKey) //0x71562b71999873DB5b286dF957af199Ec94617F7 BankLeafKey = AddressToLeafKey(TestBankAddress) - TestBankFunds = big.NewInt(100000000) + TestBankFunds = big.NewInt(params.Ether * 2) Genesis = core.GenesisBlockForTesting(Testdb, TestBankAddress, TestBankFunds) Account1Key, _ = crypto.HexToECDSA("8a1f9a8f95be41cd7ccb6168179afb4504aefe388d1e14474d32c45c72ce7b7a")