core/vm: add remaining tests from the EIP

This commit is contained in:
Felix Lange 2025-07-07 10:59:20 +02:00
parent 891ae31ad2
commit 81546c64c7

View file

@ -977,19 +977,19 @@ func TestOpCLZ(t *testing.T) {
evm := NewEVM(BlockContext{}, nil, params.TestChainConfig, Config{}) evm := NewEVM(BlockContext{}, nil, params.TestChainConfig, Config{})
tests := []struct { tests := []struct {
name string
inputHex string inputHex string
want uint64 // expected CLZ result want uint64 // expected CLZ result
}{ }{
{"zero", "0x0", 256}, {"0x0", 256},
{"one", "0x1", 255}, {"0x1", 255},
{"all-ones (256 bits)", "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 0}, {"0x6ff", 245}, // 0x6ff = 0b11011111111 (11 bits), so 256-11 = 245
{"low-40-bits", "0xffffffffff", 216}, // 40 bits, so 256-40 = 216 {"0xffffffffff", 216}, // 40 bits, so 256-40 = 216
{"low-11-bits", "0x6ff", 245}, // 0x6ff = 0b11011111111 (11 bits), so 256-11 = 245 {"0x4000000000000000000000000000000000000000000000000000000000000000", 1},
{"0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 1},
{"0x8000000000000000000000000000000000000000000000000000000000000000", 0},
{"0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 0},
} }
for _, tc := range tests { for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
// prepare a fresh stack and PC // prepare a fresh stack and PC
stack := newstack() stack := newstack()
pc := uint64(0) pc := uint64(0)
@ -1010,6 +1010,5 @@ func TestOpCLZ(t *testing.T) {
if got := result.Uint64(); got != tc.want { if got := result.Uint64(); got != tc.want {
t.Fatalf("clz(%q) = %d; want %d", tc.inputHex, got, tc.want) t.Fatalf("clz(%q) = %d; want %d", tc.inputHex, got, tc.want)
} }
})
} }
} }