Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented cli tests for pricefeed + minor bugfixes #604

Merged
merged 8 commits into from
Jun 15, 2022

Conversation

john-connor84
Copy link
Contributor

No description provided.

Create a new wallet and attempt to fill it with the required balance.
Tokens are sent by the validator, 'val'.
*/
func (s IntegrationTestSuite) fillWalletFromValidator(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would recommend using the shared one at

func FillWalletFromValidator(
.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree.

expectedPrice sdk.Dec
expectErr bool
respType proto.Message
expectedCode uint32
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is expectedCode used anywhere?

txResp := tc.respType.(*pftypes.QueryPriceResponse)
err = val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), txResp)
s.Require().NoError(err)
s.Require().Equal(tc.expectedPrice, txResp.Price.Price)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would assert the response's pairId just to be pathological.

txResp := tc.respType.(*pftypes.QueryRawPricesResponse)
err = val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), txResp)
s.Require().NoError(err)
s.Require().Equal(tc.expectedPrice, txResp.RawPrices[0].Price)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would assert the other fields (pairID, oracle, expiry) also.

x/pricefeed/client/cli/cli_test.go Outdated Show resolved Hide resolved

for _, p := range txResp.Pairs {
found := false
for _, ep := range tc.expectedPairs {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could do s.Require().Contains(tc.expectedPairs, p) to make this easier to read.


for _, pp := range txResp.Prices {
found := false
for _, epp := range tc.expectedPricePairs {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same with s.Require().Contains().

@NibiruHeisenberg NibiruHeisenberg added x/pricefeed type: tests Unit and integration test additions and improvements labels Jun 14, 2022
@NibiruHeisenberg
Copy link
Contributor

In general, I would use s.Assert() over s.Require() for checking values since it doesn't error out at the first non-matching value, and s.Require() for checking that returned errors are nil.

x/pricefeed/client/cli/query.go Outdated Show resolved Hide resolved
wctx := sdk.WrapSDKContext(ctx)
params := types.Params{
Pairs: []types.Pair{
{Token1: "btc", Token0: "usd", Oracles: nil, Active: true},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(nit) we normally have the stablecoin as token1 and the crypto asset as token0.

AgentSmithMatrix and others added 2 commits June 14, 2022 12:23
Co-authored-by: Walter White <101130700+NibiruHeisenberg@users.noreply.github.com>
@AgentSmithMatrix
Copy link
Contributor

Looks good!

"github.com/cosmos/cosmos-sdk/crypto/hd"
sdk "github.com/cosmos/cosmos-sdk/types"

banktestutil "github.com/cosmos/cosmos-sdk/x/bank/client/testutil"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a rule of thumb with imports the convention is to use 3 blocks ordered by:

  • go standard imports
  • external imports
  • project imports

@AgentSmithMatrix AgentSmithMatrix linked an issue Jun 14, 2022 that may be closed by this pull request
@NibiruHeisenberg NibiruHeisenberg merged commit 5fca2c1 into master Jun 15, 2022
@NibiruHeisenberg NibiruHeisenberg deleted the jc/pricefeed-cli-tests branch June 15, 2022 14:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: tests Unit and integration test additions and improvements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

test(pricefeed): Pricefeed CLI tests
4 participants