Fix genesis storage collision state tests (#4462)

* Enable a couple of tests that work now

* Fix genesis storage collision state tests

* IncarnationMap in t8ntool MakePreState
This commit is contained in:
Andrew Ashikhmin 2022-06-15 22:17:16 +02:00 committed by GitHub
parent 631d485476
commit bca563fd0f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 17 additions and 13 deletions

View File

@ -18,6 +18,7 @@ package t8ntool
import (
"context"
"encoding/binary"
"fmt"
"math/big"
@ -297,7 +298,11 @@ func MakePreState(chainRules *params.Rules, tx kv.RwTx, accounts core.GenesisAll
}
if len(a.Code) > 0 || len(a.Storage) > 0 {
statedb.SetIncarnation(addr, 1)
statedb.SetIncarnation(addr, state.FirstContractIncarnation)
var b [8]byte
binary.BigEndian.PutUint64(b[:], state.FirstContractIncarnation)
tx.Put(kv.IncarnationMap, addr[:], b[:])
}
}
// Commit and re-open to start with a clean state.

View File

@ -338,7 +338,7 @@ func (g *Genesis) ToBlock() (*types.Block, *state.IntraBlockState, error) {
}
if len(account.Code) > 0 || len(account.Storage) > 0 {
statedb.SetIncarnation(addr, 1)
statedb.SetIncarnation(addr, state.FirstContractIncarnation)
}
}
if err := statedb.FinalizeTx(&params.Rules{}, w); err != nil {
@ -401,7 +401,7 @@ func (g *Genesis) WriteGenesisState(tx kv.RwTx) (*types.Block, *state.IntraBlock
return nil, nil, err
}
for addr, account := range g.Alloc {
if len(account.Code) == 0 && len(account.Storage) > 0 {
if len(account.Code) > 0 || len(account.Storage) > 0 {
// Special case for weird tests - inaccessible storage
var b [8]byte
binary.BigEndian.PutUint64(b[:], state.FirstContractIncarnation)

View File

@ -46,15 +46,6 @@ func TestState(t *testing.T) {
st.skipLoad(`^stTimeConsuming/`)
st.skipLoad(`.*vmPerformance/loop.*`)
// Broken tests:
st.skipLoad(`^stCreate2/create2collisionStorage.json`)
st.skipLoad(`^stExtCodeHash/dynamicAccountOverwriteEmpty.json`)
st.skipLoad(`^stSStoreTest/InitCollision.json`)
st.skipLoad(`^stEIP1559/typeTwoBerlin.json`)
// value exceeding 256 bit is not supported
st.skipLoad(`^stTransactionTest/ValueOverflow.json`)
st.walk(t, stateTestDir, func(t *testing.T, name string, test *StateTest) {
db := memdb.NewTestDB(t)
for _, subtest := range test.Subtests() {

View File

@ -17,6 +17,7 @@
package tests
import (
"encoding/binary"
"encoding/json"
"fmt"
"math/big"
@ -274,9 +275,16 @@ func MakePreState(rules *params.Rules, tx kv.RwTx, accounts core.GenesisAlloc, b
}
if len(a.Code) > 0 || len(a.Storage) > 0 {
statedb.SetIncarnation(addr, 1)
statedb.SetIncarnation(addr, state.FirstContractIncarnation)
var b [8]byte
binary.BigEndian.PutUint64(b[:], state.FirstContractIncarnation)
if err := tx.Put(kv.IncarnationMap, addr[:], b[:]); err != nil {
return nil, err
}
}
}
// Commit and re-open to start with a clean state.
if err := statedb.FinalizeTx(rules, state.NewPlainStateWriter(tx, nil, blockNr+1)); err != nil {
return nil, err