Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
aljo242 committed Sep 23, 2024
1 parent 4cfbb95 commit 68414d8
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 3 deletions.
62 changes: 59 additions & 3 deletions tests/integration/connect_setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,33 @@ func QueryCurrencyPair(chain *cosmos.CosmosChain, cp connecttypes.CurrencyPair,
return res.Price, int64(res.Nonce), nil
}

// QueryMarket queries a market from the market map.
func QueryMarket(chain *cosmos.CosmosChain, cp connecttypes.CurrencyPair) (mmtypes.Market, error) {
grpcAddr := chain.GetHostGRPCAddress()

// create the client
cc, err := grpc.Dial(grpcAddr, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
return mmtypes.Market{}, err
}
defer cc.Close()

// create the mm client
client := mmtypes.NewQueryClient(cc)

ctx := context.Background()

// query the currency pairs
res, err := client.Market(ctx, &mmtypes.MarketRequest{
CurrencyPair: cp,
})
if err != nil {
return mmtypes.Market{}, err
}

return res.Market, nil
}

// SubmitProposal creates and submits a proposal to the chain
func SubmitProposal(chain *cosmos.CosmosChain, deposit sdk.Coin, submitter string, msgs ...sdk.Msg) (string, error) {
// build the proposal
Expand Down Expand Up @@ -375,9 +402,9 @@ func (s *ConnectIntegrationSuite) AddCurrencyPairs(chain *cosmos.CosmosChain, us
}
}

msg := &mmtypes.MsgCreateMarkets{
Authority: s.user.FormattedAddress(),
CreateMarkets: creates,
msg := &mmtypes.MsgUpsertMarkets{
Authority: s.user.FormattedAddress(),
Markets: creates,
}

tx := CreateTx(s.T(), s.chain, user, gasPrice, msg)
Expand All @@ -398,6 +425,35 @@ func (s *ConnectIntegrationSuite) AddCurrencyPairs(chain *cosmos.CosmosChain, us
return nil
}

func (s *ConnectIntegrationSuite) RemoveMarket(chain *cosmos.CosmosChain, user cosmos.User,
markets []connecttypes.CurrencyPair) error {
marketString := make([]string, len(markets))
for i, market := range markets {
marketString[i] = market.String()
}

msg := &mmtypes.MsgRemoveMarkets{
Admin: s.user.FormattedAddress(),
Markets: marketString,
}

tx := CreateTx(s.T(), s.chain, s.user, gasPrice, msg)

// get an rpc endpoint for the chain
client := chain.Nodes()[0].Client
// broadcast the tx
resp, err := client.BroadcastTxCommit(context.Background(), tx)
if err != nil {
return err
}

if resp.TxResult.Code != abcitypes.CodeTypeOK {
return fmt.Errorf(resp.TxResult.Log)
}

return nil
}

func (s *ConnectIntegrationSuite) UpdateCurrencyPair(chain *cosmos.CosmosChain, markets []mmtypes.Market) error {
msg := &mmtypes.MsgUpsertMarkets{
Authority: s.user.FormattedAddress(),
Expand Down
9 changes: 9 additions & 0 deletions tests/integration/connect_suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,15 @@ func (s *ConnectOracleIntegrationSuite) TestOracleModule() {
disabledTicker(disabledCP),
}...))

market, err := QueryMarket(s.chain, disabledCP)
s.Require().NoError(err)
s.Require().NotNil(market)

s.Require().NoError(s.RemoveMarket(s.chain, s.user, []connecttypes.CurrencyPair{disabledCP}))

// check removed
_, err = QueryMarket(s.chain, disabledCP)
s.Require().Error(err)
})

}
Expand Down

0 comments on commit 68414d8

Please sign in to comment.