Skip to content

Commit c0c3c2d

Browse files
committed
fix: fix conversion to be from unit USD
- updated the pricing policy and test
1 parent 77c0f3c commit c0c3c2d

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

grid-client/calculator/calculate.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@ func (c *Calculator) CalculateCost(cru, mru, hru, sru int64, publicIP, certified
5151
if certified {
5252
certifiedFactor = 1.25
5353
}
54-
// cost per month in mUSD
54+
// cost per month in unit-USD
5555
costPerMonth := (cu*float64(pricingPolicy.CU.Value) + su*float64(pricingPolicy.SU.Value) + ipv4*float64(pricingPolicy.IPU.Value)) * certifiedFactor * 24 * 30
5656
// convert to USD
57-
return costPerMonth / mUSDToUSD, nil
57+
return costPerMonth / UnitFactor, nil
5858
}
5959

6060
// CalculatePricesAfterDiscount calculates the prices after discount

grid-client/calculator/calculate_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,19 @@ func TestCalculator(t *testing.T) {
2626
sub.EXPECT().GetPricingPolicy(1).Return(substrate.PricingPolicy{
2727
ID: 1,
2828
SU: substrate.Policy{
29-
Value: 2,
29+
Value: 50000,
3030
},
3131
CU: substrate.Policy{
32-
Value: 2,
32+
Value: 100000,
3333
},
3434
IPU: substrate.Policy{
35-
Value: 2,
35+
Value: 40000,
3636
},
3737
}, nil).AnyTimes()
3838

3939
cost, err := calculator.CalculateCost(8, 32, 0, 50, true, true)
4040
assert.NoError(t, err)
41-
assert.Equal(t, cost, 16.65)
41+
assert.Equal(t, 76.725, cost)
4242

4343
sub.EXPECT().GetBalance(identity).Return(substrate.Balance{
4444
Free: types.U128{

0 commit comments

Comments
 (0)