mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 18:32:23 +00:00
cmd/ewasm: Tweak the way wasm files are executed
This can now be used to test code metering by running the sentinel contract
This commit is contained in:
parent
b2482f5a4a
commit
8fb0c4b53d
1 changed files with 30 additions and 10 deletions
|
|
@ -25,6 +25,7 @@ import (
|
|||
"os"
|
||||
"strconv"
|
||||
|
||||
"github.com/ethereum/go-ethereum/core"
|
||||
"github.com/ethereum/go-ethereum/params"
|
||||
|
||||
"github.com/ethereum/go-ethereum/cmd/utils"
|
||||
|
|
@ -59,12 +60,30 @@ func runCmd(ctx *cli.Context) error {
|
|||
|
||||
if args.Present() {
|
||||
filename := args.First()
|
||||
input := args.Get(1)
|
||||
inputStr := args.Get(1)
|
||||
gas, err := strconv.ParseUint(args.Get(2), 10, 64)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error parsing gas number: %v", err)
|
||||
}
|
||||
|
||||
// Convert the input
|
||||
input := []byte{}
|
||||
if inputStr[0:2] != "0x" {
|
||||
return fmt.Errorf("Invalid input, it should be a hexadecimal number starting with 0x")
|
||||
}
|
||||
inputStr = inputStr[2:]
|
||||
if len(inputStr)%2 == 1 {
|
||||
inputStr = "0" + inputStr
|
||||
}
|
||||
for inputStr != "" {
|
||||
x, err := strconv.ParseUint(inputStr[0:2], 16, 8)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Invalid byte in input")
|
||||
}
|
||||
input = append(input, byte(x))
|
||||
inputStr = inputStr[2:]
|
||||
}
|
||||
|
||||
if fd, err := os.Open(filename); err == nil {
|
||||
|
||||
fi, _ := fd.Stat()
|
||||
|
|
@ -84,16 +103,17 @@ func runCmd(ctx *cli.Context) error {
|
|||
|
||||
contract := coreVM.NewContract(coreVM.AccountRef(callerAddr), coreVM.AccountRef(contractAddr), big.NewInt(100), gas)
|
||||
contract.Code = code
|
||||
contract.Input = input
|
||||
|
||||
permissiveContext := coreVM.Context{
|
||||
CanTransfer: core.CanTransfer,
|
||||
Transfer: core.Transfer,
|
||||
}
|
||||
|
||||
evm := coreVM.NewEVM(permissiveContext, statedb, ¶ms.ChainConfig{}, coreVM.Config{})
|
||||
|
||||
evm.StateDB.SetCode(contractAddr, code)
|
||||
|
||||
evm := coreVM.NewEVM(coreVM.Context{}, statedb, ¶ms.ChainConfig{}, coreVM.Config{})
|
||||
// &ewasm.Contract{
|
||||
// StateDB: statedb,
|
||||
// Gas: 100,
|
||||
// Address: &contractAddr,
|
||||
// CodeAddr: &codeAddr,
|
||||
// Module: m,
|
||||
// VM: vm,
|
||||
// }
|
||||
|
||||
output, leftOver, err := evm.Call(coreVM.AccountRef(callerAddr), contractAddr, input, gas, big.NewInt(0))
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue