mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-18 10:50:44 +00:00
core/vm/runtime: add function TestColdAccountAccessCost
This commit is contained in:
parent
c7d49072f1
commit
1c47afb286
1 changed files with 80 additions and 0 deletions
|
|
@ -597,3 +597,83 @@ func TestEip2929Cases(t *testing.T) {
|
||||||
"account (cheap)", code)
|
"account (cheap)", code)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TestColdAccountAccessCost test that the cold account access cost is reported
|
||||||
|
// correctly
|
||||||
|
// see: https://github.com/ethereum/go-ethereum/issues/22649
|
||||||
|
func TestColdAccountAccessCost(t *testing.T) {
|
||||||
|
for i, tc := range []struct {
|
||||||
|
code []byte
|
||||||
|
step int
|
||||||
|
want uint64
|
||||||
|
}{
|
||||||
|
{ // EXTCODEHASH(0xff)
|
||||||
|
code: []byte{byte(vm.PUSH1), 0xFF, byte(vm.EXTCODEHASH), byte(vm.POP)},
|
||||||
|
step: 1,
|
||||||
|
want: 2600,
|
||||||
|
},
|
||||||
|
{ // BALANCE(0xff)
|
||||||
|
code: []byte{byte(vm.PUSH1), 0xFF, byte(vm.BALANCE), byte(vm.POP)},
|
||||||
|
step: 1,
|
||||||
|
want: 2600,
|
||||||
|
},
|
||||||
|
{ // CALL(0xff)
|
||||||
|
code: []byte{
|
||||||
|
byte(vm.PUSH1), 0x0,
|
||||||
|
byte(vm.DUP1), byte(vm.DUP1), byte(vm.DUP1), byte(vm.DUP1),
|
||||||
|
byte(vm.PUSH1), 0xff, byte(vm.DUP1), byte(vm.CALL), byte(vm.POP),
|
||||||
|
},
|
||||||
|
step: 7,
|
||||||
|
want: 2855,
|
||||||
|
},
|
||||||
|
{ // CALLCODE(0xff)
|
||||||
|
code: []byte{
|
||||||
|
byte(vm.PUSH1), 0x0,
|
||||||
|
byte(vm.DUP1), byte(vm.DUP1), byte(vm.DUP1), byte(vm.DUP1),
|
||||||
|
byte(vm.PUSH1), 0xff, byte(vm.DUP1), byte(vm.CALLCODE), byte(vm.POP),
|
||||||
|
},
|
||||||
|
step: 7,
|
||||||
|
want: 2855,
|
||||||
|
},
|
||||||
|
{ // DELEGATECALL(0xff)
|
||||||
|
code: []byte{
|
||||||
|
byte(vm.PUSH1), 0x0,
|
||||||
|
byte(vm.DUP1), byte(vm.DUP1), byte(vm.DUP1),
|
||||||
|
byte(vm.PUSH1), 0xff, byte(vm.DUP1), byte(vm.DELEGATECALL), byte(vm.POP),
|
||||||
|
},
|
||||||
|
step: 6,
|
||||||
|
want: 2855,
|
||||||
|
},
|
||||||
|
{ // STATICCALL(0xff)
|
||||||
|
code: []byte{
|
||||||
|
byte(vm.PUSH1), 0x0,
|
||||||
|
byte(vm.DUP1), byte(vm.DUP1), byte(vm.DUP1),
|
||||||
|
byte(vm.PUSH1), 0xff, byte(vm.DUP1), byte(vm.STATICCALL), byte(vm.POP),
|
||||||
|
},
|
||||||
|
step: 6,
|
||||||
|
want: 2855,
|
||||||
|
},
|
||||||
|
{ // SELFDESTRUCT(0xff)
|
||||||
|
code: []byte{
|
||||||
|
byte(vm.PUSH1), 0xff, byte(vm.SELFDESTRUCT),
|
||||||
|
},
|
||||||
|
step: 1,
|
||||||
|
want: 7600,
|
||||||
|
},
|
||||||
|
} {
|
||||||
|
tracer := vm.NewStructLogger(nil)
|
||||||
|
Execute(tc.code, nil, &Config{
|
||||||
|
EVMConfig: vm.Config{
|
||||||
|
Debug: true,
|
||||||
|
Tracer: tracer,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
have := tracer.StructLogs()[tc.step].GasCost
|
||||||
|
if want := tc.want; have != want {
|
||||||
|
for ii, op := range tracer.StructLogs() {
|
||||||
|
t.Logf("%d: %v %d", ii, op.OpName(), op.GasCost)
|
||||||
|
}
|
||||||
|
t.Fatalf("tescase %d, gas report wrong, step %d, have %d want %d", i, tc.step, have, want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue