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

Function testTwoOperandOp

core/vm/instructions_test.go:33–69  ·  view source on GitHub ↗
(t *testing.T, tests []twoOperandTest, opFn func(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error))

Source from the content-addressed store, hash-verified

31}
32
33func testTwoOperandOp(t *testing.T, tests []twoOperandTest, opFn func(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error)) {
34 var (
35 env = NewEVM(Context{}, nil, configs.TestChainConfig, Config{})
36 stack = newstack()
37 pc = uint64(0)
38 )
39 env.interpreter.intPool = poolOfIntPools.get()
40 for i, test := range tests {
41 x := new(big.Int).SetBytes(common.Hex2Bytes(test.x))
42 shift := new(big.Int).SetBytes(common.Hex2Bytes(test.y))
43 expected := new(big.Int).SetBytes(common.Hex2Bytes(test.expected))
44 stack.push(x)
45 stack.push(shift)
46 opFn(&pc, env, nil, nil, stack)
47 actual := stack.pop()
48 if actual.Cmp(expected) != 0 {
49 t.Errorf("Testcase %d, expected %v, got %v", i, expected, actual)
50 }
51 // Check pool usage
52 // 1.pool is not allowed to contain anything on the stack
53 // 2.pool is not allowed to contain the same pointers twice
54 if env.interpreter.intPool.pool.len() > 0 {
55
56 poolvals := make(map[*big.Int]struct{})
57 poolvals[actual] = struct{}{}
58
59 for env.interpreter.intPool.pool.len() > 0 {
60 key := env.interpreter.intPool.get()
61 if _, exist := poolvals[key]; exist {
62 t.Errorf("Testcase %d, pool contains double-entry", i)
63 }
64 poolvals[key] = struct{}{}
65 }
66 }
67 }
68 poolOfIntPools.put(env.interpreter.intPool)
69}
70
71func TestByteOp(t *testing.T) {
72 var (

Callers 5

TestSHLFunction · 0.85
TestSHRFunction · 0.85
TestSARFunction · 0.85
TestSGTFunction · 0.85
TestSLTFunction · 0.85

Calls 9

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

Tested by

no test coverage detected