-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add tests for
x/liquidity/types
and fix bugs
Merge pull request #111 from cosmosquad-labs/testing-1
- Loading branch information
Showing
19 changed files
with
1,169 additions
and
298 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
//go:build norace | ||
// +build norace | ||
|
||
package testutil | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/suite" | ||
) | ||
|
||
func TestIntegrationTestSuite(t *testing.T) { | ||
suite.Run(t, new(IntegrationTestSuite)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package testutil | ||
|
||
import ( | ||
"fmt" | ||
"strconv" | ||
|
||
"github.com/cosmos/cosmos-sdk/client" | ||
"github.com/cosmos/cosmos-sdk/client/flags" | ||
"github.com/cosmos/cosmos-sdk/testutil" | ||
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
"github.com/cosmosquad-labs/squad/x/liquidity/client/cli" | ||
) | ||
|
||
var commonArgs = []string{ | ||
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), | ||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock), | ||
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewInt64Coin(sdk.DefaultBondDenom, 10)).String()), | ||
} | ||
|
||
func MsgCreatePair(clientCtx client.Context, from, baseCoinDenom, quoteCoinDenom string, extraArgs ...string) (testutil.BufferWriter, error) { | ||
args := append(append([]string{ | ||
baseCoinDenom, | ||
quoteCoinDenom, | ||
fmt.Sprintf("--%s=%s", flags.FlagFrom, from), | ||
}, commonArgs...), extraArgs...) | ||
|
||
return clitestutil.ExecTestCLICmd(clientCtx, cli.NewCreatePairCmd(), args) | ||
} | ||
|
||
func MsgCreatePool(clientCtx client.Context, from string, pairId uint64, depositCoins sdk.Coins, extraArgs ...string) (testutil.BufferWriter, error) { | ||
args := append(append([]string{ | ||
strconv.FormatUint(pairId, 10), | ||
depositCoins.String(), | ||
fmt.Sprintf("--%s=%s", flags.FlagFrom, from), | ||
}, commonArgs...), extraArgs...) | ||
|
||
return clitestutil.ExecTestCLICmd(clientCtx, cli.NewCreatePoolCmd(), args) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
package testutil | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/suite" | ||
dbm "github.com/tendermint/tm-db" | ||
|
||
"github.com/cosmos/cosmos-sdk/baseapp" | ||
"github.com/cosmos/cosmos-sdk/client" | ||
servertypes "github.com/cosmos/cosmos-sdk/server/types" | ||
"github.com/cosmos/cosmos-sdk/simapp" | ||
store "github.com/cosmos/cosmos-sdk/store/types" | ||
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" | ||
"github.com/cosmos/cosmos-sdk/testutil/network" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
squadapp "github.com/cosmosquad-labs/squad/app" | ||
squadparams "github.com/cosmosquad-labs/squad/app/params" | ||
"github.com/cosmosquad-labs/squad/x/liquidity/client/cli" | ||
"github.com/cosmosquad-labs/squad/x/liquidity/types" | ||
) | ||
|
||
type IntegrationTestSuite struct { | ||
suite.Suite | ||
|
||
cfg network.Config | ||
network *network.Network | ||
val *network.Validator | ||
clientCtx client.Context | ||
} | ||
|
||
func NewAppConstructor(encodingCfg squadparams.EncodingConfig) network.AppConstructor { | ||
return func(val network.Validator) servertypes.Application { | ||
return squadapp.NewSquadApp( | ||
val.Ctx.Logger, dbm.NewMemDB(), nil, true, make(map[int64]bool), val.Ctx.Config.RootDir, 0, | ||
encodingCfg, | ||
simapp.EmptyAppOptions{}, | ||
baseapp.SetPruning(store.NewPruningOptionsFromString(val.AppConfig.Pruning)), | ||
baseapp.SetMinGasPrices(val.AppConfig.MinGasPrices), | ||
) | ||
} | ||
} | ||
|
||
func (s *IntegrationTestSuite) SetupSuite() { | ||
s.T().Log("setting up integration test suite") | ||
|
||
if testing.Short() { | ||
s.T().Skip("skipping test in unit-tests mode.") | ||
} | ||
|
||
encCfg := squadapp.MakeTestEncodingConfig() | ||
|
||
cfg := network.DefaultConfig() | ||
cfg.AppConstructor = NewAppConstructor(encCfg) | ||
cfg.GenesisState = squadapp.ModuleBasics.DefaultGenesis(cfg.Codec) | ||
cfg.NumValidators = 1 | ||
|
||
s.cfg = cfg | ||
s.network = network.New(s.T(), cfg) | ||
|
||
s.val = s.network.Validators[0] | ||
s.clientCtx = s.val.ClientCtx | ||
|
||
_, err := s.network.WaitForHeight(1) | ||
s.Require().NoError(err) | ||
|
||
s.createPair("node0token", s.cfg.BondDenom) | ||
|
||
err = s.network.WaitForNextBlock() | ||
s.Require().NoError(err) | ||
} | ||
|
||
func (s *IntegrationTestSuite) TearDownSuite() { | ||
s.T().Log("tearing down integration test suite") | ||
s.network.Cleanup() | ||
} | ||
|
||
func (s *IntegrationTestSuite) createPair(baseCoinDenom, quoteCoinDenom string) { | ||
_, err := MsgCreatePair(s.clientCtx, s.val.Address.String(), baseCoinDenom, quoteCoinDenom) | ||
s.Require().NoError(err) | ||
|
||
err = s.network.WaitForNextBlock() | ||
s.Require().NoError(err) | ||
} | ||
|
||
//nolint | ||
func (s *IntegrationTestSuite) createPool(pairId uint64, depositCoins sdk.Coins) { | ||
_, err := MsgCreatePool(s.clientCtx, s.val.Address.String(), pairId, depositCoins) | ||
s.Require().NoError(err) | ||
|
||
err = s.network.WaitForNextBlock() | ||
s.Require().NoError(err) | ||
} | ||
|
||
func (s *IntegrationTestSuite) TestGetPairsCmd() { | ||
val := s.network.Validators[0] | ||
clientCtx := val.ClientCtx | ||
|
||
cmd := cli.QueryPairs() | ||
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, []string{"--output=json"}) | ||
s.Require().NoError(err) | ||
|
||
var resp types.QueryPairsResponse | ||
s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), &resp), out.String()) | ||
s.Require().NotNil(resp.Pairs) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.