github.com/annchain/OG@v0.0.9/vm/vm_test/execute_test.go (about) 1 package vm_test 2 3 import ( 4 "fmt" 5 "github.com/annchain/OG/common" 6 "github.com/annchain/OG/common/math" 7 "github.com/annchain/OG/vm/eth/core/vm" 8 "github.com/annchain/OG/vm/ovm" 9 vmtypes "github.com/annchain/OG/vm/types" 10 ) 11 12 func ExampleExecute() { 13 14 txContext := &ovm.TxContext{ 15 From: common.HexToAddress("0x01"), 16 To: common.HexToAddress("0x02"), 17 Value: math.NewBigInt(10), 18 Data: common.Hex2BytesNoError("6060604052600a8060106000396000f360606040526008565b00"), 19 GasPrice: math.NewBigInt(10000), 20 GasLimit: DefaultGasLimit, 21 Coinbase: common.HexToAddress("0x01"), 22 SequenceID: 0, 23 } 24 coinBase := common.HexToAddress("0x03") 25 26 db := ovm.NewMemoryStateDB() 27 db.CreateAccount(txContext.From) 28 db.AddBalance(txContext.From, math.NewBigInt(10000000)) 29 db.CreateAccount(coinBase) 30 db.AddBalance(coinBase, math.NewBigInt(10000000)) 31 32 context := ovm.NewOVMContext(&ovm.DefaultChainContext{}, &coinBase, db) 33 34 evmInterpreter := vm.NewEVMInterpreter(context, txContext, &vm.InterpreterConfig{}) 35 36 ovm := ovm.NewOVM(context, []ovm.Interpreter{evmInterpreter}, &ovm.OVMConfig{NoRecursion: false}) 37 38 ret, contractAddr, leftOverGas, err := ovm.Create(vmtypes.AccountRef(txContext.From), txContext.Data, txContext.GasLimit, txContext.Value.Value) 39 fmt.Println(common.Bytes2Hex(ret), contractAddr.String(), leftOverGas, err) 40 41 ret, leftOverGas, err = ovm.Call(vmtypes.AccountRef(txContext.From), contractAddr, txContext.Data, txContext.GasLimit, txContext.Value.Value) 42 fmt.Println(common.Bytes2Hex(ret), contractAddr.String(), leftOverGas, err) 43 44 fmt.Println(db.String()) 45 }