Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better wasmvm 1.1 integration test #988

Merged
merged 2 commits into from
Sep 9, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
alpe marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -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)
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) {
alpe marked this conversation as resolved.
Show resolved Hide resolved
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)

currentStateSupply := keepers.BankKeeper.GetSupply(ctx, "stake")
require.NotEmpty(t, currentStateSupply.Amount) // ensure we have real data
specs := map[string]struct {
denom string
expAmount wasmvmtypes.Coin
}{
"known denom": {
denom: "stake",
expAmount: ConvertSdkCoinToWasmCoin(currentStateSupply),
alpe marked this conversation as resolved.
Show resolved Hide resolved
},
"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