diff --git a/core/blockchain.go b/core/blockchain.go index 5d1cf533fc13..3683bf1d7924 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -415,7 +415,7 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, genesis *Genesis } if bc.logger != nil && bc.logger.OnGenesisBlock != nil { if block := bc.CurrentBlock(); block.Number.Uint64() == 0 { - alloc, err := getGenesisState(bc.db, block.Hash()) + alloc, err := GetGenesisState(bc.db, block.Hash()) if err != nil { return nil, fmt.Errorf("failed to get genesis state: %w", err) } diff --git a/core/genesis.go b/core/genesis.go index 8ea9bfb30ff8..cccaa8235a72 100644 --- a/core/genesis.go +++ b/core/genesis.go @@ -177,7 +177,7 @@ func flushAlloc(ga *types.GenesisAlloc, triedb *triedb.Database) (common.Hash, e return root, nil } -func getGenesisState(db ethdb.Database, blockhash common.Hash) (alloc types.GenesisAlloc, err error) { +func GetGenesisState(db ethdb.Database, blockhash common.Hash) (alloc types.GenesisAlloc, err error) { blob := rawdb.ReadGenesisStateSpec(db, blockhash) if len(blob) != 0 { if err := alloc.UnmarshalJSON(blob); err != nil { diff --git a/eth/catalyst/api.go b/eth/catalyst/api.go index 435b1997ff56..877c0105961f 100644 --- a/eth/catalyst/api.go +++ b/eth/catalyst/api.go @@ -198,7 +198,7 @@ func (api *ConsensusAPI) ForkchoiceUpdatedV2(update engine.ForkchoiceStateV1, pa if params.BeaconRoot != nil { return engine.STATUS_INVALID, engine.InvalidPayloadAttributes.With(errors.New("unexpected beacon root")) } - switch api.eth.BlockChain().Config().LatestFork(params.Timestamp) { + switch api.eth.BlockChain().Config().LatestPostLondonFork(params.Timestamp) { case forks.Paris: if params.Withdrawals != nil { return engine.STATUS_INVALID, engine.InvalidPayloadAttributes.With(errors.New("withdrawals before shanghai")) @@ -224,7 +224,7 @@ func (api *ConsensusAPI) ForkchoiceUpdatedV3(update engine.ForkchoiceStateV1, pa if params.BeaconRoot == nil { return engine.STATUS_INVALID, engine.InvalidPayloadAttributes.With(errors.New("missing beacon root")) } - if api.eth.BlockChain().Config().LatestFork(params.Timestamp) != forks.Cancun && api.eth.BlockChain().Config().LatestFork(params.Timestamp) != forks.Prague { + if api.eth.BlockChain().Config().LatestPostLondonFork(params.Timestamp) != forks.Cancun && api.eth.BlockChain().Config().LatestPostLondonFork(params.Timestamp) != forks.Prague { return engine.STATUS_INVALID, engine.UnsupportedFork.With(errors.New("forkchoiceUpdatedV3 must only be called for cancun payloads")) } } @@ -477,7 +477,7 @@ func (api *ConsensusAPI) NewPayloadV2(params engine.ExecutableData) (engine.Payl if api.eth.BlockChain().Config().IsCancun(api.eth.BlockChain().Config().LondonBlock, params.Timestamp) { return engine.PayloadStatusV1{Status: engine.INVALID}, engine.InvalidParams.With(errors.New("can't use newPayloadV2 post-cancun")) } - if api.eth.BlockChain().Config().LatestFork(params.Timestamp) == forks.Shanghai { + if api.eth.BlockChain().Config().LatestPostLondonFork(params.Timestamp) == forks.Shanghai { if params.Withdrawals == nil { return engine.PayloadStatusV1{Status: engine.INVALID}, engine.InvalidParams.With(errors.New("nil withdrawals post-shanghai")) } @@ -514,7 +514,7 @@ func (api *ConsensusAPI) NewPayloadV3(params engine.ExecutableData, versionedHas return engine.PayloadStatusV1{Status: engine.INVALID}, engine.InvalidParams.With(errors.New("nil beaconRoot post-cancun")) } - if api.eth.BlockChain().Config().LatestFork(params.Timestamp) != forks.Cancun { + if api.eth.BlockChain().Config().LatestPostLondonFork(params.Timestamp) != forks.Cancun { return engine.PayloadStatusV1{Status: engine.INVALID}, engine.UnsupportedFork.With(errors.New("newPayloadV3 must only be called for cancun payloads")) } return api.newPayload(params, versionedHashes, beaconRoot) @@ -542,7 +542,7 @@ func (api *ConsensusAPI) NewPayloadV4(params engine.ExecutableData, versionedHas return engine.PayloadStatusV1{Status: engine.INVALID}, engine.InvalidParams.With(errors.New("nil beaconRoot post-cancun")) } - if api.eth.BlockChain().Config().LatestFork(params.Timestamp) != forks.Prague { + if api.eth.BlockChain().Config().LatestPostLondonFork(params.Timestamp) != forks.Prague { return engine.PayloadStatusV1{Status: engine.INVALID}, engine.UnsupportedFork.With(errors.New("newPayloadV4 must only be called for prague payloads")) } return api.newPayload(params, versionedHashes, beaconRoot) diff --git a/eth/tracers/live/supply_test.go b/eth/tracers/live/supply_test.go new file mode 100644 index 000000000000..b06c38db307e --- /dev/null +++ b/eth/tracers/live/supply_test.go @@ -0,0 +1,141 @@ +// Copyright 2024 The go-ethereum Authors +// This file is part of the go-ethereum library. +// +// The go-ethereum library is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// The go-ethereum library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with the go-ethereum library. If not, see . + +package live + +import ( + "bufio" + "bytes" + "encoding/json" + "fmt" + "os" + "path" + "path/filepath" + "strings" + "testing" + "unicode" + + "github.com/ethereum/go-ethereum/tests" +) + +type blockTest struct { + bt *tests.BlockTest + Expected []supplyInfo `json:"expected"` +} + +func (bt *blockTest) UnmarshalJSON(data []byte) error { + tmp := make(map[string]json.RawMessage) + if err := json.Unmarshal(data, &tmp); err != nil { + return err + } + if err := json.Unmarshal(tmp["expected"], &bt.Expected); err != nil { + return err + } + if err := json.Unmarshal(data, &bt.bt); err != nil { + return err + } + return nil +} + +// The tests have been filled using the executable at +// eth/tracers/live/tests/supply_filler.go. +func TestSupplyTracerBlockchain(t *testing.T) { + dirPath := filepath.Join("tests", "supply") + files, err := os.ReadDir(dirPath) + if err != nil { + t.Fatalf("failed to retrieve tracer test suite: %v", err) + } + for _, file := range files { + if !strings.HasSuffix(file.Name(), ".json") { + continue + } + file := file // capture range variable + var testcases map[string]*blockTest + var blob []byte + // Tracer test found, read if from disk + if blob, err = os.ReadFile(filepath.Join(dirPath, file.Name())); err != nil { + t.Fatalf("failed to read testcase: %v", err) + } + if err := json.Unmarshal(blob, &testcases); err != nil { + t.Fatalf("failed to parse testcase %s: %v", file.Name(), err) + } + for testname, test := range testcases { + t.Run(fmt.Sprintf("%s/%s", camel(strings.TrimSuffix(file.Name(), ".json")), testname), func(t *testing.T) { + t.Parallel() + + traceOutputPath := filepath.ToSlash(t.TempDir()) + traceOutputFilename := path.Join(traceOutputPath, "supply.jsonl") + // Load supply tracer + tracer, err := newSupply(json.RawMessage(fmt.Sprintf(`{"path":"%s"}`, traceOutputPath))) + if err != nil { + t.Fatalf("failed to create tracer: %v", err) + } + if err := test.bt.Run(false, "path", false, tracer, nil); err != nil { + t.Errorf("failed to run test: %v\n", err) + } + // Check and compare the results + file, err := os.OpenFile(traceOutputFilename, os.O_RDONLY, 0666) + if err != nil { + t.Fatalf("failed to open output file: %v", err) + } + defer file.Close() + + var ( + output []supplyInfo + scanner = bufio.NewScanner(file) + ) + for scanner.Scan() { + blockBytes := scanner.Bytes() + var info supplyInfo + if err := json.Unmarshal(blockBytes, &info); err != nil { + t.Fatalf("failed to unmarshal result: %v", err) + } + output = append(output, info) + } + if len(output) != len(test.Expected) { + fmt.Printf("output: %v\n", output) + t.Fatalf("expected %d supply infos, got %d", len(test.Expected), len(output)) + } + for i, expected := range test.Expected { + compareAsJSON(t, expected, output[i]) + } + }) + } + } +} + +// camel converts a snake cased input string into a camel cased output. +func camel(str string) string { + pieces := strings.Split(str, "_") + for i := 1; i < len(pieces); i++ { + pieces[i] = string(unicode.ToUpper(rune(pieces[i][0]))) + pieces[i][1:] + } + return strings.Join(pieces, "") +} + +func compareAsJSON(t *testing.T, expected interface{}, actual interface{}) { + want, err := json.Marshal(expected) + if err != nil { + t.Fatalf("failed to marshal expected value to JSON: %v", err) + } + have, err := json.Marshal(actual) + if err != nil { + t.Fatalf("failed to marshal actual value to JSON: %v", err) + } + if !bytes.Equal(want, have) { + t.Fatalf("incorrect supply info:\nexpected:\n%s\ngot:\n%s", string(want), string(have)) + } +} diff --git a/eth/tracers/live/tests/supply/eip1559_burn.json b/eth/tracers/live/tests/supply/eip1559_burn.json new file mode 100644 index 000000000000..44fe0a328e77 --- /dev/null +++ b/eth/tracers/live/tests/supply/eip1559_burn.json @@ -0,0 +1,87 @@ +{ + "eip1559_burn_grayGlacier": { + "blocks": [ + { + "BlockHeader": { + "BaseFeePerGas": "0x342770c0", + "BlobGasUsed": null, + "Bloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "Coinbase": "0x0100000000000000000000000000000000000000", + "Difficulty": "0x20000", + "ExcessBlobGas": null, + "ExtraData": "0x", + "GasLimit": "0x47e7c4", + "GasUsed": "0x5208", + "Hash": "0x7891c11e0cc121c578c62c4b42622b909f4ded1a66fea03336c303e6bc8d6f88", + "MixHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "Nonce": "0x0000000000000000", + "Number": "0x1", + "ParentBeaconBlockRoot": null, + "ParentHash": "0xc4265421181cafc43e4b97ae4f21530e37e00320f219a13311482c9c552bcdc7", + "ReceiptTrie": "0xf78dfb743fbd92ade140711c8bbc542b5e307f0ab7984eff35d751969fe57efa", + "StateRoot": "0x208dc296c4dc37b673a99aed4837174a2ed7f5380ad802d5aed0295e6795241d", + "Timestamp": "0xa", + "TransactionsTrie": "0x4ff793bd96fb3d8d186476e59a5118de9f1813b3f22bd8a64875a535422ac62f", + "UncleHash": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", + "WithdrawalsRoot": null + }, + "ExpectException": "", + "Rlp": "0xf9026cf901faa0c4265421181cafc43e4b97ae4f21530e37e00320f219a13311482c9c552bcdc7a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347940100000000000000000000000000000000000000a0208dc296c4dc37b673a99aed4837174a2ed7f5380ad802d5aed0295e6795241da04ff793bd96fb3d8d186476e59a5118de9f1813b3f22bd8a64875a535422ac62fa0f78dfb743fbd92ade140711c8bbc542b5e307f0ab7984eff35d751969fe57efab901000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000083020000018347e7c48252080a80a0000000000000000000000000000000000000000000000000000000000000000088000000000000000084342770c0f86cb86a02f86701800285012a05f20082520894000000000000000000000000000000000000aaaa8080c001a083b46f9cdfcb2c087934d9ae79eedeaa53df39b73c58b7cba5c77d69039bdc64a05af6144d3123f5b9850f9c40fc4b8ce02bf4782f6d6bca3f88e553689d66480bc0", + "UncleHeaders": null + } + ], + "expected": [ + { + "issuance": { + "genesisAlloc": "0xde0b6b3a7640000" + }, + "blockNumber": 0, + "hash": "0xc4265421181cafc43e4b97ae4f21530e37e00320f219a13311482c9c552bcdc7", + "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000" + }, + { + "issuance": { + "reward": "0x1bc16d674ec80000" + }, + "burn": { + "1559": "0x10b643590600" + }, + "blockNumber": 1, + "hash": "0x7891c11e0cc121c578c62c4b42622b909f4ded1a66fea03336c303e6bc8d6f88", + "parentHash": "0xc4265421181cafc43e4b97ae4f21530e37e00320f219a13311482c9c552bcdc7" + } + ], + "genesisBlockHeader": { + "BaseFeePerGas": "0x3b9aca00", + "BlobGasUsed": null, + "Bloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "Coinbase": "0x0000000000000000000000000000000000000000", + "Difficulty": "0x20000", + "ExcessBlobGas": null, + "ExtraData": "0x", + "GasLimit": "0x47e7c4", + "GasUsed": "0x0", + "Hash": "0xc4265421181cafc43e4b97ae4f21530e37e00320f219a13311482c9c552bcdc7", + "MixHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "Nonce": "0x0000000000000000", + "Number": "0x0", + "ParentBeaconBlockRoot": null, + "ParentHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "ReceiptTrie": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "StateRoot": "0x9f88be00eee1114edfd9372f52560aab3980a142efe8b5b39a09644075084275", + "Timestamp": "0x0", + "TransactionsTrie": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "UncleHash": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", + "WithdrawalsRoot": null + }, + "lastblockhash": "7891c11e0cc121c578c62c4b42622b909f4ded1a66fea03336c303e6bc8d6f88", + "network": "GrayGlacier", + "postState": {}, + "pre": { + "0x71562b71999873db5b286df957af199ec94617f7": { + "balance": "0xde0b6b3a7640000" + } + }, + "sealEngine": "" + } +} \ No newline at end of file diff --git a/eth/tracers/live/tests/supply/genesis_alloc.json b/eth/tracers/live/tests/supply/genesis_alloc.json new file mode 100644 index 000000000000..940ef6735ddb --- /dev/null +++ b/eth/tracers/live/tests/supply/genesis_alloc.json @@ -0,0 +1,87 @@ +{ + "genesis_alloc_grayGlacier": { + "blocks": [ + { + "BlockHeader": { + "BaseFeePerGas": "0x342770c0", + "BlobGasUsed": null, + "Bloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "Coinbase": "0x0100000000000000000000000000000000000000", + "Difficulty": "0x20000", + "ExcessBlobGas": null, + "ExtraData": "0x", + "GasLimit": "0x47e7c4", + "GasUsed": "0x0", + "Hash": "0x37bb7e9b45f4fb7b311abb5f815e3e00d3382d83a2c39b9b0bd22b717566cd04", + "MixHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "Nonce": "0x0000000000000000", + "Number": "0x1", + "ParentBeaconBlockRoot": null, + "ParentHash": "0xbcc9466e9fc6a8b56f4b29ca353a421ff8b51a0c1a58ca4743b427605b08f2ca", + "ReceiptTrie": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "StateRoot": "0x98d03dd72cdfee5c55acc619a1f1bcb1be6d1a10b25b512e7c4e4c4413357940", + "Timestamp": "0xa", + "TransactionsTrie": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "UncleHash": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", + "WithdrawalsRoot": null + }, + "ExpectException": "", + "Rlp": "0xf901fdf901f8a0bcc9466e9fc6a8b56f4b29ca353a421ff8b51a0c1a58ca4743b427605b08f2caa01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347940100000000000000000000000000000000000000a098d03dd72cdfee5c55acc619a1f1bcb1be6d1a10b25b512e7c4e4c4413357940a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b901000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000083020000018347e7c4800a80a0000000000000000000000000000000000000000000000000000000000000000088000000000000000084342770c0c0c0", + "UncleHeaders": null + } + ], + "expected": [ + { + "issuance": { + "genesisAlloc": "0x1bc16d674ec80000" + }, + "blockNumber": 0, + "hash": "0xbcc9466e9fc6a8b56f4b29ca353a421ff8b51a0c1a58ca4743b427605b08f2ca", + "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000" + }, + { + "issuance": { + "reward": "0x1bc16d674ec80000" + }, + "blockNumber": 1, + "hash": "0x37bb7e9b45f4fb7b311abb5f815e3e00d3382d83a2c39b9b0bd22b717566cd04", + "parentHash": "0xbcc9466e9fc6a8b56f4b29ca353a421ff8b51a0c1a58ca4743b427605b08f2ca" + } + ], + "genesisBlockHeader": { + "BaseFeePerGas": "0x3b9aca00", + "BlobGasUsed": null, + "Bloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "Coinbase": "0x0000000000000000000000000000000000000000", + "Difficulty": "0x20000", + "ExcessBlobGas": null, + "ExtraData": "0x", + "GasLimit": "0x47e7c4", + "GasUsed": "0x0", + "Hash": "0xbcc9466e9fc6a8b56f4b29ca353a421ff8b51a0c1a58ca4743b427605b08f2ca", + "MixHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "Nonce": "0x0000000000000000", + "Number": "0x0", + "ParentBeaconBlockRoot": null, + "ParentHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "ReceiptTrie": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "StateRoot": "0x4eaed1ec95373a6cad785d6b2506606a2c19e2e7c6d7faf4bab3472c21861b27", + "Timestamp": "0x0", + "TransactionsTrie": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "UncleHash": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", + "WithdrawalsRoot": null + }, + "lastblockhash": "37bb7e9b45f4fb7b311abb5f815e3e00d3382d83a2c39b9b0bd22b717566cd04", + "network": "GrayGlacier", + "postState": {}, + "pre": { + "0x703c4b2bd70c169f5717101caee543299fc946c7": { + "balance": "0xde0b6b3a7640000" + }, + "0x71562b71999873db5b286df957af199ec94617f7": { + "balance": "0xde0b6b3a7640000" + } + }, + "sealEngine": "" + } +} \ No newline at end of file diff --git a/eth/tracers/live/tests/supply/omitted_fields.json b/eth/tracers/live/tests/supply/omitted_fields.json new file mode 100644 index 000000000000..e5d4a81ab053 --- /dev/null +++ b/eth/tracers/live/tests/supply/omitted_fields.json @@ -0,0 +1,74 @@ +{ + "omitted_fields_cancun": { + "blocks": [ + { + "BlockHeader": { + "BaseFeePerGas": "0x342770c0", + "BlobGasUsed": "0x0", + "Bloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "Coinbase": "0x0100000000000000000000000000000000000000", + "Difficulty": "0x0", + "ExcessBlobGas": "0x0", + "ExtraData": "0x", + "GasLimit": "0x47e7c4", + "GasUsed": "0x0", + "Hash": "0xe430cdf604a88b9d713d4f89fd100ddddf38c1cc6b049e3d5df563c7bfd320fc", + "MixHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "Nonce": "0x0000000000000000", + "Number": "0x1", + "ParentBeaconBlockRoot": "0x0000000000000000000000000000000000000000000000000000000000000000", + "ParentHash": "0x52f276d96f0afaaf2c3cb358868bdc2779c4b0cb8de3e7e5302e247c0b66a703", + "ReceiptTrie": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "StateRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "Timestamp": "0xa", + "TransactionsTrie": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "UncleHash": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", + "WithdrawalsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421" + }, + "ExpectException": "", + "Rlp": "0xf9023ff90239a052f276d96f0afaaf2c3cb358868bdc2779c4b0cb8de3e7e5302e247c0b66a703a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347940100000000000000000000000000000000000000a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b901000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080018347e7c4800a80a0000000000000000000000000000000000000000000000000000000000000000088000000000000000084342770c0a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b4218080a00000000000000000000000000000000000000000000000000000000000000000c0c0c0", + "UncleHeaders": null + } + ], + "expected": [ + { + "blockNumber": 0, + "hash": "0x52f276d96f0afaaf2c3cb358868bdc2779c4b0cb8de3e7e5302e247c0b66a703", + "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000" + }, + { + "blockNumber": 1, + "hash": "0xe430cdf604a88b9d713d4f89fd100ddddf38c1cc6b049e3d5df563c7bfd320fc", + "parentHash": "0x52f276d96f0afaaf2c3cb358868bdc2779c4b0cb8de3e7e5302e247c0b66a703" + } + ], + "genesisBlockHeader": { + "BaseFeePerGas": "0x3b9aca00", + "BlobGasUsed": "0x0", + "Bloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "Coinbase": "0x0000000000000000000000000000000000000000", + "Difficulty": "0x20000", + "ExcessBlobGas": "0x0", + "ExtraData": "0x", + "GasLimit": "0x47e7c4", + "GasUsed": "0x0", + "Hash": "0x52f276d96f0afaaf2c3cb358868bdc2779c4b0cb8de3e7e5302e247c0b66a703", + "MixHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "Nonce": "0x0000000000000000", + "Number": "0x0", + "ParentBeaconBlockRoot": "0x0000000000000000000000000000000000000000000000000000000000000000", + "ParentHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "ReceiptTrie": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "StateRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "Timestamp": "0x0", + "TransactionsTrie": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "UncleHash": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", + "WithdrawalsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421" + }, + "lastblockhash": "e430cdf604a88b9d713d4f89fd100ddddf38c1cc6b049e3d5df563c7bfd320fc", + "network": "Cancun", + "postState": {}, + "pre": {}, + "sealEngine": "" + } +} \ No newline at end of file diff --git a/eth/tracers/live/tests/supply/selfdestruct.json b/eth/tracers/live/tests/supply/selfdestruct.json new file mode 100644 index 000000000000..ae3dff06c053 --- /dev/null +++ b/eth/tracers/live/tests/supply/selfdestruct.json @@ -0,0 +1,209 @@ +{ + "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": { + "0x0000000000000000000000000000000000000dad": { + "balance": "0xde0b6b3a7640000" + }, + "0x1111111111111111111111111111111111111111": { + "balance": "0x0", + "code": "0x61face60f01b6000527322222222222222222222222222222222222222226000806002600080855af160008103603457600080fd5b60008060008034865af1905060008103604c57600080fd5b5050" + }, + "0x2222222222222222222222222222222222222222": { + "balance": "0x12a05f200", + "code": "0x6000357fface000000000000000000000000000000000000000000000000000000000000808203602f57610dad80ff5b5050" + } + }, + "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": { + "0x0000000000000000000000000000000000000dad": { + "balance": "0xde0b6b3a7640000" + }, + "0x1111111111111111111111111111111111111111": { + "balance": "0x0", + "code": "0x61face60f01b6000527322222222222222222222222222222222222222226000806002600080855af160008103603457600080fd5b60008060008034865af1905060008103604c57600080fd5b5050" + }, + "0x2222222222222222222222222222222222222222": { + "balance": "0x0" + } + }, + "pre": { + "0x1111111111111111111111111111111111111111": { + "balance": "0x0", + "code": "0x61face60f01b6000527322222222222222222222222222222222222222226000806002600080855af160008103603457600080fd5b60008060008034865af1905060008103604c57600080fd5b5050" + }, + "0x2222222222222222222222222222222222222222": { + "balance": "0xde0b6b3a7640000", + "code": "0x6000357fface000000000000000000000000000000000000000000000000000000000000808203602f57610dad80ff5b5050" + }, + "0x71562b71999873db5b286df957af199ec94617f7": { + "balance": "0xde0b6b3a7640000" + } + }, + "sealEngine": "" + } +} \ No newline at end of file diff --git a/eth/tracers/live/tests/supply/selfdestruct_itself_and_revert.json b/eth/tracers/live/tests/supply/selfdestruct_itself_and_revert.json new file mode 100644 index 000000000000..05336e81a83f --- /dev/null +++ b/eth/tracers/live/tests/supply/selfdestruct_itself_and_revert.json @@ -0,0 +1,104 @@ +{ + "selfdestruct_itself_and_revert_grayGlacier": { + "blocks": [ + { + "BlockHeader": { + "BaseFeePerGas": "0x342770c0", + "BlobGasUsed": null, + "Bloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "Coinbase": "0x0100000000000000000000000000000000000000", + "Difficulty": "0x20000", + "ExcessBlobGas": null, + "ExtraData": "0x", + "GasLimit": "0x47e7c4", + "GasUsed": "0x97ed", + "Hash": "0x470d8e7af7bebd6c7515f35d2c77c25d003fe814b596557d5943f700b6ede5aa", + "MixHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "Nonce": "0x0000000000000000", + "Number": "0x1", + "ParentBeaconBlockRoot": null, + "ParentHash": "0xaf41e72f748de317965454508c749f7e14dc4fe444cd07bca4c981c7e952364d", + "ReceiptTrie": "0x0002d836009201e474b8e616daff83625eb48821fa40b62a5324828c86ccf656", + "StateRoot": "0xe10489118b2484cae44ccf08dbf8312047747a905e1b3888c3569d0b203062e5", + "Timestamp": "0xa", + "TransactionsTrie": "0x35f9144ebabc94d93ed27a6d644cfc8d1e08b5112c85a085fe92f37c273db18b", + "UncleHash": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", + "WithdrawalsRoot": null + }, + "ExpectException": "", + "Rlp": "0xf90267f901faa0af41e72f748de317965454508c749f7e14dc4fe444cd07bca4c981c7e952364da01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347940100000000000000000000000000000000000000a0e10489118b2484cae44ccf08dbf8312047747a905e1b3888c3569d0b203062e5a035f9144ebabc94d93ed27a6d644cfc8d1e08b5112c85a085fe92f37c273db18ba00002d836009201e474b8e616daff83625eb48821fa40b62a5324828c86ccf656b901000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000083020000018347e7c48297ed0a80a0000000000000000000000000000000000000000000000000000000000000000088000000000000000084342770c0f867f8658085012a05f200830249f0941111111111111111111111111111111111111111808025a01244162a9c8a5aadf0c178eb0fca4b1ef8d0e35506bb2a2c9523222b0241c543a00b2c673143c87b44ab4cf52cacd0ef168d579ff1544c694e31e1efa8b00f5563c0", + "UncleHeaders": null + } + ], + "expected": [ + { + "issuance": { + "genesisAlloc": "0x7ce66c50e2840000" + }, + "blockNumber": 0, + "hash": "0xaf41e72f748de317965454508c749f7e14dc4fe444cd07bca4c981c7e952364d", + "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000" + }, + { + "issuance": { + "reward": "0x1bc16d674ec80000" + }, + "burn": { + "1559": "0x1ef38c04a1c0", + "misc": "0x4563918244f40000" + }, + "blockNumber": 1, + "hash": "0x470d8e7af7bebd6c7515f35d2c77c25d003fe814b596557d5943f700b6ede5aa", + "parentHash": "0xaf41e72f748de317965454508c749f7e14dc4fe444cd07bca4c981c7e952364d" + } + ], + "genesisBlockHeader": { + "BaseFeePerGas": "0x3b9aca00", + "BlobGasUsed": null, + "Bloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "Coinbase": "0x0000000000000000000000000000000000000000", + "Difficulty": "0x20000", + "ExcessBlobGas": null, + "ExtraData": "0x", + "GasLimit": "0x47e7c4", + "GasUsed": "0x0", + "Hash": "0xaf41e72f748de317965454508c749f7e14dc4fe444cd07bca4c981c7e952364d", + "MixHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "Nonce": "0x0000000000000000", + "Number": "0x0", + "ParentBeaconBlockRoot": null, + "ParentHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "ReceiptTrie": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "StateRoot": "0x65dc2cb11746f33989e47548a362f38b6d895960cd11b0c2b950583f276933df", + "Timestamp": "0x0", + "TransactionsTrie": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "UncleHash": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", + "WithdrawalsRoot": null + }, + "lastblockhash": "470d8e7af7bebd6c7515f35d2c77c25d003fe814b596557d5943f700b6ede5aa", + "network": "GrayGlacier", + "postState": {}, + "pre": { + "0x1111111111111111111111111111111111111111": { + "balance": "0x0", + "code": "0x73222222222222222222222222222222222222222273444444444444444444444444444444444444444460006000600060006000865af160006000600060006000865af150505050" + }, + "0x2222222222222222222222222222222222222222": { + "balance": "0x4563918244f40000", + "code": "0x3080ff50" + }, + "0x3333333333333333333333333333333333333333": { + "balance": "0xde0b6b3a7640000", + "code": "0x3080ff50" + }, + "0x4444444444444444444444444444444444444444": { + "balance": "0x1bc16d674ec80000", + "code": "0x73333333333333333333333333333333333333333360006000600060006000855af160006000fd5050" + }, + "0x71562b71999873db5b286df957af199ec94617f7": { + "balance": "0xde0b6b3a7640000" + } + }, + "sealEngine": "" + } +} \ No newline at end of file diff --git a/eth/tracers/live/tests/supply/withdrawals.json b/eth/tracers/live/tests/supply/withdrawals.json new file mode 100644 index 000000000000..c94bc6465497 --- /dev/null +++ b/eth/tracers/live/tests/supply/withdrawals.json @@ -0,0 +1,77 @@ +{ + "withdrawals_cancun": { + "blocks": [ + { + "BlockHeader": { + "BaseFeePerGas": "0x342770c0", + "BlobGasUsed": "0x0", + "Bloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "Coinbase": "0x0100000000000000000000000000000000000000", + "Difficulty": "0x0", + "ExcessBlobGas": "0x0", + "ExtraData": "0x", + "GasLimit": "0x47e7c4", + "GasUsed": "0x0", + "Hash": "0x273c5dc5beed8249b8103b9a168b1c693c17f371be39d675dec50120f4d93402", + "MixHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "Nonce": "0x0000000000000000", + "Number": "0x1", + "ParentBeaconBlockRoot": "0x0000000000000000000000000000000000000000000000000000000000000000", + "ParentHash": "0x52f276d96f0afaaf2c3cb358868bdc2779c4b0cb8de3e7e5302e247c0b66a703", + "ReceiptTrie": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "StateRoot": "0x6e2ae8cee635793fd04490934e7b7d8f727c74534c5a01e42051116e12ba6a1a", + "Timestamp": "0xa", + "TransactionsTrie": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "UncleHash": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", + "WithdrawalsRoot": "0xad2dcd8b054415c239ed4cdfff00f865a00f28676fc12e33fec0ce91e4be10d6" + }, + "ExpectException": "", + "Rlp": "0xf9025af90239a052f276d96f0afaaf2c3cb358868bdc2779c4b0cb8de3e7e5302e247c0b66a703a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347940100000000000000000000000000000000000000a06e2ae8cee635793fd04490934e7b7d8f727c74534c5a01e42051116e12ba6a1aa056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b901000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080018347e7c4800a80a0000000000000000000000000000000000000000000000000000000000000000088000000000000000084342770c0a0ad2dcd8b054415c239ed4cdfff00f865a00f28676fc12e33fec0ce91e4be10d68080a00000000000000000000000000000000000000000000000000000000000000000c0c0dbda802a94ee00000000000000000000000000000000000000820539", + "UncleHeaders": null + } + ], + "expected": [ + { + "blockNumber": 0, + "hash": "0x52f276d96f0afaaf2c3cb358868bdc2779c4b0cb8de3e7e5302e247c0b66a703", + "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000" + }, + { + "issuance": { + "withdrawals": "0x1374b68fa00" + }, + "blockNumber": 1, + "hash": "0x273c5dc5beed8249b8103b9a168b1c693c17f371be39d675dec50120f4d93402", + "parentHash": "0x52f276d96f0afaaf2c3cb358868bdc2779c4b0cb8de3e7e5302e247c0b66a703" + } + ], + "genesisBlockHeader": { + "BaseFeePerGas": "0x3b9aca00", + "BlobGasUsed": "0x0", + "Bloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "Coinbase": "0x0000000000000000000000000000000000000000", + "Difficulty": "0x20000", + "ExcessBlobGas": "0x0", + "ExtraData": "0x", + "GasLimit": "0x47e7c4", + "GasUsed": "0x0", + "Hash": "0x52f276d96f0afaaf2c3cb358868bdc2779c4b0cb8de3e7e5302e247c0b66a703", + "MixHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "Nonce": "0x0000000000000000", + "Number": "0x0", + "ParentBeaconBlockRoot": "0x0000000000000000000000000000000000000000000000000000000000000000", + "ParentHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "ReceiptTrie": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "StateRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "Timestamp": "0x0", + "TransactionsTrie": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "UncleHash": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", + "WithdrawalsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421" + }, + "lastblockhash": "273c5dc5beed8249b8103b9a168b1c693c17f371be39d675dec50120f4d93402", + "network": "Cancun", + "postState": {}, + "pre": {}, + "sealEngine": "" + } +} \ No newline at end of file diff --git a/eth/tracers/internal/tracetest/supply_test.go b/eth/tracers/live/tests/supply_filler.go similarity index 51% rename from eth/tracers/internal/tracetest/supply_test.go rename to eth/tracers/live/tests/supply_filler.go index 5c11b5e47296..76ec9f909e44 100644 --- a/eth/tracers/internal/tracetest/supply_test.go +++ b/eth/tracers/live/tests/supply_filler.go @@ -1,4 +1,4 @@ -// Copyright 2021 The go-ethereum Authors +// Copyright 2024 The go-ethereum Authors // This file is part of the go-ethereum library. // // The go-ethereum library is free software: you can redistribute it and/or modify @@ -14,7 +14,7 @@ // You should have received a copy of the GNU Lesser General Public License // along with the go-ethereum library. If not, see . -package tracetest +package main import ( "bufio" @@ -25,7 +25,6 @@ import ( "os" "path" "path/filepath" - "testing" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" @@ -37,9 +36,10 @@ import ( "github.com/ethereum/go-ethereum/core/vm" "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/eth/tracers" + "github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/params" + "github.com/ethereum/go-ethereum/tests" - // Force-load live packages, to trigger registration _ "github.com/ethereum/go-ethereum/eth/tracers/live" ) @@ -65,36 +65,85 @@ type supplyInfo struct { ParentHash common.Hash `json:"parentHash"` } +func main() { + // Takes a path where the filled tests will be written. + if len(os.Args) < 2 { + fmt.Println("Please provide a path as a command-line argument") + os.Exit(1) + } + + path, err := filepath.Abs(os.Args[1]) + if err != nil { + fmt.Printf("Error resolving path: %v\n", err) + os.Exit(1) + } + + // Create all directories in the path if they don't exist + if err := os.MkdirAll(path, 0755); err != nil { + fmt.Printf("failed to create directory: %v\n", err) + os.Exit(1) + } + if err := fillSupplyOmittedFields(path); err != nil { + fmt.Printf("fillSupplyOmittedFields failed: %v\n", err) + os.Exit(1) + } + if err := fillSupplyGenesisAlloc(path); err != nil { + fmt.Printf("fillSupplyGenesisAlloc failed: %v\n", err) + os.Exit(1) + } + if err := fillSupplyEip1559Burn(path); err != nil { + fmt.Printf("fillSupplyEip1559Burn failed: %v\n") + os.Exit(1) + } + if err := fillSupplyWithdrawals(path); err != nil { + fmt.Printf("fillSupplyWithdrawals failed: %v\n", err) + os.Exit(1) + } + if err := fillSupplySelfdestruct(path); err != nil { + fmt.Printf("fillSupplySelfdestruct failed: %v\n", err) + os.Exit(1) + } + if err := fillSupplySelfdestructItselfAndRevert(path); err != nil { + fmt.Printf("fillSupplySelfdestructItselfAndRevert failed: %v\n", err) + os.Exit(1) + } +} + func emptyBlockGenerationFunc(b *core.BlockGen) {} -func TestSupplyOmittedFields(t *testing.T) { +func fillSupplyOmittedFields(path string) error { var ( config = *params.MergedTestChainConfig gspec = &core.Genesis{ Config: &config, } + expected = []supplyInfo{{ + Number: 0, + Hash: common.HexToHash("0x52f276d96f0afaaf2c3cb358868bdc2779c4b0cb8de3e7e5302e247c0b66a703"), + ParentHash: common.HexToHash("0x0000000000000000000000000000000000000000000000000000000000000000"), + }, { + Number: 1, + Hash: common.HexToHash("0xe430cdf604a88b9d713d4f89fd100ddddf38c1cc6b049e3d5df563c7bfd320fc"), + ParentHash: common.HexToHash("0x52f276d96f0afaaf2c3cb358868bdc2779c4b0cb8de3e7e5302e247c0b66a703"), + }} ) - gspec.Config.TerminalTotalDifficulty = big.NewInt(0) - - out, _, err := testSupplyTracer(t, gspec, func(b *core.BlockGen) { + out, db, chain, err := testSupplyTracer(gspec, func(b *core.BlockGen) { b.SetPoS() }) if err != nil { - t.Fatalf("failed to test supply tracer: %v", err) + return fmt.Errorf("failed to test supply tracer: %v", err) } - - expected := supplyInfo{ - Number: 0, - Hash: common.HexToHash("0x52f276d96f0afaaf2c3cb358868bdc2779c4b0cb8de3e7e5302e247c0b66a703"), - ParentHash: common.HexToHash("0x0000000000000000000000000000000000000000000000000000000000000000"), + if err := compareAsJSON(expected, out); err != nil { + return err } - actual := out[expected.Number] - - compareAsJSON(t, expected, actual) + if err := writeArtifact(filepath.Join(path, "omitted_fields.json"), "omitted_fields_cancun", db, chain, expected, nil); err != nil { + return err + } + return nil } -func TestSupplyGenesisAlloc(t *testing.T) { +func fillSupplyGenesisAlloc(path string) error { var ( key1, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291") key2, _ = crypto.HexToECDSA("8a1f9a8f95be41cd7ccb6168179afb4504aefe388d1e14474d32c45c72ce7b7a") @@ -103,64 +152,44 @@ func TestSupplyGenesisAlloc(t *testing.T) { eth1 = new(big.Int).Mul(common.Big1, big.NewInt(params.Ether)) config = *params.AllEthashProtocolChanges - - gspec = &core.Genesis{ + gspec = &core.Genesis{ Config: &config, Alloc: types.GenesisAlloc{ addr1: {Balance: eth1}, addr2: {Balance: eth1}, }, } + expected = []supplyInfo{{ + Issuance: &supplyInfoIssuance{ + GenesisAlloc: (*hexutil.Big)(new(big.Int).Mul(common.Big2, big.NewInt(params.Ether))), + }, + Number: 0, + Hash: common.HexToHash("0xbcc9466e9fc6a8b56f4b29ca353a421ff8b51a0c1a58ca4743b427605b08f2ca"), + ParentHash: common.HexToHash("0x0000000000000000000000000000000000000000000000000000000000000000"), + }, { + Issuance: &supplyInfoIssuance{ + Reward: (*hexutil.Big)(new(big.Int).Mul(common.Big2, big.NewInt(params.Ether))), + }, + Number: 1, + Hash: common.HexToHash("0x37bb7e9b45f4fb7b311abb5f815e3e00d3382d83a2c39b9b0bd22b717566cd04"), + ParentHash: common.HexToHash("0xbcc9466e9fc6a8b56f4b29ca353a421ff8b51a0c1a58ca4743b427605b08f2ca"), + }} ) - expected := supplyInfo{ - Issuance: &supplyInfoIssuance{ - GenesisAlloc: (*hexutil.Big)(new(big.Int).Mul(common.Big2, big.NewInt(params.Ether))), - }, - Number: 0, - Hash: common.HexToHash("0xbcc9466e9fc6a8b56f4b29ca353a421ff8b51a0c1a58ca4743b427605b08f2ca"), - ParentHash: common.HexToHash("0x0000000000000000000000000000000000000000000000000000000000000000"), - } - - out, _, err := testSupplyTracer(t, gspec, emptyBlockGenerationFunc) + out, db, chain, err := testSupplyTracer(gspec, emptyBlockGenerationFunc) if err != nil { - t.Fatalf("failed to test supply tracer: %v", err) + return fmt.Errorf("failed to test supply tracer: %v", err) } - - actual := out[expected.Number] - - compareAsJSON(t, expected, actual) -} - -func TestSupplyRewards(t *testing.T) { - var ( - config = *params.AllEthashProtocolChanges - - gspec = &core.Genesis{ - Config: &config, - } - ) - - expected := supplyInfo{ - Issuance: &supplyInfoIssuance{ - Reward: (*hexutil.Big)(new(big.Int).Mul(common.Big2, big.NewInt(params.Ether))), - }, - Number: 1, - Hash: common.HexToHash("0xcbb08370505be503dafedc4e96d139ea27aba3cbc580148568b8a307b3f51052"), - ParentHash: common.HexToHash("0xadeda0a83e337b6c073e3f0e9a17531a04009b397a9588c093b628f21b8bc5a3"), + if err := compareAsJSON(expected, out); err != nil { + return err } - - out, _, err := testSupplyTracer(t, gspec, emptyBlockGenerationFunc) - if err != nil { - t.Fatalf("failed to test supply tracer: %v", err) + if err := writeArtifact(filepath.Join(path, "genesis_alloc.json"), "genesis_alloc_grayGlacier", db, chain, expected, nil); err != nil { + return err } - - actual := out[expected.Number] - - compareAsJSON(t, expected, actual) + return nil } -func TestSupplyEip1559Burn(t *testing.T) { +func fillSupplyEip1559Burn(path string) error { var ( config = *params.AllEthashProtocolChanges @@ -179,9 +208,8 @@ func TestSupplyEip1559Burn(t *testing.T) { }, } ) - - signer := types.LatestSigner(gspec.Config) - + config.ChainID = big.NewInt(1) + signer := types.LatestSigner(&config) eip1559BlockGenerationFunc := func(b *core.BlockGen) { txdata := &types.DynamicFeeTx{ ChainID: gspec.Config.ChainID, @@ -197,15 +225,22 @@ func TestSupplyEip1559Burn(t *testing.T) { b.AddTx(tx) } - out, chain, err := testSupplyTracer(t, gspec, eip1559BlockGenerationFunc) + out, db, chain, err := testSupplyTracer(gspec, eip1559BlockGenerationFunc) if err != nil { - t.Fatalf("failed to test supply tracer: %v", err) + return fmt.Errorf("failed to test supply tracer: %v", err) } var ( head = chain.CurrentBlock() reward = new(big.Int).Mul(common.Big2, big.NewInt(params.Ether)) burn = new(big.Int).Mul(big.NewInt(21000), head.BaseFee) - expected = supplyInfo{ + expected = []supplyInfo{{ + Issuance: &supplyInfoIssuance{ + GenesisAlloc: (*hexutil.Big)(eth1), + }, + Number: 0, + Hash: common.HexToHash("0xc4265421181cafc43e4b97ae4f21530e37e00320f219a13311482c9c552bcdc7"), + ParentHash: common.HexToHash("0x0000000000000000000000000000000000000000000000000000000000000000"), + }, { Issuance: &supplyInfoIssuance{ Reward: (*hexutil.Big)(reward), }, @@ -215,14 +250,18 @@ func TestSupplyEip1559Burn(t *testing.T) { Number: 1, Hash: head.Hash(), ParentHash: head.ParentHash, - } + }} ) - - actual := out[expected.Number] - compareAsJSON(t, expected, actual) + if err := compareAsJSON(expected, out); err != nil { + return err + } + if err := writeArtifact(filepath.Join(path, "eip1559_burn.json"), "eip1559_burn_grayGlacier", db, chain, expected, nil); err != nil { + return err + } + return nil } -func TestSupplyWithdrawals(t *testing.T) { +func fillSupplyWithdrawals(path string) error { var ( config = *params.MergedTestChainConfig gspec = &core.Genesis{ @@ -240,25 +279,33 @@ func TestSupplyWithdrawals(t *testing.T) { }) } - out, chain, err := testSupplyTracer(t, gspec, withdrawalsBlockGenerationFunc) + out, db, chain, err := testSupplyTracer(gspec, withdrawalsBlockGenerationFunc) if err != nil { - t.Fatalf("failed to test supply tracer: %v", err) + return fmt.Errorf("failed to test supply tracer: %v", err) } var ( head = chain.CurrentBlock() - expected = supplyInfo{ + expected = []supplyInfo{{ + Number: 0, + Hash: common.HexToHash("0x52f276d96f0afaaf2c3cb358868bdc2779c4b0cb8de3e7e5302e247c0b66a703"), + ParentHash: common.HexToHash("0x0000000000000000000000000000000000000000000000000000000000000000"), + }, { Issuance: &supplyInfoIssuance{ Withdrawals: (*hexutil.Big)(big.NewInt(1337000000000)), }, Number: 1, Hash: head.Hash(), ParentHash: head.ParentHash, - } - actual = out[expected.Number] + }} ) - - compareAsJSON(t, expected, actual) + if err := compareAsJSON(expected, out); err != nil { + return err + } + if err := writeArtifact(filepath.Join(path, "withdrawals.json"), "withdrawals_cancun", db, chain, expected, nil); err != nil { + return err + } + return nil } // Tests fund retrieval after contract's selfdestruct. @@ -266,7 +313,7 @@ func TestSupplyWithdrawals(t *testing.T) { // after the selfdestruct opcode executes from Contract A. // Because Contract B is removed only at the end of the transaction // the ether sent in between is burnt before Cancun hard fork. -func TestSupplySelfdestruct(t *testing.T) { +func fillSupplySelfdestruct(path string) error { var ( config = *params.TestChainConfig @@ -295,34 +342,29 @@ func TestSupplySelfdestruct(t *testing.T) { }, }, } - ) - - 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{}, + 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) } - - 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(gspec, testBlockGenerationFunc) if err != nil { - t.Fatalf("Pre-cancun failed to test supply tracer: %v", err) + return fmt.Errorf("failed to test supply tracer: %v", err) } // Check balance at state: @@ -331,39 +373,67 @@ func TestSupplySelfdestruct(t *testing.T) { // 3. B has 0 ether statedb, _ := preCancunChain.State() if got, exp := statedb.GetBalance(dad), eth1; got.CmpBig(exp) != 0 { - t.Fatalf("Pre-cancun address \"%v\" balance, got %v exp %v\n", dad, got, exp) + return fmt.Errorf("Pre-cancun address \"%v\" balance, got %v exp %v\n", dad, got, exp) } if got, exp := statedb.GetBalance(aa), big.NewInt(0); got.CmpBig(exp) != 0 { - t.Fatalf("Pre-cancun address \"%v\" balance, got %v exp %v\n", aa, got, exp) + return fmt.Errorf("Pre-cancun address \"%v\" balance, got %v exp %v\n", aa, got, exp) } if got, exp := statedb.GetBalance(bb), big.NewInt(0); got.CmpBig(exp) != 0 { - t.Fatalf("Pre-cancun address \"%v\" balance, got %v exp %v\n", bb, got, exp) + return fmt.Errorf("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: (*hexutil.Big)(big.NewInt(55289500000000)), - Misc: (*hexutil.Big)(big.NewInt(5000000000)), - }, - Number: 1, - Hash: head.Hash(), - ParentHash: head.ParentHash, - } - - actual := preCancunOutput[expected.Number] + var ( + head = preCancunChain.CurrentBlock() + // Check live trace output + expected = []supplyInfo{{ + Issuance: &supplyInfoIssuance{ + GenesisAlloc: (*hexutil.Big)(new(big.Int).Mul(big.NewInt(2), big.NewInt(params.Ether))), + }, + Number: 0, + Hash: common.HexToHash("0xdd9fbe877f0b43987d2f0cda0df176b7939be14f33eb5137f16e6eddf4562706"), + ParentHash: common.HexToHash("0x0000000000000000000000000000000000000000000000000000000000000000"), + }, { + Issuance: &supplyInfoIssuance{ + Reward: (*hexutil.Big)(new(big.Int).Mul(big.NewInt(2), big.NewInt(params.Ether))), + }, + Burn: &supplyInfoBurn{ + EIP1559: (*hexutil.Big)(big.NewInt(55289500000000)), + Misc: (*hexutil.Big)(big.NewInt(5000000000)), + }, + Number: 1, + Hash: head.Hash(), + ParentHash: head.ParentHash, + }} + post = &types.GenesisAlloc{ + dad: {Balance: eth1}, + aa: {Balance: big.NewInt(0), Code: gspec.Alloc[aa].Code}, + bb: {Balance: big.NewInt(0)}, + } + ) - compareAsJSON(t, expected, actual) + if err := compareAsJSON(expected, preCancunOutput); err != nil { + return err + } + preCancunTest, err := btFromChain(preCancunDB, preCancunChain, post) + if err != nil { + return fmt.Errorf("failed to fill tests from chain: %v", err) + } + 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(gspec, posTestBlockGenerationFunc) if err != nil { - t.Fatalf("Post-cancun failed to test supply tracer: %v", err) + return fmt.Errorf("Post-cancun failed to test supply tracer: %v", err) } // Check balance at state: @@ -372,29 +442,50 @@ func TestSupplySelfdestruct(t *testing.T) { // 3. B has 5 gwei statedb, _ = postCancunChain.State() if got, exp := statedb.GetBalance(dad), eth1; got.CmpBig(exp) != 0 { - t.Fatalf("Post-shanghai address \"%v\" balance, got %v exp %v\n", dad, got, exp) + return fmt.Errorf("Post-shanghai address \"%v\" balance, got %v exp %v\n", dad, got, exp) } if got, exp := statedb.GetBalance(aa), big.NewInt(0); got.CmpBig(exp) != 0 { - t.Fatalf("Post-shanghai address \"%v\" balance, got %v exp %v\n", aa, got, exp) + return fmt.Errorf("Post-shanghai address \"%v\" balance, got %v exp %v\n", aa, got, exp) } if got, exp := statedb.GetBalance(bb), gwei5; got.CmpBig(exp) != 0 { - t.Fatalf("Post-shanghai address \"%v\" balance, got %v exp %v\n", bb, got, exp) + return fmt.Errorf("Post-shanghai address \"%v\" balance, got %v exp %v\n", bb, got, exp) } // Check live trace output head = postCancunChain.CurrentBlock() - expected = supplyInfo{ + expected = []supplyInfo{{ + Issuance: &supplyInfoIssuance{ + GenesisAlloc: (*hexutil.Big)(new(big.Int).Mul(big.NewInt(2), big.NewInt(params.Ether))), + }, + Number: 0, + Hash: common.HexToHash("0x16d2bb0b366d3963bf2d8d75cb4b3bc0f233047c948fa746cbd38ac82bf9cfe9"), + ParentHash: common.HexToHash("0x0000000000000000000000000000000000000000000000000000000000000000"), + }, { Burn: &supplyInfoBurn{ EIP1559: (*hexutil.Big)(big.NewInt(55289500000000)), }, Number: 1, Hash: head.Hash(), ParentHash: head.ParentHash, + }} + post = &types.GenesisAlloc{ + dad: {Balance: eth1}, + aa: {Balance: big.NewInt(0), Code: gspec.Alloc[aa].Code}, + bb: {Balance: gwei5, Code: gspec.Alloc[bb].Code}, } - actual = postCancunOutput[expected.Number] - - compareAsJSON(t, expected, actual) + if err := compareAsJSON(expected, postCancunOutput); err != nil { + return err + } + postCancunTest, err := btFromChain(postCancunDB, postCancunChain, post) + if err != nil { + return fmt.Errorf("failed to fill tests from chain: %v", err) + } + postCancunTest.Expected = expected + if err := writeBTs(filepath.Join(path, "selfdestruct.json"), map[string]*blockTest{"selfdestruct_grayGlacier": preCancunTest, "selfdestruct_cancun": postCancunTest}); err != nil { + return err + } + return nil } // Tests selfdestructing contract to send its balance to itself (burn). @@ -404,7 +495,7 @@ func TestSupplySelfdestruct(t *testing.T) { // - Contract C selfdestructs and sends the eth1 to itself. // - Contract D calls C and reverts (Burn amount of C // has to be reverted as well). -func TestSupplySelfdestructItselfAndRevert(t *testing.T) { +func fillSupplySelfdestructItselfAndRevert(path string) error { var ( config = *params.TestChainConfig @@ -479,13 +570,8 @@ func TestSupplySelfdestructItselfAndRevert(t *testing.T) { } ) - 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, @@ -501,9 +587,9 @@ func TestSupplySelfdestructItselfAndRevert(t *testing.T) { b.AddTx(tx) } - output, chain, err := testSupplyTracer(t, gspec, testBlockGenerationFunc) + output, db, chain, err := testSupplyTracer(gspec, testBlockGenerationFunc) if err != nil { - t.Fatalf("failed to test supply tracer: %v", err) + return fmt.Errorf("failed to test supply tracer: %v", err) } // Check balance at state: @@ -513,53 +599,73 @@ func TestSupplySelfdestructItselfAndRevert(t *testing.T) { // 4. D has 1 ether, reverted statedb, _ := chain.State() if got, exp := statedb.GetBalance(aa), common.Big0; got.CmpBig(exp) != 0 { - t.Fatalf("address \"%v\" balance, got %v exp %v\n", aa, got, exp) + return fmt.Errorf("address \"%v\" balance, got %v exp %v\n", aa, got, exp) } if got, exp := statedb.GetBalance(bb), common.Big0; got.CmpBig(exp) != 0 { - t.Fatalf("address \"%v\" balance, got %v exp %v\n", bb, got, exp) + return fmt.Errorf("address \"%v\" balance, got %v exp %v\n", bb, got, exp) } if got, exp := statedb.GetBalance(cc), eth1; got.CmpBig(exp) != 0 { - t.Fatalf("address \"%v\" balance, got %v exp %v\n", bb, got, exp) + return fmt.Errorf("address \"%v\" balance, got %v exp %v\n", cc, got, exp) } if got, exp := statedb.GetBalance(dd), eth2; got.CmpBig(exp) != 0 { - t.Fatalf("address \"%v\" balance, got %v exp %v\n", bb, got, exp) + return fmt.Errorf("address \"%v\" balance, got %v exp %v\n", dd, got, exp) } // Check live trace output block := chain.GetBlockByNumber(1) - - expected := supplyInfo{ + expected := []supplyInfo{{ + Issuance: &supplyInfoIssuance{ + GenesisAlloc: (*hexutil.Big)(new(big.Int).Mul(big.NewInt(9), big.NewInt(params.Ether))), + }, + Number: 0, + Hash: common.HexToHash("0xaf41e72f748de317965454508c749f7e14dc4fe444cd07bca4c981c7e952364d"), + ParentHash: common.HexToHash("0x0000000000000000000000000000000000000000000000000000000000000000"), + }, { Burn: &supplyInfoBurn{ EIP1559: (*hexutil.Big)(new(big.Int).Mul(block.BaseFee(), big.NewInt(int64(block.GasUsed())))), Misc: (*hexutil.Big)(eth5), // 5ETH burned from contract B }, + Issuance: &supplyInfoIssuance{ + Reward: (*hexutil.Big)(eth2), + }, Number: 1, Hash: block.Hash(), ParentHash: block.ParentHash(), - } + }} - actual := output[expected.Number] - - compareAsJSON(t, expected, actual) + if err := compareAsJSON(expected, output); err != nil { + return err + } + if err := writeArtifact(filepath.Join(path, "selfdestruct_itself_and_revert.json"), "selfdestruct_itself_and_revert_grayGlacier", db, chain, expected, nil); err != nil { + return err + } + return nil } -func testSupplyTracer(t *testing.T, genesis *core.Genesis, gen func(*core.BlockGen)) ([]supplyInfo, *core.BlockChain, error) { +func testSupplyTracer(genesis *core.Genesis, gen func(*core.BlockGen)) ([]supplyInfo, ethdb.Database, *core.BlockChain, error) { var ( engine = beacon.New(ethash.NewFaker()) ) - traceOutputPath := filepath.ToSlash(t.TempDir()) + tempDir, err := os.MkdirTemp("", "supply-filler-") + if err != nil { + return nil, nil, nil, fmt.Errorf("failed to generate directory for tracer outputs: %v", err) + } + defer os.RemoveAll(tempDir) // Clean up + + traceOutputPath := filepath.ToSlash(tempDir) traceOutputFilename := path.Join(traceOutputPath, "supply.jsonl") // Load supply tracer tracer, err := tracers.LiveDirectory.New("supply", json.RawMessage(fmt.Sprintf(`{"path":"%s"}`, traceOutputPath))) if err != nil { - return nil, nil, fmt.Errorf("failed to create call tracer: %v", err) + return nil, nil, nil, fmt.Errorf("failed to create tracer: %v", err) } - chain, err := core.NewBlockChain(rawdb.NewMemoryDatabase(), core.DefaultCacheConfigWithScheme(rawdb.PathScheme), genesis, nil, engine, vm.Config{Tracer: tracer}, nil) + db := rawdb.NewMemoryDatabase() + chain, err := core.NewBlockChain(db, core.DefaultCacheConfigWithScheme(rawdb.PathScheme), genesis, nil, engine, vm.Config{Tracer: tracer}, nil) if err != nil { - return nil, nil, fmt.Errorf("failed to create tester chain: %v", err) + return nil, nil, nil, fmt.Errorf("failed to create tester chain: %v", err) } defer chain.Stop() @@ -569,13 +675,13 @@ func testSupplyTracer(t *testing.T, genesis *core.Genesis, gen func(*core.BlockG }) if n, err := chain.InsertChain(blocks); err != nil { - return nil, chain, fmt.Errorf("block %d: failed to insert into chain: %v", n, err) + return nil, nil, chain, fmt.Errorf("block %d: failed to insert into chain: %v", n, err) } // Check and compare the results file, err := os.OpenFile(traceOutputFilename, os.O_RDONLY, 0666) if err != nil { - return nil, chain, fmt.Errorf("failed to open output file: %v", err) + return nil, nil, chain, fmt.Errorf("failed to open output file: %v", err) } defer file.Close() @@ -587,27 +693,73 @@ func testSupplyTracer(t *testing.T, genesis *core.Genesis, gen func(*core.BlockG var info supplyInfo if err := json.Unmarshal(blockBytes, &info); err != nil { - return nil, chain, fmt.Errorf("failed to unmarshal result: %v", err) + return nil, nil, chain, fmt.Errorf("failed to unmarshal result: %v", err) } output = append(output, info) } - return output, chain, nil + return output, db, chain, nil } -func compareAsJSON(t *testing.T, expected interface{}, actual interface{}) { +func compareAsJSON(expected interface{}, actual interface{}) error { want, err := json.Marshal(expected) if err != nil { - t.Fatalf("failed to marshal expected value to JSON: %v", err) + return fmt.Errorf("failed to marshal expected value to JSON: %v", err) } - have, err := json.Marshal(actual) if err != nil { - t.Fatalf("failed to marshal actual value to JSON: %v", err) + return fmt.Errorf("failed to marshal actual value to JSON: %v", err) } - if !bytes.Equal(want, have) { - t.Fatalf("incorrect supply info: expected %s, got %s", string(want), string(have)) + return fmt.Errorf("incorrect supply info:\nexpected:\n%s\ngot:\n%s", string(want), string(have)) + } + return nil +} + +func writeArtifact(path, name string, db ethdb.Database, chain *core.BlockChain, expected []supplyInfo, post *types.GenesisAlloc) error { + bt, err := btFromChain(db, chain, post) + if err != nil { + return fmt.Errorf("failed to fill tests from chain: %v", err) + } + bt.Expected = expected + return writeBTs(path, map[string]*blockTest{name: bt}) +} + +type blockTest struct { + bt *tests.BlockTest + Expected []supplyInfo `json:"expected"` +} + +func writeBTs(path string, tests map[string]*blockTest) error { + enc, err := json.MarshalIndent(&tests, "", " ") + if err != nil { + return fmt.Errorf("failed to marshal tests: %v", err) + } + if err := os.WriteFile(path, enc, 0644); err != nil { + return fmt.Errorf("failed to write test to file: %v", err) + } + return nil +} + +func btFromChain(db ethdb.Database, chain *core.BlockChain, post *types.GenesisAlloc) (*blockTest, error) { + bt, err := tests.FromChain(db, chain, post) + if err != nil { + return nil, err + } + return &blockTest{bt: &bt}, nil +} + +func (bt *blockTest) MarshalJSON() ([]byte, error) { + enc, err := json.Marshal(bt.bt) + if err != nil { + return nil, err + } + // Insert the expected supply info + result := make(map[string]any) + if err := json.Unmarshal(enc, &result); err != nil { + return nil, err } + result["expected"] = bt.Expected + return json.Marshal(result) } diff --git a/params/config.go b/params/config.go index 9ecf465bb67a..c366fb052f9a 100644 --- a/params/config.go +++ b/params/config.go @@ -536,6 +536,13 @@ func (c *ChainConfig) IsTerminalPoWBlock(parentTotalDiff *big.Int, totalDiff *bi return parentTotalDiff.Cmp(c.TerminalTotalDifficulty) < 0 && totalDiff.Cmp(c.TerminalTotalDifficulty) >= 0 } +// IsParis returns whether the given block is either equal to the Paris (merge) +// fork or greater. +// Note: Only usable for post-merge networks where MergeNetsplitBlock has been configured. +func (c *ChainConfig) IsParis(num *big.Int) bool { + return c.IsLondon(num) && isBlockForked(c.MergeNetsplitBlock, num) +} + // IsShanghai returns whether time is either equal to the Shanghai fork time or greater. func (c *ChainConfig) IsShanghai(num *big.Int, time uint64) bool { return c.IsLondon(num) && isTimestampForked(c.ShanghaiTime, time) @@ -735,8 +742,8 @@ func (c *ChainConfig) ElasticityMultiplier() uint64 { return DefaultElasticityMultiplier } -// LatestFork returns the latest time-based fork that would be active for the given time. -func (c *ChainConfig) LatestFork(time uint64) forks.Fork { +// LatestPostLondonFork returns the latest time-based fork that would be active for the given time. +func (c *ChainConfig) LatestPostLondonFork(time uint64) forks.Fork { // Assume last non-time-based fork has passed. london := c.LondonBlock @@ -752,6 +759,47 @@ func (c *ChainConfig) LatestFork(time uint64) forks.Fork { } } +func (c *ChainConfig) LatestFork(num *big.Int, time uint64) forks.Fork { + switch { + case c.IsPrague(num, time): + return forks.Prague + case c.IsCancun(num, time): + return forks.Cancun + case c.IsShanghai(num, time): + return forks.Shanghai + case c.IsParis(num): + return forks.Paris + case c.IsGrayGlacier(num): + return forks.GrayGlacier + case c.IsArrowGlacier(num): + return forks.ArrowGlacier + case c.IsLondon(num): + return forks.London + case c.IsBerlin(num): + return forks.Berlin + case c.IsMuirGlacier(num): + return forks.MuirGlacier + case c.IsIstanbul(num): + return forks.Istanbul + case c.IsPetersburg(num): + return forks.Petersburg + case c.IsConstantinople(num): + return forks.Constantinople + case c.IsByzantium(num): + return forks.Byzantium + case c.IsEIP158(num): + return forks.SpuriousDragon + case c.IsEIP155(num): + return forks.TangerineWhistle + case c.IsEIP150(num): + return forks.DAO + case c.IsHomestead(num): + return forks.Homestead + default: + return forks.Frontier + } +} + // isForkBlockIncompatible returns true if a fork scheduled at block s1 cannot be // rescheduled to block s2 because head is already past the fork. func isForkBlockIncompatible(s1, s2, head *big.Int) bool { diff --git a/params/forks/forks.go b/params/forks/forks.go index 4f50ff5aedbe..659f144a41b6 100644 --- a/params/forks/forks.go +++ b/params/forks/forks.go @@ -40,3 +40,48 @@ const ( Cancun Prague ) + +func (f Fork) String() string { + switch f { + case Prague: + return "prague" + case Cancun: + return "cancun" + case Shanghai: + return "shanghai" + case Paris: + return "paris" + case GrayGlacier: + return "grayGlacier" + case ArrowGlacier: + return "arrowGlacier" + case London: + return "london" + case Berlin: + return "berlin" + case MuirGlacier: + return "muirGlacier" + case Istanbul: + return "istanbul" + case Petersburg: + return "petersburg" + case Constantinople: + return "constantinople" + case Byzantium: + return "byzantium" + case SpuriousDragon: + return "spuriousDragon" + case TangerineWhistle: + return "tangerineWhistle" + case DAO: + return "dao" + case Homestead: + return "homestead" + case FrontierThawing: + return "frontierThawing" + case Frontier: + return "frontier" + default: + panic("unknown fork") + } +} diff --git a/tests/block_test_util.go b/tests/block_test_util.go index b3957601bb83..bbda7aa461db 100644 --- a/tests/block_test_util.go +++ b/tests/block_test_util.go @@ -25,6 +25,7 @@ import ( "math/big" "os" "reflect" + "strings" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" @@ -37,6 +38,7 @@ import ( "github.com/ethereum/go-ethereum/core/tracing" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/vm" + "github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/rlp" @@ -55,6 +57,47 @@ func (t *BlockTest) UnmarshalJSON(in []byte) error { return json.Unmarshal(in, &t.json) } +// MarshalJSON implements json.Marshaler interface. +func (t *BlockTest) MarshalJSON() ([]byte, error) { + return json.Marshal(t.json) +} + +// FromChain creates a BlockTest from the history of the given chain. +func FromChain(db ethdb.Database, chain *core.BlockChain, post *types.GenesisAlloc) (BlockTest, error) { + var ( + bt = BlockTest{} + head = chain.CurrentHeader() + blocks = make([]btBlock, head.Number.Uint64()) + ) + for i := 1; i <= int(head.Number.Uint64()); i++ { + block := chain.GetBlockByNumber(uint64(i)) + if block == nil { + return bt, fmt.Errorf("block %d not found", i) + } + btBlock, err := FromBlock(block) + if err != nil { + return bt, err + } + blocks[i-1] = btBlock + } + alloc, err := core.GetGenesisState(db, chain.Genesis().Hash()) + if err != nil { + return bt, fmt.Errorf("failed to get genesis alloc: %v", err) + } + if post == nil { + post = &types.GenesisAlloc{} + } + bt.json = btJSON{ + Network: capitalize(chain.Config().LatestFork(head.Number, head.Time).String()), + Blocks: blocks, + Genesis: FromHeader(chain.Genesis().Header()), + Pre: alloc, + Post: *post, + BestBlock: common.UnprefixedHash(head.Hash()), + } + return bt, nil +} + type btJSON struct { Blocks []btBlock `json:"blocks"` Genesis btHeader `json:"genesisBlockHeader"` @@ -72,6 +115,18 @@ type btBlock struct { UncleHeaders []*btHeader } +func FromBlock(block *types.Block) (btBlock, error) { + header := FromHeader(block.Header()) + enc, err := rlp.EncodeToBytes(block) + if err != nil { + return btBlock{}, err + } + return btBlock{ + BlockHeader: &header, + Rlp: "0x" + common.Bytes2Hex(enc), + }, nil +} + //go:generate go run github.com/fjl/gencodec -type btHeader -field-override btHeaderMarshaling -out gen_btheader.go type btHeader struct { @@ -98,6 +153,32 @@ type btHeader struct { ParentBeaconBlockRoot *common.Hash } +func FromHeader(header *types.Header) btHeader { + return btHeader{ + Bloom: header.Bloom, + Coinbase: header.Coinbase, + MixHash: header.MixDigest, + Nonce: header.Nonce, + Number: header.Number, + Hash: header.Hash(), + ParentHash: header.ParentHash, + ReceiptTrie: header.ReceiptHash, + StateRoot: header.Root, + TransactionsTrie: header.TxHash, + UncleHash: header.UncleHash, + ExtraData: header.Extra, + Difficulty: header.Difficulty, + GasLimit: header.GasLimit, + GasUsed: header.GasUsed, + Timestamp: header.Time, + BaseFeePerGas: header.BaseFee, + WithdrawalsRoot: header.WithdrawalsHash, + BlobGasUsed: header.BlobGasUsed, + ExcessBlobGas: header.ExcessBlobGas, + ParentBeaconBlockRoot: header.ParentBeaconRoot, + } +} + type btHeaderMarshaling struct { ExtraData hexutil.Bytes Number *math.HexOrDecimal256 @@ -379,3 +460,11 @@ func (bb *btBlock) decode() (*types.Block, error) { err = rlp.DecodeBytes(data, &b) return &b, err } + +func capitalize(s string) string { + // Check if the string is empty + if len(s) == 0 { + return s + } + return strings.ToUpper(string(s[0])) + s[1:] +}