run

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: 4 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AccountCaseAction = func(c *cli.Context) error {
	anum := c.Int("number")
	output := c.String("output")
	keysfile := c.GlobalString("keys")
	configfile := c.GlobalString("config")

	it, err := itest.Load(keysfile, configfile)
	if err != nil {
		return err
	}

	accounts, err := it.CreateAccountN(anum)
	if err != nil {
		return err
	}

	if err := itest.DumpAccounts(accounts, output); err != nil {
		return err
	}

	return nil
}

AccountCaseAction is the action of account test case

View Source
var AccountCaseCommand = cli.Command{
	Name:      "account_case",
	ShortName: "a_case",
	Usage:     "run account test case",
	Flags:     AccountCaseFlags,
	Action:    AccountCaseAction,
}

AccountCaseCommand is the command of account test case

View Source
var AccountCaseFlags = []cli.Flag{
	cli.IntFlag{
		Name:  "number, n",
		Value: 10,
		Usage: "number of account",
	},
	cli.StringFlag{
		Name:  "output, o",
		Value: "accounts.json",
		Usage: "output of account information",
	},
}

AccountCaseFlags is the flags of account test case

View Source
var BenchmarkAction = func(c *cli.Context) error {
	dfile := "benchmark.json"

	r := itest.NewRunner(dfile)
	if err := r.Run(); err != nil {
		return err
	}

	<-r.Done()
	if err := r.Err(); err != nil {
		return err
	}

	return nil
}

BenchmarkAction is the action of benchmark

View Source
var BenchmarkCommand = cli.Command{
	Name:      "benchmark",
	ShortName: "bench",
	Usage:     "run benchmark test by data",
	Action:    BenchmarkAction,
}

BenchmarkCommand is the command of benchmark

View Source
var Command = cli.Command{
	Name:  "run",
	Usage: "run test by benchmark data",
	Flags: Flags,
	Subcommands: []cli.Command{
		AccountCaseCommand,
		TransferCaseCommand,
		ContractCaseCommand,
		CommonVoteCaseCommand,
		VoteCaseCommand,
		BenchmarkCommand,
	},
}

Command is the command of run

View Source
var CommonVoteCaseAction = func(c *cli.Context) error {
	afile := c.String("account")
	keysfile := c.GlobalString("keys")
	configfile := c.GlobalString("newVoteConfig")
	it, err := itest.Load(keysfile, configfile)
	if err != nil {
		return err
	}
	client := it.GetClients()[0]
	accounts, err := itest.LoadAccounts(afile)
	if err != nil {
		return err
	}

	newVoteConfig := make(map[string]interface{})
	newVoteConfig["resultNumber"] = 2
	newVoteConfig["minVote"] = 10
	newVoteConfig["options"] = []string{"option1", "option2", "option3", "option4"}
	newVoteConfig["anyOption"] = false
	newVoteConfig["freezeTime"] = 0
	bank := it.GetDefaultAccount()
	hash, err := it.CallActionWithRandClient(it.GetDefaultAccount(), "vote.iost", "NewVote", bank.ID, "test vote", newVoteConfig)
	if err != nil {
		return err
	}
	receipt, err := client.GetReceipt(hash)
	if err != nil {
		return err
	}
	js, err := simplejson.NewJson([]byte(receipt.Returns[0]))
	if err != nil {
		return err
	}
	voteID, err := js.GetIndex(0).String()
	if err != nil {
		return err
	}
	fmt.Println("vote id is", voteID)
	allArgs := make([][]interface{}, 0)
	allArgs = append(allArgs, []interface{}{voteID, accounts[1].ID, "option3", "5"})
	allArgs = append(allArgs, []interface{}{voteID, accounts[1].ID, "option3", "5"})
	allArgs = append(allArgs, []interface{}{voteID, accounts[1].ID, "option1", "20"})
	allArgs = append(allArgs, []interface{}{voteID, accounts[0].ID, "option3", "100"})
	var callingAccounts = []*itest.Account{accounts[1], accounts[1], accounts[1], accounts[0]}

	res := make(chan interface{})
	go func() {
		for idx := range allArgs {
			go func(i int, res chan interface{}) {
				_, err := it.CallActionWithRandClient(callingAccounts[i], "vote.iost", "Vote", allArgs[i]...)
				res <- err
			}(idx, res)
		}
	}()
	for range allArgs {
		switch value := (<-res).(type) {
		case error:
			return value.(error)
		}
	}

	checkReturn := func(actionName string, expected string, args ...interface{}) error {
		hash, err := client.CallAction(bank, "vote.iost", actionName, args...)
		if err != nil {
			return err
		}
		receipt, err = client.GetReceipt(hash)
		if err != nil {
			return err
		}
		js, err := simplejson.NewJson([]byte(receipt.Returns[0]))
		if err != nil {
			return err
		}
		result, err := js.GetIndex(0).String()
		if err != nil {
			return err
		}
		if result != expected {
			return fmt.Errorf("invalid return %v, expect %v", result, expected)
		}
		return nil
	}
	res2 := make(chan error)
	go func() {
		res2 <- checkReturn("GetResult", `[{"option":"option3","votes":"110"},{"option":"option1","votes":"20"}]`, voteID)
	}()
	go func() {
		res2 <- checkReturn("GetOption", `{"votes":"110","deleted":false,"clearTime":-1}`, voteID, "option3")
	}()

	for i := 0; i < 2; i++ {
		if err := <-res2; err != nil {
			return err
		}
	}
	return nil
}

