From 259047e0eb317f80722e7b555072fe44fbea9644 Mon Sep 17 00:00:00 2001 From: Daniel Wedul Date: Mon, 13 Nov 2023 17:37:52 -0700 Subject: [PATCH] [1701]: Unit tests on the validation queries. Query unit tests done. --- x/exchange/client/cli/cli_test.go | 12 ++++ x/exchange/client/cli/query_test.go | 94 +++++++++++++++++++++++++++-- 2 files changed, 102 insertions(+), 4 deletions(-) diff --git a/x/exchange/client/cli/cli_test.go b/x/exchange/client/cli/cli_test.go index c24f9ce51c..11042ccb42 100644 --- a/x/exchange/client/cli/cli_test.go +++ b/x/exchange/client/cli/cli_test.go @@ -161,6 +161,18 @@ func (s *CmdTestSuite) SetupSuite() { {Address: s.addr1.String(), Permissions: exchange.AllPermissions()}, }, }, + exchange.Market{ + // This market has an invalid setup. Don't mess with it. + MarketId: 421, + MarketDetails: exchange.MarketDetails{Name: "Broken"}, + FeeSellerSettlementRatios: []exchange.FeeRatio{ + {Price: sdk.NewInt64Coin("peach", 55), Fee: sdk.NewInt64Coin("peach", 1)}, + }, + FeeBuyerSettlementRatios: []exchange.FeeRatio{ + {Price: sdk.NewInt64Coin("peach", 56), Fee: sdk.NewInt64Coin("peach", 1)}, + {Price: sdk.NewInt64Coin("plum", 57), Fee: sdk.NewInt64Coin("plum", 1)}, + }, + }, ) toHold := make(map[string]sdk.Coins) exchangeGen.Orders = make([]exchange.Order, 60) diff --git a/x/exchange/client/cli/query_test.go b/x/exchange/client/cli/query_test.go index 6589bb3284..52bb6404f9 100644 --- a/x/exchange/client/cli/query_test.go +++ b/x/exchange/client/cli/query_test.go @@ -410,7 +410,7 @@ func (s *CmdTestSuite) TestCmdQueryGetAllMarkets() { { name: "get all", args: []string{"all-markets"}, - expInOut: []string{`market_id: 3`, `market_id: 5`, `market_id: 420`}, + expInOut: []string{`market_id: 3`, `market_id: 5`, `market_id: 420`, `market_id: 421`}, }, { name: "no markets", @@ -457,8 +457,94 @@ func (s *CmdTestSuite) TestCmdQueryParams() { } } -// TODO[1701]: func (s *CmdTestSuite) TestCmdQueryValidateCreateMarket() +func (s *CmdTestSuite) TestCmdQueryValidateCreateMarket() { + tests := []queryCmdTestCase{ + { + name: "cmd error", + args: []string{"validate-create-market", "--create-ask", "orange"}, + expInErr: []string{"invalid coin expression: \"orange\""}, + }, + { + name: "problem with proposal", + args: []string{"val-create-market", "--market", "420", "--name", "Other Name", "--output", "json"}, + expOut: `{"error":"market id 420 account cosmos1dmk5hcws5xfue8rd6pl5lu6uh8jyt9fpqs0kf6 already exists","gov_prop_will_pass":false}` + "\n", + }, + { + name: "okay", + args: []string{"validate-create-market", + "--name", "New Market", "--create-ask", "50nhash", "--create-bid", "50nhash", + "--accepting-orders", + }, + expOut: `error: "" +gov_prop_will_pass: true +`, + }, + } + + for _, tc := range tests { + s.Run(tc.name, func() { + s.runQueryCmdTestCase(tc) + }) + } +} + +func (s *CmdTestSuite) TestCmdQueryValidateMarket() { + tests := []queryCmdTestCase{ + { + name: "no market id", + args: []string{"validate-market"}, + expInErr: []string{"no provided"}, + }, + { + name: "invalid market", + args: []string{"val-market", "--output", "json", "--market", "421"}, + expOut: `{"error":"buyer settlement fee ratios have price denom \"plum\" but there is not a seller settlement fee ratio with that price denom"}` + "\n", + }, + { + name: "valid market", + args: []string{"market-validate", "420"}, + expOut: `error: "" +`, + }, + } -// TODO[1701]: func (s *CmdTestSuite) TestCmdQueryValidateMarket() + for _, tc := range tests { + s.Run(tc.name, func() { + s.runQueryCmdTestCase(tc) + }) + } +} -// TODO[1701]: func (s *CmdTestSuite) TestCmdQueryValidateManageFees() +func (s *CmdTestSuite) TestCmdQueryValidateManageFees() { + tests := []queryCmdTestCase{ + { + name: "cmd error", + args: []string{"validate-manage-fees", "--seller-flat-add", "orange", "--market", "419"}, + expInErr: []string{"invalid coin expression: \"orange\""}, + }, + { + name: "problem with proposal", + args: []string{"val-manage-fees", "--market", "420", + "--seller-ratios-add", "123plum:5plum", + "--buyer-ratios-add", "123pear:5pear", + }, + expOut: `error: |- + seller settlement fee ratios have price denom "plum" but there are no buyer settlement fee ratios with that price denom + buyer settlement fee ratios have price denom "pear" but there is not a seller settlement fee ratio with that price denom +gov_prop_will_pass: true +`, + }, + { + name: "fixes existing problem", + args: []string{"val-manage-fees", "--market", "421", + "--seller-ratios-add", "123plum:5plum", "--output", "json"}, + expOut: `{"error":"","gov_prop_will_pass":true}` + "\n", + }, + } + + for _, tc := range tests { + s.Run(tc.name, func() { + s.runQueryCmdTestCase(tc) + }) + } +}