mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
add a test to verify the transition from legacy to contract
This commit is contained in:
parent
7f330c1c0b
commit
e423d5cf9e
1 changed files with 74 additions and 0 deletions
|
|
@ -18,6 +18,7 @@ package vm
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"math/big"
|
||||
|
|
@ -791,6 +792,79 @@ func TestBlobHash(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestBlockHashEip2935(t *testing.T) {
|
||||
type testcase struct {
|
||||
name string
|
||||
idx uint64
|
||||
expect common.Hash
|
||||
hashes []common.Hash
|
||||
}
|
||||
var (
|
||||
statedb, _ = state.New(types.EmptyRootHash, state.NewDatabase(rawdb.NewMemoryDatabase()), nil)
|
||||
expect = common.HexToHash("0x1234")
|
||||
getHash = func(uint64) common.Hash {
|
||||
return expect
|
||||
}
|
||||
newUint64 = func(val uint64) *uint64 { return &val }
|
||||
blockContext = BlockContext{BlockNumber: big.NewInt(100), GetHash: getHash, Time: 0}
|
||||
chainConfig = ¶ms.ChainConfig{
|
||||
ChainID: big.NewInt(1337),
|
||||
HomesteadBlock: big.NewInt(0),
|
||||
EIP150Block: big.NewInt(0),
|
||||
EIP155Block: big.NewInt(0),
|
||||
EIP158Block: big.NewInt(0),
|
||||
ByzantiumBlock: big.NewInt(0),
|
||||
ConstantinopleBlock: big.NewInt(0),
|
||||
PetersburgBlock: big.NewInt(0),
|
||||
IstanbulBlock: big.NewInt(0),
|
||||
MuirGlacierBlock: big.NewInt(0),
|
||||
BerlinBlock: big.NewInt(0),
|
||||
LondonBlock: big.NewInt(0),
|
||||
ArrowGlacierBlock: big.NewInt(0),
|
||||
GrayGlacierBlock: big.NewInt(0),
|
||||
ShanghaiTime: newUint64(0),
|
||||
PragueTime: newUint64(0),
|
||||
TerminalTotalDifficulty: big.NewInt(0),
|
||||
TerminalTotalDifficultyPassed: true,
|
||||
}
|
||||
env = NewEVM(blockContext, TxContext{}, statedb, chainConfig, Config{})
|
||||
stack = newstack()
|
||||
pc = uint64(0)
|
||||
evmInterpreter = env.interpreter
|
||||
callBlockHash10 = func(t *testing.T, name string) {
|
||||
stack.push(uint256.NewInt(10))
|
||||
opBlockhash(&pc, evmInterpreter, &ScopeContext{nil, stack, nil})
|
||||
if len(stack.data) != 1 {
|
||||
t.Errorf("Expected one item on stack got %d: ", len(stack.data))
|
||||
}
|
||||
actual := stack.pop()
|
||||
expected, overflow := uint256.FromBig(new(big.Int).SetBytes(expect.Bytes()))
|
||||
if overflow {
|
||||
t.Errorf("invalid overflow")
|
||||
}
|
||||
if actual.Cmp(expected) != 0 {
|
||||
t.Errorf("%s: expected %x, got %x", name, expected, actual)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
// insert 500 block hashes, starting from genesis.
|
||||
for i := uint64(0); i < 500; i++ {
|
||||
var blockNumber common.Hash
|
||||
binary.BigEndian.PutUint64(blockNumber[24:], i)
|
||||
statedb.SetState(params.HistoryStorageAddress, blockNumber, expect)
|
||||
}
|
||||
|
||||
// simulate a call to BLOCKHASH at block 100, i.e. less than 256
|
||||
// blocks after a genesis with eip 2935 activated.
|
||||
callBlockHash10(t, "legacy")
|
||||
|
||||
// now do the same thing much later, after all blocks have
|
||||
// been inserted.
|
||||
env.Context.BlockNumber.SetInt64(500)
|
||||
callBlockHash10(t, "contract")
|
||||
}
|
||||
|
||||
func TestOpMCopy(t *testing.T) {
|
||||
// Test cases from https://eips.ethereum.org/EIPS/eip-5656#test-cases
|
||||
for i, tc := range []struct {
|
||||
|
|
|
|||
Loading…
Reference in a new issue