diff --git a/x/metadata/client/cli/tx.go b/x/metadata/client/cli/tx.go index aa7f50cf3..1c5357d5b 100644 --- a/x/metadata/client/cli/tx.go +++ b/x/metadata/client/cli/tx.go @@ -1320,7 +1320,7 @@ func ParseNetAssetValueString(netAssetValuesString string) ([]types.NetAssetValu } if len(parts) == 2 { volume, err := strconv.ParseUint(parts[1], 10, 64) - if err != nil { + if err != nil || volume < 1 { return []types.NetAssetValue{}, fmt.Errorf("invalid volume : %s", parts[1]) } netAssetValues[i] = types.NewNetAssetValue(coin, volume) diff --git a/x/metadata/keeper/scope.go b/x/metadata/keeper/scope.go index c2c017db9..b7220adc3 100644 --- a/x/metadata/keeper/scope.go +++ b/x/metadata/keeper/scope.go @@ -701,7 +701,12 @@ func (k Keeper) SetNetAssetValue(ctx sdk.Context, scopeID types.MetadataAddress, return err } - setNetAssetValueEvent := types.NewEventSetNetAssetValue(scopeID, netAssetValue.Price, source) + // Since this field was added we need to ensure the default value matches the previous behavior of always presuming one is used. + if netAssetValue.Volume < 1 { + netAssetValue.Volume = 1 + } + + setNetAssetValueEvent := types.NewEventSetNetAssetValue(scopeID, netAssetValue.Price, netAssetValue.Volume, source) if err := ctx.EventManager().EmitTypedEvent(setNetAssetValueEvent); err != nil { return err } @@ -757,7 +762,7 @@ func (k Keeper) SetNetAssetValueWithBlockHeight(ctx sdk.Context, scopeID types.M return err } - setNetAssetValueEvent := types.NewEventSetNetAssetValue(scopeID, netAssetValue.Price, source) + setNetAssetValueEvent := types.NewEventSetNetAssetValue(scopeID, netAssetValue.Price, 1, source) if err := ctx.EventManager().EmitTypedEvent(setNetAssetValueEvent); err != nil { return err } diff --git a/x/metadata/keeper/scope_test.go b/x/metadata/keeper/scope_test.go index ccb03b0d9..2ed635bc2 100644 --- a/x/metadata/keeper/scope_test.go +++ b/x/metadata/keeper/scope_test.go @@ -2550,7 +2550,7 @@ func (s *ScopeKeeperTestSuite) TestSetNetAssetValue() { var expErrs []string var expEvents sdk.Events if len(tc.expErr) == 0 { - event := types.NewEventSetNetAssetValue(scopeID, tc.netAssetValue.Price, "test") + event := types.NewEventSetNetAssetValue(scopeID, tc.netAssetValue.Price, 1, "test") eventU, err := sdk.TypedEventToEvent(event) s.Require().NoError(err, "TypedEventToEvent(NewEventSetNetAssetValue)") expEvents = sdk.Events{eventU} @@ -2588,6 +2588,7 @@ func (s *ScopeKeeperTestSuite) TestRemoveNetAssetValues() { Denom: "usd", Amount: sdkmath.NewInt(1000), }, + Volume: 1, }, expErr: "", }, @@ -2605,7 +2606,7 @@ func (s *ScopeKeeperTestSuite) TestRemoveNetAssetValues() { }) s.Require().NoError(err, "IterateNetAssetValues err") s.Require().Len(netAssetValues, 1, "Should have added a NAV") - s.Require().Equal(tc.netAssetValue, netAssetValues[0], "Should have added the test case nave.") + s.Require().Equal(tc.netAssetValue, netAssetValues[0], "Should have added the test case nav.") s.app.MetadataKeeper.RemoveNetAssetValues(ctx, tc.scopeID) netAssetValues = []types.NetAssetValue{} err = s.app.MetadataKeeper.IterateNetAssetValues(ctx, tc.scopeID, func(state types.NetAssetValue) (stop bool) { diff --git a/x/metadata/types/events.go b/x/metadata/types/events.go index 85373f4a4..885864dc4 100644 --- a/x/metadata/types/events.go +++ b/x/metadata/types/events.go @@ -1,6 +1,8 @@ package types import ( + "strconv" + "github.com/hashicorp/go-metrics" "github.com/cosmos/cosmos-sdk/telemetry" @@ -277,10 +279,11 @@ func NewEventOSLocatorDeleted(owner string) *EventOSLocatorDeleted { } // NewEventSetNetAssetValue returns a new instance of EventSetNetAssetValue -func NewEventSetNetAssetValue(scopeID MetadataAddress, price sdk.Coin, source string) *EventSetNetAssetValue { +func NewEventSetNetAssetValue(scopeID MetadataAddress, price sdk.Coin, volume uint64, source string) *EventSetNetAssetValue { return &EventSetNetAssetValue{ ScopeId: scopeID.String(), Price: price.String(), Source: source, + Volume: strconv.FormatUint(volume, 10), } }