core/vm: fix tests

This commit is contained in:
Martin Holst Swende 2020-03-14 09:19:35 +01:00
parent 69459f6bfd
commit e431a23c09
No known key found for this signature in database
GPG key ID: 683B438C05A5DDF0

View file

@ -109,7 +109,7 @@ func testTwoOperandOp(t *testing.T, tests []TwoOperandTestcase, opFn executionFu
expected := new(big.Int).SetBytes(common.Hex2Bytes(test.Expected)) expected := new(big.Int).SetBytes(common.Hex2Bytes(test.Expected))
stack.push(x) stack.push(x)
stack.push(y) stack.push(y)
opFn(&pc, evmInterpreter, nil, nil, stack) opFn(&pc, evmInterpreter, &CallCtx{nil, stack, nil})
actual := stack.pop() actual := stack.pop()
if actual.Cmp(expected) != 0 { if actual.Cmp(expected) != 0 {
@ -223,7 +223,7 @@ func getResult(args []*twoOperandParams, opFn executionFunc) []TwoOperandTestcas
y := new(big.Int).SetBytes(common.Hex2Bytes(param.y)) y := new(big.Int).SetBytes(common.Hex2Bytes(param.y))
stack.push(x) stack.push(x)
stack.push(y) stack.push(y)
opFn(&pc, interpreter, nil, nil, stack) opFn(&pc, interpreter, &CallCtx{nil, stack, nil})
actual := stack.pop() actual := stack.pop()
result[i] = TwoOperandTestcase{param.x, param.y, fmt.Sprintf("%064x", actual)} result[i] = TwoOperandTestcase{param.x, param.y, fmt.Sprintf("%064x", actual)}
} }
@ -260,7 +260,7 @@ func TestJsonTestcases(t *testing.T) {
} }
} }
func opBenchmark(bench *testing.B, op func(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *Memory, stack *Stack) ([]byte, error), args ...string) { func opBenchmark(bench *testing.B, op executionFunc, args ...string) {
var ( var (
env = NewEVM(Context{}, nil, params.TestChainConfig, Config{}) env = NewEVM(Context{}, nil, params.TestChainConfig, Config{})
stack = newstack() stack = newstack()
@ -281,7 +281,7 @@ func opBenchmark(bench *testing.B, op func(pc *uint64, interpreter *EVMInterpret
a := new(big.Int).SetBytes(arg) a := new(big.Int).SetBytes(arg)
stack.push(a) stack.push(a)
} }
op(&pc, evmInterpreter, nil, nil, stack) op(&pc, evmInterpreter, &CallCtx{nil, stack, nil})
stack.pop() stack.pop()
} }
poolOfIntPools.put(evmInterpreter.intPool) poolOfIntPools.put(evmInterpreter.intPool)
@ -509,12 +509,12 @@ func TestOpMstore(t *testing.T) {
pc := uint64(0) pc := uint64(0)
v := "abcdef00000000000000abba000000000deaf000000c0de00100000000133700" v := "abcdef00000000000000abba000000000deaf000000c0de00100000000133700"
stack.pushN(new(big.Int).SetBytes(common.Hex2Bytes(v)), big.NewInt(0)) stack.pushN(new(big.Int).SetBytes(common.Hex2Bytes(v)), big.NewInt(0))
opMstore(&pc, evmInterpreter, nil, mem, stack) opMstore(&pc, evmInterpreter, &CallCtx{mem, stack, nil})
if got := common.Bytes2Hex(mem.GetCopy(0, 32)); got != v { if got := common.Bytes2Hex(mem.GetCopy(0, 32)); got != v {
t.Fatalf("Mstore fail, got %v, expected %v", got, v) t.Fatalf("Mstore fail, got %v, expected %v", got, v)
} }
stack.pushN(big.NewInt(0x1), big.NewInt(0)) stack.pushN(big.NewInt(0x1), big.NewInt(0))
opMstore(&pc, evmInterpreter, nil, mem, stack) opMstore(&pc, evmInterpreter, &CallCtx{mem, stack, nil})
if common.Bytes2Hex(mem.GetCopy(0, 32)) != "0000000000000000000000000000000000000000000000000000000000000001" { if common.Bytes2Hex(mem.GetCopy(0, 32)) != "0000000000000000000000000000000000000000000000000000000000000001" {
t.Fatalf("Mstore failed to overwrite previous value") t.Fatalf("Mstore failed to overwrite previous value")
} }
@ -539,7 +539,7 @@ func BenchmarkOpMstore(bench *testing.B) {
bench.ResetTimer() bench.ResetTimer()
for i := 0; i < bench.N; i++ { for i := 0; i < bench.N; i++ {
stack.pushN(value, memStart) stack.pushN(value, memStart)
opMstore(&pc, evmInterpreter, nil, mem, stack) opMstore(&pc, evmInterpreter, &CallCtx{mem, stack, nil})
} }
poolOfIntPools.put(evmInterpreter.intPool) poolOfIntPools.put(evmInterpreter.intPool)
} }
@ -560,7 +560,7 @@ func BenchmarkOpSHA3(bench *testing.B) {
bench.ResetTimer() bench.ResetTimer()
for i := 0; i < bench.N; i++ { for i := 0; i < bench.N; i++ {
stack.pushN(big.NewInt(32), start) stack.pushN(big.NewInt(32), start)
opSha3(&pc, evmInterpreter, nil, mem, stack) opSha3(&pc, evmInterpreter, &CallCtx{mem, stack, nil})
} }
poolOfIntPools.put(evmInterpreter.intPool) poolOfIntPools.put(evmInterpreter.intPool)
} }