diff --git a/app/app.go b/app/app.go index 23259d0d0d..a25e507607 100644 --- a/app/app.go +++ b/app/app.go @@ -507,7 +507,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], diff --git a/x/wasm/keeper/keeper_test.go b/x/wasm/keeper/keeper_test.go index ac26f10397..ec6a44e9e9 100644 --- a/x/wasm/keeper/keeper_test.go +++ b/x/wasm/keeper/keeper_test.go @@ -40,7 +40,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) diff --git a/x/wasm/keeper/reflect_test.go b/x/wasm/keeper/reflect_test.go index 079324fac5..8e4f4829eb 100644 --- a/x/wasm/keeper/reflect_test.go +++ b/x/wasm/keeper/reflect_test.go @@ -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 @@ -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())) diff --git a/x/wasm/keeper/testdata/reflect.wasm b/x/wasm/keeper/testdata/reflect.wasm index 312f45768d..412241177b 100644 Binary files a/x/wasm/keeper/testdata/reflect.wasm and b/x/wasm/keeper/testdata/reflect.wasm differ diff --git a/x/wasm/keeper/testdata/reflect.wasm.v1_0 b/x/wasm/keeper/testdata/reflect.wasm.v1_0 new file mode 100644 index 0000000000..312f45768d Binary files /dev/null and b/x/wasm/keeper/testdata/reflect.wasm.v1_0 differ diff --git a/x/wasm/module_test.go b/x/wasm/module_test.go index f9dde8769e..8417225ade 100644 --- a/x/wasm/module_test.go +++ b/x/wasm/module_test.go @@ -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),