MCPcopy Create free account
hub / github.com/CPChain/chain / TestByteOp

Function TestByteOp

core/vm/instructions_test.go:71–104  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

69}
70
71func TestByteOp(t *testing.T) {
72 var (
73 env = NewEVM(Context{}, nil, configs.TestChainConfig, Config{})
74 stack = newstack()
75 )
76 env.interpreter.intPool = poolOfIntPools.get()
77 tests := []struct {
78 v string
79 th uint64
80 expected *big.Int
81 }{
82 {"ABCDEF0908070605040302010000000000000000000000000000000000000000", 0, big.NewInt(0xAB)},
83 {"ABCDEF0908070605040302010000000000000000000000000000000000000000", 1, big.NewInt(0xCD)},
84 {"00CDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff", 0, big.NewInt(0x00)},
85 {"00CDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff", 1, big.NewInt(0xCD)},
86 {"0000000000000000000000000000000000000000000000000000000000102030", 31, big.NewInt(0x30)},
87 {"0000000000000000000000000000000000000000000000000000000000102030", 30, big.NewInt(0x20)},
88 {"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 32, big.NewInt(0x0)},
89 {"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 0xFFFFFFFFFFFFFFFF, big.NewInt(0x0)},
90 }
91 pc := uint64(0)
92 for _, test := range tests {
93 val := new(big.Int).SetBytes(common.Hex2Bytes(test.v))
94 th := new(big.Int).SetUint64(test.th)
95 stack.push(val)
96 stack.push(th)
97 opByte(&pc, env, nil, nil, stack)
98 actual := stack.pop()
99 if actual.Cmp(test.expected) != 0 {
100 t.Fatalf("Expected [%v] %v:th byte to be %v, was %v.", test.v, test.th, test.expected, actual)
101 }
102 }
103 poolOfIntPools.put(env.interpreter.intPool)
104}
105
106func TestSHL(t *testing.T) {
107 // Testcases from https://github.com/ethereum/EIPs/blob/master/EIPS/eip-145.md#shl-shift-left

Callers

nothing calls this directly

Calls 9

NewEVMFunction · 0.85
newstackFunction · 0.85
opByteFunction · 0.85
SetBytesMethod · 0.80
popMethod · 0.80
CmpMethod · 0.80
getMethod · 0.45
pushMethod · 0.45
putMethod · 0.45

Tested by

no test coverage detected