diff --git a/eth/tracers/live/supply_fill_test.go b/eth/tracers/live/supply_fill_test.go index ea7596c652..56e5388355 100644 --- a/eth/tracers/live/supply_fill_test.go +++ b/eth/tracers/live/supply_fill_test.go @@ -254,32 +254,27 @@ func TestSupplySelfdestruct(t *testing.T) { }, }, } + signer = types.LatestSigner(gspec.Config) + + testBlockGenerationFunc = func(b *core.BlockGen) { + txdata := &types.LegacyTx{ + Nonce: 0, + To: &aa, + Value: gwei5, + Gas: 150000, + GasPrice: gwei5, + Data: []byte{}, + } + + tx := types.NewTx(txdata) + tx, _ = types.SignTx(tx, signer, key1) + + b.AddTx(tx) + } ) - gspec.Config.TerminalTotalDifficulty = big.NewInt(0) - - signer := types.LatestSigner(gspec.Config) - - testBlockGenerationFunc := func(b *core.BlockGen) { - b.SetPoS() - - txdata := &types.LegacyTx{ - Nonce: 0, - To: &aa, - Value: gwei5, - Gas: 150000, - GasPrice: gwei5, - Data: []byte{}, - } - - tx := types.NewTx(txdata) - tx, _ = types.SignTx(tx, signer, key1) - - b.AddTx(tx) - } - // 1. Test pre Cancun - preCancunOutput, _, preCancunChain, err := testSupplyTracer(t, gspec, testBlockGenerationFunc) + preCancunOutput, preCancunDB, preCancunChain, err := testSupplyTracer(t, gspec, testBlockGenerationFunc) if err != nil { t.Fatalf("Pre-cancun failed to test supply tracer: %v", err) } @@ -299,28 +294,49 @@ func TestSupplySelfdestruct(t *testing.T) { t.Fatalf("Pre-cancun address \"%v\" balance, got %v exp %v\n", bb, got, exp) } - head := preCancunChain.CurrentBlock() - // Check live trace output - expected := supplyInfo{ - Burn: &supplyInfoBurn{ - EIP1559: big.NewInt(55289500000000), - Misc: big.NewInt(5000000000), - }, - Number: 1, - Hash: head.Hash(), - ParentHash: head.ParentHash, + var ( + head = preCancunChain.CurrentBlock() + // Check live trace output + expected = []supplyInfo{{ + Issuance: &supplyInfoIssuance{ + GenesisAlloc: new(big.Int).Mul(big.NewInt(2), big.NewInt(params.Ether)), + }, + Number: 0, + Hash: common.HexToHash("0xdd9fbe877f0b43987d2f0cda0df176b7939be14f33eb5137f16e6eddf4562706"), + ParentHash: common.HexToHash("0x0000000000000000000000000000000000000000000000000000000000000000"), + }, { + Issuance: &supplyInfoIssuance{ + Reward: new(big.Int).Mul(big.NewInt(2), big.NewInt(params.Ether)), + }, + Burn: &supplyInfoBurn{ + EIP1559: big.NewInt(55289500000000), + Misc: big.NewInt(5000000000), + }, + Number: 1, + Hash: head.Hash(), + ParentHash: head.ParentHash, + }} + ) + + compareAsJSON(t, expected, preCancunOutput) + preCancunTest, err := btFromChain(preCancunDB, preCancunChain, nil) + if err != nil { + t.Fatalf("failed to fill tests from chain: %v", err) } - - actual := preCancunOutput[expected.Number] - - compareAsJSON(t, expected, actual) + preCancunTest.Expected = expected // 2. Test post Cancun cancunTime := uint64(0) + gspec.Config = params.MergedTestChainConfig gspec.Config.ShanghaiTime = &cancunTime gspec.Config.CancunTime = &cancunTime - - postCancunOutput, _, postCancunChain, err := testSupplyTracer(t, gspec, testBlockGenerationFunc) + gspec.Config.TerminalTotalDifficulty = big.NewInt(0) + signer = types.LatestSigner(gspec.Config) + posTestBlockGenerationFunc := func(b *core.BlockGen) { + b.SetPoS() + testBlockGenerationFunc(b) + } + postCancunOutput, postCancunDB, postCancunChain, err := testSupplyTracer(t, gspec, posTestBlockGenerationFunc) if err != nil { t.Fatalf("Post-cancun failed to test supply tracer: %v", err) } @@ -342,18 +358,29 @@ func TestSupplySelfdestruct(t *testing.T) { // Check live trace output head = postCancunChain.CurrentBlock() - expected = supplyInfo{ + expected = []supplyInfo{{ + Issuance: &supplyInfoIssuance{ + GenesisAlloc: new(big.Int).Mul(big.NewInt(2), big.NewInt(params.Ether)), + }, + Number: 0, + Hash: common.HexToHash("0x16d2bb0b366d3963bf2d8d75cb4b3bc0f233047c948fa746cbd38ac82bf9cfe9"), + ParentHash: common.HexToHash("0x0000000000000000000000000000000000000000000000000000000000000000"), + }, { Burn: &supplyInfoBurn{ EIP1559: big.NewInt(55289500000000), }, Number: 1, Hash: head.Hash(), ParentHash: head.ParentHash, + }} + + compareAsJSON(t, expected, postCancunOutput) + postCancunTest, err := btFromChain(postCancunDB, postCancunChain, nil) + if err != nil { + t.Fatalf("failed to fill tests from chain: %v", err) } - - actual = postCancunOutput[expected.Number] - - compareAsJSON(t, expected, actual) + postCancunTest.Expected = expected + writeBTs(t, map[string]*BlockTest{"selfdestruct_grayGlacier": preCancunTest, "selfdestruct_cancun": postCancunTest}) } // Tests selfdestructing contract to send its balance to itself (burn). @@ -531,7 +558,6 @@ func testSupplyTracer(t *testing.T, genesis *core.Genesis, gen func(*core.BlockG gen(b) }) - fmt.Printf("blocks: %v\n", blocks) if n, err := chain.InsertChain(blocks); err != nil { return nil, nil, chain, fmt.Errorf("block %d: failed to insert into chain: %v", n, err) } @@ -581,9 +607,11 @@ func writeArtifact(t *testing.T, name string, db ethdb.Database, chain *core.Blo t.Fatalf("failed to fill tests from chain: %v", err) } bt.Expected = expected - result := make(map[string]any) - result[name] = bt - enc, err := json.MarshalIndent(&result, "", " ") + writeBTs(t, map[string]*BlockTest{name: bt}) +} + +func writeBTs(t *testing.T, tests map[string]*BlockTest) { + enc, err := json.MarshalIndent(&tests, "", " ") if err != nil { t.Fatalf("failed to marshal tests: %v", err) } diff --git a/eth/tracers/live/testdata/supply/selfdestruct.json b/eth/tracers/live/testdata/supply/selfdestruct.json new file mode 100644 index 0000000000..717041be2d --- /dev/null +++ b/eth/tracers/live/testdata/supply/selfdestruct.json @@ -0,0 +1,186 @@ +{ + "selfdestruct_cancun": { + "blocks": [ + { + "BlockHeader": { + "BaseFeePerGas": "0x342770c0", + "BlobGasUsed": "0x0", + "Bloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "Coinbase": "0x0100000000000000000000000000000000000000", + "Difficulty": "0x0", + "ExcessBlobGas": "0x0", + "ExtraData": "0x", + "GasLimit": "0x47e7c4", + "GasUsed": "0xf6d4", + "Hash": "0xd5a0d7e4b5fa687dd355938a24e34229db3c01cd2a999e5023369016371a98ac", + "MixHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "Nonce": "0x0000000000000000", + "Number": "0x1", + "ParentBeaconBlockRoot": "0x0000000000000000000000000000000000000000000000000000000000000000", + "ParentHash": "0x16d2bb0b366d3963bf2d8d75cb4b3bc0f233047c948fa746cbd38ac82bf9cfe9", + "ReceiptTrie": "0x6bd5a500652764abb50a6bfd441a2f52f9dc2a38644170adb7951804998e0176", + "StateRoot": "0x90899467081bda450d3ef7a6fb0f0c37ddfefea28c810a38323af55f79122c50", + "Timestamp": "0xa", + "TransactionsTrie": "0x8cfce1fa6bf3370d316650ab9ac77c2cfd69c9b3fd4e3def07b9e650769836e0", + "UncleHash": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", + "WithdrawalsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421" + }, + "ExpectException": "", + "Rlp": "0xf902aef9023ba016d2bb0b366d3963bf2d8d75cb4b3bc0f233047c948fa746cbd38ac82bf9cfe9a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347940100000000000000000000000000000000000000a090899467081bda450d3ef7a6fb0f0c37ddfefea28c810a38323af55f79122c50a08cfce1fa6bf3370d316650ab9ac77c2cfd69c9b3fd4e3def07b9e650769836e0a06bd5a500652764abb50a6bfd441a2f52f9dc2a38644170adb7951804998e0176b901000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080018347e7c482f6d40a80a0000000000000000000000000000000000000000000000000000000000000000088000000000000000084342770c0a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b4218080a00000000000000000000000000000000000000000000000000000000000000000f86cf86a8085012a05f200830249f094111111111111111111111111111111111111111185012a05f2008026a03c8f16fd94b4c5e56c1c2ff249685a19b2afedb5d6529fc2950a79c3f9c8d599a01a7882a80e333850532a917631347435237f751c9f7a0b810aae8098f5a6225ec0c0", + "UncleHeaders": null + } + ], + "expected": [ + { + "issuance": { + "genesisAlloc": "0x1bc16d674ec80000" + }, + "blockNumber": 0, + "hash": "0x16d2bb0b366d3963bf2d8d75cb4b3bc0f233047c948fa746cbd38ac82bf9cfe9", + "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000" + }, + { + "burn": { + "1559": "0x32491701df00" + }, + "blockNumber": 1, + "hash": "0xd5a0d7e4b5fa687dd355938a24e34229db3c01cd2a999e5023369016371a98ac", + "parentHash": "0x16d2bb0b366d3963bf2d8d75cb4b3bc0f233047c948fa746cbd38ac82bf9cfe9" + } + ], + "genesisBlockHeader": { + "BaseFeePerGas": "0x3b9aca00", + "BlobGasUsed": "0x0", + "Bloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "Coinbase": "0x0000000000000000000000000000000000000000", + "Difficulty": "0x20000", + "ExcessBlobGas": "0x0", + "ExtraData": "0x", + "GasLimit": "0x47e7c4", + "GasUsed": "0x0", + "Hash": "0x16d2bb0b366d3963bf2d8d75cb4b3bc0f233047c948fa746cbd38ac82bf9cfe9", + "MixHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "Nonce": "0x0000000000000000", + "Number": "0x0", + "ParentBeaconBlockRoot": "0x0000000000000000000000000000000000000000000000000000000000000000", + "ParentHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "ReceiptTrie": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "StateRoot": "0xb4187a1038a0611c5ca076f45fdbcf3d741c3e126a57b966edd44f844323a72f", + "Timestamp": "0x0", + "TransactionsTrie": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "UncleHash": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", + "WithdrawalsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421" + }, + "lastblockhash": "d5a0d7e4b5fa687dd355938a24e34229db3c01cd2a999e5023369016371a98ac", + "network": "Cancun", + "postState": {}, + "pre": { + "0x1111111111111111111111111111111111111111": { + "balance": "0x0", + "code": "0x61face60f01b6000527322222222222222222222222222222222222222226000806002600080855af160008103603457600080fd5b60008060008034865af1905060008103604c57600080fd5b5050" + }, + "0x2222222222222222222222222222222222222222": { + "balance": "0xde0b6b3a7640000", + "code": "0x6000357fface000000000000000000000000000000000000000000000000000000000000808203602f57610dad80ff5b5050" + }, + "0x71562b71999873db5b286df957af199ec94617f7": { + "balance": "0xde0b6b3a7640000" + } + }, + "sealEngine": "" + }, + "selfdestruct_grayGlacier": { + "blocks": [ + { + "BlockHeader": { + "BaseFeePerGas": "0x342770c0", + "BlobGasUsed": null, + "Bloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "Coinbase": "0x0100000000000000000000000000000000000000", + "Difficulty": "0x20000", + "ExcessBlobGas": null, + "ExtraData": "0x", + "GasLimit": "0x47e7c4", + "GasUsed": "0xf6d4", + "Hash": "0xf7f68f34d07d7acc5dad5ba9bbde99c82347a74471801e7c0c22e5b2ed6d0bc6", + "MixHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "Nonce": "0x0000000000000000", + "Number": "0x1", + "ParentBeaconBlockRoot": null, + "ParentHash": "0xdd9fbe877f0b43987d2f0cda0df176b7939be14f33eb5137f16e6eddf4562706", + "ReceiptTrie": "0x6bd5a500652764abb50a6bfd441a2f52f9dc2a38644170adb7951804998e0176", + "StateRoot": "0xbd0a2414c9584c14678caa39773fa17db8aab8667f897b251bb3fc025822e449", + "Timestamp": "0xa", + "TransactionsTrie": "0x8cfce1fa6bf3370d316650ab9ac77c2cfd69c9b3fd4e3def07b9e650769836e0", + "UncleHash": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", + "WithdrawalsRoot": null + }, + "ExpectException": "", + "Rlp": "0xf9026cf901faa0dd9fbe877f0b43987d2f0cda0df176b7939be14f33eb5137f16e6eddf4562706a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347940100000000000000000000000000000000000000a0bd0a2414c9584c14678caa39773fa17db8aab8667f897b251bb3fc025822e449a08cfce1fa6bf3370d316650ab9ac77c2cfd69c9b3fd4e3def07b9e650769836e0a06bd5a500652764abb50a6bfd441a2f52f9dc2a38644170adb7951804998e0176b901000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000083020000018347e7c482f6d40a80a0000000000000000000000000000000000000000000000000000000000000000088000000000000000084342770c0f86cf86a8085012a05f200830249f094111111111111111111111111111111111111111185012a05f2008026a03c8f16fd94b4c5e56c1c2ff249685a19b2afedb5d6529fc2950a79c3f9c8d599a01a7882a80e333850532a917631347435237f751c9f7a0b810aae8098f5a6225ec0", + "UncleHeaders": null + } + ], + "expected": [ + { + "issuance": { + "genesisAlloc": "0x1bc16d674ec80000" + }, + "blockNumber": 0, + "hash": "0xdd9fbe877f0b43987d2f0cda0df176b7939be14f33eb5137f16e6eddf4562706", + "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000" + }, + { + "issuance": { + "reward": "0x1bc16d674ec80000" + }, + "burn": { + "1559": "0x32491701df00", + "misc": "0x12a05f200" + }, + "blockNumber": 1, + "hash": "0xf7f68f34d07d7acc5dad5ba9bbde99c82347a74471801e7c0c22e5b2ed6d0bc6", + "parentHash": "0xdd9fbe877f0b43987d2f0cda0df176b7939be14f33eb5137f16e6eddf4562706" + } + ], + "genesisBlockHeader": { + "BaseFeePerGas": "0x3b9aca00", + "BlobGasUsed": null, + "Bloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "Coinbase": "0x0000000000000000000000000000000000000000", + "Difficulty": "0x20000", + "ExcessBlobGas": null, + "ExtraData": "0x", + "GasLimit": "0x47e7c4", + "GasUsed": "0x0", + "Hash": "0xdd9fbe877f0b43987d2f0cda0df176b7939be14f33eb5137f16e6eddf4562706", + "MixHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "Nonce": "0x0000000000000000", + "Number": "0x0", + "ParentBeaconBlockRoot": null, + "ParentHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "ReceiptTrie": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "StateRoot": "0xb4187a1038a0611c5ca076f45fdbcf3d741c3e126a57b966edd44f844323a72f", + "Timestamp": "0x0", + "TransactionsTrie": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "UncleHash": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", + "WithdrawalsRoot": null + }, + "lastblockhash": "f7f68f34d07d7acc5dad5ba9bbde99c82347a74471801e7c0c22e5b2ed6d0bc6", + "network": "GrayGlacier", + "postState": {}, + "pre": { + "0x1111111111111111111111111111111111111111": { + "balance": "0x0", + "code": "0x61face60f01b6000527322222222222222222222222222222222222222226000806002600080855af160008103603457600080fd5b60008060008034865af1905060008103604c57600080fd5b5050" + }, + "0x2222222222222222222222222222222222222222": { + "balance": "0xde0b6b3a7640000", + "code": "0x6000357fface000000000000000000000000000000000000000000000000000000000000808203602f57610dad80ff5b5050" + }, + "0x71562b71999873db5b286df957af199ec94617f7": { + "balance": "0xde0b6b3a7640000" + } + }, + "sealEngine": "" + } +} \ No newline at end of file