diff --git a/go.mod b/go.mod index 896ccfafa01..e834173848e 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/CosmWasm/wasmd go 1.14 require ( - github.com/CosmWasm/go-cosmwasm v0.11.0-alpha2 + github.com/CosmWasm/go-cosmwasm v0.11.0-rc github.com/cosmos/cosmos-sdk v0.39.1-0.20200727135228-9d00f712e334 github.com/golang/mock v1.4.3 // indirect github.com/google/gofuzz v1.0.0 diff --git a/go.sum b/go.sum index c588daeeae6..4c56241fb2e 100644 --- a/go.sum +++ b/go.sum @@ -15,6 +15,8 @@ github.com/CosmWasm/go-cosmwasm v0.11.0-alpha1 h1:5c87JcnA+ncQlSJO/mEK6z9oIi/oS4 github.com/CosmWasm/go-cosmwasm v0.11.0-alpha1/go.mod h1:gAFCwllx97ejI+m9SqJQrmd2SBW7HA0fOjvWWJjM2uc= github.com/CosmWasm/go-cosmwasm v0.11.0-alpha2 h1:w42GtYC4P/6dXOVlqEutr96tSsy/EO0aC9d3sbkk5hs= github.com/CosmWasm/go-cosmwasm v0.11.0-alpha2/go.mod h1:gAFCwllx97ejI+m9SqJQrmd2SBW7HA0fOjvWWJjM2uc= +github.com/CosmWasm/go-cosmwasm v0.11.0-rc h1:qKMUR/84LluMStwuOgaWxupQj8STmnRaxFgFXrhY95o= +github.com/CosmWasm/go-cosmwasm v0.11.0-rc/go.mod h1:gAFCwllx97ejI+m9SqJQrmd2SBW7HA0fOjvWWJjM2uc= github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0= github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWXgklEdEo= diff --git a/x/wasm/internal/keeper/querier_test.go b/x/wasm/internal/keeper/querier_test.go index 9fbe2b78297..7f005102ca3 100644 --- a/x/wasm/internal/keeper/querier_test.go +++ b/x/wasm/internal/keeper/querier_test.go @@ -135,12 +135,10 @@ func TestQueryContractState(t *testing.T) { // if smart query, check custom response if spec.srcPath[2] != QueryMethodContractStateAll { - fmt.Printf("path: %s\n", spec.srcPath[2]) require.Equal(t, spec.expRes, binResult) return } - fmt.Printf("all state: %s\n", spec.srcPath[2]) // otherwise, check returned models var r []types.Model if spec.expErr == nil { diff --git a/x/wasm/internal/keeper/reflect_test.go b/x/wasm/internal/keeper/reflect_test.go index 7bc4011ce78..88ff938ff45 100644 --- a/x/wasm/internal/keeper/reflect_test.go +++ b/x/wasm/internal/keeper/reflect_test.go @@ -379,7 +379,54 @@ func TestMaskReflectWasmQueries(t *testing.T) { var reflectStateRes maskState mustParse(t, reflectRawRes.Data, &reflectStateRes) require.Equal(t, reflectStateRes.Owner, []byte(creator)) +} + +func TestWasmRawQueryWithNil(t *testing.T) { + tempDir, err := ioutil.TempDir("", "wasm") + require.NoError(t, err) + defer os.RemoveAll(tempDir) + ctx, keepers := CreateTestInput(t, false, tempDir, MaskFeatures, maskEncoders(MakeTestCodec()), nil) + accKeeper, keeper := keepers.AccountKeeper, keepers.WasmKeeper + + deposit := sdk.NewCoins(sdk.NewInt64Coin("denom", 100000)) + creator := createFakeFundedAccount(ctx, accKeeper, deposit) + + // upload mask code + maskCode, err := ioutil.ReadFile("./testdata/reflect.wasm") + require.NoError(t, err) + maskID, err := keeper.Create(ctx, creator, maskCode, "", "", nil) + require.NoError(t, err) + require.Equal(t, uint64(1), maskID) + // creator instantiates a contract and gives it tokens + maskStart := sdk.NewCoins(sdk.NewInt64Coin("denom", 40000)) + maskAddr, err := keeper.Instantiate(ctx, maskID, creator, nil, []byte("{}"), "mask contract 2", maskStart) + require.NoError(t, err) + require.NotEmpty(t, maskAddr) + + // control: query directly + missingKey := []byte{0, 1, 2, 3, 4} + raw := keeper.QueryRaw(ctx, maskAddr, missingKey) + require.Nil(t, raw) + + // and with queryRaw + reflectQuery := MaskQueryMsg{Chain: &ChainQuery{Request: &wasmTypes.QueryRequest{Wasm: &wasmTypes.WasmQuery{ + Raw: &wasmTypes.RawQuery{ + ContractAddr: maskAddr.String(), + Key: missingKey, + }, + }}}} + reflectStateBin := buildMaskQuery(t, &reflectQuery) + res, err := keeper.QuerySmart(ctx, maskAddr, reflectStateBin) + require.NoError(t, err) + + // first we pull out the data from chain response, before parsing the original response + var reflectRawRes ChainResponse + mustParse(t, res, &reflectRawRes) + // and make sure there is no data + require.Empty(t, reflectRawRes.Data) + // we get an empty byte slice not nil (if anyone care in go-land) + require.Equal(t, []byte{}, reflectRawRes.Data) } func checkAccount(t *testing.T, ctx sdk.Context, accKeeper auth.AccountKeeper, addr sdk.AccAddress, expected sdk.Coins) {