From 832f630bec0c7eafc001c9226acdb89e5ea100ee Mon Sep 17 00:00:00 2001 From: ze97286 Date: Mon, 13 May 2024 11:50:07 +0100 Subject: [PATCH] fix: fix type of notional position --- .../entities/time_weighted_notional_position.go | 8 ++++---- .../time_weighted_notional_position_test.go | 13 +++++++------ 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/datanode/entities/time_weighted_notional_position.go b/datanode/entities/time_weighted_notional_position.go index c4d0f398e2f..cb6be8f6a62 100644 --- a/datanode/entities/time_weighted_notional_position.go +++ b/datanode/entities/time_weighted_notional_position.go @@ -16,9 +16,9 @@ package entities import ( - "strconv" "time" + "code.vegaprotocol.io/vega/libs/num" v2 "code.vegaprotocol.io/vega/protos/data-node/api/v2" eventspb "code.vegaprotocol.io/vega/protos/vega/events/v1" ) @@ -28,12 +28,12 @@ type TimeWeightedNotionalPosition struct { AssetID AssetID PartyID PartyID GameID GameID - TimeWeightedNotionalPosition uint64 + TimeWeightedNotionalPosition num.Decimal VegaTime time.Time } func TimeWeightedNotionalPositionFromProto(event *eventspb.TimeWeightedNotionalPositionUpdated, vegaTime time.Time) (*TimeWeightedNotionalPosition, error) { - twNotionalPosition, err := strconv.ParseUint(event.TimeWeightedNotionalPosition, 10, 64) + twNotionalPosition, err := num.DecimalFromString(event.TimeWeightedNotionalPosition) if err != nil { return nil, err } @@ -53,7 +53,7 @@ func (tw *TimeWeightedNotionalPosition) ToProto() *v2.TimeWeightedNotionalPositi PartyId: tw.PartyID.String(), GameId: tw.GameID.String(), AtEpoch: tw.EpochSeq, - TimeWeightedNotionalPosition: strconv.FormatUint(tw.TimeWeightedNotionalPosition, 10), + TimeWeightedNotionalPosition: tw.TimeWeightedNotionalPosition.String(), LastUpdated: tw.VegaTime.UnixNano(), } } diff --git a/datanode/sqlstore/time_weighted_notional_position_test.go b/datanode/sqlstore/time_weighted_notional_position_test.go index 85d576c45fe..c0a4fd26460 100644 --- a/datanode/sqlstore/time_weighted_notional_position_test.go +++ b/datanode/sqlstore/time_weighted_notional_position_test.go @@ -21,6 +21,7 @@ import ( "code.vegaprotocol.io/vega/datanode/entities" "code.vegaprotocol.io/vega/datanode/sqlstore" + "code.vegaprotocol.io/vega/libs/num" "code.vegaprotocol.io/vega/libs/ptr" "github.com/georgysavva/scany/pgxscan" @@ -37,7 +38,7 @@ func TestTimeWeightedNotionalPosition_Upsert(t *testing.T) { PartyID: entities.PartyID(GenerateID()), GameID: entities.GameID(GenerateID()), EpochSeq: 1, - TimeWeightedNotionalPosition: 1000, + TimeWeightedNotionalPosition: num.DecimalFromInt64(1000), VegaTime: time.Now().Truncate(time.Microsecond), } err := tw.Upsert(ctx, want) @@ -57,12 +58,12 @@ func TestTimeWeightedNotionalPosition_Upsert(t *testing.T) { PartyID: entities.PartyID(GenerateID()), GameID: entities.GameID(GenerateID()), EpochSeq: 2, - TimeWeightedNotionalPosition: 1000, + TimeWeightedNotionalPosition: num.DecimalFromInt64(1000), VegaTime: time.Now().Truncate(time.Microsecond), } err := tw.Upsert(ctx, want) require.NoError(t, err) - want.TimeWeightedNotionalPosition = 2000 + want.TimeWeightedNotionalPosition = num.DecimalFromInt64(2000) err = tw.Upsert(ctx, want) require.NoError(t, err) var got entities.TimeWeightedNotionalPosition @@ -83,7 +84,7 @@ func TestTimeWeightedNotionalPosition_Get(t *testing.T) { PartyID: entities.PartyID(GenerateID()), GameID: entities.GameID(GenerateID()), EpochSeq: 1, - TimeWeightedNotionalPosition: 1000, + TimeWeightedNotionalPosition: num.DecimalFromInt64(1000), VegaTime: time.Now().Truncate(time.Microsecond), } err := tw.Upsert(ctx, want) @@ -100,13 +101,13 @@ func TestTimeWeightedNotionalPosition_Get(t *testing.T) { PartyID: entities.PartyID(GenerateID()), GameID: entities.GameID(GenerateID()), EpochSeq: 1, - TimeWeightedNotionalPosition: 1000, + TimeWeightedNotionalPosition: num.DecimalFromInt64(1000), VegaTime: time.Now().Truncate(time.Microsecond), } err := tw.Upsert(ctx, want) require.NoError(t, err) want.EpochSeq = 2 - want.TimeWeightedNotionalPosition = 2000 + want.TimeWeightedNotionalPosition = num.DecimalFromInt64(2000) want.VegaTime = want.VegaTime.Add(time.Second) err = tw.Upsert(ctx, want) require.NoError(t, err)