diff --git a/x/wasm/keeper/custom_test.go b/x/wasm/keeper/custom_test.go index 63458c90a..d2eb9a65a 100644 --- a/x/wasm/keeper/custom_test.go +++ b/x/wasm/keeper/custom_test.go @@ -88,6 +88,9 @@ type bindingsTesterTaxCapQueryMsg struct { type bindingsTesterExchangeRatesQueryMsg struct { ExchangeRates exchangeRatesQueryMsg `json:"exchange_rates"` } +type bindingsTesterContractInfoQuerymsg struct { + ContractInfo contractInfoQueryMsg `json:"contract_info"` +} type swapQueryMsg struct { OfferCoin wasmvmtypes.Coin `json:"offer_coin"` AskDenom string `json:"ask_denom"` @@ -100,6 +103,9 @@ type exchangeRatesQueryMsg struct { BaseDenom string `json:"base_denom"` QuoteDenoms []string `json:"quote_denoms"` } +type contractInfoQueryMsg struct { + ContractAddress string `json:"contract_address"` +} func TestInstantiateMaker(t *testing.T) { input := CreateTestInput(t) @@ -240,6 +246,37 @@ func TestExchangeRatesQuerier(t *testing.T) { require.Equal(t, KRWExchangeRate, exchangeRateDec) } +func TestContractInfoQuerier(t *testing.T) { + input, _, testerAddr, _ := setupBindingsTesterContract(t) + + ctx, keeper := input.Ctx, input.WasmKeeper + + contractInfoQueryMsg := bindingsTesterContractInfoQuerymsg{ + ContractInfo: contractInfoQueryMsg{ + ContractAddress: testerAddr.String(), + }, + } + + bz, err := json.Marshal(contractInfoQueryMsg) + require.NoError(t, err) + + res, err := keeper.queryToContract(ctx, testerAddr, bz) + require.NoError(t, err) + + var contractInfoResponse ContractInfoQueryResponse + err = json.Unmarshal(res, &contractInfoResponse) + require.NoError(t, err) + + contractInfo, err := keeper.GetContractInfo(ctx, testerAddr) + require.NoError(t, err) + require.Equal(t, contractInfoResponse, ContractInfoQueryResponse{ + CodeID: contractInfo.CodeID, + Address: contractInfo.Address, + Creator: contractInfo.Creator, + Admin: contractInfo.Admin, + }) +} + func TestBuyMsg(t *testing.T) { input, creatorAddr, makerAddr, offerCoin := setupMakerContract(t) diff --git a/x/wasm/keeper/testdata/bindings_tester.wasm b/x/wasm/keeper/testdata/bindings_tester.wasm index 32b8be56c..4731d71f1 100644 Binary files a/x/wasm/keeper/testdata/bindings_tester.wasm and b/x/wasm/keeper/testdata/bindings_tester.wasm differ diff --git a/x/wasm/keeper/wasm_interface.go b/x/wasm/keeper/wasm_interface.go index 39e5f6a3d..b70765b39 100644 --- a/x/wasm/keeper/wasm_interface.go +++ b/x/wasm/keeper/wasm_interface.go @@ -2,6 +2,7 @@ package keeper import ( "encoding/json" + "fmt" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" @@ -189,6 +190,7 @@ func (querier WasmQuerier) QueryCustom(ctx sdk.Context, data json.RawMessage) ([ CodeID: contractInfo.CodeID, }) + fmt.Println("SIBONG", string(bz)) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) } diff --git a/x/wasm/keeper/wasm_interface_test.go b/x/wasm/keeper/wasm_interface_test.go index 07d84a1c3..a1d8d0222 100644 --- a/x/wasm/keeper/wasm_interface_test.go +++ b/x/wasm/keeper/wasm_interface_test.go @@ -235,5 +235,4 @@ func TestQueryContractInfo(t *testing.T) { Admin: "", CodeID: 1, }) - }