-
Notifications
You must be signed in to change notification settings - Fork 558
/
wasm.go
87 lines (73 loc) · 3.16 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
package osmosisibctesting
import (
"fmt"
"io/ioutil"
"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/v3/modules/apps/transfer/types"
"github.com/osmosis-labs/osmosis/v13/x/ibc-rate-limit/types"
"github.com/stretchr/testify/suite"
)
func (chain *TestChain) StoreContractCode(suite *suite.Suite, path string) {
osmosisApp := chain.GetOsmosisApp()
govKeeper := osmosisApp.GovKeeper
wasmCode, err := ioutil.ReadFile(path)
suite.Require().NoError(err)
addr := osmosisApp.AccountKeeper.GetModuleAddress(govtypes.ModuleName)
src := wasmtypes.StoreCodeProposalFixture(func(p *wasmtypes.StoreCodeProposal) {
p.RunAs = addr.String()
p.WASMByteCode = wasmCode
})
// when stored
storedProposal, err := govKeeper.SubmitProposal(chain.GetContext(), src, false)
suite.Require().NoError(err)
// and proposal execute
handler := govKeeper.Router().GetRoute(storedProposal.ProposalRoute())
err = handler(chain.GetContext(), storedProposal.GetContent())
suite.Require().NoError(err)
}
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) InstantiateContract(suite *suite.Suite, msg string) sdk.AccAddress {
osmosisApp := chain.GetOsmosisApp()
contractKeeper := wasmkeeper.NewDefaultPermissionKeeper(osmosisApp.WasmKeeper)
codeID := uint64(1)
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) 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)
}