CommonVoteCaseAction is the action of vote test case

View Source
var CommonVoteCaseCommand = cli.Command{
	Name:      "common_vote_case",
	ShortName: "cv_case",
	Usage:     "run common VoteProducer test case",
	Flags:     CommonVoteCaseFlags,
	Action:    CommonVoteCaseAction,
}

CommonVoteCaseCommand is the command of common vote test case

View Source
var CommonVoteCaseFlags = []cli.Flag{
	cli.StringFlag{
		Name:  "account, a",
		Value: "accounts.json",
		Usage: "load accounts from `FILE`",
	},
}

CommonVoteCaseFlags is the flags of vote test case

View Source
var ContractCaseAction = func(c *cli.Context) error {
	afile := c.String("account")
	output := c.String("output")
	tnum := c.Int("number")
	keysfile := c.GlobalString("keys")
	configfile := c.GlobalString("config")
	codefile := c.GlobalString("code")
	abifile := c.GlobalString("abi")

	it, err := itest.Load(keysfile, configfile)
	if err != nil {
		return err
	}

	contract, err := itest.LoadContract(codefile, abifile)
	if err != nil {
		return err
	}

	accounts, err := itest.LoadAccounts(afile)
	if err != nil {
		return err
	}

	cid, err := it.SetContract(contract)
	if err != nil {
		return err
	}

	if err := it.ContractTransferN(cid, tnum, accounts); err != nil {
		return err
	}

	if err := it.CheckAccounts(accounts); err != nil {
		return err
	}

	if err := itest.DumpAccounts(accounts, output); err != nil {
		return err
	}

	return nil
}

ContractCaseAction is the action of contract test case

View Source
var ContractCaseCommand = cli.Command{
	Name:      "contract_case",
	ShortName: "c_case",
	Usage:     "run contract test case",
	Flags:     ContractCaseFlags,
	Action:    ContractCaseAction,
}

ContractCaseCommand is the command of contract test case

View Source
var ContractCaseFlags = []cli.Flag{
	cli.IntFlag{
		Name:  "number, n",
		Value: 1000,
		Usage: "number of transaction",
	},
	cli.StringFlag{
		Name:  "account, a",
		Value: "accounts.json",
		Usage: "load accounts from `FILE`",
	},
	cli.StringFlag{
		Name:  "output, o",
		Value: "accounts.json",
		Usage: "output of account information",
	},
}

