@@ -12,9 +12,6 @@ import (
1212
1313 commonpb "github.com/code-payments/code-protobuf-api/generated/go/common/v1"
1414
15- "github.com/code-payments/code-server/pkg/currency"
16- timelock_token_v1 "github.com/code-payments/code-server/pkg/solana/timelock/v1"
17- "github.com/code-payments/code-server/pkg/testutil"
1815 "github.com/code-payments/code-server/pkg/code/common"
1916 code_data "github.com/code-payments/code-server/pkg/code/data"
2017 "github.com/code-payments/code-server/pkg/code/data/account"
@@ -23,6 +20,10 @@ import (
2320 "github.com/code-payments/code-server/pkg/code/data/intent"
2421 "github.com/code-payments/code-server/pkg/code/data/payment"
2522 "github.com/code-payments/code-server/pkg/code/data/transaction"
23+ "github.com/code-payments/code-server/pkg/currency"
24+ "github.com/code-payments/code-server/pkg/pointer"
25+ timelock_token_v1 "github.com/code-payments/code-server/pkg/solana/timelock/v1"
26+ "github.com/code-payments/code-server/pkg/testutil"
2627)
2728
2829func TestDefaultCalculationMethods_NewCodeAccount (t * testing.T ) {
@@ -45,7 +46,7 @@ func TestDefaultCalculationMethods_NewCodeAccount(t *testing.T) {
4546 require .NoError (t , err )
4647 assert .EqualValues (t , 0 , balance )
4748
48- balanceByAccount , err := DefaultBatchCalculationWithAccountRecords (env .ctx , env .data , accountRecords [commonpb .AccountType_PRIMARY ])
49+ balanceByAccount , err := DefaultBatchCalculationWithAccountRecords (env .ctx , env .data , accountRecords [commonpb .AccountType_PRIMARY ][ 0 ] )
4950 require .NoError (t , err )
5051 require .Len (t , balanceByAccount , 1 )
5152 assert .EqualValues (t , 0 , balanceByAccount [newTokenAccount .PublicKey ().ToBase58 ()])
@@ -91,7 +92,7 @@ func TestDefaultCalculationMethods_DepositFromExternalWallet(t *testing.T) {
9192 accountRecords , err := common .GetLatestTokenAccountRecordsForOwner (env .ctx , env .data , owner )
9293 require .NoError (t , err )
9394
94- balanceByAccount , err := DefaultBatchCalculationWithAccountRecords (env .ctx , env .data , accountRecords [commonpb .AccountType_PRIMARY ])
95+ balanceByAccount , err := DefaultBatchCalculationWithAccountRecords (env .ctx , env .data , accountRecords [commonpb .AccountType_PRIMARY ][ 0 ] )
9596 require .NoError (t , err )
9697 require .Len (t , balanceByAccount , 1 )
9798 assert .EqualValues (t , 11 , balanceByAccount [depositAccount .PublicKey ().ToBase58 ()])
@@ -197,7 +198,7 @@ func TestDefaultCalculationMethods_MultipleIntents(t *testing.T) {
197198 accountRecords4 , err := common .GetLatestTokenAccountRecordsForOwner (env .ctx , env .data , owner4 )
198199 require .NoError (t , err )
199200
200- balanceByAccount , err := DefaultBatchCalculationWithAccountRecords (env .ctx , env .data , accountRecords1 [commonpb .AccountType_PRIMARY ], accountRecords2 [commonpb .AccountType_PRIMARY ], accountRecords3 [commonpb .AccountType_PRIMARY ], accountRecords4 [commonpb .AccountType_PRIMARY ])
201+ balanceByAccount , err := DefaultBatchCalculationWithAccountRecords (env .ctx , env .data , accountRecords1 [commonpb .AccountType_PRIMARY ][ 0 ] , accountRecords2 [commonpb .AccountType_PRIMARY ][ 0 ] , accountRecords3 [commonpb .AccountType_PRIMARY ][ 0 ] , accountRecords4 [commonpb .AccountType_PRIMARY ][ 0 ])
201202 require .NoError (t , err )
202203 require .Len (t , balanceByAccount , 4 )
203204 assert .EqualValues (t , 11 , balanceByAccount [a1 .PublicKey ().ToBase58 ()])
@@ -264,7 +265,7 @@ func TestDefaultCalculationMethods_BackAndForth(t *testing.T) {
264265 accountRecords2 , err := common .GetLatestTokenAccountRecordsForOwner (env .ctx , env .data , owner2 )
265266 require .NoError (t , err )
266267
267- balanceByAccount , err := DefaultBatchCalculationWithAccountRecords (env .ctx , env .data , accountRecords1 [commonpb .AccountType_PRIMARY ], accountRecords2 [commonpb .AccountType_PRIMARY ])
268+ balanceByAccount , err := DefaultBatchCalculationWithAccountRecords (env .ctx , env .data , accountRecords1 [commonpb .AccountType_PRIMARY ][ 0 ] , accountRecords2 [commonpb .AccountType_PRIMARY ][ 0 ])
268269 require .NoError (t , err )
269270 require .Len (t , balanceByAccount , 2 )
270271 assert .EqualValues (t , 0 , balanceByAccount [a1 .PublicKey ().ToBase58 ()])
@@ -316,7 +317,7 @@ func TestDefaultCalculationMethods_SelfPayments(t *testing.T) {
316317 accountRecords , err := common .GetLatestTokenAccountRecordsForOwner (env .ctx , env .data , ownerAccount )
317318 require .NoError (t , err )
318319
319- balanceByAccount , err := DefaultBatchCalculationWithAccountRecords (env .ctx , env .data , accountRecords [commonpb .AccountType_PRIMARY ])
320+ balanceByAccount , err := DefaultBatchCalculationWithAccountRecords (env .ctx , env .data , accountRecords [commonpb .AccountType_PRIMARY ][ 0 ] )
320321 require .NoError (t , err )
321322 require .Len (t , balanceByAccount , 1 )
322323 assert .EqualValues (t , 1 , balanceByAccount [tokenAccount .PublicKey ().ToBase58 ()])
@@ -354,7 +355,7 @@ func TestDefaultCalculationMethods_NotManagedByCode(t *testing.T) {
354355 _ , err = DefaultCalculation (env .ctx , env .data , tokenAccount )
355356 assert .Equal (t , ErrNotManagedByCode , err )
356357
357- _ , err = DefaultBatchCalculationWithAccountRecords (env .ctx , env .data , accountRecords [commonpb .AccountType_PRIMARY ])
358+ _ , err = DefaultBatchCalculationWithAccountRecords (env .ctx , env .data , accountRecords [commonpb .AccountType_PRIMARY ][ 0 ] )
358359 assert .Equal (t , ErrNotManagedByCode , err )
359360
360361 _ , err = DefaultBatchCalculationWithTokenAccounts (env .ctx , env .data , tokenAccount )
@@ -419,7 +420,7 @@ func TestGetAggregatedBalances(t *testing.T) {
419420
420421 balance := uint64 (math .Pow10 (i ))
421422 expectedTotalBalance += balance
422- if accountType != commonpb .AccountType_PRIMARY {
423+ if accountType != commonpb .AccountType_PRIMARY && accountType != commonpb . AccountType_RELATIONSHIP {
423424 expectedPrivateBalance += balance
424425 }
425426
@@ -435,6 +436,9 @@ func TestGetAggregatedBalances(t *testing.T) {
435436 TokenAccount : timelockRecord .VaultAddress ,
436437 AccountType : accountType ,
437438 }
439+ if accountType == commonpb .AccountType_RELATIONSHIP {
440+ accountInfoRecord .RelationshipTo = pointer .String ("example.com" )
441+ }
438442 require .NoError (t , env .data .CreateAccountInfo (env .ctx , & accountInfoRecord ))
439443
440444 actionRecord := action.Record {
0 commit comments