@@ -972,3 +972,47 @@ func TestPush(t *testing.T) {
972972 }
973973 }
974974}
975+
976+ func TestOpCLZ (t * testing.T ) {
977+ // set up once
978+ evm := NewEVM (BlockContext {}, nil , params .TestChainConfig , Config {})
979+
980+ tests := []struct {
981+ name string
982+ inputHex string // hexadecimal input for clarity
983+ want uint64 // expected CLZ result
984+ }{
985+ {"zero" , "0x0" , 256 },
986+ {"one" , "0x1" , 255 },
987+ {"all-ones (256 bits)" , "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" , 0 },
988+ {"low-10-bytes ones" , "0xffffffffff" , 216 }, // 10 bytes = 80 bits, so 256-80=176? Actually input is 0xffffffffff = 40 bits so 256-40=216
989+ }
990+
991+ for _ , tc := range tests {
992+ t .Run (tc .name , func (t * testing.T ) {
993+
994+ // prepare a fresh stack and PC
995+ stack := newstack ()
996+ pc := uint64 (0 )
997+
998+ // parse input
999+ val := new (uint256.Int )
1000+ if _ , err := fmt .Sscan (tc .inputHex , val ); err != nil {
1001+ // fallback: try hex
1002+ val .SetFromHex (tc .inputHex )
1003+ }
1004+
1005+ stack .push (val )
1006+ opCLZ (& pc , evm .interpreter , & ScopeContext {Stack : stack })
1007+
1008+ if gotLen := stack .len (); gotLen != 1 {
1009+ t .Fatalf ("stack length = %d; want 1" , gotLen )
1010+ }
1011+ result := stack .pop ()
1012+
1013+ if got := result .Uint64 (); got != tc .want {
1014+ t .Fatalf ("clz(%q) = %d; want %d" , tc .inputHex , got , tc .want )
1015+ }
1016+ })
1017+ }
1018+ }
0 commit comments