From 891ae31ad2d75f8502d31d37083d6693d5f3134b Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Mon, 7 Jul 2025 10:51:18 +0200 Subject: [PATCH] core/vm: update tests --- core/vm/instructions_test.go | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/core/vm/instructions_test.go b/core/vm/instructions_test.go index 3885926265..84218e03f2 100644 --- a/core/vm/instructions_test.go +++ b/core/vm/instructions_test.go @@ -974,18 +974,18 @@ func TestPush(t *testing.T) { } func TestOpCLZ(t *testing.T) { - // set up once evm := NewEVM(BlockContext{}, nil, params.TestChainConfig, Config{}) tests := []struct { name string - inputHex string // hexadecimal input for clarity + inputHex string want uint64 // expected CLZ result }{ {"zero", "0x0", 256}, {"one", "0x1", 255}, {"all-ones (256 bits)", "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 0}, - {"low-10-bytes ones", "0xffffffffff", 216}, // 10 bytes = 80 bits, so 256-80=176? Actually input is 0xffffffffff = 40 bits so 256-40=216 + {"low-40-bits", "0xffffffffff", 216}, // 40 bits, so 256-40 = 216 + {"low-11-bits", "0x6ff", 245}, // 0x6ff = 0b11011111111 (11 bits), so 256-11 = 245 } for _, tc := range tests { @@ -996,9 +996,8 @@ func TestOpCLZ(t *testing.T) { // parse input val := new(uint256.Int) - if _, err := fmt.Sscan(tc.inputHex, val); err != nil { - // fallback: try hex - val.SetFromHex(tc.inputHex) + if err := val.SetFromHex(tc.inputHex); err != nil { + t.Fatal("invalid hex uint256:", tc.inputHex) } stack.push(val) @@ -1008,7 +1007,6 @@ func TestOpCLZ(t *testing.T) { t.Fatalf("stack length = %d; want 1", gotLen) } result := stack.pop() - if got := result.Uint64(); got != tc.want { t.Fatalf("clz(%q) = %d; want %d", tc.inputHex, got, tc.want) }