-
Notifications
You must be signed in to change notification settings - Fork 113
/
contract_case.go
85 lines (73 loc) · 1.77 KB
/
contract_case.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package run
import (
"github.com/iost-official/go-iost/itest"
"github.com/urfave/cli"
)
// ContractCaseCommand is the command of contract test case
var ContractCaseCommand = cli.Command{
Name: "contract_case",
ShortName: "c_case",
Usage: "run contract test case",
Flags: ContractCaseFlags,
Action: ContractCaseAction,
}
// ContractCaseFlags ...
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",
},
cli.IntFlag{
Name: "memo, m",
Value: 0,
Usage: "The size of a random memo message that would be contained in the transaction",
},
}
// ContractCaseAction is the action of contract test case
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")
memoSize := c.Int("memo")
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, memoSize, true); 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
}