-
Notifications
You must be signed in to change notification settings - Fork 608
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
Update record sanity check #2741
Changes from 8 commits
29539a1
7b87cd8
0cbfc04
b09e65f
dfc2307
cd78749
5e9e64b
a7b94af
17618aa
5c3e98a
f7fcdc3
c43885d
acf03e3
0409367
77502d9
fa28336
95713c2
24da39c
ad6bd30
71991e9
bc79f48
c6f1b8f
277d7a7
2f5103d
6574fa6
a00dbcf
d9f3a6a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -227,7 +227,8 @@ func (s *TestSuite) TestUpdateRecord() { | |
defaultTwoAssetCoins[1].Denom, defaultTwoAssetCoins[0].Denom, | ||
test.spotPriceResult1.Sp, test.spotPriceResult1.Err) | ||
|
||
newRecord := s.twapkeeper.UpdateRecord(s.Ctx, test.record) | ||
newRecord, err := s.twapkeeper.UpdateRecord(s.Ctx, test.record) | ||
s.Require().NoError(err) | ||
s.Equal(test.expRecord, newRecord) | ||
}) | ||
} | ||
|
@@ -1026,25 +1027,11 @@ func (s *TestSuite) TestUpdateRecords() { | |
}, | ||
}, | ||
|
||
expectedHistoricalRecords: []expectedResults{ | ||
// The original record at t. | ||
{ | ||
spotPriceA: baseRecord.P0LastSpotPrice, | ||
spotPriceB: baseRecord.P1LastSpotPrice, | ||
}, | ||
// The new record added. | ||
// TODO: it should not be possible to add a record between existing records. | ||
// https://github.com/osmosis-labs/osmosis/issues/2686 | ||
{ | ||
spotPriceA: sdk.OneDec(), | ||
spotPriceB: sdk.OneDec().Add(sdk.OneDec()), | ||
isMostRecent: true, | ||
}, | ||
// The original record at t + 1. | ||
{ | ||
spotPriceA: tPlus10sp5Record.P0LastSpotPrice, | ||
spotPriceB: tPlus10sp5Record.P1LastSpotPrice, | ||
}, | ||
expectError: types.InvalidRecordTimeError{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we also add a test case for having block height greater than the last record's time and checking the error? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes of course |
||
RecordBlockHeight: tPlus10sp5Record.Height, | ||
RecordTime: tPlus10sp5Record.Time, | ||
ActualBlockHeight: (baseRecord.Height + 1), | ||
ActualTime: baseRecord.Time.Add(time.Second * 5), | ||
}, | ||
}, | ||
// TODO: complete multi-asset pool tests: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,3 +62,14 @@ type InvalidRecordCountError struct { | |
func (e InvalidRecordCountError) Error() string { | ||
return fmt.Sprintf("The number of records do not match, expected: %d\n got: %d", e.Expected, e.Actual) | ||
} | ||
|
||
type InvalidRecordTimeError struct { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm wondering if we should change this to |
||
RecordBlockHeight int64 | ||
RecordTime time.Time | ||
ActualBlockHeight int64 | ||
ActualTime time.Time | ||
} | ||
|
||
func (e InvalidRecordTimeError) Error() string { | ||
return fmt.Sprintf("Can not update the record, the context time must be greater than record time. Record: block %d at %s\n Actual: block %d at %s\n", e.RecordBlockHeight, e.RecordTime, e.ActualBlockHeight, e.ActualTime) | ||
alexanderbez marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} |
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 is it not
>
but>=
? Can the record not have same height as blockheight by design?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.
Its a case when creating new pool. New twap records will be created and updated immediately. I limit this by adding the condition
ArithmeticTwapAccumulator
must be zero (init twap record). But I should split it upThere 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.
sweet, can we add this context as inline comment?