itest

package
v2.1.0+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 3, 2019 License: LGPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultCode = `` /* 301-byte string literal not displayed */

	DefaultABI = `` /* 251-byte string literal not displayed */

)

Constant of Contract

View Source
const (
	DefaultITestConfig = `` /* 259-byte string literal not displayed */

)

Constant of itest config

View Source
const (
	DefaultKeys = `` /* 641-byte string literal not displayed */

)

Constant of key

View Source
const (
	Zero = 1e-6
)

Constant of itest

Variables

View Source
var (
	Interval   = 15 * time.Second
	Timeout    = (90 + 30) * time.Second
	InitToken  = "iost"
	InitAmount = "1000000"
	InitPledge = "1000000"
	InitRAM    = "1000000"
)

Constant of Client

View Source
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: "iost", Val: "unlimited"}}
)

Constant of Transaction

Functions

func DumpAccounts

func DumpAccounts(accounts []*Account, file string) error

DumpAccounts will dump the accounts to file

func DumpKeys

func DumpKeys(keys []*Key, file string) error

DumpKeys will dump the keys to file

Types

type Account

type Account struct {
	ID string
	// contains filtered or unexported fields
}

Account is account of user

func LoadAccounts

func LoadAccounts(file string) ([]*Account, error)

LoadAccounts will load accounts from file

func NewAccount

func NewAccount(id string, seckey string, algorithm string) *Account

NewAccount return a new account

func (*Account) AddBalance

func (a *Account) AddBalance(amount float64)

AddBalance will add the balance of this account

func (*Account) Balance

func (a *Account) Balance() float64

Balance will return the balance of this account

func (*Account) MarshalJSON

func (a *Account) MarshalJSON() ([]byte, error)

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

func (a *Account) UnmarshalJSON(b []byte) error

UnmarshalJSON will unmarshal account from json

type AccountJSON

type AccountJSON struct {
	ID        string `json:"id"`
	Balance   string `json:"balance"`
	Seckey    string `json:"seckey"`
	Algorithm string `json:"algorithm"`
}

AccountJSON is the json serialization of account

type Client

type Client struct {
	Name string
	Addr string
	// contains filtered or unexported fields
}

Client is a grpc client for iserver

func (*Client) CallAction

func (c *Client) CallAction(sender *Account, contractName, actionName string, args ...interface{}) (string, error)

CallAction send a tx with given actions

func (*Client) ContractTransfer

func (c *Client) ContractTransfer(cid string, sender, recipient *Account, amount string) error

ContractTransfer will contract transfer token by sending transaction

func (*Client) CreateAccount

func (c *Client) CreateAccount(creator *Account, name string, key *Key) (*Account, error)

CreateAccount will create account by sending transaction

func (*Client) GetAccount

func (c *Client) GetAccount(name string) (*Account, error)

GetAccount will get account by name

func (*Client) GetReceipt

func (c *Client) GetReceipt(hash string) (*Receipt, error)

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) (string, error)

SendTransaction will send transaction to blockchain

func (*Client) SetContract

func (c *Client) SetContract(creator *Account, contract *Contract) (string, error)

SetContract will set the contract by sending transaction

func (*Client) Transfer

func (c *Client) Transfer(sender, recipient *Account, token, amount string) error

Transfer will transfer token by sending transaction

func (*Client) Vote

func (c *Client) Vote(sender *Account, voteID, recipient, amount string) error

Vote ...

func (*Client) VoteProducer

func (c *Client) VoteProducer(sender *Account, recipient, amount string) error

VoteProducer will vote producer by sending transaction

type Config

type Config struct {
	Bank    *Account
	Clients []*Client
}

Config is the config of itest

func LoadConfig

func LoadConfig(file string) (*Config, error)

LoadConfig will load the itest config from file

type Contract

type Contract struct {
	*contract.Contract
}

Contract is the contract object

func LoadContract

func LoadContract(codepath, abipath string) (*Contract, error)

LoadContract will load a contract from file

func NewContract

func NewContract(code, abi string) (*Contract, error)

NewContract will return a new contract

func (*Contract) String

func (c *Contract) String() string

String will return the string of contract

type ITest

type ITest struct {
	// contains filtered or unexported fields
}

ITest is the test controller

func Load

func Load(keysfile, configfile string) (*ITest, error)

