-
Notifications
You must be signed in to change notification settings - Fork 27
/
setup.go
177 lines (148 loc) · 5.77 KB
/
setup.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
package e2e
import (
"context"
"encoding/json"
"fmt"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil"
"github.com/strangelove-ventures/interchaintest/v8"
"github.com/strangelove-ventures/interchaintest/v8/chain/cosmos"
"github.com/strangelove-ventures/interchaintest/v8/ibc"
"github.com/strangelove-ventures/interchaintest/v8/testutil"
sdkmath "cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
wasm "github.com/CosmWasm/wasmd/x/wasm/types"
globalfee "github.com/strangelove-ventures/globalfee/x/globalfee/types"
poa "github.com/strangelove-ventures/poa"
tokenfactory "github.com/strangelove-ventures/tokenfactory/x/tokenfactory/types"
)
var (
VotingPeriod = "15s"
MaxDepositPeriod = "10s"
Denom = "usnr"
Name = "sonr"
ChainID = "chainid-1"
Binary = "sonrd"
Bech32 = "idx"
NumberVals = 1
NumberFullNodes = 0
GenesisFundsAmount = sdkmath.NewInt(1000_000000) // 1k tokens
ChainImage = ibc.NewDockerImage("sonr", "local", "1025:1025")
DefaultGenesis = []cosmos.GenesisKV{
// default
cosmos.NewGenesisKV("app_state.gov.params.voting_period", VotingPeriod),
cosmos.NewGenesisKV("app_state.gov.params.max_deposit_period", MaxDepositPeriod),
cosmos.NewGenesisKV("app_state.gov.params.min_deposit.0.denom", Denom),
cosmos.NewGenesisKV("app_state.gov.params.min_deposit.0.amount", "1"),
// poa: gov & testing account
cosmos.NewGenesisKV("app_state.poa.params.admins", []string{"idx10d07y265gmmuvt4z0w9aw880jnsr700j9kqcfa", "idx1hj5fveer5cjtn4wd6wstzugjfdxzl0xpecp0nd"}),
// globalfee: set minimum fee requirements
cosmos.NewGenesisKV("app_state.globalfee.params.minimum_gas_prices", sdk.DecCoins{sdk.NewDecCoinFromDec(Denom, sdkmath.LegacyMustNewDecFromStr("0.0"))}),
// tokenfactory: set create cost in set denom or in gas usage.
cosmos.NewGenesisKV("app_state.tokenfactory.params.denom_creation_fee", nil),
cosmos.NewGenesisKV("app_state.tokenfactory.params.denom_creation_gas_consume", 1), // cost 1 gas to create a new denom
}
DefaultChainConfig = ibc.ChainConfig{
Images: []ibc.DockerImage{
ChainImage,
},
GasAdjustment: 1.5,
ModifyGenesis: cosmos.ModifyGenesis(DefaultGenesis),
EncodingConfig: func() *moduletestutil.TestEncodingConfig {
cfg := cosmos.DefaultEncoding()
// TODO: add encoding types here for the modules you want to use
wasm.RegisterInterfaces(cfg.InterfaceRegistry)
tokenfactory.RegisterInterfaces(cfg.InterfaceRegistry)
globalfee.RegisterInterfaces(cfg.InterfaceRegistry)
poa.RegisterInterfaces(cfg.InterfaceRegistry)
return &cfg
}(),
Type: "cosmos",
Name: Name,
ChainID: ChainID,
Bin: Binary,
Bech32Prefix: Bech32,
Denom: Denom,
CoinType: "118",
GasPrices: "0" + Denom,
TrustingPeriod: "336h",
}
DefaultChainSpec = interchaintest.ChainSpec{
Name: Name,
ChainName: Name,
Version: ChainImage.Version,
ChainConfig: DefaultChainConfig,
NumValidators: &NumberVals,
NumFullNodes: &NumberFullNodes,
}
// cosmos1hj5fveer5cjtn4wd6wstzugjfdxzl0xpxvjjvr - test_node.sh
AccMnemonic = "decorate bright ozone fork gallery riot bus exhaust worth way bone indoor calm squirrel merry zero scheme cotton until shop any excess stage laundry"
Acc1Mnemonic = "wealth flavor believe regret funny network recall kiss grape useless pepper cram hint member few certain unveil rather brick bargain curious require crowd raise"
RelayerRepo = "ghcr.io/cosmos/relayer"
RelayerVersion = "main"
)
// Other Helpers
func ExecuteQuery(ctx context.Context, chain *cosmos.CosmosChain, cmd []string, i interface{}, extraFlags ...string) {
flags := []string{
"--node", chain.GetRPCAddress(),
"--output=json",
}
flags = append(flags, extraFlags...)
ExecuteExec(ctx, chain, cmd, i, flags...)
}
func ExecuteExec(ctx context.Context, chain *cosmos.CosmosChain, cmd []string, i interface{}, extraFlags ...string) {
command := []string{chain.Config().Bin}
command = append(command, cmd...)
command = append(command, extraFlags...)
fmt.Println(command)
stdout, _, err := chain.Exec(ctx, command, nil)
if err != nil {
fmt.Println(err)
}
fmt.Println(string(stdout))
if err := json.Unmarshal(stdout, &i); err != nil {
fmt.Println(err)
}
}
// Executes a command from CommandBuilder
func ExecuteTransaction(ctx context.Context, chain *cosmos.CosmosChain, cmd []string) (sdk.TxResponse, error) {
var err error
var stdout []byte
stdout, _, err = chain.Exec(ctx, cmd, nil)
if err != nil {
return sdk.TxResponse{}, err
}
if err := testutil.WaitForBlocks(ctx, 2, chain); err != nil {
return sdk.TxResponse{}, err
}
var res sdk.TxResponse
if err := json.Unmarshal(stdout, &res); err != nil {
return res, err
}
return res, err
}
func TxCommandBuilder(ctx context.Context, chain *cosmos.CosmosChain, cmd []string, fromUser string, extraFlags ...string) []string {
return TxCommandBuilderNode(ctx, chain.GetNode(), cmd, fromUser, extraFlags...)
}
func TxCommandBuilderNode(ctx context.Context, node *cosmos.ChainNode, cmd []string, fromUser string, extraFlags ...string) []string {
command := []string{node.Chain.Config().Bin}
command = append(command, cmd...)
command = append(command, "--node", node.Chain.GetRPCAddress())
command = append(command, "--home", node.HomeDir())
command = append(command, "--chain-id", node.Chain.Config().ChainID)
command = append(command, "--from", fromUser)
command = append(command, "--keyring-backend", keyring.BackendTest)
command = append(command, "--output=json")
command = append(command, "--yes")
gasFlag := false
for _, flag := range extraFlags {
if flag == "--gas" {
gasFlag = true
}
}
if !gasFlag {
command = append(command, "--gas", "500000")
}
command = append(command, extraFlags...)
return command
}