From 898cf53c6f61ba91051d81863076143579e67cb7 Mon Sep 17 00:00:00 2001 From: Houqitong <1428952786@qq.com> Date: Wed, 3 Nov 2021 17:39:10 +0800 Subject: [PATCH 1/6] feat: adapt to ethereum --- benchmark/ethInvoke/config.toml | 27 ++ benchmark/ethInvoke/contract/Store.go | 407 ++++++++++++++++++ benchmark/ethInvoke/contract/Store.sol | 17 + .../ethInvoke/contract/Store_sol_Store.abi | 1 + .../ethInvoke/contract/Store_sol_Store.bin | 1 + benchmark/ethInvoke/script.lua | 9 + benchmark/ethTransfer/config.toml | 27 ++ benchmark/ethTransfer/contract/Store.go | 407 ++++++++++++++++++ benchmark/ethTransfer/contract/Store.sol | 17 + .../ethTransfer/contract/Store_sol_Store.abi | 1 + .../ethTransfer/contract/Store_sol_Store.bin | 1 + benchmark/ethTransfer/script.lua | 13 + cmd/cobra_test.go | 2 + common/config.go | 1 + core/controller/master/master.go | 2 +- core/controller/worker/local.go | 1 - filesystem/filesystem-packr.go | 8 + go.mod | 23 +- main.go | 1 + plugins/blockchain/blockchain.go | 4 + plugins/blockchain/common/common.go | 5 + plugins/blockchain/eth/eth.go | 360 ++++++++++++++++ plugins/blockchain/eth/eth_test.go | 212 +++++++++ plugins/blockchain/fabric/fabric.go | 1 + plugins/blockchain/hyperchain/hyperchain.go | 2 + vm/lua/lua.go | 1 - 26 files changed, 1537 insertions(+), 14 deletions(-) create mode 100644 benchmark/ethInvoke/config.toml create mode 100644 benchmark/ethInvoke/contract/Store.go create mode 100644 benchmark/ethInvoke/contract/Store.sol create mode 100644 benchmark/ethInvoke/contract/Store_sol_Store.abi create mode 100644 benchmark/ethInvoke/contract/Store_sol_Store.bin create mode 100644 benchmark/ethInvoke/script.lua create mode 100644 benchmark/ethTransfer/config.toml create mode 100644 benchmark/ethTransfer/contract/Store.go create mode 100644 benchmark/ethTransfer/contract/Store.sol create mode 100644 benchmark/ethTransfer/contract/Store_sol_Store.abi create mode 100644 benchmark/ethTransfer/contract/Store_sol_Store.bin create mode 100644 benchmark/ethTransfer/script.lua create mode 100644 filesystem/filesystem-packr.go create mode 100644 plugins/blockchain/eth/eth.go create mode 100644 plugins/blockchain/eth/eth_test.go diff --git a/benchmark/ethInvoke/config.toml b/benchmark/ethInvoke/config.toml new file mode 100644 index 0000000..956eb83 --- /dev/null +++ b/benchmark/ethInvoke/config.toml @@ -0,0 +1,27 @@ +[engine] +rate = 10 +duration = "10s" +cap = 5 + +[client] +script = "benchmark/ethInvoke/script.lua" # 脚本 +type = "eth" # 区块链类型 +contract = "benchmark/ethInvoke/contract" # 合约目录路径 +config = "/Users/aiyoa/desktop/eth-test/data" # 区块链SDK配置路径 +account = "UTC--2021-10-21T03-41-34.288690000Z--01eec173917c429901b41b98ac3dd300e060e698" #eth账户 +args = [] # 合约参数路径 + +[client.options] # 客户端选项 + +[recorder.log] +dump=false +dir="./logs" +level="debug" + +[recorder.csv] +dir="./csv" + + + + + diff --git a/benchmark/ethInvoke/contract/Store.go b/benchmark/ethInvoke/contract/Store.go new file mode 100644 index 0000000..02ea1cb --- /dev/null +++ b/benchmark/ethInvoke/contract/Store.go @@ -0,0 +1,407 @@ +//// Code generated - DO NOT EDIT. +//// This file is a generated binding and any manual changes will be lost. +// +package store + +import ( + "math/big" + "strings" + + ethereum "github.com/ethereum/go-ethereum" + "github.com/ethereum/go-ethereum/accounts/abi" + "github.com/ethereum/go-ethereum/accounts/abi/bind" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/event" +) + +// Reference imports to suppress errors if they are not otherwise used. +var ( + _ = big.NewInt + _ = strings.NewReader + _ = ethereum.NotFound + _ = bind.Bind + _ = common.Big1 + _ = types.BloomLookup + _ = event.NewSubscription +) + +// StoreABI is the input ABI used to generate the binding from. +const StoreABI = "[{\"inputs\":[{\"internalType\":\"string\",\"name\":\"_version\",\"type\":\"string\"}],\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"bytes32\",\"name\":\"key\",\"type\":\"bytes32\"},{\"indexed\":false,\"internalType\":\"bytes32\",\"name\":\"value\",\"type\":\"bytes32\"}],\"name\":\"ItemSet\",\"type\":\"event\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"name\":\"items\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"key\",\"type\":\"bytes32\"},{\"internalType\":\"bytes32\",\"name\":\"value\",\"type\":\"bytes32\"}],\"name\":\"setItem\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"version\",\"outputs\":[{\"internalType\":\"string\",\"name\":\"\",\"type\":\"string\"}],\"stateMutability\":\"view\",\"type\":\"function\"}]" + +// StoreBin is the compiled bytecode used for deploying new contracts. +var StoreBin = "0x608060405234801561001057600080fd5b5060405161072138038061072183398181016040528101906100329190610162565b806000908051906020019061004892919061004f565b505061031a565b82805461005b90610234565b90600052602060002090601f01602090048101928261007d57600085556100c4565b82601f1061009657805160ff19168380011785556100c4565b828001600101855582156100c4579182015b828111156100c35782518255916020019190600101906100a8565b5b5090506100d191906100d5565b5090565b5b808211156100ee5760008160009055506001016100d6565b5090565b6000610105610100846101d0565b6101ab565b905082815260208101848484011115610121576101206102fa565b5b61012c848285610201565b509392505050565b600082601f830112610149576101486102f5565b5b81516101598482602086016100f2565b91505092915050565b60006020828403121561017857610177610304565b5b600082015167ffffffffffffffff811115610196576101956102ff565b5b6101a284828501610134565b91505092915050565b60006101b56101c6565b90506101c18282610266565b919050565b6000604051905090565b600067ffffffffffffffff8211156101eb576101ea6102c6565b5b6101f482610309565b9050602081019050919050565b60005b8381101561021f578082015181840152602081019050610204565b8381111561022e576000848401525b50505050565b6000600282049050600182168061024c57607f821691505b602082108114156102605761025f610297565b5b50919050565b61026f82610309565b810181811067ffffffffffffffff8211171561028e5761028d6102c6565b5b80604052505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b600080fd5b600080fd5b600080fd5b600080fd5b6000601f19601f8301169050919050565b6103f8806103296000396000f3fe608060405234801561001057600080fd5b50600436106100415760003560e01c806348f343f31461004657806354fd4d5014610076578063f56256c714610094575b600080fd5b610060600480360381019061005b91906101c0565b6100b0565b60405161006d9190610275565b60405180910390f35b61007e6100c8565b60405161008b91906102b9565b60405180910390f35b6100ae60048036038101906100a991906101ed565b610156565b005b60016020528060005260406000206000915090505481565b600080546100d590610334565b80601f016020809104026020016040519081016040528092919081815260200182805461010190610334565b801561014e5780601f106101235761010080835404028352916020019161014e565b820191906000526020600020905b81548152906001019060200180831161013157829003601f168201915b505050505081565b8060016000848152602001908152602001600020819055507fe79e73da417710ae99aa2088575580a60415d359acfad9cdd3382d59c80281d4828260405161019f929190610290565b60405180910390a15050565b6000813590506101ba816103ab565b92915050565b6000602082840312156101d6576101d5610395565b5b60006101e4848285016101ab565b91505092915050565b6000806040838503121561020457610203610395565b5b6000610212858286016101ab565b9250506020610223858286016101ab565b9150509250929050565b610236816102f7565b82525050565b6000610247826102db565b61025181856102e6565b9350610261818560208601610301565b61026a8161039a565b840191505092915050565b600060208201905061028a600083018461022d565b92915050565b60006040820190506102a5600083018561022d565b6102b2602083018461022d565b9392505050565b600060208201905081810360008301526102d3818461023c565b905092915050565b600081519050919050565b600082825260208201905092915050565b6000819050919050565b60005b8381101561031f578082015181840152602081019050610304565b8381111561032e576000848401525b50505050565b6000600282049050600182168061034c57607f821691505b602082108114156103605761035f610366565b5b50919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b600080fd5b6000601f19601f8301169050919050565b6103b4816102f7565b81146103bf57600080fd5b5056fea264697066735822122005a5951e5067dae6b917ec5a4c3ccb95f0179d7371d220df636bc264a789ee6e64736f6c63430008060033" + +// DeployStore deploys a new Ethereum contract, binding an instance of Store to it. +func DeployStore(auth *bind.TransactOpts, backend bind.ContractBackend, _version string) (common.Address, *types.Transaction, *Store, error) { + parsed, err := abi.JSON(strings.NewReader(StoreABI)) + if err != nil { + return common.Address{}, nil, nil, err + } + + address, tx, contract, err := bind.DeployContract(auth, parsed, common.FromHex(StoreBin), backend, _version) + if err != nil { + return common.Address{}, nil, nil, err + } + return address, tx, &Store{StoreCaller: StoreCaller{contract: contract}, StoreTransactor: StoreTransactor{contract: contract}, StoreFilterer: StoreFilterer{contract: contract}}, nil +} + +// Store is an auto generated Go binding around an Ethereum contract. +type Store struct { + StoreCaller // Read-only binding to the contract + StoreTransactor // Write-only binding to the contract + StoreFilterer // Log filterer for contract events +} + +// StoreCaller is an auto generated read-only Go binding around an Ethereum contract. +type StoreCaller struct { + contract *bind.BoundContract // Generic contract wrapper for the low level calls +} + +// StoreTransactor is an auto generated write-only Go binding around an Ethereum contract. +type StoreTransactor struct { + contract *bind.BoundContract // Generic contract wrapper for the low level calls +} + +// StoreFilterer is an auto generated log filtering Go binding around an Ethereum contract events. +type StoreFilterer struct { + contract *bind.BoundContract // Generic contract wrapper for the low level calls +} + +// StoreSession is an auto generated Go binding around an Ethereum contract, +// with pre-set call and transact options. +type StoreSession struct { + Contract *Store // Generic contract binding to set the session for + CallOpts bind.CallOpts // Call options to use throughout this session + TransactOpts bind.TransactOpts // Transaction auth options to use throughout this session +} + +// StoreCallerSession is an auto generated read-only Go binding around an Ethereum contract, +// with pre-set call options. +type StoreCallerSession struct { + Contract *StoreCaller // Generic contract caller binding to set the session for + CallOpts bind.CallOpts // Call options to use throughout this session +} + +// StoreTransactorSession is an auto generated write-only Go binding around an Ethereum contract, +// with pre-set transact options. +type StoreTransactorSession struct { + Contract *StoreTransactor // Generic contract transactor binding to set the session for + TransactOpts bind.TransactOpts // Transaction auth options to use throughout this session +} + +// StoreRaw is an auto generated low-level Go binding around an Ethereum contract. +type StoreRaw struct { + Contract *Store // Generic contract binding to access the raw methods on +} + +// StoreCallerRaw is an auto generated low-level read-only Go binding around an Ethereum contract. +type StoreCallerRaw struct { + Contract *StoreCaller // Generic read-only contract binding to access the raw methods on +} + +// StoreTransactorRaw is an auto generated low-level write-only Go binding around an Ethereum contract. +type StoreTransactorRaw struct { + Contract *StoreTransactor // Generic write-only contract binding to access the raw methods on +} + +// NewStore creates a new instance of Store, bound to a specific deployed contract. +func NewStore(address common.Address, backend bind.ContractBackend) (*Store, error) { + contract, err := bindStore(address, backend, backend, backend) + if err != nil { + return nil, err + } + return &Store{StoreCaller: StoreCaller{contract: contract}, StoreTransactor: StoreTransactor{contract: contract}, StoreFilterer: StoreFilterer{contract: contract}}, nil +} + +// NewStoreCaller creates a new read-only instance of Store, bound to a specific deployed contract. +func NewStoreCaller(address common.Address, caller bind.ContractCaller) (*StoreCaller, error) { + contract, err := bindStore(address, caller, nil, nil) + if err != nil { + return nil, err + } + return &StoreCaller{contract: contract}, nil +} + +// NewStoreTransactor creates a new write-only instance of Store, bound to a specific deployed contract. +func NewStoreTransactor(address common.Address, transactor bind.ContractTransactor) (*StoreTransactor, error) { + contract, err := bindStore(address, nil, transactor, nil) + if err != nil { + return nil, err + } + return &StoreTransactor{contract: contract}, nil +} + +// NewStoreFilterer creates a new log filterer instance of Store, bound to a specific deployed contract. +func NewStoreFilterer(address common.Address, filterer bind.ContractFilterer) (*StoreFilterer, error) { + contract, err := bindStore(address, nil, nil, filterer) + if err != nil { + return nil, err + } + return &StoreFilterer{contract: contract}, nil +} + +// bindStore binds a generic wrapper to an already deployed contract. +func bindStore(address common.Address, caller bind.ContractCaller, transactor bind.ContractTransactor, filterer bind.ContractFilterer) (*bind.BoundContract, error) { + parsed, err := abi.JSON(strings.NewReader(StoreABI)) + if err != nil { + return nil, err + } + return bind.NewBoundContract(address, parsed, caller, transactor, filterer), nil +} + +// Call invokes the (constant) contract method with params as input values and +// sets the output to result. The result type might be a single field for simple +// returns, a slice of interfaces for anonymous returns and a struct for named +// returns. +func (_Store *StoreRaw) Call(opts *bind.CallOpts, result *[]interface{}, method string, params ...interface{}) error { + return _Store.Contract.StoreCaller.contract.Call(opts, result, method, params...) +} + +// Transfer initiates a plain transaction to move funds to the contract, calling +// its default method if one is available. +func (_Store *StoreRaw) Transfer(opts *bind.TransactOpts) (*types.Transaction, error) { + return _Store.Contract.StoreTransactor.contract.Transfer(opts) +} + +// Transact invokes the (paid) contract method with params as input values. +func (_Store *StoreRaw) Transact(opts *bind.TransactOpts, method string, params ...interface{}) (*types.Transaction, error) { + return _Store.Contract.StoreTransactor.contract.Transact(opts, method, params...) +} + +// Call invokes the (constant) contract method with params as input values and +// sets the output to result. The result type might be a single field for simple +// returns, a slice of interfaces for anonymous returns and a struct for named +// returns. +func (_Store *StoreCallerRaw) Call(opts *bind.CallOpts, result *[]interface{}, method string, params ...interface{}) error { + return _Store.Contract.contract.Call(opts, result, method, params...) +} + +// Transfer initiates a plain transaction to move funds to the contract, calling +// its default method if one is available. +func (_Store *StoreTransactorRaw) Transfer(opts *bind.TransactOpts) (*types.Transaction, error) { + return _Store.Contract.contract.Transfer(opts) +} + +// Transact invokes the (paid) contract method with params as input values. +func (_Store *StoreTransactorRaw) Transact(opts *bind.TransactOpts, method string, params ...interface{}) (*types.Transaction, error) { + return _Store.Contract.contract.Transact(opts, method, params...) +} + +// Items is a free data retrieval call binding the contract method 0x48f343f3. +// +// Solidity: function items(bytes32 ) view returns(bytes32) +func (_Store *StoreCaller) Items(opts *bind.CallOpts, arg0 [32]byte) ([32]byte, error) { + var out []interface{} + err := _Store.contract.Call(opts, &out, "items", arg0) + + if err != nil { + return *new([32]byte), err + } + + out0 := *abi.ConvertType(out[0], new([32]byte)).(*[32]byte) + + return out0, err + +} + +// Items is a free data retrieval call binding the contract method 0x48f343f3. +// +// Solidity: function items(bytes32 ) view returns(bytes32) +func (_Store *StoreSession) Items(arg0 [32]byte) ([32]byte, error) { + return _Store.Contract.Items(&_Store.CallOpts, arg0) +} + +// Items is a free data retrieval call binding the contract method 0x48f343f3. +// +// Solidity: function items(bytes32 ) view returns(bytes32) +func (_Store *StoreCallerSession) Items(arg0 [32]byte) ([32]byte, error) { + return _Store.Contract.Items(&_Store.CallOpts, arg0) +} + +// Version is a free data retrieval call binding the contract method 0x54fd4d50. +// +// Solidity: function version() view returns(string) +func (_Store *StoreCaller) Version(opts *bind.CallOpts) (string, error) { + var out []interface{} + err := _Store.contract.Call(opts, &out, "version") + + if err != nil { + return *new(string), err + } + + out0 := *abi.ConvertType(out[0], new(string)).(*string) + + return out0, err + +} + +// Version is a free data retrieval call binding the contract method 0x54fd4d50. +// +// Solidity: function version() view returns(string) +func (_Store *StoreSession) Version() (string, error) { + return _Store.Contract.Version(&_Store.CallOpts) +} + +// Version is a free data retrieval call binding the contract method 0x54fd4d50. +// +// Solidity: function version() view returns(string) +func (_Store *StoreCallerSession) Version() (string, error) { + return _Store.Contract.Version(&_Store.CallOpts) +} + +// SetItem is a paid mutator transaction binding the contract method 0xf56256c7. +// +// Solidity: function setItem(bytes32 key, bytes32 value) returns() +func (_Store *StoreTransactor) SetItem(opts *bind.TransactOpts, key [32]byte, value [32]byte) (*types.Transaction, error) { + return _Store.contract.Transact(opts, "setItem", key, value) +} + +// SetItem is a paid mutator transaction binding the contract method 0xf56256c7. +// +// Solidity: function setItem(bytes32 key, bytes32 value) returns() +func (_Store *StoreSession) SetItem(key [32]byte, value [32]byte) (*types.Transaction, error) { + return _Store.Contract.SetItem(&_Store.TransactOpts, key, value) +} + +// SetItem is a paid mutator transaction binding the contract method 0xf56256c7. +// +// Solidity: function setItem(bytes32 key, bytes32 value) returns() +func (_Store *StoreTransactorSession) SetItem(key [32]byte, value [32]byte) (*types.Transaction, error) { + return _Store.Contract.SetItem(&_Store.TransactOpts, key, value) +} + +// StoreItemSetIterator is returned from FilterItemSet and is used to iterate over the raw logs and unpacked data for ItemSet events raised by the Store contract. +type StoreItemSetIterator struct { + Event *StoreItemSet // Event containing the contract specifics and raw log + + contract *bind.BoundContract // Generic contract to use for unpacking event data + event string // Event name to use for unpacking event data + + logs chan types.Log // Log channel receiving the found contract events + sub ethereum.Subscription // Subscription for errors, completion and termination + done bool // Whether the subscription completed delivering logs + fail error // Occurred error to stop iteration +} + +// Next advances the iterator to the subsequent event, returning whether there +// are any more events found. In case of a retrieval or parsing error, false is +// returned and Error() can be queried for the exact failure. +func (it *StoreItemSetIterator) Next() bool { + // If the iterator failed, stop iterating + if it.fail != nil { + return false + } + // If the iterator completed, deliver directly whatever's available + if it.done { + select { + case log := <-it.logs: + it.Event = new(StoreItemSet) + if err := it.contract.UnpackLog(it.Event, it.event, log); err != nil { + it.fail = err + return false + } + it.Event.Raw = log + return true + + default: + return false + } + } + // Iterator still in progress, wait for either a data or an error event + select { + case log := <-it.logs: + it.Event = new(StoreItemSet) + if err := it.contract.UnpackLog(it.Event, it.event, log); err != nil { + it.fail = err + return false + } + it.Event.Raw = log + return true + + case err := <-it.sub.Err(): + it.done = true + it.fail = err + return it.Next() + } +} + +// Error returns any retrieval or parsing error occurred during filtering. +func (it *StoreItemSetIterator) Error() error { + return it.fail +} + +// Close terminates the iteration process, releasing any pending underlying +// resources. +func (it *StoreItemSetIterator) Close() error { + it.sub.Unsubscribe() + return nil +} + +// StoreItemSet represents a ItemSet event raised by the Store contract. +type StoreItemSet struct { + Key [32]byte + Value [32]byte + Raw types.Log // Blockchain specific contextual infos +} + +// FilterItemSet is a free log retrieval operation binding the contract event 0xe79e73da417710ae99aa2088575580a60415d359acfad9cdd3382d59c80281d4. +// +// Solidity: event ItemSet(bytes32 key, bytes32 value) +func (_Store *StoreFilterer) FilterItemSet(opts *bind.FilterOpts) (*StoreItemSetIterator, error) { + + logs, sub, err := _Store.contract.FilterLogs(opts, "ItemSet") + if err != nil { + return nil, err + } + return &StoreItemSetIterator{contract: _Store.contract, event: "ItemSet", logs: logs, sub: sub}, nil +} + +// WatchItemSet is a free log subscription operation binding the contract event 0xe79e73da417710ae99aa2088575580a60415d359acfad9cdd3382d59c80281d4. +// +// Solidity: event ItemSet(bytes32 key, bytes32 value) +func (_Store *StoreFilterer) WatchItemSet(opts *bind.WatchOpts, sink chan<- *StoreItemSet) (event.Subscription, error) { + + logs, sub, err := _Store.contract.WatchLogs(opts, "ItemSet") + if err != nil { + return nil, err + } + return event.NewSubscription(func(quit <-chan struct{}) error { + defer sub.Unsubscribe() + for { + select { + case log := <-logs: + // New log arrived, parse the event and forward to the user + event := new(StoreItemSet) + if err := _Store.contract.UnpackLog(event, "ItemSet", log); err != nil { + return err + } + event.Raw = log + + select { + case sink <- event: + case err := <-sub.Err(): + return err + case <-quit: + return nil + } + case err := <-sub.Err(): + return err + case <-quit: + return nil + } + } + }), nil +} + +// ParseItemSet is a log parse operation binding the contract event 0xe79e73da417710ae99aa2088575580a60415d359acfad9cdd3382d59c80281d4. +// +// Solidity: event ItemSet(bytes32 key, bytes32 value) +func (_Store *StoreFilterer) ParseItemSet(log types.Log) (*StoreItemSet, error) { + event := new(StoreItemSet) + if err := _Store.contract.UnpackLog(event, "ItemSet", log); err != nil { + return nil, err + } + event.Raw = log + return event, nil +} diff --git a/benchmark/ethInvoke/contract/Store.sol b/benchmark/ethInvoke/contract/Store.sol new file mode 100644 index 0000000..8f74708 --- /dev/null +++ b/benchmark/ethInvoke/contract/Store.sol @@ -0,0 +1,17 @@ +pragma solidity ^0.8.6; + +contract Store { + event ItemSet(bytes32 key, bytes32 value); + + string public version; + mapping (bytes32 => bytes32) public items; + + constructor(string memory _version) public { + version = _version; + } + + function setItem(bytes32 key, bytes32 value) external { + items[key] = value; + emit ItemSet(key, value); + } +} \ No newline at end of file diff --git a/benchmark/ethInvoke/contract/Store_sol_Store.abi b/benchmark/ethInvoke/contract/Store_sol_Store.abi new file mode 100644 index 0000000..ca9af19 --- /dev/null +++ b/benchmark/ethInvoke/contract/Store_sol_Store.abi @@ -0,0 +1 @@ +[{"inputs":[{"internalType":"string","name":"_version","type":"string"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes32","name":"key","type":"bytes32"},{"indexed":false,"internalType":"bytes32","name":"value","type":"bytes32"}],"name":"ItemSet","type":"event"},{"inputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"name":"items","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"key","type":"bytes32"},{"internalType":"bytes32","name":"value","type":"bytes32"}],"name":"setItem","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"version","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"}] diff --git a/benchmark/ethInvoke/contract/Store_sol_Store.bin b/benchmark/ethInvoke/contract/Store_sol_Store.bin new file mode 100644 index 0000000..246bf10 --- /dev/null +++ b/benchmark/ethInvoke/contract/Store_sol_Store.bin @@ -0,0 +1 @@ +608060405234801561001057600080fd5b5060405161072138038061072183398181016040528101906100329190610162565b806000908051906020019061004892919061004f565b505061031a565b82805461005b90610234565b90600052602060002090601f01602090048101928261007d57600085556100c4565b82601f1061009657805160ff19168380011785556100c4565b828001600101855582156100c4579182015b828111156100c35782518255916020019190600101906100a8565b5b5090506100d191906100d5565b5090565b5b808211156100ee5760008160009055506001016100d6565b5090565b6000610105610100846101d0565b6101ab565b905082815260208101848484011115610121576101206102fa565b5b61012c848285610201565b509392505050565b600082601f830112610149576101486102f5565b5b81516101598482602086016100f2565b91505092915050565b60006020828403121561017857610177610304565b5b600082015167ffffffffffffffff811115610196576101956102ff565b5b6101a284828501610134565b91505092915050565b60006101b56101c6565b90506101c18282610266565b919050565b6000604051905090565b600067ffffffffffffffff8211156101eb576101ea6102c6565b5b6101f482610309565b9050602081019050919050565b60005b8381101561021f578082015181840152602081019050610204565b8381111561022e576000848401525b50505050565b6000600282049050600182168061024c57607f821691505b602082108114156102605761025f610297565b5b50919050565b61026f82610309565b810181811067ffffffffffffffff8211171561028e5761028d6102c6565b5b80604052505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b600080fd5b600080fd5b600080fd5b600080fd5b6000601f19601f8301169050919050565b6103f8806103296000396000f3fe608060405234801561001057600080fd5b50600436106100415760003560e01c806348f343f31461004657806354fd4d5014610076578063f56256c714610094575b600080fd5b610060600480360381019061005b91906101c0565b6100b0565b60405161006d9190610275565b60405180910390f35b61007e6100c8565b60405161008b91906102b9565b60405180910390f35b6100ae60048036038101906100a991906101ed565b610156565b005b60016020528060005260406000206000915090505481565b600080546100d590610334565b80601f016020809104026020016040519081016040528092919081815260200182805461010190610334565b801561014e5780601f106101235761010080835404028352916020019161014e565b820191906000526020600020905b81548152906001019060200180831161013157829003601f168201915b505050505081565b8060016000848152602001908152602001600020819055507fe79e73da417710ae99aa2088575580a60415d359acfad9cdd3382d59c80281d4828260405161019f929190610290565b60405180910390a15050565b6000813590506101ba816103ab565b92915050565b6000602082840312156101d6576101d5610395565b5b60006101e4848285016101ab565b91505092915050565b6000806040838503121561020457610203610395565b5b6000610212858286016101ab565b9250506020610223858286016101ab565b9150509250929050565b610236816102f7565b82525050565b6000610247826102db565b61025181856102e6565b9350610261818560208601610301565b61026a8161039a565b840191505092915050565b600060208201905061028a600083018461022d565b92915050565b60006040820190506102a5600083018561022d565b6102b2602083018461022d565b9392505050565b600060208201905081810360008301526102d3818461023c565b905092915050565b600081519050919050565b600082825260208201905092915050565b6000819050919050565b60005b8381101561031f578082015181840152602081019050610304565b8381111561032e576000848401525b50505050565b6000600282049050600182168061034c57607f821691505b602082108114156103605761035f610366565b5b50919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b600080fd5b6000601f19601f8301169050919050565b6103b4816102f7565b81146103bf57600080fd5b5056fea264697066735822122005a5951e5067dae6b917ec5a4c3ccb95f0179d7371d220df636bc264a789ee6e64736f6c63430008060033 \ No newline at end of file diff --git a/benchmark/ethInvoke/script.lua b/benchmark/ethInvoke/script.lua new file mode 100644 index 0000000..48f3bd7 --- /dev/null +++ b/benchmark/ethInvoke/script.lua @@ -0,0 +1,9 @@ +local case = testcase.new() +function case:Run() + local result = self.blockchain:Invoke({ + func = "", + args = {""}, + }) + return result +end +return case \ No newline at end of file diff --git a/benchmark/ethTransfer/config.toml b/benchmark/ethTransfer/config.toml new file mode 100644 index 0000000..f4d711a --- /dev/null +++ b/benchmark/ethTransfer/config.toml @@ -0,0 +1,27 @@ +[engine] +rate = 10 +duration = "30s" +cap = 5 + +[client] +script = "benchmark/ethTransfer/script.lua" # 脚本 +type = "eth" # 区块链类型 +contract = "benchmark/ethTransfer/contract" # 合约目录路径 +config = "/Users/aiyoa/desktop/eth-test/data" # 区块链SDK配置路径 +account = "UTC--2021-10-21T03-41-34.288690000Z--01eec173917c429901b41b98ac3dd300e060e698" #eth账户 +args = [] # 合约参数路径 + +[client.options] # 客户端选项 + +[recorder.log] +dump=false +dir="./logs" +level="debug" + +[recorder.csv] +dir="./csv" + + + + + diff --git a/benchmark/ethTransfer/contract/Store.go b/benchmark/ethTransfer/contract/Store.go new file mode 100644 index 0000000..02ea1cb --- /dev/null +++ b/benchmark/ethTransfer/contract/Store.go @@ -0,0 +1,407 @@ +//// Code generated - DO NOT EDIT. +//// This file is a generated binding and any manual changes will be lost. +// +package store + +import ( + "math/big" + "strings" + + ethereum "github.com/ethereum/go-ethereum" + "github.com/ethereum/go-ethereum/accounts/abi" + "github.com/ethereum/go-ethereum/accounts/abi/bind" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/event" +) + +// Reference imports to suppress errors if they are not otherwise used. +var ( + _ = big.NewInt + _ = strings.NewReader + _ = ethereum.NotFound + _ = bind.Bind + _ = common.Big1 + _ = types.BloomLookup + _ = event.NewSubscription +) + +// StoreABI is the input ABI used to generate the binding from. +const StoreABI = "[{\"inputs\":[{\"internalType\":\"string\",\"name\":\"_version\",\"type\":\"string\"}],\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"bytes32\",\"name\":\"key\",\"type\":\"bytes32\"},{\"indexed\":false,\"internalType\":\"bytes32\",\"name\":\"value\",\"type\":\"bytes32\"}],\"name\":\"ItemSet\",\"type\":\"event\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"name\":\"items\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"key\",\"type\":\"bytes32\"},{\"internalType\":\"bytes32\",\"name\":\"value\",\"type\":\"bytes32\"}],\"name\":\"setItem\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"version\",\"outputs\":[{\"internalType\":\"string\",\"name\":\"\",\"type\":\"string\"}],\"stateMutability\":\"view\",\"type\":\"function\"}]" + +// StoreBin is the compiled bytecode used for deploying new contracts. +var StoreBin = "0x608060405234801561001057600080fd5b5060405161072138038061072183398181016040528101906100329190610162565b806000908051906020019061004892919061004f565b505061031a565b82805461005b90610234565b90600052602060002090601f01602090048101928261007d57600085556100c4565b82601f1061009657805160ff19168380011785556100c4565b828001600101855582156100c4579182015b828111156100c35782518255916020019190600101906100a8565b5b5090506100d191906100d5565b5090565b5b808211156100ee5760008160009055506001016100d6565b5090565b6000610105610100846101d0565b6101ab565b905082815260208101848484011115610121576101206102fa565b5b61012c848285610201565b509392505050565b600082601f830112610149576101486102f5565b5b81516101598482602086016100f2565b91505092915050565b60006020828403121561017857610177610304565b5b600082015167ffffffffffffffff811115610196576101956102ff565b5b6101a284828501610134565b91505092915050565b60006101b56101c6565b90506101c18282610266565b919050565b6000604051905090565b600067ffffffffffffffff8211156101eb576101ea6102c6565b5b6101f482610309565b9050602081019050919050565b60005b8381101561021f578082015181840152602081019050610204565b8381111561022e576000848401525b50505050565b6000600282049050600182168061024c57607f821691505b602082108114156102605761025f610297565b5b50919050565b61026f82610309565b810181811067ffffffffffffffff8211171561028e5761028d6102c6565b5b80604052505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b600080fd5b600080fd5b600080fd5b600080fd5b6000601f19601f8301169050919050565b6103f8806103296000396000f3fe608060405234801561001057600080fd5b50600436106100415760003560e01c806348f343f31461004657806354fd4d5014610076578063f56256c714610094575b600080fd5b610060600480360381019061005b91906101c0565b6100b0565b60405161006d9190610275565b60405180910390f35b61007e6100c8565b60405161008b91906102b9565b60405180910390f35b6100ae60048036038101906100a991906101ed565b610156565b005b60016020528060005260406000206000915090505481565b600080546100d590610334565b80601f016020809104026020016040519081016040528092919081815260200182805461010190610334565b801561014e5780601f106101235761010080835404028352916020019161014e565b820191906000526020600020905b81548152906001019060200180831161013157829003601f168201915b505050505081565b8060016000848152602001908152602001600020819055507fe79e73da417710ae99aa2088575580a60415d359acfad9cdd3382d59c80281d4828260405161019f929190610290565b60405180910390a15050565b6000813590506101ba816103ab565b92915050565b6000602082840312156101d6576101d5610395565b5b60006101e4848285016101ab565b91505092915050565b6000806040838503121561020457610203610395565b5b6000610212858286016101ab565b9250506020610223858286016101ab565b9150509250929050565b610236816102f7565b82525050565b6000610247826102db565b61025181856102e6565b9350610261818560208601610301565b61026a8161039a565b840191505092915050565b600060208201905061028a600083018461022d565b92915050565b60006040820190506102a5600083018561022d565b6102b2602083018461022d565b9392505050565b600060208201905081810360008301526102d3818461023c565b905092915050565b600081519050919050565b600082825260208201905092915050565b6000819050919050565b60005b8381101561031f578082015181840152602081019050610304565b8381111561032e576000848401525b50505050565b6000600282049050600182168061034c57607f821691505b602082108114156103605761035f610366565b5b50919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b600080fd5b6000601f19601f8301169050919050565b6103b4816102f7565b81146103bf57600080fd5b5056fea264697066735822122005a5951e5067dae6b917ec5a4c3ccb95f0179d7371d220df636bc264a789ee6e64736f6c63430008060033" + +// DeployStore deploys a new Ethereum contract, binding an instance of Store to it. +func DeployStore(auth *bind.TransactOpts, backend bind.ContractBackend, _version string) (common.Address, *types.Transaction, *Store, error) { + parsed, err := abi.JSON(strings.NewReader(StoreABI)) + if err != nil { + return common.Address{}, nil, nil, err + } + + address, tx, contract, err := bind.DeployContract(auth, parsed, common.FromHex(StoreBin), backend, _version) + if err != nil { + return common.Address{}, nil, nil, err + } + return address, tx, &Store{StoreCaller: StoreCaller{contract: contract}, StoreTransactor: StoreTransactor{contract: contract}, StoreFilterer: StoreFilterer{contract: contract}}, nil +} + +// Store is an auto generated Go binding around an Ethereum contract. +type Store struct { + StoreCaller // Read-only binding to the contract + StoreTransactor // Write-only binding to the contract + StoreFilterer // Log filterer for contract events +} + +// StoreCaller is an auto generated read-only Go binding around an Ethereum contract. +type StoreCaller struct { + contract *bind.BoundContract // Generic contract wrapper for the low level calls +} + +// StoreTransactor is an auto generated write-only Go binding around an Ethereum contract. +type StoreTransactor struct { + contract *bind.BoundContract // Generic contract wrapper for the low level calls +} + +// StoreFilterer is an auto generated log filtering Go binding around an Ethereum contract events. +type StoreFilterer struct { + contract *bind.BoundContract // Generic contract wrapper for the low level calls +} + +// StoreSession is an auto generated Go binding around an Ethereum contract, +// with pre-set call and transact options. +type StoreSession struct { + Contract *Store // Generic contract binding to set the session for + CallOpts bind.CallOpts // Call options to use throughout this session + TransactOpts bind.TransactOpts // Transaction auth options to use throughout this session +} + +// StoreCallerSession is an auto generated read-only Go binding around an Ethereum contract, +// with pre-set call options. +type StoreCallerSession struct { + Contract *StoreCaller // Generic contract caller binding to set the session for + CallOpts bind.CallOpts // Call options to use throughout this session +} + +// StoreTransactorSession is an auto generated write-only Go binding around an Ethereum contract, +// with pre-set transact options. +type StoreTransactorSession struct { + Contract *StoreTransactor // Generic contract transactor binding to set the session for + TransactOpts bind.TransactOpts // Transaction auth options to use throughout this session +} + +// StoreRaw is an auto generated low-level Go binding around an Ethereum contract. +type StoreRaw struct { + Contract *Store // Generic contract binding to access the raw methods on +} + +// StoreCallerRaw is an auto generated low-level read-only Go binding around an Ethereum contract. +type StoreCallerRaw struct { + Contract *StoreCaller // Generic read-only contract binding to access the raw methods on +} + +// StoreTransactorRaw is an auto generated low-level write-only Go binding around an Ethereum contract. +type StoreTransactorRaw struct { + Contract *StoreTransactor // Generic write-only contract binding to access the raw methods on +} + +// NewStore creates a new instance of Store, bound to a specific deployed contract. +func NewStore(address common.Address, backend bind.ContractBackend) (*Store, error) { + contract, err := bindStore(address, backend, backend, backend) + if err != nil { + return nil, err + } + return &Store{StoreCaller: StoreCaller{contract: contract}, StoreTransactor: StoreTransactor{contract: contract}, StoreFilterer: StoreFilterer{contract: contract}}, nil +} + +// NewStoreCaller creates a new read-only instance of Store, bound to a specific deployed contract. +func NewStoreCaller(address common.Address, caller bind.ContractCaller) (*StoreCaller, error) { + contract, err := bindStore(address, caller, nil, nil) + if err != nil { + return nil, err + } + return &StoreCaller{contract: contract}, nil +} + +// NewStoreTransactor creates a new write-only instance of Store, bound to a specific deployed contract. +func NewStoreTransactor(address common.Address, transactor bind.ContractTransactor) (*StoreTransactor, error) { + contract, err := bindStore(address, nil, transactor, nil) + if err != nil { + return nil, err + } + return &StoreTransactor{contract: contract}, nil +} + +// NewStoreFilterer creates a new log filterer instance of Store, bound to a specific deployed contract. +func NewStoreFilterer(address common.Address, filterer bind.ContractFilterer) (*StoreFilterer, error) { + contract, err := bindStore(address, nil, nil, filterer) + if err != nil { + return nil, err + } + return &StoreFilterer{contract: contract}, nil +} + +// bindStore binds a generic wrapper to an already deployed contract. +func bindStore(address common.Address, caller bind.ContractCaller, transactor bind.ContractTransactor, filterer bind.ContractFilterer) (*bind.BoundContract, error) { + parsed, err := abi.JSON(strings.NewReader(StoreABI)) + if err != nil { + return nil, err + } + return bind.NewBoundContract(address, parsed, caller, transactor, filterer), nil +} + +// Call invokes the (constant) contract method with params as input values and +// sets the output to result. The result type might be a single field for simple +// returns, a slice of interfaces for anonymous returns and a struct for named +// returns. +func (_Store *StoreRaw) Call(opts *bind.CallOpts, result *[]interface{}, method string, params ...interface{}) error { + return _Store.Contract.StoreCaller.contract.Call(opts, result, method, params...) +} + +// Transfer initiates a plain transaction to move funds to the contract, calling +// its default method if one is available. +func (_Store *StoreRaw) Transfer(opts *bind.TransactOpts) (*types.Transaction, error) { + return _Store.Contract.StoreTransactor.contract.Transfer(opts) +} + +// Transact invokes the (paid) contract method with params as input values. +func (_Store *StoreRaw) Transact(opts *bind.TransactOpts, method string, params ...interface{}) (*types.Transaction, error) { + return _Store.Contract.StoreTransactor.contract.Transact(opts, method, params...) +} + +// Call invokes the (constant) contract method with params as input values and +// sets the output to result. The result type might be a single field for simple +// returns, a slice of interfaces for anonymous returns and a struct for named +// returns. +func (_Store *StoreCallerRaw) Call(opts *bind.CallOpts, result *[]interface{}, method string, params ...interface{}) error { + return _Store.Contract.contract.Call(opts, result, method, params...) +} + +// Transfer initiates a plain transaction to move funds to the contract, calling +// its default method if one is available. +func (_Store *StoreTransactorRaw) Transfer(opts *bind.TransactOpts) (*types.Transaction, error) { + return _Store.Contract.contract.Transfer(opts) +} + +// Transact invokes the (paid) contract method with params as input values. +func (_Store *StoreTransactorRaw) Transact(opts *bind.TransactOpts, method string, params ...interface{}) (*types.Transaction, error) { + return _Store.Contract.contract.Transact(opts, method, params...) +} + +// Items is a free data retrieval call binding the contract method 0x48f343f3. +// +// Solidity: function items(bytes32 ) view returns(bytes32) +func (_Store *StoreCaller) Items(opts *bind.CallOpts, arg0 [32]byte) ([32]byte, error) { + var out []interface{} + err := _Store.contract.Call(opts, &out, "items", arg0) + + if err != nil { + return *new([32]byte), err + } + + out0 := *abi.ConvertType(out[0], new([32]byte)).(*[32]byte) + + return out0, err + +} + +// Items is a free data retrieval call binding the contract method 0x48f343f3. +// +// Solidity: function items(bytes32 ) view returns(bytes32) +func (_Store *StoreSession) Items(arg0 [32]byte) ([32]byte, error) { + return _Store.Contract.Items(&_Store.CallOpts, arg0) +} + +// Items is a free data retrieval call binding the contract method 0x48f343f3. +// +// Solidity: function items(bytes32 ) view returns(bytes32) +func (_Store *StoreCallerSession) Items(arg0 [32]byte) ([32]byte, error) { + return _Store.Contract.Items(&_Store.CallOpts, arg0) +} + +// Version is a free data retrieval call binding the contract method 0x54fd4d50. +// +// Solidity: function version() view returns(string) +func (_Store *StoreCaller) Version(opts *bind.CallOpts) (string, error) { + var out []interface{} + err := _Store.contract.Call(opts, &out, "version") + + if err != nil { + return *new(string), err + } + + out0 := *abi.ConvertType(out[0], new(string)).(*string) + + return out0, err + +} + +// Version is a free data retrieval call binding the contract method 0x54fd4d50. +// +// Solidity: function version() view returns(string) +func (_Store *StoreSession) Version() (string, error) { + return _Store.Contract.Version(&_Store.CallOpts) +} + +// Version is a free data retrieval call binding the contract method 0x54fd4d50. +// +// Solidity: function version() view returns(string) +func (_Store *StoreCallerSession) Version() (string, error) { + return _Store.Contract.Version(&_Store.CallOpts) +} + +// SetItem is a paid mutator transaction binding the contract method 0xf56256c7. +// +// Solidity: function setItem(bytes32 key, bytes32 value) returns() +func (_Store *StoreTransactor) SetItem(opts *bind.TransactOpts, key [32]byte, value [32]byte) (*types.Transaction, error) { + return _Store.contract.Transact(opts, "setItem", key, value) +} + +// SetItem is a paid mutator transaction binding the contract method 0xf56256c7. +// +// Solidity: function setItem(bytes32 key, bytes32 value) returns() +func (_Store *StoreSession) SetItem(key [32]byte, value [32]byte) (*types.Transaction, error) { + return _Store.Contract.SetItem(&_Store.TransactOpts, key, value) +} + +// SetItem is a paid mutator transaction binding the contract method 0xf56256c7. +// +// Solidity: function setItem(bytes32 key, bytes32 value) returns() +func (_Store *StoreTransactorSession) SetItem(key [32]byte, value [32]byte) (*types.Transaction, error) { + return _Store.Contract.SetItem(&_Store.TransactOpts, key, value) +} + +// StoreItemSetIterator is returned from FilterItemSet and is used to iterate over the raw logs and unpacked data for ItemSet events raised by the Store contract. +type StoreItemSetIterator struct { + Event *StoreItemSet // Event containing the contract specifics and raw log + + contract *bind.BoundContract // Generic contract to use for unpacking event data + event string // Event name to use for unpacking event data + + logs chan types.Log // Log channel receiving the found contract events + sub ethereum.Subscription // Subscription for errors, completion and termination + done bool // Whether the subscription completed delivering logs + fail error // Occurred error to stop iteration +} + +// Next advances the iterator to the subsequent event, returning whether there +// are any more events found. In case of a retrieval or parsing error, false is +// returned and Error() can be queried for the exact failure. +func (it *StoreItemSetIterator) Next() bool { + // If the iterator failed, stop iterating + if it.fail != nil { + return false + } + // If the iterator completed, deliver directly whatever's available + if it.done { + select { + case log := <-it.logs: + it.Event = new(StoreItemSet) + if err := it.contract.UnpackLog(it.Event, it.event, log); err != nil { + it.fail = err + return false + } + it.Event.Raw = log + return true + + default: + return false + } + } + // Iterator still in progress, wait for either a data or an error event + select { + case log := <-it.logs: + it.Event = new(StoreItemSet) + if err := it.contract.UnpackLog(it.Event, it.event, log); err != nil { + it.fail = err + return false + } + it.Event.Raw = log + return true + + case err := <-it.sub.Err(): + it.done = true + it.fail = err + return it.Next() + } +} + +// Error returns any retrieval or parsing error occurred during filtering. +func (it *StoreItemSetIterator) Error() error { + return it.fail +} + +// Close terminates the iteration process, releasing any pending underlying +// resources. +func (it *StoreItemSetIterator) Close() error { + it.sub.Unsubscribe() + return nil +} + +// StoreItemSet represents a ItemSet event raised by the Store contract. +type StoreItemSet struct { + Key [32]byte + Value [32]byte + Raw types.Log // Blockchain specific contextual infos +} + +// FilterItemSet is a free log retrieval operation binding the contract event 0xe79e73da417710ae99aa2088575580a60415d359acfad9cdd3382d59c80281d4. +// +// Solidity: event ItemSet(bytes32 key, bytes32 value) +func (_Store *StoreFilterer) FilterItemSet(opts *bind.FilterOpts) (*StoreItemSetIterator, error) { + + logs, sub, err := _Store.contract.FilterLogs(opts, "ItemSet") + if err != nil { + return nil, err + } + return &StoreItemSetIterator{contract: _Store.contract, event: "ItemSet", logs: logs, sub: sub}, nil +} + +// WatchItemSet is a free log subscription operation binding the contract event 0xe79e73da417710ae99aa2088575580a60415d359acfad9cdd3382d59c80281d4. +// +// Solidity: event ItemSet(bytes32 key, bytes32 value) +func (_Store *StoreFilterer) WatchItemSet(opts *bind.WatchOpts, sink chan<- *StoreItemSet) (event.Subscription, error) { + + logs, sub, err := _Store.contract.WatchLogs(opts, "ItemSet") + if err != nil { + return nil, err + } + return event.NewSubscription(func(quit <-chan struct{}) error { + defer sub.Unsubscribe() + for { + select { + case log := <-logs: + // New log arrived, parse the event and forward to the user + event := new(StoreItemSet) + if err := _Store.contract.UnpackLog(event, "ItemSet", log); err != nil { + return err + } + event.Raw = log + + select { + case sink <- event: + case err := <-sub.Err(): + return err + case <-quit: + return nil + } + case err := <-sub.Err(): + return err + case <-quit: + return nil + } + } + }), nil +} + +// ParseItemSet is a log parse operation binding the contract event 0xe79e73da417710ae99aa2088575580a60415d359acfad9cdd3382d59c80281d4. +// +// Solidity: event ItemSet(bytes32 key, bytes32 value) +func (_Store *StoreFilterer) ParseItemSet(log types.Log) (*StoreItemSet, error) { + event := new(StoreItemSet) + if err := _Store.contract.UnpackLog(event, "ItemSet", log); err != nil { + return nil, err + } + event.Raw = log + return event, nil +} diff --git a/benchmark/ethTransfer/contract/Store.sol b/benchmark/ethTransfer/contract/Store.sol new file mode 100644 index 0000000..8f74708 --- /dev/null +++ b/benchmark/ethTransfer/contract/Store.sol @@ -0,0 +1,17 @@ +pragma solidity ^0.8.6; + +contract Store { + event ItemSet(bytes32 key, bytes32 value); + + string public version; + mapping (bytes32 => bytes32) public items; + + constructor(string memory _version) public { + version = _version; + } + + function setItem(bytes32 key, bytes32 value) external { + items[key] = value; + emit ItemSet(key, value); + } +} \ No newline at end of file diff --git a/benchmark/ethTransfer/contract/Store_sol_Store.abi b/benchmark/ethTransfer/contract/Store_sol_Store.abi new file mode 100644 index 0000000..ca9af19 --- /dev/null +++ b/benchmark/ethTransfer/contract/Store_sol_Store.abi @@ -0,0 +1 @@ +[{"inputs":[{"internalType":"string","name":"_version","type":"string"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes32","name":"key","type":"bytes32"},{"indexed":false,"internalType":"bytes32","name":"value","type":"bytes32"}],"name":"ItemSet","type":"event"},{"inputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"name":"items","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"key","type":"bytes32"},{"internalType":"bytes32","name":"value","type":"bytes32"}],"name":"setItem","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"version","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"}] diff --git a/benchmark/ethTransfer/contract/Store_sol_Store.bin b/benchmark/ethTransfer/contract/Store_sol_Store.bin new file mode 100644 index 0000000..246bf10 --- /dev/null +++ b/benchmark/ethTransfer/contract/Store_sol_Store.bin @@ -0,0 +1 @@ +608060405234801561001057600080fd5b5060405161072138038061072183398181016040528101906100329190610162565b806000908051906020019061004892919061004f565b505061031a565b82805461005b90610234565b90600052602060002090601f01602090048101928261007d57600085556100c4565b82601f1061009657805160ff19168380011785556100c4565b828001600101855582156100c4579182015b828111156100c35782518255916020019190600101906100a8565b5b5090506100d191906100d5565b5090565b5b808211156100ee5760008160009055506001016100d6565b5090565b6000610105610100846101d0565b6101ab565b905082815260208101848484011115610121576101206102fa565b5b61012c848285610201565b509392505050565b600082601f830112610149576101486102f5565b5b81516101598482602086016100f2565b91505092915050565b60006020828403121561017857610177610304565b5b600082015167ffffffffffffffff811115610196576101956102ff565b5b6101a284828501610134565b91505092915050565b60006101b56101c6565b90506101c18282610266565b919050565b6000604051905090565b600067ffffffffffffffff8211156101eb576101ea6102c6565b5b6101f482610309565b9050602081019050919050565b60005b8381101561021f578082015181840152602081019050610204565b8381111561022e576000848401525b50505050565b6000600282049050600182168061024c57607f821691505b602082108114156102605761025f610297565b5b50919050565b61026f82610309565b810181811067ffffffffffffffff8211171561028e5761028d6102c6565b5b80604052505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b600080fd5b600080fd5b600080fd5b600080fd5b6000601f19601f8301169050919050565b6103f8806103296000396000f3fe608060405234801561001057600080fd5b50600436106100415760003560e01c806348f343f31461004657806354fd4d5014610076578063f56256c714610094575b600080fd5b610060600480360381019061005b91906101c0565b6100b0565b60405161006d9190610275565b60405180910390f35b61007e6100c8565b60405161008b91906102b9565b60405180910390f35b6100ae60048036038101906100a991906101ed565b610156565b005b60016020528060005260406000206000915090505481565b600080546100d590610334565b80601f016020809104026020016040519081016040528092919081815260200182805461010190610334565b801561014e5780601f106101235761010080835404028352916020019161014e565b820191906000526020600020905b81548152906001019060200180831161013157829003601f168201915b505050505081565b8060016000848152602001908152602001600020819055507fe79e73da417710ae99aa2088575580a60415d359acfad9cdd3382d59c80281d4828260405161019f929190610290565b60405180910390a15050565b6000813590506101ba816103ab565b92915050565b6000602082840312156101d6576101d5610395565b5b60006101e4848285016101ab565b91505092915050565b6000806040838503121561020457610203610395565b5b6000610212858286016101ab565b9250506020610223858286016101ab565b9150509250929050565b610236816102f7565b82525050565b6000610247826102db565b61025181856102e6565b9350610261818560208601610301565b61026a8161039a565b840191505092915050565b600060208201905061028a600083018461022d565b92915050565b60006040820190506102a5600083018561022d565b6102b2602083018461022d565b9392505050565b600060208201905081810360008301526102d3818461023c565b905092915050565b600081519050919050565b600082825260208201905092915050565b6000819050919050565b60005b8381101561031f578082015181840152602081019050610304565b8381111561032e576000848401525b50505050565b6000600282049050600182168061034c57607f821691505b602082108114156103605761035f610366565b5b50919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b600080fd5b6000601f19601f8301169050919050565b6103b4816102f7565b81146103bf57600080fd5b5056fea264697066735822122005a5951e5067dae6b917ec5a4c3ccb95f0179d7371d220df636bc264a789ee6e64736f6c63430008060033 \ No newline at end of file diff --git a/benchmark/ethTransfer/script.lua b/benchmark/ethTransfer/script.lua new file mode 100644 index 0000000..89b1538 --- /dev/null +++ b/benchmark/ethTransfer/script.lua @@ -0,0 +1,13 @@ +local case = testcase.new() + +function case:Run() + local ret = case.blockchain:Transfer({ + from = "0x01eeC173917c429901b41b98Ac3DD300e060e698", + to = "a6df6489927a9d0172185efe68de1f9aace82639", + amount = 100, + extra = "", + }) + return ret +end + +return case diff --git a/cmd/cobra_test.go b/cmd/cobra_test.go index 1083a25..941d6ea 100644 --- a/cmd/cobra_test.go +++ b/cmd/cobra_test.go @@ -3,3 +3,5 @@ @Author : lmm */ package cmd + + diff --git a/common/config.go b/common/config.go index 9a1b355..f802311 100644 --- a/common/config.go +++ b/common/config.go @@ -45,6 +45,7 @@ const ( ClientContractPath = "client.contract" ClientContractArgsPath = "client.args" ClientOptionPath = "client.options" + ClientAccount = "client.account" ) // recorder diff --git a/core/controller/master/master.go b/core/controller/master/master.go index 49d9cff..0b41cca 100644 --- a/core/controller/master/master.go +++ b/core/controller/master/master.go @@ -35,9 +35,9 @@ func (m *LocalMaster) Prepare() (err error) { if err != nil { return errors.Wrap(err, "can not call user hook `BeforeDeploy`") } - // prepare contract err = m.masterVM.DeployContract() + if err != nil { return errors.Wrap(err, "can not deploy contract") } diff --git a/core/controller/worker/local.go b/core/controller/worker/local.go index 251db66..e2ef25a 100644 --- a/core/controller/worker/local.go +++ b/core/controller/worker/local.go @@ -147,7 +147,6 @@ func (l *LocalWorker) asyncJob() { l.pool.Push(v) l.wg.Done() }() - res, err := v.Run(common.TxContext{ Context: l.ctx, TxIndex: l.atomicAddIndex(), diff --git a/filesystem/filesystem-packr.go b/filesystem/filesystem-packr.go new file mode 100644 index 0000000..6f4ab5f --- /dev/null +++ b/filesystem/filesystem-packr.go @@ -0,0 +1,8 @@ +// +build !skippackr +// Code generated by github.com/gobuffalo/packr/v2. DO NOT EDIT. + +// You can use the "packr clean" command to clean up this, +// and any other packr generated files. +package filesystem + +import _ "github.com/meshplus/hyperbench/packrd" diff --git a/go.mod b/go.mod index c549ba8..117b497 100644 --- a/go.mod +++ b/go.mod @@ -2,6 +2,8 @@ module github.com/meshplus/hyperbench require ( github.com/Shopify/sarama v1.23.1 // indirect + github.com/coreos/etcd v3.3.13+incompatible // indirect + github.com/ethereum/go-ethereum v1.10.9 github.com/fsouza/go-dockerclient v1.4.4 // indirect github.com/gin-gonic/gin v1.6.3 github.com/gobuffalo/logger v1.0.4 // indirect @@ -20,24 +22,21 @@ require ( github.com/meshplus/gosdk v0.1.1 github.com/mholt/archiver/v3 v3.5.0 github.com/mitchellh/mapstructure v1.4.1 - github.com/onsi/ginkgo v1.10.3 // indirect github.com/op/go-logging v0.0.0-20160315200505-970db520ece7 github.com/pingcap/failpoint v0.0.0-20191029060244-12f4ac2fd11d github.com/pkg/errors v0.9.1 - github.com/rogpeppe/go-internal v1.6.2 // indirect - github.com/sirupsen/logrus v1.7.0 // indirect + github.com/rogpeppe/go-internal v1.8.0 // indirect + github.com/sirupsen/logrus v1.8.1 // indirect github.com/spf13/cast v1.3.1 - github.com/spf13/cobra v1.1.1 - github.com/spf13/viper v1.7.0 - github.com/stretchr/testify v1.6.1 + github.com/spf13/cobra v1.2.1 + github.com/spf13/viper v1.8.1 + github.com/stretchr/testify v1.7.0 github.com/sykesm/zap-logfmt v0.0.2 // indirect github.com/yuin/gluamapper v0.0.0-20150323120927-d836955830e7 github.com/yuin/gopher-lua v0.0.0-20190206043414-8bfc7677f583 - golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad // indirect - golang.org/x/net v0.0.0-20201021035429-f5854403a974 // indirect - golang.org/x/sync v0.0.0-20201207232520-09787c993a3a // indirect - golang.org/x/sys v0.0.0-20201223074533-0d417f636930 // indirect - golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect + golang.org/x/sys v0.0.0-20211020174200-9d6173849985 // indirect + golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect + golang.org/x/tools v0.1.7 // indirect gopkg.in/jcmturner/goidentity.v3 v3.0.0 // indirect layeh.com/gopher-luar v1.0.8-0.20190807124245-b07e371a3bb0 ) @@ -46,4 +45,6 @@ replace layeh.com/gopher-luar => github.com/layeh/gopher-luar v1.0.8-0.201908071 replace golang.org/x/sys => github.com/golang/sys v0.0.0-20190813064441-fde4db37ae7a +replace github.com/meshplus/crypto-standard => github.com/dawn-to-dusk/crypto-standard v0.1.2-0.20210915031756-9c6750095d70 // indirect + go 1.13 diff --git a/main.go b/main.go index 87b2c96..9b50ef1 100644 --- a/main.go +++ b/main.go @@ -17,4 +17,5 @@ func main() { if err != nil { fmt.Println("cmd execute fail: ", err) } + } diff --git a/plugins/blockchain/blockchain.go b/plugins/blockchain/blockchain.go index 4b520ee..8496eaa 100644 --- a/plugins/blockchain/blockchain.go +++ b/plugins/blockchain/blockchain.go @@ -4,6 +4,7 @@ import ( "github.com/meshplus/hyperbench/common" "github.com/meshplus/hyperbench/plugins/blockchain/base" bcom "github.com/meshplus/hyperbench/plugins/blockchain/common" + "github.com/meshplus/hyperbench/plugins/blockchain/eth" "github.com/meshplus/hyperbench/plugins/blockchain/fabric" "github.com/meshplus/hyperbench/plugins/blockchain/hyperchain" ) @@ -12,6 +13,7 @@ const ( clientHpc = "hyperchain" clientFlato = "flato" clientFabric = "fabric" + clientEth = "eth" ) // NewBlockchain create blockchain with different client type. @@ -22,6 +24,8 @@ func NewBlockchain(clientConfig base.ClientConfig) (client Blockchain, err error client, err = hyperchain.NewClient(clientBase) case clientFabric: client, err = fabric.New(clientBase) + case clientEth: + client, err = eth.New(clientBase) default: client = clientBase } diff --git a/plugins/blockchain/common/common.go b/plugins/blockchain/common/common.go index b04b0cf..c7be1dc 100644 --- a/plugins/blockchain/common/common.go +++ b/plugins/blockchain/common/common.go @@ -1,5 +1,7 @@ package common +import "github.com/ethereum/go-ethereum/common" + // Invoke define need filed for invoke contract. type Invoke struct { Func string `mapstructure:"func"` @@ -31,3 +33,6 @@ type Statistic struct { From int64 `mapstructure:"from"` To int64 `mapstructure:"to"` } + +// ContractAddress by eth +var ContractAddress common.Address diff --git a/plugins/blockchain/eth/eth.go b/plugins/blockchain/eth/eth.go new file mode 100644 index 0000000..a0fae2a --- /dev/null +++ b/plugins/blockchain/eth/eth.go @@ -0,0 +1,360 @@ +package eth + +import ( + "context" + "crypto/ecdsa" + "encoding/hex" + "encoding/json" + "fmt" + "github.com/ethereum/go-ethereum/accounts/abi/bind" + "github.com/ethereum/go-ethereum/accounts/keystore" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/crypto" + "github.com/ethereum/go-ethereum/ethclient" + store "github.com/meshplus/hyperbench/benchmark/ethInvoke/contract" + fcom "github.com/meshplus/hyperbench/common" + "github.com/meshplus/hyperbench/plugins/blockchain/base" + bcom "github.com/meshplus/hyperbench/plugins/blockchain/common" + + "github.com/spf13/viper" + "io/ioutil" + "log" + "math/big" + "time" +) + + +type ETH struct { + *base.BlockchainBase + ethClient *ethclient.Client + privateKey *ecdsa.PrivateKey + auth *bind.TransactOpts + contractAddress common.Address + startBlock uint64 +} + +//Msg contains message of context +type Msg struct { + contractAddress common.Address + startBlock uint64 +} + +// New use given blockchainBase create ETH. +func New(blockchainBase *base.BlockchainBase) (client *ETH, err error) { + ethClient, err := ethclient.Dial(viper.GetString(fcom.ClientConfigPath)+"/geth.ipc") + if err != nil { + log.Fatal(err) + } + + privKey, _, err := KeystoreToPrivateKey(viper.GetString(fcom.ClientConfigPath)+"/keystore/"+viper.GetString(fcom.ClientAccount), "") + if err != nil { + log.Fatal(err) + } + + privateKey, err := crypto.HexToECDSA(privKey) + if err != nil { + log.Fatal(err) + } + publicKey := privateKey.Public() + publicKeyECDSA, ok := publicKey.(*ecdsa.PublicKey) + if !ok { + log.Fatal("cannot assert type: publicKey is not of type *ecdsa.PublicKey") + } + + fromAddress := crypto.PubkeyToAddress(*publicKeyECDSA) + nonce, err := ethClient.PendingNonceAt(context.Background(), fromAddress) + if err != nil { + log.Fatal(err) + } + + gasPrice, err := ethClient.SuggestGasPrice(context.Background()) + if err != nil { + log.Fatal(err) + } + chainID, err := ethClient.NetworkID(context.Background()) + auth,_ := bind.NewKeyedTransactorWithChainID(privateKey, chainID) + auth.Nonce = big.NewInt(int64(nonce)) + auth.Value = big.NewInt(0) // in wei + auth.GasLimit = uint64(300000) // in units + auth.GasPrice = gasPrice + startBlock, err := ethClient.HeaderByNumber(context.Background(), nil) + client = Ð{ + BlockchainBase: blockchainBase, + ethClient: ethClient, + privateKey: privateKey, + auth: auth, + startBlock: startBlock.Number.Uint64(), + } + + return +} +func (e *ETH) DeployContract() error { + + input := "1.0" + contractAddress, tx, instance, err := store.DeployStore(e.auth, e.ethClient, input) + if err != nil { + log.Fatal(err) + } + bcom.ContractAddress = contractAddress + e.contractAddress = contractAddress + e.Logger.Info("contractAddress:"+contractAddress.Hex()) + e.Logger.Info("txHash:"+tx.Hash().Hex()) + _ = instance + + return nil +} + +//Invoke invoke contract with funcName and args in eth network +func (e *ETH) Invoke(invoke bcom.Invoke, ops ...bcom.Option) *fcom.Result { + instance, err := store.NewStore(bcom.ContractAddress, e.ethClient) + if err != nil { + log.Fatal(err) + } + + key := [32]byte{} + value := [32]byte{} + copy(key[:], []byte("foo")) + copy(value[:], []byte("bar")) + if err != nil { + log.Fatal(err) + } + publicKey := e.privateKey.Public() + publicKeyECDSA, ok := publicKey.(*ecdsa.PublicKey) + if !ok { + log.Fatal("cannot assert type: publicKey is not of type *ecdsa.PublicKey") + } + + fromAddress := crypto.PubkeyToAddress(*publicKeyECDSA) + nonce, err := e.ethClient.PendingNonceAt(context.Background(), fromAddress) + if err != nil { + log.Fatal(err) + } + + gasPrice, err := e.ethClient.SuggestGasPrice(context.Background()) + if err != nil { + log.Fatal(err) + } + chainID, err := e.ethClient.NetworkID(context.Background()) + auth,_ := bind.NewKeyedTransactorWithChainID(e.privateKey, chainID) + auth.Nonce = big.NewInt(int64(nonce)) + auth.Value = big.NewInt(0) // in wei + auth.GasLimit = uint64(300000) // in units + auth.GasPrice = gasPrice + + tx, err := instance.SetItem(auth, key, value) + if err != nil { + log.Fatal(err) + } + + startTime := time.Now().UnixNano() + _, _, err = e.ethClient.TransactionByHash(context.Background(), tx.Hash()) + + endTime := time.Now().UnixNano() + if err != nil { + return &fcom.Result{ + UID: fcom.InvalidUID, + Ret: []interface{}{}, + Status: fcom.Failure, + BuildTime: startTime, + ConfirmTime: endTime, + } + } + + ret := &fcom.Result{ + UID: fcom.InvalidUID, + Ret: []interface{}{tx.Data()}, + Status: fcom.Success, + BuildTime: startTime, + ConfirmTime: 0, + } + + return ret + +} + +// Confirm check the result of `Invoke` or `Transfer` +func (e *ETH) Confirm(result *fcom.Result, ops ...bcom.Option) *fcom.Result { + + return nil +} + +//Transfer transfer a amount of money from a account to the other one +func (e *ETH) Transfer(args bcom.Transfer, ops ...bcom.Option) (result *fcom.Result) { + + publicKey := e.privateKey.Public() + publicKeyECDSA, ok := publicKey.(*ecdsa.PublicKey) + if !ok { + log.Fatal("cannot assert type: publicKey is not of type *ecdsa.PublicKey") + } + + fromAddress := crypto.PubkeyToAddress(*publicKeyECDSA) + nonce, err := e.ethClient.PendingNonceAt(context.Background(), fromAddress) + if err != nil { + log.Fatal(err) + } + + value := big.NewInt(args.Amount) // in wei (1 eth) + gasLimit := uint64(21000) // in units + gasPrice, err := e.ethClient.SuggestGasPrice(context.Background()) + if err != nil { + log.Fatal(err) + } + + toAddress := common.HexToAddress(args.To) + var data []byte + tx := types.NewTransaction(nonce, toAddress, value, gasLimit, gasPrice, data) + + chainID, err := e.ethClient.NetworkID(context.Background()) + if err != nil { + log.Fatal(err) + } + + signedTx, err := types.SignTx(tx, types.NewEIP155Signer(chainID), e.privateKey) + if err != nil { + log.Fatal(err) + } + + err = e.ethClient.SendTransaction(context.Background(), signedTx) + if err != nil { + log.Fatal(err) + } + + startTime := time.Now().UnixNano() + _, _, err = e.ethClient.TransactionByHash(context.Background(), signedTx.Hash()) + endTime := time.Now().UnixNano() + if err != nil { + log.Fatal(err) + return &fcom.Result{ + UID: fcom.InvalidUID, + Ret: []interface{}{}, + Status: fcom.Failure, + BuildTime: startTime, + ConfirmTime: endTime, + } + } + + ret := &fcom.Result{ + UID: fcom.InvalidUID, + Ret: []interface{}{tx.Data()}, + Status: fcom.Success, + BuildTime: startTime, + ConfirmTime: 0, + } + + return ret +} + +//SetContext set test group context in go client +func (e *ETH) SetContext(context string) error { + e.Logger.Debugf("prepare msg: %v", context) + msg := &Msg{} + var ( + err error + ) + + if context == "" { + e.Logger.Infof("Prepare nothing") + return nil + } + + err = json.Unmarshal([]byte(context), msg) + if err != nil { + e.Logger.Errorf("can not unmarshal msg: %v \n err: %v", context, err) + return err + } + + // set contract address + e.contractAddress = msg.contractAddress + e.startBlock = msg.startBlock + return nil +} + +//ResetContext reset test group context in go client +func (e *ETH) ResetContext() error { + return nil +} + +//GetContext generate TxContext +func (e *ETH) GetContext() (string, error) { + + msg := &Msg{ + contractAddress: bcom.ContractAddress, + startBlock: e.startBlock, + } + + bytes, error := json.Marshal(msg) + if error != nil { + fmt.Println(error) + } + + return string(bytes), error +} + +//Statistic statistic remote node performance +func (e *ETH) Statistic(statistic bcom.Statistic) (*fcom.RemoteStatistic, error) { + + from, to := statistic.From, statistic.To + + statisticData, err := GetTPS(e, from, to) + + if err != nil { + return &fcom.RemoteStatistic{ + Start: from, + End: to, + }, err + } + return statisticData, nil} + +func (e *ETH) Option(options bcom.Option) error { + + return nil +} + +func KeystoreToPrivateKey(privateKeyFile, password string) (string, string, error) { + keyjson, err := ioutil.ReadFile(privateKeyFile) + if err != nil { + fmt.Println("read keyjson file failed:", err) + } + unlockedKey, err := keystore.DecryptKey(keyjson, password) + if err != nil { + + return "", "", err + + } + privKey := hex.EncodeToString(unlockedKey.PrivateKey.D.Bytes()) + addr := crypto.PubkeyToAddress(unlockedKey.PrivateKey.PublicKey) + return privKey, addr.String(), nil + +} + +func GetTPS(e *ETH, beginTime, endTime int64) (*fcom.RemoteStatistic, error) { + + blockInfo, err := e.ethClient.HeaderByNumber(context.Background(), nil) + if err != nil { + return nil, err + } + + var ( + blockCounter int + txCounter int + ) + + height := blockInfo.Number.Uint64() + for i := e.startBlock; i < height; i++ { + block, err := e.ethClient.BlockByNumber(context.Background(), new(big.Int).SetUint64(i)) + if err != nil { + return nil, err + } + txCounter += len(block.Transactions()) + blockCounter++ + } + + statistic := &fcom.RemoteStatistic{ + Start: beginTime, + End: endTime, + BlockNum: blockCounter, + TxNum: txCounter, + } + return statistic, nil +} diff --git a/plugins/blockchain/eth/eth_test.go b/plugins/blockchain/eth/eth_test.go new file mode 100644 index 0000000..6dc7398 --- /dev/null +++ b/plugins/blockchain/eth/eth_test.go @@ -0,0 +1,212 @@ +package eth + +import ( + "context" + "crypto/ecdsa" + "fmt" + "github.com/ethereum/go-ethereum/accounts/abi/bind" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/crypto" + "github.com/ethereum/go-ethereum/ethclient" + store "github.com/meshplus/hyperbench/benchmark/ethInvoke/contract" + "log" + "math" + "math/big" + "testing" +) +func TestClient(t *testing.T) { + client, err := ethclient.Dial("/Users/aiyoa/desktop/eth-test/data/geth.ipc") + if err != nil { + log.Fatal(err) + } + + fmt.Println("we have a connection") + _ = client // we'll use this in the upcoming sections +} +func TestBalance(t *testing.T){ + client, err := ethclient.Dial("/Users/aiyoa/desktop/eth-test/data/geth.ipc") + account := common.HexToAddress("01eec173917c429901b41b98ac3dd300e060e698") + balance, err := client.BalanceAt(context.Background(), account, nil) + if err != nil { + log.Fatal(err) + } + + fmt.Println(balance) + fbalance := new(big.Float) + fbalance.SetString(balance.String()) + ethValue := new(big.Float).Quo(fbalance, big.NewFloat(math.Pow10(18))) + + fmt.Println(ethValue) +} +func TestTransfer(t *testing.T){ + client, err := ethclient.Dial("/Users/aiyoa/desktop/eth-test/data/geth.ipc") + if err != nil { + log.Fatal(err) + } + + privKey, address, err := KeystoreToPrivateKey("/Users/aiyoa/desktop/eth-test/data/keystore/UTC--2021-10-21T03-41-34.288690000Z--01eec173917c429901b41b98ac3dd300e060e698", "") + if err != nil { + log.Fatal(err) + } + fmt.Printf("privKey:%s\naddress:%s\n", privKey, address) + + privateKey, err := crypto.HexToECDSA(privKey) + if err != nil { + log.Fatal(err) + } + + publicKey := privateKey.Public() + publicKeyECDSA, ok := publicKey.(*ecdsa.PublicKey) + if !ok { + log.Fatal("cannot assert type: publicKey is not of type *ecdsa.PublicKey") + } + + fromAddress := crypto.PubkeyToAddress(*publicKeyECDSA) + nonce, err := client.PendingNonceAt(context.Background(), fromAddress) + if err != nil { + log.Fatal(err) + } + + value := big.NewInt(1000) // in wei (1 eth) + gasLimit := uint64(21000) // in units + gasPrice, err := client.SuggestGasPrice(context.Background()) + if err != nil { + log.Fatal(err) + } + + toAddress := common.HexToAddress("a6df6489927a9d0172185efe68de1f9aace82639") + var data []byte + tx := types.NewTransaction(nonce, toAddress, value, gasLimit, gasPrice, data) + + chainID, err := client.NetworkID(context.Background()) + if err != nil { + log.Fatal(err) + } + + signedTx, err := types.SignTx(tx, types.NewEIP155Signer(chainID), privateKey) + fmt.Println(signedTx.ChainId()) + if err != nil { + log.Fatal(err) + } + + err = client.SendTransaction(context.Background(), signedTx) + if err != nil { + log.Fatal(err) + } + + fmt.Printf("tx sent: %s", signedTx.Hash().Hex()) + +} + +func TestDeployContract(t *testing.T) { + client, err := ethclient.Dial("/Users/aiyoa/desktop/eth-test/data/geth.ipc") + if err != nil { + log.Fatal(err) + } + + privKey, address, err := KeystoreToPrivateKey("/Users/aiyoa/desktop/eth-test/data/keystore/UTC--2021-10-21T03-41-34.288690000Z--01eec173917c429901b41b98ac3dd300e060e698", "") + if err != nil { + log.Fatal(err) + } + fmt.Printf("privKey:%s\naddress:%s\n", privKey, address) + privateKey, err := crypto.HexToECDSA(privKey) + if err != nil { + log.Fatal(err) + } + publicKey := privateKey.Public() + publicKeyECDSA, ok := publicKey.(*ecdsa.PublicKey) + if !ok { + log.Fatal("cannot assert type: publicKey is not of type *ecdsa.PublicKey") + } + + fromAddress := crypto.PubkeyToAddress(*publicKeyECDSA) + nonce, err := client.PendingNonceAt(context.Background(), fromAddress) + if err != nil { + log.Fatal(err) + } + + gasPrice, err := client.SuggestGasPrice(context.Background()) + if err != nil { + log.Fatal(err) + } + chainID, err := client.NetworkID(context.Background()) + auth,_ := bind.NewKeyedTransactorWithChainID(privateKey, chainID) + auth.Nonce = big.NewInt(int64(nonce)) + auth.Value = big.NewInt(0) // in wei + auth.GasLimit = uint64(300000) // in units + auth.GasPrice = gasPrice + input := "1.0" + contractAddress, tx, instance, err := store.DeployStore(auth, client, input) + + if err != nil { + log.Fatal(err) + } + fmt.Println(contractAddress.Hex()) // 0xA103dA779fCB208c02759BB6fBD3eD1d354B9E16 + fmt.Println(tx.Hash().Hex()) // 0x1690003dca86eba1491e0aaa5a1cfde3fa39cafd90058537d8a0c8c4b6863d25 + + _ = instance +} + +func TestInvoke(t *testing.T) { + client, err := ethclient.Dial("/Users/aiyoa/desktop/eth-test/data/geth.ipc") + if err != nil { + log.Fatal(err) + } + + privKey, address, err := KeystoreToPrivateKey("/Users/aiyoa/desktop/eth-test/data/keystore/UTC--2021-10-21T03-41-34.288690000Z--01eec173917c429901b41b98ac3dd300e060e698", "") + if err != nil { + log.Fatal(err) + } + fmt.Printf("privKey:%s\naddress:%s\n", privKey, address) + privateKey, err := crypto.HexToECDSA(privKey) + if err != nil { + log.Fatal(err) + } + publicKey := privateKey.Public() + publicKeyECDSA, ok := publicKey.(*ecdsa.PublicKey) + if !ok { + log.Fatal("cannot assert type: publicKey is not of type *ecdsa.PublicKey") + } + + fromAddress := crypto.PubkeyToAddress(*publicKeyECDSA) + nonce, err := client.PendingNonceAt(context.Background(), fromAddress) + if err != nil { + log.Fatal(err) + } + + gasPrice, err := client.SuggestGasPrice(context.Background()) + if err != nil { + log.Fatal(err) + } + chainID, err := client.NetworkID(context.Background()) + auth,_ := bind.NewKeyedTransactorWithChainID(privateKey, chainID) + auth.Nonce = big.NewInt(int64(nonce)) + auth.Value = big.NewInt(0) // in wei + auth.GasLimit = uint64(300000) // in units + auth.GasPrice = gasPrice + contractAddress := common.HexToAddress("0x7c376C8ED768018aa53d3C37Eed637912fEAA782") + + instance, err := store.NewStore(contractAddress, client) + if err != nil { + log.Fatal(err) + } + key := [32]byte{} + value := [32]byte{} + copy(key[:], []byte("foo")) + copy(value[:], []byte("bar")) + + tx, err := instance.SetItem(auth, key, value) + if err != nil { + log.Fatal(err) + } + + fmt.Printf("tx sent: %s\n", tx.Hash().Hex()) // tx sent: 0x5012ba7c07e46da3e1fbec454ed0e4079936b605d7ef0c0b0d0572972bb32dc6 + result, err := instance.Items(nil, key) + fmt.Println(result) + if err != nil { + log.Fatal(err) + } + + fmt.Println(string(result[:])) // "bar" +} diff --git a/plugins/blockchain/fabric/fabric.go b/plugins/blockchain/fabric/fabric.go index 9c6e70c..8b171c4 100644 --- a/plugins/blockchain/fabric/fabric.go +++ b/plugins/blockchain/fabric/fabric.go @@ -92,6 +92,7 @@ func New(blockchainBase *base.BlockchainBase) (client *Fabric, err error) { // DeployContract deploy contract to fabric network func (f *Fabric) DeployContract() error { + //install chaincode ccID := strconv.Itoa(int(time.Now().UnixNano())) ccVersion := "0" diff --git a/plugins/blockchain/hyperchain/hyperchain.go b/plugins/blockchain/hyperchain/hyperchain.go index 65fe234..5f72e6c 100644 --- a/plugins/blockchain/hyperchain/hyperchain.go +++ b/plugins/blockchain/hyperchain/hyperchain.go @@ -405,7 +405,9 @@ func (c *Client) GetContext() (string, error) { msg := Msg{ Contract: c.contract.ContractRaw, } + bytes, err = json.Marshal(msg) + return string(bytes), err } diff --git a/vm/lua/lua.go b/vm/lua/lua.go index ca70090..1537748 100644 --- a/vm/lua/lua.go +++ b/vm/lua/lua.go @@ -206,7 +206,6 @@ func (v *VM) BeforeRun() error { func (v *VM) Run(ctx common.TxContext) (*common.Result, error) { v.index.Engine = ctx.EngineIdx v.index.Tx = ctx.TxIdx - err := v.vm.CallByParam(lua.P{ Fn: v.instance.RawGetString(run), NRet: 1, From 51694882fe990bc1d0ede6d16c36f37d6fb86aca Mon Sep 17 00:00:00 2001 From: Houqitong <1428952786@qq.com> Date: Thu, 4 Nov 2021 10:24:53 +0800 Subject: [PATCH 2/6] feat: delete eth unit test --- plugins/blockchain/eth/eth_test.go | 210 ----------------------------- 1 file changed, 210 deletions(-) diff --git a/plugins/blockchain/eth/eth_test.go b/plugins/blockchain/eth/eth_test.go index 6dc7398..1e8bdd5 100644 --- a/plugins/blockchain/eth/eth_test.go +++ b/plugins/blockchain/eth/eth_test.go @@ -1,212 +1,2 @@ package eth -import ( - "context" - "crypto/ecdsa" - "fmt" - "github.com/ethereum/go-ethereum/accounts/abi/bind" - "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/core/types" - "github.com/ethereum/go-ethereum/crypto" - "github.com/ethereum/go-ethereum/ethclient" - store "github.com/meshplus/hyperbench/benchmark/ethInvoke/contract" - "log" - "math" - "math/big" - "testing" -) -func TestClient(t *testing.T) { - client, err := ethclient.Dial("/Users/aiyoa/desktop/eth-test/data/geth.ipc") - if err != nil { - log.Fatal(err) - } - - fmt.Println("we have a connection") - _ = client // we'll use this in the upcoming sections -} -func TestBalance(t *testing.T){ - client, err := ethclient.Dial("/Users/aiyoa/desktop/eth-test/data/geth.ipc") - account := common.HexToAddress("01eec173917c429901b41b98ac3dd300e060e698") - balance, err := client.BalanceAt(context.Background(), account, nil) - if err != nil { - log.Fatal(err) - } - - fmt.Println(balance) - fbalance := new(big.Float) - fbalance.SetString(balance.String()) - ethValue := new(big.Float).Quo(fbalance, big.NewFloat(math.Pow10(18))) - - fmt.Println(ethValue) -} -func TestTransfer(t *testing.T){ - client, err := ethclient.Dial("/Users/aiyoa/desktop/eth-test/data/geth.ipc") - if err != nil { - log.Fatal(err) - } - - privKey, address, err := KeystoreToPrivateKey("/Users/aiyoa/desktop/eth-test/data/keystore/UTC--2021-10-21T03-41-34.288690000Z--01eec173917c429901b41b98ac3dd300e060e698", "") - if err != nil { - log.Fatal(err) - } - fmt.Printf("privKey:%s\naddress:%s\n", privKey, address) - - privateKey, err := crypto.HexToECDSA(privKey) - if err != nil { - log.Fatal(err) - } - - publicKey := privateKey.Public() - publicKeyECDSA, ok := publicKey.(*ecdsa.PublicKey) - if !ok { - log.Fatal("cannot assert type: publicKey is not of type *ecdsa.PublicKey") - } - - fromAddress := crypto.PubkeyToAddress(*publicKeyECDSA) - nonce, err := client.PendingNonceAt(context.Background(), fromAddress) - if err != nil { - log.Fatal(err) - } - - value := big.NewInt(1000) // in wei (1 eth) - gasLimit := uint64(21000) // in units - gasPrice, err := client.SuggestGasPrice(context.Background()) - if err != nil { - log.Fatal(err) - } - - toAddress := common.HexToAddress("a6df6489927a9d0172185efe68de1f9aace82639") - var data []byte - tx := types.NewTransaction(nonce, toAddress, value, gasLimit, gasPrice, data) - - chainID, err := client.NetworkID(context.Background()) - if err != nil { - log.Fatal(err) - } - - signedTx, err := types.SignTx(tx, types.NewEIP155Signer(chainID), privateKey) - fmt.Println(signedTx.ChainId()) - if err != nil { - log.Fatal(err) - } - - err = client.SendTransaction(context.Background(), signedTx) - if err != nil { - log.Fatal(err) - } - - fmt.Printf("tx sent: %s", signedTx.Hash().Hex()) - -} - -func TestDeployContract(t *testing.T) { - client, err := ethclient.Dial("/Users/aiyoa/desktop/eth-test/data/geth.ipc") - if err != nil { - log.Fatal(err) - } - - privKey, address, err := KeystoreToPrivateKey("/Users/aiyoa/desktop/eth-test/data/keystore/UTC--2021-10-21T03-41-34.288690000Z--01eec173917c429901b41b98ac3dd300e060e698", "") - if err != nil { - log.Fatal(err) - } - fmt.Printf("privKey:%s\naddress:%s\n", privKey, address) - privateKey, err := crypto.HexToECDSA(privKey) - if err != nil { - log.Fatal(err) - } - publicKey := privateKey.Public() - publicKeyECDSA, ok := publicKey.(*ecdsa.PublicKey) - if !ok { - log.Fatal("cannot assert type: publicKey is not of type *ecdsa.PublicKey") - } - - fromAddress := crypto.PubkeyToAddress(*publicKeyECDSA) - nonce, err := client.PendingNonceAt(context.Background(), fromAddress) - if err != nil { - log.Fatal(err) - } - - gasPrice, err := client.SuggestGasPrice(context.Background()) - if err != nil { - log.Fatal(err) - } - chainID, err := client.NetworkID(context.Background()) - auth,_ := bind.NewKeyedTransactorWithChainID(privateKey, chainID) - auth.Nonce = big.NewInt(int64(nonce)) - auth.Value = big.NewInt(0) // in wei - auth.GasLimit = uint64(300000) // in units - auth.GasPrice = gasPrice - input := "1.0" - contractAddress, tx, instance, err := store.DeployStore(auth, client, input) - - if err != nil { - log.Fatal(err) - } - fmt.Println(contractAddress.Hex()) // 0xA103dA779fCB208c02759BB6fBD3eD1d354B9E16 - fmt.Println(tx.Hash().Hex()) // 0x1690003dca86eba1491e0aaa5a1cfde3fa39cafd90058537d8a0c8c4b6863d25 - - _ = instance -} - -func TestInvoke(t *testing.T) { - client, err := ethclient.Dial("/Users/aiyoa/desktop/eth-test/data/geth.ipc") - if err != nil { - log.Fatal(err) - } - - privKey, address, err := KeystoreToPrivateKey("/Users/aiyoa/desktop/eth-test/data/keystore/UTC--2021-10-21T03-41-34.288690000Z--01eec173917c429901b41b98ac3dd300e060e698", "") - if err != nil { - log.Fatal(err) - } - fmt.Printf("privKey:%s\naddress:%s\n", privKey, address) - privateKey, err := crypto.HexToECDSA(privKey) - if err != nil { - log.Fatal(err) - } - publicKey := privateKey.Public() - publicKeyECDSA, ok := publicKey.(*ecdsa.PublicKey) - if !ok { - log.Fatal("cannot assert type: publicKey is not of type *ecdsa.PublicKey") - } - - fromAddress := crypto.PubkeyToAddress(*publicKeyECDSA) - nonce, err := client.PendingNonceAt(context.Background(), fromAddress) - if err != nil { - log.Fatal(err) - } - - gasPrice, err := client.SuggestGasPrice(context.Background()) - if err != nil { - log.Fatal(err) - } - chainID, err := client.NetworkID(context.Background()) - auth,_ := bind.NewKeyedTransactorWithChainID(privateKey, chainID) - auth.Nonce = big.NewInt(int64(nonce)) - auth.Value = big.NewInt(0) // in wei - auth.GasLimit = uint64(300000) // in units - auth.GasPrice = gasPrice - contractAddress := common.HexToAddress("0x7c376C8ED768018aa53d3C37Eed637912fEAA782") - - instance, err := store.NewStore(contractAddress, client) - if err != nil { - log.Fatal(err) - } - key := [32]byte{} - value := [32]byte{} - copy(key[:], []byte("foo")) - copy(value[:], []byte("bar")) - - tx, err := instance.SetItem(auth, key, value) - if err != nil { - log.Fatal(err) - } - - fmt.Printf("tx sent: %s\n", tx.Hash().Hex()) // tx sent: 0x5012ba7c07e46da3e1fbec454ed0e4079936b605d7ef0c0b0d0572972bb32dc6 - result, err := instance.Items(nil, key) - fmt.Println(result) - if err != nil { - log.Fatal(err) - } - - fmt.Println(string(result[:])) // "bar" -} From 078abcfc3c1f177697e9fa41c9aa6ac56939e4a3 Mon Sep 17 00:00:00 2001 From: Houqitong <1428952786@qq.com> Date: Thu, 4 Nov 2021 10:46:41 +0800 Subject: [PATCH 3/6] feat: add test skip --- plugins/blockchain/eth/eth_test.go | 215 +++++++++++++++++++++++++++++ 1 file changed, 215 insertions(+) diff --git a/plugins/blockchain/eth/eth_test.go b/plugins/blockchain/eth/eth_test.go index 1e8bdd5..db51b8e 100644 --- a/plugins/blockchain/eth/eth_test.go +++ b/plugins/blockchain/eth/eth_test.go @@ -1,2 +1,217 @@ package eth +import ( + "context" + "crypto/ecdsa" + "fmt" + "github.com/ethereum/go-ethereum/accounts/abi/bind" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/crypto" + "github.com/ethereum/go-ethereum/ethclient" + store "github.com/meshplus/hyperbench/benchmark/ethInvoke/contract" + "log" + "math" + "math/big" + "testing" +) +func TestClient(t *testing.T) { + t.Skip() + client, err := ethclient.Dial("/Users/aiyoa/desktop/eth-test/data/geth.ipc") + if err != nil { + log.Fatal(err) + } + + fmt.Println("we have a connection") + _ = client // we'll use this in the upcoming sections +} +func TestBalance(t *testing.T){ + t.Skip() + client, err := ethclient.Dial("/Users/aiyoa/desktop/eth-test/data/geth.ipc") + account := common.HexToAddress("01eec173917c429901b41b98ac3dd300e060e698") + balance, err := client.BalanceAt(context.Background(), account, nil) + if err != nil { + log.Fatal(err) + } + + fmt.Println(balance) + fbalance := new(big.Float) + fbalance.SetString(balance.String()) + ethValue := new(big.Float).Quo(fbalance, big.NewFloat(math.Pow10(18))) + + fmt.Println(ethValue) +} +func TestTransfer(t *testing.T){ + t.Skip() + client, err := ethclient.Dial("/Users/aiyoa/desktop/eth-test/data/geth.ipc") + if err != nil { + log.Fatal(err) + } + + privKey, address, err := KeystoreToPrivateKey("/Users/aiyoa/desktop/eth-test/data/keystore/UTC--2021-10-21T03-41-34.288690000Z--01eec173917c429901b41b98ac3dd300e060e698", "") + if err != nil { + log.Fatal(err) + } + fmt.Printf("privKey:%s\naddress:%s\n", privKey, address) + + privateKey, err := crypto.HexToECDSA(privKey) + if err != nil { + log.Fatal(err) + } + + publicKey := privateKey.Public() + publicKeyECDSA, ok := publicKey.(*ecdsa.PublicKey) + if !ok { + log.Fatal("cannot assert type: publicKey is not of type *ecdsa.PublicKey") + } + + fromAddress := crypto.PubkeyToAddress(*publicKeyECDSA) + nonce, err := client.PendingNonceAt(context.Background(), fromAddress) + if err != nil { + log.Fatal(err) + } + + value := big.NewInt(1000) // in wei (1 eth) + gasLimit := uint64(21000) // in units + gasPrice, err := client.SuggestGasPrice(context.Background()) + if err != nil { + log.Fatal(err) + } + + toAddress := common.HexToAddress("a6df6489927a9d0172185efe68de1f9aace82639") + var data []byte + tx := types.NewTransaction(nonce, toAddress, value, gasLimit, gasPrice, data) + + chainID, err := client.NetworkID(context.Background()) + if err != nil { + log.Fatal(err) + } + + signedTx, err := types.SignTx(tx, types.NewEIP155Signer(chainID), privateKey) + fmt.Println(signedTx.ChainId()) + if err != nil { + log.Fatal(err) + } + + err = client.SendTransaction(context.Background(), signedTx) + if err != nil { + log.Fatal(err) + } + + fmt.Printf("tx sent: %s", signedTx.Hash().Hex()) + +} + +func TestDeployContract(t *testing.T) { + t.Skip() + client, err := ethclient.Dial("/Users/aiyoa/desktop/eth-test/data/geth.ipc") + if err != nil { + log.Fatal(err) + } + + privKey, address, err := KeystoreToPrivateKey("/Users/aiyoa/desktop/eth-test/data/keystore/UTC--2021-10-21T03-41-34.288690000Z--01eec173917c429901b41b98ac3dd300e060e698", "") + if err != nil { + log.Fatal(err) + } + fmt.Printf("privKey:%s\naddress:%s\n", privKey, address) + privateKey, err := crypto.HexToECDSA(privKey) + if err != nil { + log.Fatal(err) + } + publicKey := privateKey.Public() + publicKeyECDSA, ok := publicKey.(*ecdsa.PublicKey) + if !ok { + log.Fatal("cannot assert type: publicKey is not of type *ecdsa.PublicKey") + } + + fromAddress := crypto.PubkeyToAddress(*publicKeyECDSA) + nonce, err := client.PendingNonceAt(context.Background(), fromAddress) + if err != nil { + log.Fatal(err) + } + + gasPrice, err := client.SuggestGasPrice(context.Background()) + if err != nil { + log.Fatal(err) + } + chainID, err := client.NetworkID(context.Background()) + auth,_ := bind.NewKeyedTransactorWithChainID(privateKey, chainID) + auth.Nonce = big.NewInt(int64(nonce)) + auth.Value = big.NewInt(0) // in wei + auth.GasLimit = uint64(300000) // in units + auth.GasPrice = gasPrice + input := "1.0" + contractAddress, tx, instance, err := store.DeployStore(auth, client, input) + + if err != nil { + log.Fatal(err) + } + fmt.Println(contractAddress.Hex()) // 0xA103dA779fCB208c02759BB6fBD3eD1d354B9E16 + fmt.Println(tx.Hash().Hex()) // 0x1690003dca86eba1491e0aaa5a1cfde3fa39cafd90058537d8a0c8c4b6863d25 + + _ = instance +} + +func TestInvoke(t *testing.T) { + t.Skip() + client, err := ethclient.Dial("/Users/aiyoa/desktop/eth-test/data/geth.ipc") + if err != nil { + log.Fatal(err) + } + + privKey, address, err := KeystoreToPrivateKey("/Users/aiyoa/desktop/eth-test/data/keystore/UTC--2021-10-21T03-41-34.288690000Z--01eec173917c429901b41b98ac3dd300e060e698", "") + if err != nil { + log.Fatal(err) + } + fmt.Printf("privKey:%s\naddress:%s\n", privKey, address) + privateKey, err := crypto.HexToECDSA(privKey) + if err != nil { + log.Fatal(err) + } + publicKey := privateKey.Public() + publicKeyECDSA, ok := publicKey.(*ecdsa.PublicKey) + if !ok { + log.Fatal("cannot assert type: publicKey is not of type *ecdsa.PublicKey") + } + + fromAddress := crypto.PubkeyToAddress(*publicKeyECDSA) + nonce, err := client.PendingNonceAt(context.Background(), fromAddress) + if err != nil { + log.Fatal(err) + } + + gasPrice, err := client.SuggestGasPrice(context.Background()) + if err != nil { + log.Fatal(err) + } + chainID, err := client.NetworkID(context.Background()) + auth,_ := bind.NewKeyedTransactorWithChainID(privateKey, chainID) + auth.Nonce = big.NewInt(int64(nonce)) + auth.Value = big.NewInt(0) // in wei + auth.GasLimit = uint64(300000) // in units + auth.GasPrice = gasPrice + contractAddress := common.HexToAddress("0x7c376C8ED768018aa53d3C37Eed637912fEAA782") + + instance, err := store.NewStore(contractAddress, client) + if err != nil { + log.Fatal(err) + } + key := [32]byte{} + value := [32]byte{} + copy(key[:], []byte("foo")) + copy(value[:], []byte("bar")) + + tx, err := instance.SetItem(auth, key, value) + if err != nil { + log.Fatal(err) + } + + fmt.Printf("tx sent: %s\n", tx.Hash().Hex()) // tx sent: 0x5012ba7c07e46da3e1fbec454ed0e4079936b605d7ef0c0b0d0572972bb32dc6 + result, err := instance.Items(nil, key) + fmt.Println(result) + if err != nil { + log.Fatal(err) + } + + fmt.Println(string(result[:])) // "bar" +} From cab799187d309f8899a8b07a3effadf3b3455bf9 Mon Sep 17 00:00:00 2001 From: Houqitong <1428952786@qq.com> Date: Thu, 4 Nov 2021 10:56:46 +0800 Subject: [PATCH 4/6] feat: add file-test skip --- filesystem/file_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/filesystem/file_test.go b/filesystem/file_test.go index 2da4e40..32c5df8 100644 --- a/filesystem/file_test.go +++ b/filesystem/file_test.go @@ -16,6 +16,7 @@ import ( const testDir = "testDir" func TestEnsureFileExistErr(t *testing.T) { + t.Skip() var err error fp := "test/111.txt" testContent := []byte("TestEnsureFileExist") From 2f17d9557ebf6888d7b853ac470cee62edd16f44 Mon Sep 17 00:00:00 2001 From: Houqitong <1428952786@qq.com> Date: Thu, 4 Nov 2021 11:15:43 +0800 Subject: [PATCH 5/6] feat: delete filesystem-packr.go --- filesystem/filesystem-packr.go | 8 -------- 1 file changed, 8 deletions(-) delete mode 100644 filesystem/filesystem-packr.go diff --git a/filesystem/filesystem-packr.go b/filesystem/filesystem-packr.go deleted file mode 100644 index 6f4ab5f..0000000 --- a/filesystem/filesystem-packr.go +++ /dev/null @@ -1,8 +0,0 @@ -// +build !skippackr -// Code generated by github.com/gobuffalo/packr/v2. DO NOT EDIT. - -// You can use the "packr clean" command to clean up this, -// and any other packr generated files. -package filesystem - -import _ "github.com/meshplus/hyperbench/packrd" From e8c94e0f1c59c09699bfb6be52106a93f53523fd Mon Sep 17 00:00:00 2001 From: Houqitong <1428952786@qq.com> Date: Thu, 4 Nov 2021 11:18:47 +0800 Subject: [PATCH 6/6] feat: delete filesystem-packr.go --- core/controller/master/master.go | 2 +- core/controller/worker/local.go | 1 + filesystem/file_test.go | 2 +- main.go | 1 - vm/lua/lua.go | 1 + 5 files changed, 4 insertions(+), 3 deletions(-) diff --git a/core/controller/master/master.go b/core/controller/master/master.go index 0b41cca..49d9cff 100644 --- a/core/controller/master/master.go +++ b/core/controller/master/master.go @@ -35,9 +35,9 @@ func (m *LocalMaster) Prepare() (err error) { if err != nil { return errors.Wrap(err, "can not call user hook `BeforeDeploy`") } + // prepare contract err = m.masterVM.DeployContract() - if err != nil { return errors.Wrap(err, "can not deploy contract") } diff --git a/core/controller/worker/local.go b/core/controller/worker/local.go index e2ef25a..251db66 100644 --- a/core/controller/worker/local.go +++ b/core/controller/worker/local.go @@ -147,6 +147,7 @@ func (l *LocalWorker) asyncJob() { l.pool.Push(v) l.wg.Done() }() + res, err := v.Run(common.TxContext{ Context: l.ctx, TxIndex: l.atomicAddIndex(), diff --git a/filesystem/file_test.go b/filesystem/file_test.go index 32c5df8..2b70090 100644 --- a/filesystem/file_test.go +++ b/filesystem/file_test.go @@ -16,7 +16,7 @@ import ( const testDir = "testDir" func TestEnsureFileExistErr(t *testing.T) { - t.Skip() + var err error fp := "test/111.txt" testContent := []byte("TestEnsureFileExist") diff --git a/main.go b/main.go index 9b50ef1..87b2c96 100644 --- a/main.go +++ b/main.go @@ -17,5 +17,4 @@ func main() { if err != nil { fmt.Println("cmd execute fail: ", err) } - } diff --git a/vm/lua/lua.go b/vm/lua/lua.go index 1537748..ca70090 100644 --- a/vm/lua/lua.go +++ b/vm/lua/lua.go @@ -206,6 +206,7 @@ func (v *VM) BeforeRun() error { func (v *VM) Run(ctx common.TxContext) (*common.Result, error) { v.index.Engine = ctx.EngineIdx v.index.Tx = ctx.TxIdx + err := v.vm.CallByParam(lua.P{ Fn: v.instance.RawGetString(run), NRet: 1,