ContractCaseFlags ...

View Source
var Flags = []cli.Flag{
	cli.StringFlag{
		Name:  "keys, k",
		Value: "",
		Usage: "Load keys from `FILE`",
	},
	cli.StringFlag{
		Name:  "config, c",
		Value: "",
		Usage: "Load itest configuration from `FILE`",
	},
	cli.StringFlag{
		Name:  "code",
		Value: "",
		Usage: "Load contract code from `FILE`",
	},
	cli.StringFlag{
		Name:  "abi",
		Value: "",
		Usage: "Load contract abi from `FILE`",
	},
}

Flags is the flags of run command

View Source
var TransferCaseAction = func(c *cli.Context) error {
	afile := c.String("account")
	output := c.String("output")
	tnum := c.Int("number")
	keysfile := c.GlobalString("keys")
	configfile := c.GlobalString("config")

	it, err := itest.Load(keysfile, configfile)
	if err != nil {
		return err
	}

	accounts, err := itest.LoadAccounts(afile)
	if err != nil {
		return err
	}

	if err := it.TransferN(tnum, accounts); err != nil {
		return err
	}

	if err := it.CheckAccounts(accounts); err != nil {
		return err
	}

	if err := itest.DumpAccounts(accounts, output); err != nil {
		return err
	}

	return nil
}

TransferCaseAction is the action of transfer test case

View Source
var TransferCaseCommand = cli.Command{
	Name:      "transfer_case",
	ShortName: "t_case",
	Usage:     "run transfer test case",
	Flags:     TransferCaseFlags,
	Action:    TransferCaseAction,
}

TransferCaseCommand is the command of transfer test case

View Source
var TransferCaseFlags = []cli.Flag{
	cli.IntFlag{
		Name:  "number, n",
		Value: 1000,
		Usage: "number of transaction",
	},
	cli.StringFlag{
		Name:  "account, a",
		Value: "accounts.json",
		Usage: "load accounts from `FILE`",
	},
	cli.StringFlag{
		Name:  "output, o",
		Value: "accounts.json",
		Usage: "output of account information",
	},
}

TransferCaseFlags is the flags of transfer test case

View Source
var VoteCaseAction = func(c *cli.Context) error {
	afile := c.String("account")
	output := c.String("output")
	tnum := c.Int("number")
	punm := c.Int("pnumber")
	keysfile := c.GlobalString("keys")
	configfile := c.GlobalString("config")

	it, err := itest.Load(keysfile, configfile)
	if err != nil {
		return err
	}

	accounts, err := itest.LoadAccounts(afile)
	if err != nil {
		return err
	}

	if err := it.VoteN(tnum, punm, accounts); err != nil {
		return err
	}

	if err := it.CheckAccounts(accounts); err != nil {
		return err
	}

	if err := itest.DumpAccounts(accounts, output); err != nil {
		return err
	}

	return nil
}

VoteCaseAction is the action of vote test case

View Source
var VoteCaseCommand = cli.Command{
	Name:      "vote_case",
	ShortName: "v_case",
	Usage:     "run VoteProducer test case",
	Flags:     VoteCaseFlags,
	Action:    VoteCaseAction,
}

VoteCaseCommand is the command of vote test case

View Source
var VoteCaseFlags = []cli.Flag{
	cli.IntFlag{
		Name:  "number, n",
		Value: 1000,
		Usage: "number of transaction",
	},
	cli.IntFlag{
		Name:  "pnumber, pn",
		Value: 1,
		Usage: "number of producer",
	},
	cli.StringFlag{
		Name:  "account, a",
		Value: "accounts.json",
		Usage: "load accounts from `FILE`",
	},
	cli.StringFlag{
		Name:  "output, o",
		Value: "accounts.json",
		Usage: "output of account information",
	},
}

VoteCaseFlags is the flags of vote test case

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

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