github.com/cheng762/platon-go@v1.8.17-0.20190529111256-7deff2d7be26/core/vm/interpreter_life_test.go (about) 1 2 package vm 3 4 import ( 5 "github.com/PlatONnetwork/PlatON-Go/common" 6 "github.com/PlatONnetwork/PlatON-Go/core/types" 7 "fmt" 8 "io/ioutil" 9 "math/big" 10 "testing" 11 ) 12 13 var abi = `{ 14 "version": "0.01", 15 "abi": [{ 16 "method": "transfer", 17 "args": [{ 18 "name": "from", 19 "typeName": "Address", 20 "realTypeName": "string" 21 }, { 22 "name": "to", 23 "typeName": "address", 24 "realTypeName": "string" 25 }, { 26 "name": "asset", 27 "typeName": "", 28 "realTypeName": "int64" 29 } 30 ] 31 } 32 ] 33 }` 34 35 func TestAddressUtil(t *testing.T) { 36 ref := ContractRefSelf{} 37 addr := ref.Address() 38 fmt.Println(addr.Hex()) 39 } 40 41 func TestWasmInterpreter(t *testing.T) { 42 43 evm := &EVM{ 44 StateDB: stateDB{}, 45 Context: Context{ 46 GasLimit: 1000000, 47 BlockNumber:big.NewInt(10), 48 }, 49 } 50 cfg := Config{} 51 52 53 wasmInterpreter := NewWASMInterpreter(evm, cfg) 54 55 code, _ := ioutil.ReadFile("..\\..\\life\\contract\\hello.wasm") 56 57 contract := &Contract{ 58 CallerAddress: common.BigToAddress(big.NewInt(88888)), 59 caller: ContractRefCaller{}, 60 self: ContractRefSelf{}, 61 Code : code, 62 Gas: 1000000, 63 ABI: []byte(abi), 64 } 65 // build input, {1}{transfer}{from}{to}{asset} 66 input := genInput() 67 wasmInterpreter.Run(contract, input, true) 68 69 } 70 71 type stateDB struct { 72 StateDB 73 } 74 75 func (stateDB) CreateAccount(common.Address){} 76 77 func (stateDB) SubBalance(common.Address, *big.Int){} 78 func (stateDB) AddBalance(common.Address, *big.Int){} 79 func (stateDB) GetBalance(common.Address) *big.Int{return nil} 80 81 func (stateDB) GetNonce(common.Address) uint64{return 0} 82 func (stateDB) SetNonce(common.Address, uint64){} 83 84 func (stateDB) GetCodeHash(common.Address) common.Hash{return common.Hash{}} 85 func (stateDB) GetCode(common.Address) []byte{return nil} 86 func (stateDB) SetCode(common.Address, []byte){} 87 func (stateDB) GetCodeSize(common.Address) int{return 0} 88 89 // todo: new func for abi of contract. 90 func (stateDB) GetAbiHash(common.Address) common.Hash{return common.Hash{}} 91 func (stateDB) GetAbi(common.Address) []byte{return nil} 92 func (stateDB) SetAbi(common.Address, []byte){} 93 94 func (stateDB) AddRefund(uint64){} 95 func (stateDB) SubRefund(uint64){} 96 func (stateDB) GetRefund() uint64{return 0} 97 98 func (stateDB) GetCommittedState(common.Address, []byte) []byte{return nil} 99 func (stateDB) GetState(common.Address, []byte) []byte{return []byte("world+++++++**")} 100 func (stateDB) SetState(common.Address, []byte, []byte){} 101 func (stateDB) Suicide(common.Address) bool{return true} 102 func (stateDB) HasSuicided(common.Address) bool{return true} 103 104 // Exist reports whether the given account exists in state. 105 // Notably this should also return true for suicided accounts. 106 func (stateDB) Exist(common.Address) bool {return true} 107 // Empty returns whether the given account is empty. Empty 108 // is defined according to EIP161 (balance = nonce = code = 0). 109 func (stateDB) Empty(common.Address) bool {return true} 110 111 func (stateDB) RevertToSnapshot(int){} 112 func (stateDB) Snapshot() int {return 0} 113 114 func (stateDB) AddPreimage(common.Hash, []byte){} 115 116 func (stateDB) ForEachStorage(common.Address, func(common.Hash, common.Hash) bool){} 117 118 func (stateDB) AddLog(*types.Log) { 119 fmt.Println("add log") 120 }