Skip to content

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
javiersuweijie committed Mar 27, 2024
1 parent 9765caa commit da0231c
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 65 deletions.
4 changes: 2 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ import (
authsims "github.com/cosmos/cosmos-sdk/x/auth/simulation"

wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
"github.com/terra-money/core/v2/app/custom_queriers"
"github.com/terra-money/core/v2/app/keepers"
"github.com/terra-money/core/v2/app/post"
"github.com/terra-money/core/v2/app/rpc"
tokenfactorybindings "github.com/terra-money/core/v2/x/tokenfactory/bindings"

dbm "github.com/cometbft/cometbft-db"
abci "github.com/cometbft/cometbft/abci/types"
Expand Down Expand Up @@ -478,7 +478,7 @@ func (app *TerraApp) GetWasmOpts(appOpts servertypes.AppOptions) []wasmkeeper.Op
wasmOpts = append(wasmOpts, wasmkeeper.WithVMCacheMetrics(prometheus.DefaultRegisterer))
}

wasmOpts = append(wasmOpts, tokenfactorybindings.RegisterCustomPlugins(
wasmOpts = append(wasmOpts, custom_queriers.RegisterCustomPlugins(
&app.Keepers.BankKeeper.BaseKeeper,
&app.Keepers.TokenFactoryKeeper,
&app.Keepers.AllianceKeeper)...,
Expand Down
52 changes: 52 additions & 0 deletions app/custom_queriers/custom_queriers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package custom_queriers

import (
"encoding/json"
"fmt"
"github.com/CosmWasm/wasmd/x/wasm"
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
alliancebindings "github.com/terra-money/alliance/x/alliance/bindings"
alliancekeeper "github.com/terra-money/alliance/x/alliance/keeper"
tokenfactorybindings "github.com/terra-money/core/v2/x/tokenfactory/bindings"
tokenfactorykeeper "github.com/terra-money/core/v2/x/tokenfactory/keeper"
"strings"

sdk "github.com/cosmos/cosmos-sdk/types"
)

type Querier func(ctx sdk.Context, request json.RawMessage) ([]byte, error)

func CustomQueriers(queriers ...Querier) func(ctx sdk.Context, request json.RawMessage) ([]byte, error) {
return func(ctx sdk.Context, request json.RawMessage) ([]byte, error) {
for _, querier := range queriers {
res, err := querier(ctx, request)
if err == nil || !strings.Contains(err.Error(), "unknown query") {
return res, err
}
}
return nil, fmt.Errorf("unknown query")

Check warning on line 28 in app/custom_queriers/custom_queriers.go

View check run for this annotation

Codecov / codecov/patch

app/custom_queriers/custom_queriers.go#L28

Added line #L28 was not covered by tests
}
}

func RegisterCustomPlugins(
bank *bankkeeper.BaseKeeper,
tokenFactory *tokenfactorykeeper.Keeper,
allianceKeeper *alliancekeeper.Keeper,
) []wasmkeeper.Option {
tfQuerier := tokenfactorybindings.CustomQuerier(tokenfactorybindings.NewQueryPlugin(bank, tokenFactory))
allianceQuerier := alliancebindings.CustomQuerier(alliancebindings.NewAllianceQueryPlugin(allianceKeeper))
queriers := CustomQueriers(tfQuerier, allianceQuerier)

Check warning on line 39 in app/custom_queriers/custom_queriers.go

View check run for this annotation

Codecov / codecov/patch

app/custom_queriers/custom_queriers.go#L36-L39

Added lines #L36 - L39 were not covered by tests

queryPluginOpt := wasmkeeper.WithQueryPlugins(&wasmkeeper.QueryPlugins{
Custom: queriers,
})
messengerDecoratorOpt := wasmkeeper.WithMessageHandlerDecorator(
tokenfactorybindings.CustomMessageDecorator(bank, tokenFactory),
)

Check warning on line 46 in app/custom_queriers/custom_queriers.go

View check run for this annotation

Codecov / codecov/patch

app/custom_queriers/custom_queriers.go#L41-L46

Added lines #L41 - L46 were not covered by tests

return []wasm.Option{
queryPluginOpt,
messengerDecoratorOpt,

Check warning on line 50 in app/custom_queriers/custom_queriers.go

View check run for this annotation

Codecov / codecov/patch

app/custom_queriers/custom_queriers.go#L48-L50

Added lines #L48 - L50 were not covered by tests
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
package wasm
package custom_queriers

import (
"encoding/json"
"fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
"runtime"
"testing"

"github.com/stretchr/testify/require"
alliancebindings "github.com/terra-money/alliance/x/alliance/bindings"
"github.com/terra-money/alliance/x/alliance/bindings/types"
"github.com/terra-money/core/v2/x/tokenfactory/bindings"
types2 "github.com/terra-money/core/v2/x/tokenfactory/bindings/types"
"runtime"
"testing"

sdk "github.com/cosmos/cosmos-sdk/types"
)

func AlwaysErrorQuerier(ctx sdk.Context, request json.RawMessage) ([]byte, error) {
Expand Down Expand Up @@ -51,7 +53,7 @@ func TestWithTfAndAllianceButCallAlliance(t *testing.T) {
stack := make([]byte, 1024)
runtime.Stack(stack, false)
// We make sure alliance is called here
require.Containsf(t, string(stack), "keeper.Keeper.GetAssetByDenom", "")
require.Containsf(t, string(stack), "GetAlliance", "")
}
}()

Expand All @@ -78,7 +80,7 @@ func TestWithTfAndAllianceButCallTf(t *testing.T) {
stack := make([]byte, 1024)
runtime.Stack(stack, false)
// We make sure tf is called here
require.Containsf(t, string(stack), "bindings.QueryPlugin.GetParams", "")
require.Containsf(t, string(stack), "GetParams", "")
}
}()

Expand Down
7 changes: 4 additions & 3 deletions app/upgrades/v2.11/upgrade.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package v2_11

import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
ibctransferkeeper "github.com/cosmos/ibc-go/v7/modules/apps/transfer/keeper"
transfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"
custombankkeeper "github.com/terra-money/core/v2/x/bank/keeper"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
)

type EscrowUpdate struct {
Expand Down
1 change: 1 addition & 0 deletions cmd/terrad/testnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"cosmossdk.io/math"

"cosmossdk.io/simapp"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/tx"
Expand Down
32 changes: 0 additions & 32 deletions x/tokenfactory/bindings/wasm.go
Original file line number Diff line number Diff line change
@@ -1,34 +1,2 @@
package bindings

import (
"github.com/CosmWasm/wasmd/x/wasm"
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
alliancebindings "github.com/terra-money/alliance/x/alliance/bindings"
alliancekeeper "github.com/terra-money/alliance/x/alliance/keeper"
tokenfactorykeeper "github.com/terra-money/core/v2/x/tokenfactory/keeper"
wasm2 "github.com/terra-money/core/v2/x/wasm"

bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
)

func RegisterCustomPlugins(
bank *bankkeeper.BaseKeeper,
tokenFactory *tokenfactorykeeper.Keeper,
allianceKeeper *alliancekeeper.Keeper,
) []wasmkeeper.Option {
tfQuerier := CustomQuerier(NewQueryPlugin(bank, tokenFactory))
allianceQuerier := alliancebindings.CustomQuerier(alliancebindings.NewAllianceQueryPlugin(allianceKeeper))
queriers := wasm2.CustomQueriers(tfQuerier, allianceQuerier)

queryPluginOpt := wasmkeeper.WithQueryPlugins(&wasmkeeper.QueryPlugins{
Custom: queriers,
})
messengerDecoratorOpt := wasmkeeper.WithMessageHandlerDecorator(
CustomMessageDecorator(bank, tokenFactory),
)

return []wasm.Option{
queryPluginOpt,
messengerDecoratorOpt,
}
}
22 changes: 0 additions & 22 deletions x/wasm/custom_queriers.go

This file was deleted.

0 comments on commit da0231c

Please sign in to comment.