Load will load the itest from file

func New

func New(c *Config, keys []*Key) *ITest

New will return the itest by config and keys

func (*ITest) CallActionWithRandClient

func (t *ITest) CallActionWithRandClient(sender *Account, contractName, actionName string, args ...interface{}) (string, error)

CallActionWithRandClient randomly select one client and use it to send a tx

func (*ITest) CheckAccounts

func (t *ITest) CheckAccounts(a []*Account) error

CheckAccounts will check account info by getting account info

func (*ITest) ContractTransfer

func (t *ITest) ContractTransfer(cid string, sender, recipient *Account, amount string) error

ContractTransfer will contract transfer token from sender to recipient

func (*ITest) ContractTransferN

func (t *ITest) ContractTransferN(cid string, num int, accounts []*Account) error

ContractTransferN will send n contract transfer transaction concurrently

func (*ITest) CreateAccount

func (t *ITest) CreateAccount(name string) (*Account, error)

CreateAccount will create a account by name

func (*ITest) CreateAccountN

func (t *ITest) CreateAccountN(num int) ([]*Account, error)

CreateAccountN will create n accounts concurrently

func (*ITest) GetAccount

func (t *ITest) GetAccount(name string) (*Account, error)

GetAccount will get account by name

func (*ITest) GetClients

func (t *ITest) GetClients() []*Client

GetClients returns the clients

func (*ITest) GetDefaultAccount

func (t *ITest) GetDefaultAccount() *Account

GetDefaultAccount return the bank account

func (*ITest) GetTransaction

func (t *ITest) GetTransaction(hash string) (*Transaction, error)

GetTransaction will get transaction by tx hash

func (*ITest) SendTransaction

func (t *ITest) SendTransaction(transaction *Transaction) (string, error)

SendTransaction will send transaction to blockchain

func (*ITest) SetContract

func (t *ITest) SetContract(contract *Contract) (string, error)

SetContract will set the contract on blockchain

func (*ITest) Transfer

func (t *ITest) Transfer(sender, recipient *Account, token, amount string) error

Transfer will transfer token from sender to recipient

func (*ITest) TransferN

func (t *ITest) TransferN(num int, accounts []*Account) error

TransferN will send n transfer transaction concurrently

func (*ITest) Vote

func (t *ITest) Vote(sender *Account, recipient, amount string) error

Vote will vote producer from sender to recipient

func (*ITest) VoteN

func (t *ITest) VoteN(num, pnum int, accounts []*Account) error

VoteN will send n vote transaction concurrently

type Key

type Key struct {
	*account.KeyPair
}

Key is the key pair

func LoadKeys

func LoadKeys(file string) ([]*Key, error)

LoadKeys will load keys from file

func NewKey

func NewKey(seckey []byte, algo crypto.Algorithm) *Key

NewKey will return a new key

func (*Key) MarshalJSON

func (k *Key) MarshalJSON() ([]byte, error)

MarshalJSON will marshal key to json

func (*Key) UnmarshalJSON

func (k *Key) UnmarshalJSON(b []byte) error

UnmarshalJSON will unmarshal key from json

type KeyJSON

type KeyJSON struct {
	Seckey    string `json:"seckey"`
	Algorithm string `json:"algorithm"`
}

KeyJSON is the json serialization of key

type Receipt

type Receipt struct {
	*tx.TxReceipt
}

Receipt is the transaction receipt object

func NewReceiptFromPb

func NewReceiptFromPb(tr *rpcpb.TxReceipt) *Receipt

NewReceiptFromPb returns a new Receipt instance from protobuffer struct.

func (*Receipt) Success

func (r *Receipt) Success() bool

Success will return weather the receipt is successful

type Runner

type Runner struct {
	// contains filtered or unexported fields
}

Runner is the benchmark runner

func NewRunner

func NewRunner(dfile string) *Runner

NewRunner will return a new runner

func (*Runner) Done

func (r *Runner) Done() <-chan struct{}

Done will return nil until the runner is done

func (*Runner) Err

func (r *Runner) Err() error

Err will return the error of runner

func (*Runner) Run

func (r *Runner) Run() error

Run will run the benchmark

type Transaction

type Transaction struct {
	*tx.Tx
}

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.

Directories

Path Synopsis
command
run

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL