From e83f2b7c9a95e96051e6e2a6023d0ffc47c1bf23 Mon Sep 17 00:00:00 2001 From: Mason Fischer Date: Wed, 22 Jan 2020 15:16:02 -0500 Subject: [PATCH] Add call function in test --- core/vm/instructions.go | 4 ++-- tests/ovm_test.go | 46 ++++++++++++++++++++++++++--------------- 2 files changed, 31 insertions(+), 19 deletions(-) diff --git a/core/vm/instructions.go b/core/vm/instructions.go index 61c719f617..75f0dd5792 100644 --- a/core/vm/instructions.go +++ b/core/vm/instructions.go @@ -34,7 +34,7 @@ var ( tt255 = math.BigPow(2, 255) OvmSLOADMethodId = hashSha3([]byte("ovmSLOAD()"))[0:4] OvmSSTOREMethodId = hashSha3([]byte("ovmSStore()"))[0:4] - OvmContractAddress = []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1} + OvmContractAddress = common.FromHex("000000000000000000000000000000000000001") errWriteProtection = errors.New("evm: write protection") errReturnDataOutOfBounds = errors.New("evm: return data out of bounds") errExecutionReverted = errors.New("evm: execution reverted") @@ -768,11 +768,11 @@ func opCall(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory toAddr := common.BigToAddress(addr) value = math.U256(value) + fmt.Printf("value %s\n", value) fmt.Printf("inOffset %s\n", inOffset) fmt.Printf("inSize %s\n", inSize) fmt.Printf("retOffset %s\n", retOffset) fmt.Printf("retSize %s\n", retSize) - fmt.Printf("value %s\n", value) fmt.Printf("address 0x%020x\n", addr) // Get the arguments from the memory. args := memory.GetPtr(inOffset.Int64(), inSize.Int64()) diff --git a/tests/ovm_test.go b/tests/ovm_test.go index 9b7d9e8576..c28c3e2f6c 100644 --- a/tests/ovm_test.go +++ b/tests/ovm_test.go @@ -1,7 +1,6 @@ package tests import ( - "fmt" "testing" "github.com/ethereum/go-ethereum/common" @@ -23,27 +22,40 @@ func mstoreBytes(bytes []byte) []byte { return output } +func call(addr []byte, value uint, inOffset uint, inSize uint, retOffset uint, retSize uint) []byte { + output := []byte{ + byte(vm.PUSH1), 0, + byte(vm.PUSH1), 0, + byte(vm.PUSH1), byte(retSize), + byte(vm.PUSH1), byte(retOffset), + byte(vm.PUSH1), byte(inSize), + byte(vm.PUSH1), byte(inOffset), + byte(vm.PUSH1), byte(value), + } + output = append(output, []byte{ + byte(vm.PUSH20)}...) + output = append(output, addr...) + output = append(output, []byte{ + byte(vm.GAS), + byte(vm.CALL), + }...) + return output +} + func TestOvm(t *testing.T) { db := state.NewDatabase(rawdb.NewMemoryDatabase()) state, _ := state.New(common.Hash{}, db) address := common.HexToAddress("0x0a") - fmt.Printf("%x\n", mstoreBytes(vm.OvmSLOADMethodId)) - code := mstoreBytes(vm.OvmSLOADMethodId) - code = append(code, []byte{ - byte(vm.PUSH1), 0, - byte(vm.PUSH1), 0, - byte(vm.PUSH1), 0, - byte(vm.PUSH1), 0, - byte(vm.PUSH1), 4, - byte(vm.PUSH1), 0, - byte(vm.PUSH1), 0, - // 0x00000000000000000001 - byte(vm.PUSH20), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, - byte(vm.GAS), - byte(vm.CALL), - }...) + code := append( + mstoreBytes(vm.OvmSLOADMethodId), + call( + vm.OvmContractAddress, + 0, + 0, + 4, + 0, + 0)...) - fmt.Printf("%x", code) state.SetCode(address, code) _, _, err := runtime.Call(address, nil, &runtime.Config{State: state, Debug: true})