(t *testing.T, tests []twoOperandTest, opFn func(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error))
| 31 | } |
| 32 | |
| 33 | func 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 | |
| 71 | func TestByteOp(t *testing.T) { |
| 72 | var ( |
no test coverage detected