-
Notifications
You must be signed in to change notification settings - Fork 193
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
Conversation
…TWAP to be empty instead of defaulting to zero
There was a problem hiding this 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{} { |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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-"
PoolPrices
type, I made the Dec fields nullable so that they would no longer be equivalent to theZeroDec
. For more info on this, see issue test(x/perp): Include checks for the queryResp.MarginRatioIndex in 'TestOpenPositionsAndCloseCmd'. #809Solution
This query now returns the expected result when index price is not active.
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 tosdk.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.Using the nil, blank Dec seems to solve the problem... That is, until you
make localnet
and try the query at the CLI.Not fixed.