-
Notifications
You must be signed in to change notification settings - Fork 80
/
utils.go
79 lines (71 loc) · 2.27 KB
/
utils.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
package e2e
import (
"context"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
"github.com/strangelove-ventures/interchaintest/v8/chain/cosmos"
"github.com/strangelove-ventures/interchaintest/v8/ibc"
"github.com/strangelove-ventures/interchaintest/v8/testutil"
"gopkg.in/yaml.v2"
)
type QueryMsg struct {
GetCount *struct{} `json:"get_count"`
}
type QueryContractResponse struct {
Data QueryContractResponseObj `json:"data"`
}
type QueryContractResponseObj struct {
UpCount int64 `json:"up_count"`
DownCount int64 `json:"down_count"`
}
func InstantiateContract(chain *cosmos.CosmosChain, user ibc.Wallet, ctx context.Context, codeId string, initMsg string) (string, error) {
// Instantiate the contract
cmd := []string{
chain.Config().Bin, "tx", "wasm", "instantiate", codeId, initMsg,
"--label", "cwica-contract", "--admin", user.FormattedAddress(),
"--from", user.KeyName(), "--keyring-backend", keyring.BackendTest,
"--fees", "2000ustars",
"--node", chain.GetRPCAddress(),
"--home", chain.HomeDir(),
"--chain-id", chain.Config().ChainID,
"--output", "json",
"-y",
}
if _, _, err := chain.Exec(ctx, cmd, nil); err != nil {
return "", err
}
if err := testutil.WaitForBlocks(ctx, 1, chain); err != nil {
return "", err
}
// Getting the contract address
cmd = []string{
chain.Config().Bin, "q", "wasm", "list-contract-by-code", codeId,
"--node", chain.GetRPCAddress(),
"--home", chain.HomeDir(),
"--chain-id", chain.Config().ChainID,
}
stdout, _, err := chain.Exec(ctx, cmd, nil)
if err != nil {
return "", err
}
contactsRes := cosmos.QueryContractResponse{}
if err = yaml.Unmarshal(stdout, &contactsRes); err != nil {
return "", err
}
return contactsRes.Contracts[0], nil
}
func ExecuteContract(chain *cosmos.CosmosChain, user ibc.Wallet, ctx context.Context, contractAddress string, execMsg string) error {
cmd := []string{
chain.Config().Bin, "tx", "wasm", "execute", contractAddress, execMsg,
"--from", user.KeyName(), "--keyring-backend", keyring.BackendTest,
"--fees", "2000ustars",
"--node", chain.GetRPCAddress(),
"--home", chain.HomeDir(),
"--chain-id", chain.Config().ChainID,
"--output", "json",
"-y",
}
if _, _, err := chain.Exec(ctx, cmd, nil); err != nil {
return err
}
return testutil.WaitForBlocks(ctx, 1, chain)
}