Added a test to prove code change at block level works

This commit is contained in:
Matthieu Vachon 2025-03-07 17:37:01 -05:00
parent d2ea5c22ff
commit 0488cd98e9
2 changed files with 79 additions and 0 deletions

View file

@ -0,0 +1,42 @@
package firehose_test
import (
"math/big"
"path/filepath"
"testing"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/tracing"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/trie"
)
func TestPolygon_TracerBlockLevelOnCodeChange(t *testing.T) {
tracer, hooks, onClose := newFirehoseTestTracer(t, tracingModelFirehose2_3)
defer onClose()
hooks.OnBlockchainInit(params.BorMainnetChainConfig)
hooks.OnBlockStart(tracing.BlockEvent{Block: testBlock()})
hooks.OnCodeChange(common.Address{}, common.BytesToHash([]byte{0x01}), []byte{0x01}, common.BytesToHash([]byte{0x02}), []byte{0x02})
hooks.OnBlockEnd(nil)
assertBlockEquals(t, tracer, filepath.Join("testdata", "PolygonBlockLevelCodeChange"), 1)
}
func testBlock() *types.Block {
block := types.NewBlock(&types.Header{
ParentHash: common.Hash{},
Number: big.NewInt(1),
Difficulty: big.NewInt(0),
Coinbase: common.Address{},
Time: 1,
GasLimit: 210000,
BaseFee: big.NewInt(1000000000),
ParentBeaconRoot: ptr(common.Hash{}),
}, &types.Body{
Transactions: []*types.Transaction{},
}, nil, trie.NewStackTrie(nil))
return block
}

View file

@ -0,0 +1,37 @@
{
"codeChanges": [
{
"address": "AAAAAAAAAAAAAAAAAAAAAAAAAAA=",
"newCode": "Ag==",
"newHash": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAI=",
"oldCode": "AQ==",
"oldHash": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAE=",
"ordinal": "1"
}
],
"hash": "WLGMKK1ccyTrarRdy4zscMOz8v4oSRmSquZyaMFyvTA=",
"header": {
"baseFeePerGas": {
"bytes": "O5rKAA=="
},
"coinbase": "AAAAAAAAAAAAAAAAAAAAAAAAAAA=",
"difficulty": {
"bytes": "AA=="
},
"gasLimit": "210000",
"hash": "WLGMKK1ccyTrarRdy4zscMOz8v4oSRmSquZyaMFyvTA=",
"logsBloom": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==",
"mixHash": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=",
"number": "1",
"parentBeaconRoot": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=",
"parentHash": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=",
"receiptRoot": "VugfFxvMVab/g0XmksD4bltI4BuZbK3AAWIvteNjtCE=",
"stateRoot": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=",
"timestamp": "1970-01-01T00:00:01Z",
"transactionsRoot": "VugfFxvMVab/g0XmksD4bltI4BuZbK3AAWIvteNjtCE=",
"uncleHash": "HcxN6N7HXXqrhbVntszUGtMSRRuUinQT8KFC/UDUk0c="
},
"number": "1",
"size": "545",
"ver": 3
}