Skip to content

Commit 8880276

Browse files
authored
Merge pull request #355 from urnetwork/balance-code-updates
Balance code updates
2 parents 0c682e3 + b2773a6 commit 8880276

7 files changed

Lines changed: 116 additions & 16 deletions

connect/connect_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -773,10 +773,12 @@ func testConnect(
773773

774774
initialTransferBalance := ByteCount(1024) * ByteCount(1024) * ByteCount(1024) * ByteCount(1024)
775775

776+
subscriptionYearDuration := 365 * 24 * time.Hour
777+
776778
balanceCodeA, err := model.CreateBalanceCode(
777779
ctx,
778780
initialTransferBalance,
779-
24*time.Hour,
781+
subscriptionYearDuration,
780782
0,
781783
"test-1",
782784
"",
@@ -796,7 +798,7 @@ func testConnect(
796798
balanceCodeB, err := model.CreateBalanceCode(
797799
ctx,
798800
initialTransferBalance,
799-
24*time.Hour,
801+
subscriptionYearDuration,
800802
0,
801803
"test-2",
802804
"",

controller/account_payment_controller_test.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,17 @@ func TestSubscriptionSendPayment(t *testing.T) {
5959
// we don't want to send out messages in our tests
6060
SetMessageSender(mockAWSMessageSender)
6161

62-
balanceCode, err := model.CreateBalanceCode(ctx, netTransferByteCount, 24*time.Hour, netRevenue, "", "", "")
62+
subscriptionYearDuration := 365 * 24 * time.Hour
63+
64+
balanceCode, err := model.CreateBalanceCode(
65+
ctx,
66+
netTransferByteCount,
67+
subscriptionYearDuration,
68+
netRevenue,
69+
"",
70+
"",
71+
"",
72+
)
6373
assert.Equal(t, err, nil)
6474
model.RedeemBalanceCode(&model.RedeemBalanceCodeArgs{
6575
Secret: balanceCode.Secret,

model/account_payment_model_test.go

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,17 @@ func TestCancelAccountPayment(t *testing.T) {
3636
ClientId: &destinationId,
3737
})
3838

39-
balanceCode, err := CreateBalanceCode(ctx, netTransferByteCount, 24*time.Hour, netRevenue, "", "", "")
39+
subscriptionYearDuration := 365 * 24 * time.Hour
40+
41+
balanceCode, err := CreateBalanceCode(
42+
ctx,
43+
netTransferByteCount,
44+
subscriptionYearDuration,
45+
netRevenue,
46+
"",
47+
"",
48+
"",
49+
)
4050
assert.Equal(t, err, nil)
4151
RedeemBalanceCode(&RedeemBalanceCodeArgs{
4252
Secret: balanceCode.Secret,
@@ -139,7 +149,17 @@ func TestGetNetworkProvideStats(t *testing.T) {
139149
// fund the source network
140150
netTransferByteCount := ByteCount(1024 * 1024)
141151
netRevenue := UsdToNanoCents(10.00)
142-
balanceCode, err := CreateBalanceCode(ctx, netTransferByteCount, 24*time.Hour, netRevenue, "", "", "")
152+
subscriptionYearDuration := 365 * 24 * time.Hour
153+
154+
balanceCode, err := CreateBalanceCode(
155+
ctx,
156+
netTransferByteCount,
157+
subscriptionYearDuration,
158+
netRevenue,
159+
"",
160+
"",
161+
"",
162+
)
143163
assert.Equal(t, err, nil)
144164
RedeemBalanceCode(&RedeemBalanceCodeArgs{
145165
Secret: balanceCode.Secret,
@@ -264,7 +284,17 @@ func TestPaymentPlanSubsidy(t *testing.T) {
264284
assert.Equal(t, getAccountBalanceResult.Balance.PaidByteCount, ByteCount(0))
265285
assert.Equal(t, getAccountBalanceResult.Balance.PaidNetRevenue, NanoCents(0))
266286

267-
balanceCode, err := CreateBalanceCode(ctx, netTransferByteCount, 24*time.Hour, netRevenue, "", "", "")
287+
subscriptionYearDuration := 365 * 24 * time.Hour
288+
289+
balanceCode, err := CreateBalanceCode(
290+
ctx,
291+
netTransferByteCount,
292+
subscriptionYearDuration,
293+
netRevenue,
294+
"",
295+
"",
296+
"",
297+
)
268298
assert.Equal(t, err, nil)
269299
RedeemBalanceCode(&RedeemBalanceCodeArgs{
270300
Secret: balanceCode.Secret,

model/account_point_model_test.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,16 @@ func TestAccountPointsPerPayout(t *testing.T) {
192192
/**
193193
* Create balance for network C
194194
*/
195-
balanceCode, err := CreateBalanceCode(ctx, 2*netTransferByteCount, 24*time.Hour, 2*netRevenue, "", "", "")
195+
subscriptionYearDuration := 365 * 24 * time.Hour
196+
balanceCode, err := CreateBalanceCode(
197+
ctx,
198+
2*netTransferByteCount,
199+
subscriptionYearDuration,
200+
2*netRevenue,
201+
"",
202+
"",
203+
"",
204+
)
196205
assert.Equal(t, err, nil)
197206
RedeemBalanceCode(&RedeemBalanceCodeArgs{
198207
Secret: balanceCode.Secret,

model/leaderboard_model_test.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,16 @@ func TestLeaderboard(t *testing.T) {
6262
/**
6363
* Create balance for network C
6464
*/
65-
balanceCode, err := CreateBalanceCode(ctx, 2*netTransferByteCount, 24*time.Hour, 2*netRevenue, "", "", "")
65+
subscriptionYearDuration := 365 * 24 * time.Hour
66+
balanceCode, err := CreateBalanceCode(
67+
ctx,
68+
2*netTransferByteCount,
69+
subscriptionYearDuration,
70+
2*netRevenue,
71+
"",
72+
"",
73+
"",
74+
)
6675
assert.Equal(t, err, nil)
6776
RedeemBalanceCode(&RedeemBalanceCodeArgs{
6877
Secret: balanceCode.Secret,

model/subscription_model.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -437,19 +437,27 @@ func RedeemBalanceCode(
437437

438438
balanceId := server.NewId()
439439

440+
now := server.NowUtc()
441+
duration := balanceCode.EndTime.Sub(balanceCode.StartTime)
442+
endTime := now.Add(duration)
443+
440444
server.RaisePgResult(tx.Exec(
441445
session.Ctx,
442446
`
443447
UPDATE transfer_balance_code
444448
SET
445449
redeem_time = $2,
446-
redeem_balance_id = $3
450+
redeem_balance_id = $3,
451+
start_time = $4,
452+
end_time = $5
447453
WHERE
448454
balance_code_id = $1
449455
`,
450456
balanceCode.BalanceCodeId,
451-
server.NowUtc(),
457+
now,
452458
balanceId,
459+
now,
460+
endTime,
453461
))
454462

455463
server.RaisePgResult(tx.Exec(
@@ -468,8 +476,8 @@ func RedeemBalanceCode(
468476
`,
469477
balanceId,
470478
session.ByJwt.NetworkId,
471-
balanceCode.StartTime,
472-
balanceCode.EndTime,
479+
now,
480+
endTime,
473481
balanceCode.BalanceByteCount,
474482
balanceCode.NetRevenue,
475483
))

model/subscription_model_test.go

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,17 @@ func TestEscrow(t *testing.T) {
103103
assert.Equal(t, getAccountBalanceResult.Balance.PaidByteCount, ByteCount(0))
104104
assert.Equal(t, getAccountBalanceResult.Balance.PaidNetRevenue, NanoCents(0))
105105

106-
balanceCode, err := CreateBalanceCode(ctx, netTransferByteCount, 24*time.Hour, netRevenue, "", "", "")
106+
subscriptionYearDuration := 365 * 24 * time.Hour
107+
108+
balanceCode, err := CreateBalanceCode(
109+
ctx,
110+
netTransferByteCount,
111+
subscriptionYearDuration,
112+
netRevenue,
113+
"",
114+
"",
115+
"",
116+
)
107117
assert.Equal(t, err, nil)
108118
RedeemBalanceCode(&RedeemBalanceCodeArgs{
109119
Secret: balanceCode.Secret,
@@ -340,7 +350,17 @@ func TestCompanionEscrowAndCheckpoint(t *testing.T) {
340350
assert.Equal(t, getAccountBalanceResult.Balance.PaidByteCount, ByteCount(0))
341351
assert.Equal(t, getAccountBalanceResult.Balance.PaidNetRevenue, NanoCents(0))
342352

343-
balanceCode, err := CreateBalanceCode(ctx, 2*netTransferByteCount, 24*time.Hour, 2*netRevenue, "", "", "")
353+
subscriptionYearDuration := 365 * 24 * time.Hour
354+
355+
balanceCode, err := CreateBalanceCode(
356+
ctx,
357+
2*netTransferByteCount,
358+
subscriptionYearDuration,
359+
2*netRevenue,
360+
"",
361+
"",
362+
"",
363+
)
344364
assert.Equal(t, err, nil)
345365
RedeemBalanceCode(&RedeemBalanceCodeArgs{
346366
Secret: balanceCode.Secret,
@@ -600,10 +620,12 @@ func TestBalanceCode(t *testing.T) {
600620
assert.Equal(t, err, nil)
601621
assert.NotEqual(t, checkResult0.Error, nil)
602622

623+
subscriptionYearDuration := 365 * 24 * time.Hour
624+
603625
balanceCode, err := CreateBalanceCode(
604626
ctx,
605627
1024,
606-
24*time.Hour,
628+
subscriptionYearDuration,
607629
100,
608630
"test-purchase-1",
609631
"rest-purchase-1-receipt",
@@ -1276,7 +1298,17 @@ func TestGetOpenTransferByteCount(t *testing.T) {
12761298
ClientId: &sourceId,
12771299
})
12781300

1279-
balanceCode, err := CreateBalanceCode(ctx, 2*netTransferByteCount, 24*time.Hour, 2*netRevenue, "", "", "")
1301+
subscriptionYearDuration := 365 * 24 * time.Hour
1302+
1303+
balanceCode, err := CreateBalanceCode(
1304+
ctx,
1305+
2*netTransferByteCount,
1306+
subscriptionYearDuration,
1307+
2*netRevenue,
1308+
"",
1309+
"",
1310+
"",
1311+
)
12801312
assert.Equal(t, err, nil)
12811313
RedeemBalanceCode(&RedeemBalanceCodeArgs{
12821314
Secret: balanceCode.Secret,

0 commit comments

Comments
 (0)