diff --git a/x/twap/types/genesis.go b/x/twap/types/genesis.go index fdd273bcd7b..67a892bd9a9 100644 --- a/x/twap/types/genesis.go +++ b/x/twap/types/genesis.go @@ -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 } diff --git a/x/twap/types/genesis_test.go b/x/twap/types/genesis_test.go index bc65efe03ad..29e300331f6 100644 --- a/x/twap/types/genesis_test.go +++ b/x/twap/types/genesis_test.go @@ -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 @@ -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),