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

test(vpool): Lots of testing for 'nibid q vpool all-pools'. #830

Merged
merged 9 commits into from
Aug 19, 2022

Conversation

Unique-Divine
Copy link
Member

@Unique-Divine Unique-Divine commented Aug 16, 2022

  • feat,test(vpool): add pair field to PoolPrices allow index price and TWAP to be empty instead of defaulting to zero
  • tests more fields in the query server
  • test: GetPoolPrices has several test scenarios and full coverage.
  • In the PoolPrices type, I made the Dec fields nullable so that they would no longer be equivalent to the ZeroDec. For more info on this, see issue test(x/perp): Include checks for the queryResp.MarginRatioIndex in 'TestOpenPositionsAndCloseCmd'. #809
  • test: add marginRatioIndex check to the perp cli_test

Solution

nibid q vpool all-pools | jq .

This query now returns the expected result when index price is not active.

// ... just showing prices field 
"prices": [
  {
    "pair": "ubtc:unusd",
    "mark_price": "20000.000000000000000000",
    "index_price": "",
    "twap_mark": "20000.000000000000000000",
    "swap_invariant": "50000000000000000000000000",
    "block_number": "15"
  },
  {
    "pair": "ueth:unusd",
    "mark_price": "1500.001500001500001500",
    "index_price": "",
    "twap_mark": "1500.001500001500001500",
    "swap_invariant": "666666000000000000000000000",
    "block_number": "15"
  }
]

wk34-n480-WindowsTerminal_JejM

Context / Background - Attempt at creating this behavior using pointer types

This section shows what the old behavior for this query looked like. The issue is that we see a zero value where we expect an empty return.

Commit 51232e8 examples a passing code state where I tried setting gogo.proto nullable to true to see if nil values for an *sdk.Dec{} would get the job done. However, the type casting to sdk.Dec forces the default value to zero as can be see in this screenshot of the query's output at the CLI.

Here's the output from printing the %v and %s forms of the formatted string.

wk34-n478-WindowsTerminal_S9Ia

Using the nil, blank Dec seems to solve the problem... That is, until you make localnet and try the query at the CLI.

wk34-n477-Discord_d0Xv

Not fixed.

@Unique-Divine Unique-Divine requested a review from a team as a code owner August 16, 2022 07:31
@Unique-Divine Unique-Divine marked this pull request as draft August 16, 2022 17:50
@Unique-Divine Unique-Divine marked this pull request as ready for review August 19, 2022 05:17
@Unique-Divine Unique-Divine enabled auto-merge (squash) August 19, 2022 05:19
Copy link
Collaborator

@testinginprod testinginprod left a comment

Choose a reason for hiding this comment

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

LGTM. Left some nits.

@@ -200,3 +200,19 @@ func (pairs AssetPairs) MarshalJSON() ([]byte, error) {
}
return json.Marshal(assetPairsJSON(pairs))
}

func ToSdkPointer(num interface{}) interface{} {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I can't see where this function is being used in the current PR. Plus I think the name is a little misleading.

gomock "github.com/golang/mock/gomock"
)

/* AppendCtxWithMockLogger sets the logger for an input context as a mock logger
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we stick with // comments as they're more idiomatic and common in go

@@ -120,22 +120,44 @@ func (k Keeper) GetAllPools(ctx sdk.Context) []*types.Pool {
}

// GetPoolPrices returns the mark price, twap (mark) price, and index price for a vpool.
func (k Keeper) GetPoolPrices(ctx sdk.Context, pool types.Pool) types.PoolPrices {
// An error is returned if
Copy link
Collaborator

Choose a reason for hiding this comment

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

forgot to finish documentation?

ctx sdk.Context, pool types.Pool,
) (prices types.PoolPrices, err error) {
// Validation - guarantees no panics in GetUnderlyingPrice or GetCurrentTWAP
if err := pool.Pair.Validate(); err != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this is a proof that the current design of AssetPair is not ideal. Ref: #799

@@ -105,16 +112,10 @@ message PoolPrices {
];

// IndexPrice is the price of the "underlying" for the perp
string index_price = 11 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why the removal of the custom type?

k.codec.MustUnmarshal(bz, &price)
if price.Price.IsZero() {
return types.CurrentTWAP{}, types.ErrNoValidPrice
// spotPriceAsTwap returns a CurrentTWAP as defined by the instantaneous spot price.
Copy link
Collaborator

Choose a reason for hiding this comment

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

comment should be update to match function name.

regarding the TODO, maybe opening an issue so we don't lose track of this.

@@ -47,6 +47,7 @@ func GetSnapshotKey(pair common.AssetPair, counter uint64) []byte {
}

// CurrentTWAPKey returns the prefix for the current TWAP price
func CurrentTWAPKey(twapPairID string) []byte {
func CurrentTWAPKey(pair common.AssetPair) []byte {
twapPairID := "twap-" + pair.String()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do we prepend "twap-"

@Unique-Divine Unique-Divine merged commit fb1cb6b into master Aug 19, 2022
@Unique-Divine Unique-Divine deleted the ud/809-vpool-query-resp-improvements branch August 19, 2022 08:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants