Documentation ¶
Index ¶
- Constants
- Variables
- func DumpAccounts(accounts []*Account, file string) error
- func DumpKeys(keys []*Key, file string) error
- type Account
- type AccountJSON
- type Block
- type Client
- func (c *Client) BuyRAM(sender *Account, amount int64, check bool) error
- func (c *Client) CallAction(check bool, sender *Account, contractName, actionName string, args ...any) (string, error)
- func (c *Client) CancelVoteProducer(sender *Account, recipient, amount string) error
- func (c *Client) CheckTransactionWithTimeout(hash string, expire time.Time) (*Receipt, error)
- func (c *Client) ContractTransfer(cid string, sender, recipient *Account, amount string, memoSize int, ...) error
- func (c *Client) CreateAccount(creator *Account, name string, key *Key, check bool) (*Account, error)
- func (c *Client) ExchangeTransfer(sender, recipient *Account, token, amount string, memoSize int, check bool) error
- func (c *Client) GetAccount(name string) (*Account, error)
- func (c *Client) GetBlockByNumber(number int64) (*Block, error)
- func (c *Client) GetContractStorage(id, key, field string) (data string, hash string, number int64, err error)
- func (c *Client) GetGRPC() (rpcpb.ApiServiceClient, error)
- func (c *Client) GetReceipt(hash string) (*Receipt, error)
- func (c *Client) GetTransaction(hash string) (*Transaction, error)
- func (c *Client) Pledge(sender *Account, amount string, check bool) error
- func (c *Client) SellRAM(sender *Account, amount int64, check bool) error
- func (c *Client) SendTransaction(transaction *Transaction, check bool) (string, error)
- func (c *Client) SetContract(creator *Account, contract *Contract) (string, error)
- func (c *Client) Transfer(sender, recipient *Account, token, amount string, memoSize int, check bool) error
- func (c *Client) Unpledge(sender *Account, amount string, check bool) error
- func (c *Client) VoteProducer(sender *Account, recipient, amount string) error
- type Config
- type Contract
- type ITest
- func (t *ITest) BuyRAM(sender *Account, amount int64, check bool) error
- func (t *ITest) BuyRAMN(actionType string, num int, accounts []*Account, check bool) (successNum int, firstErr error)
- func (t *ITest) CallActionWithRandClient(sender *Account, contractName, actionName string, args ...any) (string, error)
- func (t *ITest) CancelVoteNode(num int, accounts []*Account) error
- func (t *ITest) CheckAccounts(a []*Account) error
- func (t *ITest) ContractTransfer(cid string, sender, recipient *Account, amount string, memoSize int, ...) error
- func (t *ITest) ContractTransferN(cid string, num int, accounts []*Account, memoSize int, check bool) (successNum int, firstErr error)
- func (t *ITest) CreateAccount(creator *Account, name string, check bool) (*Account, error)
- func (t *ITest) CreateAccountN(num int, randName bool, check bool) ([]*Account, error)
- func (t *ITest) CreateAccountRoundN(num int, randName bool, check bool, round int) ([]*Account, error)
- func (t *ITest) ExchangeTransfer(sender, recipient *Account, amount string, memoSize int, check bool) error
- func (t *ITest) ExchangeTransferN(num int, accounts []*Account, memoSize int, check bool) (successNum int, firstErr error)
- func (t *ITest) GetAccount(name string) (*Account, error)
- func (t *ITest) GetBlockByNumber(number int64) (*Block, error)
- func (t *ITest) GetClients() []*Client
- func (t *ITest) GetContractStorage(id, key, field string) (data string, hash string, number int64, err error)
- func (t *ITest) GetDefaultAccount() *Account
- func (t *ITest) GetRandClient() *Client
- func (t *ITest) GetTransaction(hash string) (*Transaction, error)
- func (t *ITest) Pledge(sender *Account, amount string, check bool) error
- func (t *ITest) PledgeGasN(actionType string, num int, accounts []*Account, check bool) (successNum int, firstErr error)
- func (t *ITest) SellRAM(sender *Account, amount int64, check bool) error
- func (t *ITest) SendTransaction(transaction *Transaction, check bool) (string, error)
- func (t *ITest) SendTransactionN(trxs []*Transaction, check bool) ([]string, []error)
- func (t *ITest) SetContract(contract *Contract) (string, error)
- func (t *ITest) Transfer(sender, recipient *Account, token, amount string, memoSize int, check bool) error
- func (t *ITest) TransferN(num int, accounts []*Account, memoSize int, check bool) (successNum int, firstErr error)
- func (t *ITest) Unpledge(sender *Account, amount string, check bool) error
- func (t *ITest) VoteN(num, pnum int, accounts []*Account) error
- func (t *ITest) VoteNode(num int, accounts []*Account) error
- type Key
- type KeyJSON
- type Receipt
- type Transaction
Constants ¶
const ( DefaultCode = `` /* 233-byte string literal not displayed */ DefaultABI = `` /* 266-byte string literal not displayed */ )
Constant of Contract
const (
DefaultITestConfig = `` /* 259-byte string literal not displayed */
)
Constant of itest config
const (
DefaultKeys = `` /* 641-byte string literal not displayed */
)
Constant of key
const (
Zero = 1e-6
)
Constant of itest
Variables ¶
var ( Interval = 15 * time.Second Timeout = (90 + 30) * time.Second InitToken = "iost" InitAmount = "1000000" InitPledge = "1000000" InitRAM = "1000000" )
Constant of Client
var ( GasLimit = int64(100000000) // about 30000~100000 gas per tx GasRatio = int64(100) // 1 mutiple gas Expiration = int64(math.MaxInt64) // Max expired time is 90 seconds Delay = int64(0 * time.Second) // No delay Signers = make([]string, 0) // No mutiple signers AmountLimit = []*contract.Amount{{Token: "*", Val: "unlimited"}} ChainID = uint32(1020) )
Constant of Transaction
Functions ¶
func DumpAccounts ¶
DumpAccounts will dump the accounts to file
Types ¶
type Account ¶
type Account struct { ID string // contains filtered or unexported fields }
Account is account of user
func LoadAccounts ¶
LoadAccounts will load accounts from file
func NewAccount ¶
NewAccount return a new account
func (*Account) AddBalance ¶
AddBalance will add the balance of this account
func (*Account) MarshalJSON ¶
MarshalJSON will marshal account to json
func (*Account) Sign ¶
func (a *Account) Sign(t *Transaction) (*Transaction, error)
Sign will sign the transaction by current account
func (*Account) UnmarshalJSON ¶
UnmarshalJSON will unmarshal account from json
type AccountJSON ¶
type AccountJSON struct { ID string `json:"id"` Balance string `json:"balance"` Vote string `json:"vote"` Seckey string `json:"seckey"` Algorithm string `json:"algorithm"` }
AccountJSON is the json serialization of account
type Block ¶
type Block struct { Hash string Version int64 ParentHash string TxMerkleHash string TxReceiptMerkleHash string Number int64 Witness string Time int64 }
Block is the block object
func NewBlockFromPb ¶
NewBlockFromPb returns a new Block instance from protobuffer struct.
type Client ¶
Client is a grpc client for iserver
func (*Client) CallAction ¶
func (c *Client) CallAction(check bool, sender *Account, contractName, actionName string, args ...any) (string, error)
CallAction send a tx with given actions
func (*Client) CancelVoteProducer ¶
CancelVoteProducer will vote producer by sending transaction
func (*Client) CheckTransactionWithTimeout ¶
CheckTransactionWithTimeout will check transaction receipt with expire time
func (*Client) ContractTransfer ¶
func (c *Client) ContractTransfer(cid string, sender, recipient *Account, amount string, memoSize int, check bool) error
ContractTransfer will contract transfer token by sending transaction
func (*Client) CreateAccount ¶
func (c *Client) CreateAccount(creator *Account, name string, key *Key, check bool) (*Account, error)
CreateAccount will create account by sending transaction
func (*Client) ExchangeTransfer ¶
func (c *Client) ExchangeTransfer(sender, recipient *Account, token, amount string, memoSize int, check bool) error
ExchangeTransfer will contract transfer token by sending transaction
func (*Client) GetAccount ¶
GetAccount will get account by name
func (*Client) GetBlockByNumber ¶
GetBlockByNumber will get block by number
func (*Client) GetContractStorage ¶
func (c *Client) GetContractStorage(id, key, field string) (data string, hash string, number int64, err error)
GetContractStorage will get contract storage by contract id, key and field
func (*Client) GetGRPC ¶
func (c *Client) GetGRPC() (rpcpb.ApiServiceClient, error)
GetGRPC return the underlying grpc client
func (*Client) GetReceipt ¶
GetReceipt will get receipt by tx hash
func (*Client) GetTransaction ¶
func (c *Client) GetTransaction(hash string) (*Transaction, error)
GetTransaction will get transaction by tx hash
func (*Client) SendTransaction ¶
func (c *Client) SendTransaction(transaction *Transaction, check bool) (string, error)
SendTransaction will send transaction to blockchain
func (*Client) SetContract ¶
SetContract will set the contract by sending transaction
func (*Client) Transfer ¶
func (c *Client) Transfer(sender, recipient *Account, token, amount string, memoSize int, check bool) error
Transfer will transfer token by sending transaction
type Config ¶
Config is the config of itest
func LoadConfig ¶
LoadConfig will load the itest config from file
type Contract ¶
Contract is the contract object
func LoadContract ¶
LoadContract will load a contract from file
func NewContract ¶
NewContract will return a new contract
type ITest ¶
type ITest struct {
// contains filtered or unexported fields
}
ITest is the test controller
func (*ITest) BuyRAMN ¶
func (t *ITest) BuyRAMN(actionType string, num int, accounts []*Account, check bool) (successNum int, firstErr error)
BuyRAMN will send n buy/sell ram transaction concurrently
func (*ITest) CallActionWithRandClient ¶
func (t *ITest) CallActionWithRandClient(sender *Account, contractName, actionName string, args ...any) (string, error)
CallActionWithRandClient randomly select one client and use it to send a tx
func (*ITest) CancelVoteNode ¶
CancelVoteNode will send n Cancel vote transaction concurrently
func (*ITest) CheckAccounts ¶
CheckAccounts will check account info by getting account info
func (*ITest) ContractTransfer ¶
func (t *ITest) ContractTransfer(cid string, sender, recipient *Account, amount string, memoSize int, check bool) error
ContractTransfer will contract transfer token from sender to recipient
func (*ITest) ContractTransferN ¶
func (t *ITest) ContractTransferN(cid string, num int, accounts []*Account, memoSize int, check bool) (successNum int, firstErr error)
ContractTransferN will send n contract transfer transaction concurrently
func (*ITest) CreateAccount ¶
CreateAccount will create a account by name
func (*ITest) CreateAccountN ¶
CreateAccountN will create n accounts concurrently
func (*ITest) CreateAccountRoundN ¶
func (t *ITest) CreateAccountRoundN(num int, randName bool, check bool, round int) ([]*Account, error)
CreateAccountRoundN will create n accounts concurrently
func (*ITest) ExchangeTransfer ¶
func (t *ITest) ExchangeTransfer(sender, recipient *Account, amount string, memoSize int, check bool) error
ExchangeTransfer will contract transfer token from sender to recipient
func (*ITest) ExchangeTransferN ¶
func (t *ITest) ExchangeTransferN(num int, accounts []*Account, memoSize int, check bool) (successNum int, firstErr error)
ExchangeTransferN will send n contract transfer transaction concurrently
func (*ITest) GetAccount ¶
GetAccount will get account by name
func (*ITest) GetBlockByNumber ¶
GetBlockByNumber will get block by number
func (*ITest) GetContractStorage ¶
func (t *ITest) GetContractStorage(id, key, field string) (data string, hash string, number int64, err error)
GetContractStorage will get contract storage by contract id, key and field
func (*ITest) GetDefaultAccount ¶
GetDefaultAccount return the bank account
func (*ITest) GetRandClient ¶
GetRandClient return a random client
func (*ITest) GetTransaction ¶
func (t *ITest) GetTransaction(hash string) (*Transaction, error)
GetTransaction will get transaction by tx hash
func (*ITest) PledgeGasN ¶
func (t *ITest) PledgeGasN(actionType string, num int, accounts []*Account, check bool) (successNum int, firstErr error)
PledgeGasN will send n pledge/unpledge transaction concurrently
func (*ITest) SendTransaction ¶
func (t *ITest) SendTransaction(transaction *Transaction, check bool) (string, error)
SendTransaction will send transaction to blockchain
func (*ITest) SendTransactionN ¶
func (t *ITest) SendTransactionN(trxs []*Transaction, check bool) ([]string, []error)
SendTransactionN will send n transaction to blockchain concurrently
func (*ITest) SetContract ¶
SetContract will set the contract on blockchain
func (*ITest) Transfer ¶
func (t *ITest) Transfer(sender, recipient *Account, token, amount string, memoSize int, check bool) error
Transfer will transfer token from sender to recipient
func (*ITest) TransferN ¶
func (t *ITest) TransferN(num int, accounts []*Account, memoSize int, check bool) (successNum int, firstErr error)
TransferN will send n transfer transaction concurrently
type Key ¶
Key is the key pair
func (*Key) MarshalJSON ¶
MarshalJSON will marshal key to json
func (*Key) UnmarshalJSON ¶
UnmarshalJSON will unmarshal key from json
type Receipt ¶
Receipt is the transaction receipt object
func NewReceiptFromPb ¶
NewReceiptFromPb returns a new Receipt instance from protobuffer struct.
type Transaction ¶
Transaction is the transaction object
func NewTransaction ¶
func NewTransaction(actions []*tx.Action) *Transaction
NewTransaction will return a new transaction by actions
func NewTransactionFromPb ¶
func NewTransactionFromPb(t *rpcpb.Transaction) *Transaction
NewTransactionFromPb returns a new transaction instance from protobuffer transaction struct.
func (*Transaction) ToTxRequest ¶
func (t *Transaction) ToTxRequest() *rpcpb.TransactionRequest
ToTxRequest converts tx to rpcpb.TransactionRequest.