mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
Add call function in test
This commit is contained in:
parent
608d3355d5
commit
e83f2b7c9a
2 changed files with 31 additions and 19 deletions
|
|
@ -34,7 +34,7 @@ var (
|
||||||
tt255 = math.BigPow(2, 255)
|
tt255 = math.BigPow(2, 255)
|
||||||
OvmSLOADMethodId = hashSha3([]byte("ovmSLOAD()"))[0:4]
|
OvmSLOADMethodId = hashSha3([]byte("ovmSLOAD()"))[0:4]
|
||||||
OvmSSTOREMethodId = hashSha3([]byte("ovmSStore()"))[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")
|
errWriteProtection = errors.New("evm: write protection")
|
||||||
errReturnDataOutOfBounds = errors.New("evm: return data out of bounds")
|
errReturnDataOutOfBounds = errors.New("evm: return data out of bounds")
|
||||||
errExecutionReverted = errors.New("evm: execution reverted")
|
errExecutionReverted = errors.New("evm: execution reverted")
|
||||||
|
|
@ -768,11 +768,11 @@ func opCall(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory
|
||||||
toAddr := common.BigToAddress(addr)
|
toAddr := common.BigToAddress(addr)
|
||||||
value = math.U256(value)
|
value = math.U256(value)
|
||||||
|
|
||||||
|
fmt.Printf("value %s\n", value)
|
||||||
fmt.Printf("inOffset %s\n", inOffset)
|
fmt.Printf("inOffset %s\n", inOffset)
|
||||||
fmt.Printf("inSize %s\n", inSize)
|
fmt.Printf("inSize %s\n", inSize)
|
||||||
fmt.Printf("retOffset %s\n", retOffset)
|
fmt.Printf("retOffset %s\n", retOffset)
|
||||||
fmt.Printf("retSize %s\n", retSize)
|
fmt.Printf("retSize %s\n", retSize)
|
||||||
fmt.Printf("value %s\n", value)
|
|
||||||
fmt.Printf("address 0x%020x\n", addr)
|
fmt.Printf("address 0x%020x\n", addr)
|
||||||
// Get the arguments from the memory.
|
// Get the arguments from the memory.
|
||||||
args := memory.GetPtr(inOffset.Int64(), inSize.Int64())
|
args := memory.GetPtr(inOffset.Int64(), inSize.Int64())
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
package tests
|
package tests
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
|
|
@ -23,27 +22,40 @@ func mstoreBytes(bytes []byte) []byte {
|
||||||
return output
|
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) {
|
func TestOvm(t *testing.T) {
|
||||||
db := state.NewDatabase(rawdb.NewMemoryDatabase())
|
db := state.NewDatabase(rawdb.NewMemoryDatabase())
|
||||||
state, _ := state.New(common.Hash{}, db)
|
state, _ := state.New(common.Hash{}, db)
|
||||||
address := common.HexToAddress("0x0a")
|
address := common.HexToAddress("0x0a")
|
||||||
fmt.Printf("%x\n", mstoreBytes(vm.OvmSLOADMethodId))
|
code := append(
|
||||||
code := mstoreBytes(vm.OvmSLOADMethodId)
|
mstoreBytes(vm.OvmSLOADMethodId),
|
||||||
code = append(code, []byte{
|
call(
|
||||||
byte(vm.PUSH1), 0,
|
vm.OvmContractAddress,
|
||||||
byte(vm.PUSH1), 0,
|
0,
|
||||||
byte(vm.PUSH1), 0,
|
0,
|
||||||
byte(vm.PUSH1), 0,
|
4,
|
||||||
byte(vm.PUSH1), 4,
|
0,
|
||||||
byte(vm.PUSH1), 0,
|
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),
|
|
||||||
}...)
|
|
||||||
|
|
||||||
fmt.Printf("%x", code)
|
|
||||||
state.SetCode(address, code)
|
state.SetCode(address, code)
|
||||||
|
|
||||||
_, _, err := runtime.Call(address, nil, &runtime.Config{State: state, Debug: true})
|
_, _, err := runtime.Call(address, nil, &runtime.Config{State: state, Debug: true})
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue