Skip to content

Commit

Permalink
[1789]: Fix the exchange cli tests that broke from the commitment cha…
Browse files Browse the repository at this point in the history
…nges.
  • Loading branch information
SpicyLemon committed Jan 26, 2024
1 parent e50c7c7 commit 79c690e
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
44 changes: 43 additions & 1 deletion x/exchange/client/cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import (

abci "github.com/tendermint/tendermint/abci/types"

sdkmath "cosmossdk.io/math"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
Expand All @@ -40,6 +42,7 @@ import (
"github.com/provenance-io/provenance/x/exchange"
"github.com/provenance-io/provenance/x/exchange/client/cli"
"github.com/provenance-io/provenance/x/hold"
markertypes "github.com/provenance-io/provenance/x/marker/types"
)

type CmdTestSuite struct {
Expand Down Expand Up @@ -102,14 +105,27 @@ func (s *CmdTestSuite) SetupSuite() {
cli.AuthorityAddr.String(): "authorityAddr",
}

cherryMarker := &markertypes.MarkerAccount{
BaseAccount: &authtypes.BaseAccount{
Address: markertypes.MustGetMarkerAddress("cherry").String(),
},
Status: markertypes.StatusActive,
Denom: "cherry",
Supply: sdkmath.NewInt(0),
MarkerType: markertypes.MarkerType_Coin,
SupplyFixed: false,
AllowGovernanceControl: true,
}

// Add accounts to auth gen state.
var authGen authtypes.GenesisState
err := s.cfg.Codec.UnmarshalJSON(s.cfg.GenesisState[authtypes.ModuleName], &authGen)
s.Require().NoError(err, "UnmarshalJSON auth gen state")
genAccs := make(authtypes.GenesisAccounts, len(s.accountAddrs))
genAccs := make(authtypes.GenesisAccounts, len(s.accountAddrs), len(s.accountAddrs)+1)
for i, addr := range s.accountAddrs {
genAccs[i] = authtypes.NewBaseAccount(addr, nil, 0, 1)
}
genAccs = append(genAccs, cherryMarker)
newAccounts, err := authtypes.PackAccounts(genAccs)
s.Require().NoError(err, "PackAccounts")
authGen.Accounts = append(authGen.Accounts, newAccounts...)
Expand Down Expand Up @@ -140,6 +156,9 @@ func (s *CmdTestSuite) SetupSuite() {
{Address: s.addr2.String(), Permissions: exchange.AllPermissions()},
{Address: s.addr3.String(), Permissions: []exchange.Permission{exchange.Permission_cancel, exchange.Permission_attributes}},
},
AcceptingCommitments: true,
CommitmentSettlementBips: 50,
IntermediaryDenom: "cherry",
},
exchange.Market{
MarketId: 5,
Expand All @@ -158,6 +177,9 @@ func (s *CmdTestSuite) SetupSuite() {
AccessGrants: []exchange.AccessGrant{
{Address: s.addr1.String(), Permissions: exchange.AllPermissions()},
},
AcceptingCommitments: true,
CommitmentSettlementBips: 50,
IntermediaryDenom: "cherry",
},
// Do not make a market 419, lots of tests expect it to not exist.
exchange.Market{
Expand Down Expand Up @@ -186,6 +208,12 @@ func (s *CmdTestSuite) SetupSuite() {
},
ReqAttrCreateAsk: []string{"seller.kyc"},
ReqAttrCreateBid: []string{"buyer.kyc"},

AcceptingCommitments: true,
FeeCreateCommitmentFlat: []sdk.Coin{sdk.NewInt64Coin("peach", 5)},
CommitmentSettlementBips: 50,
IntermediaryDenom: "cherry",
ReqAttrCreateCommitment: []string{"committer.kyc"},
},
exchange.Market{
// This market has an invalid setup. Don't mess with it.
Expand Down Expand Up @@ -224,6 +252,20 @@ func (s *CmdTestSuite) SetupSuite() {
s.cfg.GenesisState[hold.ModuleName], err = s.cfg.Codec.MarshalJSON(&holdGen)
s.Require().NoError(err, "MarshalJSON hold gen state")

var markerGen markertypes.GenesisState
err = s.cfg.Codec.UnmarshalJSON(s.cfg.GenesisState[markertypes.ModuleName], &markerGen)
s.Require().NoError(err, "UnmarshalJSON marker gen state")
markerGen.NetAssetValues = append(markerGen.NetAssetValues,
markertypes.MarkerNetAssetValues{
Address: cherryMarker.Address,
NetAssetValues: []markertypes.NetAssetValue{
{Price: sdk.NewInt64Coin("nhash", 100), Volume: 1},
},
},
)
s.cfg.GenesisState[markertypes.ModuleName], err = s.cfg.Codec.MarshalJSON(&markerGen)
s.Require().NoError(err, "MarshalJSON marker gen state")

// Add balances to bank gen state.
// Any initial holds for an account are added to this so that
// this is what's available to each at the start of the unit tests.
Expand Down
8 changes: 8 additions & 0 deletions x/exchange/client/cli/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ func (s *CmdTestSuite) TestCmdQueryGetMarket() {
args: []string{"market", "420"},
expOut: `address: cosmos1dmk5hcws5xfue8rd6pl5lu6uh8jyt9fpqs0kf6
market:
accepting_commitments: true
accepting_orders: true
access_grants:
- address: ` + s.addr1.String() + `
Expand All @@ -344,6 +345,7 @@ market:
- PERMISSION_PERMISSIONS
- PERMISSION_ATTRIBUTES
allow_user_settlement: true
commitment_settlement_bips: 50
fee_buyer_settlement_flat:
- amount: "105"
denom: peach
Expand All @@ -366,6 +368,9 @@ market:
fee_create_bid_flat:
- amount: "25"
denom: peach
fee_create_commitment_flat:
- amount: "5"
denom: peach
fee_seller_settlement_flat:
- amount: "100"
denom: peach
Expand All @@ -376,6 +381,7 @@ market:
price:
amount: "75"
denom: peach
intermediary_denom: cherry
market_details:
description: It's coming; you know it. It has all the fees.
icon_uri: ""
Expand All @@ -386,6 +392,8 @@ market:
- seller.kyc
req_attr_create_bid:
- buyer.kyc
req_attr_create_commitment:
- committer.kyc
`,
},
}
Expand Down

0 comments on commit 79c690e

Please sign in to comment.