Skip to content

Commit cb91f91

Browse files
committed
core: testcase for eip-7907
1 parent cd3f4ea commit cb91f91

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

core/blockchain_test.go

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import (
4343
"github.com/ethereum/go-ethereum/eth/tracers/logger"
4444
"github.com/ethereum/go-ethereum/ethdb"
4545
"github.com/ethereum/go-ethereum/ethdb/pebble"
46+
"github.com/ethereum/go-ethereum/log"
4647
"github.com/ethereum/go-ethereum/params"
4748
"github.com/ethereum/go-ethereum/trie"
4849
"github.com/holiman/uint256"
@@ -4390,3 +4391,76 @@ func testInsertChainWithCutoff(t *testing.T, cutoff uint64, ancientLimit uint64,
43904391
}
43914392
}
43924393
}
4394+
4395+
func TestEIP7907(t *testing.T) {
4396+
glogger := log.NewGlogHandler(log.NewTerminalHandler(os.Stderr, false))
4397+
glogger.Verbosity(3)
4398+
log.SetDefault(log.NewLogger(glogger))
4399+
4400+
junk := make([]byte, 1024*250) // 250kb
4401+
for i := range junk {
4402+
junk[i] = byte(i)
4403+
}
4404+
code := program.New().Op(vm.ADDRESS).Op(vm.POP).ReturnViaCodeCopy(junk).Bytes()
4405+
var (
4406+
config = *params.MergedTestChainConfig
4407+
signer = types.LatestSigner(&config)
4408+
engine = beacon.New(ethash.NewFaker())
4409+
key1, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
4410+
key2, _ = crypto.HexToECDSA("8a1f9a8f95be41cd7ccb6168179afb4504aefe388d1e14474d32c45c72ce7b7a")
4411+
addr1 = crypto.PubkeyToAddress(key1.PublicKey)
4412+
addr2 = crypto.PubkeyToAddress(key2.PublicKey)
4413+
aa = common.HexToAddress("0x000000000000000000000000000000000000aaaa")
4414+
bb = common.HexToAddress("0x000000000000000000000000000000000000bbbb")
4415+
funds = new(big.Int).Mul(common.Big1, big.NewInt(params.Ether))
4416+
)
4417+
gspec := &Genesis{
4418+
Config: &config,
4419+
GasLimit: 70000000,
4420+
Alloc: types.GenesisAlloc{
4421+
addr1: {Balance: funds},
4422+
addr2: {Balance: funds},
4423+
aa: { // The address 0xAAAA calls into addr2
4424+
Code: code,
4425+
Nonce: 0,
4426+
Balance: big.NewInt(0),
4427+
},
4428+
bb: { // The address 0xBBBB copies and deploys the contract.
4429+
Code: program.New().ExtcodeCopy(aa, 0, 0, len(code)).Push0().Push(len(code)).Push0().Push0().Op(vm.CREATE).Op(vm.EXTCODESIZE).Bytes(),
4430+
Nonce: 0,
4431+
Balance: big.NewInt(0),
4432+
},
4433+
},
4434+
}
4435+
4436+
_, blocks, _ := GenerateChainWithGenesis(gspec, engine, 1, func(i int, b *BlockGen) {
4437+
b.SetCoinbase(aa)
4438+
txdata := &types.DynamicFeeTx{
4439+
ChainID: gspec.Config.ChainID,
4440+
Nonce: 0,
4441+
To: &bb,
4442+
Gas: 70000000,
4443+
GasFeeCap: newGwei(5),
4444+
GasTipCap: big.NewInt(2),
4445+
}
4446+
tx := types.MustSignNewTx(key1, signer, txdata)
4447+
b.AddTx(tx)
4448+
})
4449+
chain, err := NewBlockChain(rawdb.NewMemoryDatabase(), nil, gspec, nil, engine, vm.Config{Tracer: logger.NewMarkdownLogger(&logger.Config{}, os.Stderr).Hooks()}, nil)
4450+
if err != nil {
4451+
t.Fatalf("failed to create tester chain: %v", err)
4452+
}
4453+
defer chain.Stop()
4454+
if n, err := chain.InsertChain(blocks); err != nil {
4455+
t.Fatalf("block %d: failed to insert into chain: %v", n, err)
4456+
}
4457+
4458+
// Verify delegation designations were deployed.
4459+
created := crypto.CreateAddress(bb, 0)
4460+
fmt.Println(created.Hex())
4461+
state, _ := chain.State()
4462+
code, want := state.GetCode(created), junk
4463+
if !bytes.Equal(code, want) {
4464+
t.Fatalf("created code incorrect: got %d, want %d", len(code), len(want))
4465+
}
4466+
}

0 commit comments

Comments
 (0)