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

fix(x/twap): geometric twap genesis validation #4262

Merged
merged 1 commit into from
Feb 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions x/twap/types/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ func (t TwapRecord) validate() error {
return fmt.Errorf("twap record p1 accumulator cannot be negative, was (%s)", t.P1ArithmeticTwapAccumulator)
}

if t.GeometricTwapAccumulator.IsNil() || t.GeometricTwapAccumulator.IsNegative() {
return fmt.Errorf("twap record geometric accumulator cannot be negative, was (%s)", t.GeometricTwapAccumulator)
if t.GeometricTwapAccumulator.IsNil() {
return fmt.Errorf("twap record geometric accumulator cannot be nil, was (%s)", t.GeometricTwapAccumulator)
}
return nil
}
12 changes: 12 additions & 0 deletions x/twap/types/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ func TestGenesisState_Validate(t *testing.T) {
})
)

withGeometricAcc := func(record TwapRecord, geometricAcc sdk.Dec) TwapRecord {
record.GeometricTwapAccumulator = geometricAcc
return record
}

testCases := map[string]struct {
twapGenesis *GenesisState

Expand All @@ -90,6 +95,13 @@ func TestGenesisState_Validate(t *testing.T) {
"valid empty records": {
twapGenesis: NewGenesisState(basicParams, []TwapRecord{}),
},
"valid geometric twap acc is negative": {
twapGenesis: NewGenesisState(basicParams, []TwapRecord{withGeometricAcc(baseRecord, sdk.NewDec(-1))}),
},
"invalid geometric twap acc is nil": {
twapGenesis: NewGenesisState(basicParams, []TwapRecord{withGeometricAcc(baseRecord, sdk.Dec{})}),
expectedErr: true,
},
"invalid genesis - pool ID doesn't exist": {
twapGenesis: NewGenesisState(
NewParams("week", 48*time.Hour),
Expand Down