itest

package
v0.0.0-...-376a440 Latest Latest
Warning

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

Go to latest
Published: May 10, 2020 License: LGPL-3.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

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

	DefaultABI = `` /* 266-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  = global.Token
	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: "*", Val: "unlimited"}}
	ChainID     = uint32(1020)
)

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"`
	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

func NewBlockFromPb(b *rpcpb.Block) *Block

NewBlockFromPb returns a new Block instance from protobuffer struct.

type Client

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

Client is a grpc client for iserver

func (*Client) BuyRAM

func (c *Client) BuyRAM(sender *Account, amount int64, check bool) error

BuyRAM ...

func (*Client) CallAction

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

CallAction send a tx with given actions

func (*Client) CancelVoteProducer

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

CancelVoteProducer will vote producer by sending transaction

func (*Client) CheckTransactionWithTimeout

func (c *Client) CheckTransactionWithTimeout(hash string, expire time.Time) (*Receipt, error)

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

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

GetAccount will get account by name

func (*Client) GetBlockByNumber

func (c *Client) GetBlockByNumber(number int64) (*Block, error)

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

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) Pledge

func (c *Client) Pledge(sender *Account, amount string, check bool) error

Pledge ...

func (*Client) SellRAM

func (c *Client) SellRAM(sender *Account, amount int64, check bool) error

SellRAM ...

func (*Client) SendTransaction

func (c *Client) SendTransaction(transaction *Transaction, check bool) (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, memoSize int, check bool) error

Transfer will transfer token by sending transaction

func (*Client) Unpledge

func (c *Client) Unpledge(sender *Account, amount string, check bool) error

Unpledge ...

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) BuyRAM

func (t *ITest) BuyRAM(sender *Account, amount int64, check bool) error

BuyRAM will buy ram for sender

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 ...interface{}) (string, error)

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

func (*ITest) CancelVoteNode

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

CancelVoteNode will send n Cancel vote transaction concurrently

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, 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

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

CreateAccount will create a account by name

func (*ITest) CreateAccountN

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

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

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

GetAccount will get account by name

func (*ITest) GetBlockByNumber

func (t *ITest) GetBlockByNumber(number int64) (*Block, error)

GetBlockByNumber will get block by number

func (*ITest) GetClients

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

GetClients returns the clients

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

func (t *ITest) GetDefaultAccount() *Account

GetDefaultAccount return the bank account

func (*ITest) GetRandClient

func (t *ITest) GetRandClient() *Client

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) Pledge

func (t *ITest) Pledge(sender *Account, amount string, check bool) error

Pledge will pledge gas for sender

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) SellRAM

func (t *ITest) SellRAM(sender *Account, amount int64, check bool) error

SellRAM will sell ram for sender

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

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, 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

func (*ITest) Unpledge

func (t *ITest) Unpledge(sender *Account, amount string, check bool) error

Unpledge will unpledge gas for sender

func (*ITest) VoteN

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

VoteN will send n vote transaction concurrently

func (*ITest) VoteNode

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

VoteNode 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 whether the receipt is successful

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