add boilerplate post state

This commit is contained in:
Sina Mahmoodi 2024-09-04 16:26:34 +02:00 committed by Martin Holst Swende
parent 8d95b10bb9
commit 69747c05a4
No known key found for this signature in database
GPG key ID: 683B438C05A5DDF0
3 changed files with 29 additions and 23 deletions

View file

@ -67,8 +67,7 @@ func TestSupplyOmittedFields(t *testing.T) {
}
compareAsJSON(t, expected, out)
writeArtifact(t, "omitted_fields_cancun", db, chain, expected)
writeArtifact(t, "omitted_fields_cancun", db, chain, expected, nil)
}
func TestSupplyGenesisAlloc(t *testing.T) {
@ -109,7 +108,7 @@ func TestSupplyGenesisAlloc(t *testing.T) {
t.Fatalf("failed to test supply tracer: %v", err)
}
compareAsJSON(t, expected, out)
writeArtifact(t, "genesis_alloc_grayGlacier", db, chain, expected)
writeArtifact(t, "genesis_alloc_grayGlacier", db, chain, expected, nil)
}
func TestSupplyEip1559Burn(t *testing.T) {
@ -176,7 +175,7 @@ func TestSupplyEip1559Burn(t *testing.T) {
}}
)
compareAsJSON(t, expected, out)
writeArtifact(t, "eip1559_burn_grayGlacier", db, chain, expected)
writeArtifact(t, "eip1559_burn_grayGlacier", db, chain, expected, nil)
}
func TestSupplyWithdrawals(t *testing.T) {
@ -218,7 +217,7 @@ func TestSupplyWithdrawals(t *testing.T) {
}}
)
compareAsJSON(t, expected, out)
writeArtifact(t, "withdrawals_cancun", db, chain, expected)
writeArtifact(t, "withdrawals_cancun", db, chain, expected, nil)
}
// Tests fund retrieval after contract's selfdestruct.
@ -439,13 +438,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,
@ -461,7 +455,7 @@ func TestSupplySelfdestructItselfAndRevert(t *testing.T) {
b.AddTx(tx)
}
output, _, chain, err := testSupplyTracer(t, gspec, testBlockGenerationFunc)
output, db, chain, err := testSupplyTracer(t, gspec, testBlockGenerationFunc)
if err != nil {
t.Fatalf("failed to test supply tracer: %v", err)
}
@ -487,20 +481,28 @@ func TestSupplySelfdestructItselfAndRevert(t *testing.T) {
// Check live trace output
block := chain.GetBlockByNumber(1)
expected := supplyInfo{
expected := []supplyInfo{{
Issuance: &supplyInfoIssuance{
GenesisAlloc: new(big.Int).Mul(big.NewInt(9), big.NewInt(params.Ether)),
},
Number: 0,
Hash: common.HexToHash("0xaf41e72f748de317965454508c749f7e14dc4fe444cd07bca4c981c7e952364d"),
ParentHash: common.HexToHash("0x0000000000000000000000000000000000000000000000000000000000000000"),
}, {
Burn: &supplyInfoBurn{
EIP1559: new(big.Int).Mul(block.BaseFee(), big.NewInt(int64(block.GasUsed()))),
Misc: eth5, // 5ETH burned from contract B
},
Issuance: &supplyInfoIssuance{
Reward: eth2,
},
Number: 1,
Hash: block.Hash(),
ParentHash: block.ParentHash(),
}
}}
actual := output[expected.Number]
compareAsJSON(t, expected, actual)
compareAsJSON(t, expected, output)
writeArtifact(t, "selfdestruct_itself_and_revert_grayGlacier", db, chain, expected, nil)
}
func testSupplyTracer(t *testing.T, genesis *core.Genesis, gen func(*core.BlockGen)) ([]supplyInfo, ethdb.Database, *core.BlockChain, error) {
@ -573,8 +575,8 @@ func compareAsJSON(t *testing.T, expected interface{}, actual interface{}) {
}
}
func writeArtifact(t *testing.T, name string, db ethdb.Database, chain *core.BlockChain, expected []supplyInfo) {
bt, err := btFromChain(db, chain)
func writeArtifact(t *testing.T, name string, db ethdb.Database, chain *core.BlockChain, expected []supplyInfo, post *types.GenesisAlloc) {
bt, err := btFromChain(db, chain, post)
if err != nil {
t.Fatalf("failed to fill tests from chain: %v", err)
}

View file

@ -4,6 +4,7 @@ import (
"encoding/json"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/tests"
)
@ -13,8 +14,8 @@ type BlockTest struct {
Expected []supplyInfo `json:"expected"`
}
func btFromChain(db ethdb.Database, chain *core.BlockChain) (*BlockTest, error) {
bt, err := tests.FromChain(db, chain)
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
}

View file

@ -64,7 +64,7 @@ func (t *BlockTest) MarshalJSON() ([]byte, error) {
}
// FromChain creates a BlockTest from the history of the given chain.
func FromChain(db ethdb.Database, chain *core.BlockChain) (BlockTest, error) {
func FromChain(db ethdb.Database, chain *core.BlockChain, post *types.GenesisAlloc) (BlockTest, error) {
var (
bt = BlockTest{}
head = chain.CurrentHeader()
@ -86,12 +86,15 @@ func FromChain(db ethdb.Database, chain *core.BlockChain) (BlockTest, error) {
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: make(types.GenesisAlloc),
Post: *post,
BestBlock: common.UnprefixedHash(head.Hash()),
}
return bt, nil