Skip to content

Commit

Permalink
add testing code for contract info query wasm interface
Browse files Browse the repository at this point in the history
  • Loading branch information
yun-yeo committed Jul 22, 2021
1 parent b634ee4 commit ca7f35b
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 1 deletion.
37 changes: 37 additions & 0 deletions x/wasm/keeper/custom_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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)
Expand Down Expand Up @@ -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)

Expand Down
Binary file modified x/wasm/keeper/testdata/bindings_tester.wasm
Binary file not shown.
2 changes: 2 additions & 0 deletions x/wasm/keeper/wasm_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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())
}
Expand Down
1 change: 0 additions & 1 deletion x/wasm/keeper/wasm_interface_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,5 +235,4 @@ func TestQueryContractInfo(t *testing.T) {
Admin: "",
CodeID: 1,
})

}

0 comments on commit ca7f35b

Please sign in to comment.