Skip to content

Commit

Permalink
Better wasmvm 1.1 integration test (CosmWasm#988)
Browse files Browse the repository at this point in the history
* Add cosmwasm_1_1 cability, bump reflect contract, supply query integration test

* Review feedback
  • Loading branch information
alpe authored and conorpp committed Feb 1, 2023
1 parent 57ce507 commit ad5a55d
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ func NewWasmApp(

// The last arguments can contain custom message handlers, and custom query handlers,
// if we want to allow any custom callbacks
supportedFeatures := "iterator,staking,stargate"
supportedFeatures := "iterator,staking,stargate,cosmwasm_1_1"
app.WasmKeeper = wasm.NewKeeper(
appCodec,
keys[wasm.StoreKey],
Expand Down
2 changes: 1 addition & 1 deletion x/wasm/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func init() {

var hackatomWasm []byte

const SupportedFeatures = "iterator,staking,stargate"
const SupportedFeatures = "iterator,staking,stargate,cosmwasm_1_1"

func TestNewKeeper(t *testing.T) {
_, keepers := CreateTestInput(t, false, SupportedFeatures)
Expand Down
53 changes: 52 additions & 1 deletion x/wasm/keeper/reflect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func mustParse(t *testing.T, data []byte, res interface{}) {
require.NoError(t, err)
}

const ReflectFeatures = "staking,mask,stargate"
const ReflectFeatures = "staking,mask,stargate,cosmwasm_1_1"

func TestReflectContractSend(t *testing.T) {
cdc := MakeEncodingConfig(t).Marshaler
Expand Down Expand Up @@ -298,6 +298,57 @@ func TestReflectStargateQuery(t *testing.T) {
assert.Equal(t, simpleBalance.Amount[0].Denom, expectedBalance[0].Denom)
}

func TestReflectTotalSupplyQuery(t *testing.T) {
cdc := MakeEncodingConfig(t).Marshaler
ctx, keepers := CreateTestInput(t, false, ReflectFeatures, WithMessageEncoders(reflectEncoders(cdc)), WithQueryPlugins(reflectPlugins()))
keeper := keepers.WasmKeeper
// upload code
codeID := StoreReflectContract(t, ctx, keepers)
// creator instantiates a contract and gives it tokens
creator := RandomAccountAddress(t)
contractAddr, _, err := keepers.ContractKeeper.Instantiate(ctx, codeID, creator, nil, []byte("{}"), "testing", nil)
require.NoError(t, err)

currentStakeSupply := keepers.BankKeeper.GetSupply(ctx, "stake")
require.NotEmpty(t, currentStakeSupply.Amount) // ensure we have real data
specs := map[string]struct {
denom string
expAmount wasmvmtypes.Coin
}{
"known denom": {
denom: "stake",
expAmount: ConvertSdkCoinToWasmCoin(currentStakeSupply),
},
"unknown denom": {
denom: "unknown",
expAmount: wasmvmtypes.Coin{Denom: "unknown", Amount: "0"},
},
}
for name, spec := range specs {
t.Run(name, func(t *testing.T) {
// when
queryBz := mustMarshal(t, testdata.ReflectQueryMsg{
Chain: &testdata.ChainQuery{
Request: &wasmvmtypes.QueryRequest{
Bank: &wasmvmtypes.BankQuery{
Supply: &wasmvmtypes.SupplyQuery{spec.denom},
},
},
},
})
simpleRes, err := keeper.QuerySmart(ctx, contractAddr, queryBz)

// then
require.NoError(t, err)
var rsp testdata.ChainResponse
mustParse(t, simpleRes, &rsp)
var supplyRsp wasmvmtypes.SupplyResponse
mustParse(t, rsp.Data, &supplyRsp)
assert.Equal(t, spec.expAmount, supplyRsp.Amount, spec.expAmount)
})
}
}

func TestReflectInvalidStargateQuery(t *testing.T) {
cdc := MakeEncodingConfig(t).Marshaler
ctx, keepers := CreateTestInput(t, false, ReflectFeatures, WithMessageEncoders(reflectEncoders(cdc)), WithQueryPlugins(reflectPlugins()))
Expand Down
Binary file modified x/wasm/keeper/testdata/reflect.wasm
Binary file not shown.
Binary file added x/wasm/keeper/testdata/reflect.wasm.v1_0
Binary file not shown.
2 changes: 1 addition & 1 deletion x/wasm/module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type testData struct {
}

func setupTest(t *testing.T) testData {
ctx, keepers := CreateTestInput(t, false, "iterator,staking,stargate")
ctx, keepers := CreateTestInput(t, false, "iterator,staking,stargate,cosmwasm_1_1")
cdc := keeper.MakeTestCodec(t)
data := testData{
module: NewAppModule(cdc, keepers.WasmKeeper, keepers.StakingKeeper, keepers.AccountKeeper, keepers.BankKeeper),
Expand Down

0 comments on commit ad5a55d

Please sign in to comment.