-
Notifications
You must be signed in to change notification settings - Fork 568
/
wasm.go
93 lines (78 loc) · 3.5 KB
/
wasm.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
package osmosisibctesting
import (
"fmt"
"os"
"github.com/tidwall/gjson"
"github.com/stretchr/testify/require"
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
sdk "github.com/cosmos/cosmos-sdk/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
transfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"
"github.com/stretchr/testify/suite"
"github.com/osmosis-labs/osmosis/v24/x/ibc-rate-limit/types"
)
func (chain *TestChain) StoreContractCode(suite *suite.Suite, path string) {
chain.StoreContractCodeDirect(suite, path)
}
func (chain *TestChain) InstantiateRLContract(suite *suite.Suite, quotas string) sdk.AccAddress {
osmosisApp := chain.GetOsmosisApp()
transferModule := osmosisApp.AccountKeeper.GetModuleAddress(transfertypes.ModuleName)
govModule := osmosisApp.AccountKeeper.GetModuleAddress(govtypes.ModuleName)
initMsgBz := []byte(fmt.Sprintf(`{
"gov_module": "%s",
"ibc_module":"%s",
"paths": [%s]
}`,
govModule, transferModule, quotas))
contractKeeper := wasmkeeper.NewDefaultPermissionKeeper(osmosisApp.WasmKeeper)
codeID := uint64(1)
creator := osmosisApp.AccountKeeper.GetModuleAddress(govtypes.ModuleName)
addr, _, err := contractKeeper.Instantiate(chain.GetContext(), codeID, creator, creator, initMsgBz, "rate limiting contract", nil)
suite.Require().NoError(err)
return addr
}
func (chain *TestChain) StoreContractCodeDirect(suite *suite.Suite, path string) uint64 {
osmosisApp := chain.GetOsmosisApp()
govKeeper := wasmkeeper.NewGovPermissionKeeper(osmosisApp.WasmKeeper)
creator := osmosisApp.AccountKeeper.GetModuleAddress(govtypes.ModuleName)
wasmCode, err := os.ReadFile(path)
suite.Require().NoError(err)
accessEveryone := wasmtypes.AccessConfig{Permission: wasmtypes.AccessTypeEverybody}
codeID, _, err := govKeeper.Create(chain.GetContext(), creator, wasmCode, &accessEveryone)
suite.Require().NoError(err)
return codeID
}
func (chain *TestChain) InstantiateContract(suite *suite.Suite, msg string, codeID uint64) sdk.AccAddress {
osmosisApp := chain.GetOsmosisApp()
contractKeeper := wasmkeeper.NewDefaultPermissionKeeper(osmosisApp.WasmKeeper)
creator := osmosisApp.AccountKeeper.GetModuleAddress(govtypes.ModuleName)
addr, _, err := contractKeeper.Instantiate(chain.GetContext(), codeID, creator, creator, []byte(msg), "contract", nil)
suite.Require().NoError(err)
return addr
}
func (chain *TestChain) QueryContract(suite *suite.Suite, contract sdk.AccAddress, key []byte) string {
osmosisApp := chain.GetOsmosisApp()
state, err := osmosisApp.WasmKeeper.QuerySmart(chain.GetContext(), contract, key)
suite.Require().NoError(err)
return string(state)
}
func (chain *TestChain) QueryContractJson(suite *suite.Suite, contract sdk.AccAddress, key []byte) gjson.Result {
osmosisApp := chain.GetOsmosisApp()
state, err := osmosisApp.WasmKeeper.QuerySmart(chain.GetContext(), contract, key)
suite.Require().NoError(err)
suite.Require().True(gjson.Valid(string(state)))
json := gjson.Parse(string(state))
suite.Require().NoError(err)
return json
}
func (chain *TestChain) RegisterRateLimitingContract(addr []byte) {
addrStr, err := sdk.Bech32ifyAddressBytes("osmo", addr)
require.NoError(chain.T, err)
params, err := types.NewParams(addrStr)
require.NoError(chain.T, err)
osmosisApp := chain.GetOsmosisApp()
paramSpace, ok := osmosisApp.AppKeepers.ParamsKeeper.GetSubspace(types.ModuleName)
require.True(chain.T, ok)
paramSpace.SetParamSet(chain.GetContext(), ¶ms)
}