Skip to content

Commit

Permalink
fix: fix type of notional position
Browse files Browse the repository at this point in the history
  • Loading branch information
ze97286 committed May 13, 2024
1 parent b341aea commit 832f630
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
8 changes: 4 additions & 4 deletions datanode/entities/time_weighted_notional_position.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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
}
Expand All @@ -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(),
}
}
13 changes: 7 additions & 6 deletions datanode/sqlstore/time_weighted_notional_position_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 832f630

Please sign in to comment.