From 487ad84b234c6f092867cfa442cfaa3e6a3a1603 Mon Sep 17 00:00:00 2001 From: Qweder93 Date: Wed, 10 Mar 2021 19:20:55 +0200 Subject: [PATCH] storagenode:consoleAPI flacky tests for estimatedPayout fixed joinedAt date now is 2 months before time.Now which should fix calculations on early dates. Change-Id: I6250ec2463c2dd609e811b74d908a02a3e64f19a --- storagenode/console/consoleapi/storagenode_test.go | 10 +++------- .../payouts/estimatedpayouts/estimatedpayouts.go | 2 +- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/storagenode/console/consoleapi/storagenode_test.go b/storagenode/console/consoleapi/storagenode_test.go index 12b2f40b3..c1895bc7b 100644 --- a/storagenode/console/consoleapi/storagenode_test.go +++ b/storagenode/console/consoleapi/storagenode_test.go @@ -18,7 +18,6 @@ import ( "storj.io/common/pb" "storj.io/common/storj" "storj.io/common/testcontext" - "storj.io/storj/private/date" "storj.io/storj/private/testplanet" "storj.io/storj/satellite" "storj.io/storj/storagenode/payouts/estimatedpayouts" @@ -96,12 +95,9 @@ func TestStorageNodeApi(t *testing.T) { }) require.NoError(t, err) - now2 := time.Now().UTC() - daysPerMonth := date.UTCEndOfMonth(now2).Day() - err = reputationdb.Store(ctx, reputation.Stats{ SatelliteID: satellite.ID(), - JoinedAt: now.AddDate(0, 0, -daysPerMonth+3), + JoinedAt: now.AddDate(0, -2, 0), }) require.NoError(t, err) @@ -134,8 +130,8 @@ func TestStorageNodeApi(t *testing.T) { require.NoError(t, err) // round CurrentMonthExpectations to 3 decimal places to resolve precision issues - bodyPayout.CurrentMonthExpectations = math.Floor(bodyPayout.CurrentMonthExpectations*1000) / 1000 - expectedPayout.CurrentMonthExpectations = math.Floor(expectedPayout.CurrentMonthExpectations*1000) / 1000 + bodyPayout.CurrentMonthExpectations = math.Round(bodyPayout.CurrentMonthExpectations*100) / 100 + expectedPayout.CurrentMonthExpectations = math.Round(expectedPayout.CurrentMonthExpectations*100) / 100 require.EqualValues(t, expectedPayout, bodyPayout) }) diff --git a/storagenode/payouts/estimatedpayouts/estimatedpayouts.go b/storagenode/payouts/estimatedpayouts/estimatedpayouts.go index d972bce2c..f312febfc 100644 --- a/storagenode/payouts/estimatedpayouts/estimatedpayouts.go +++ b/storagenode/payouts/estimatedpayouts/estimatedpayouts.go @@ -97,7 +97,7 @@ func (estimatedPayout *EstimatedPayout) Set(current, previous PayoutMonthly, now return } - estimatedPayout.CurrentMonthExpectations += estimatedPayout.CurrentMonth.Payout / daysSinceJoined * daysPerMonth + estimatedPayout.CurrentMonthExpectations += estimatedPayout.CurrentMonth.Payout / math.Round(daysSinceJoined) * daysPerMonth } // Add adds estimate into the receiver.