@@ -363,26 +363,16 @@ func TestGetTokenAccountInfos_RemoteSendGiftCard_HappyPath(t *testing.T) {
363363 expectedClaimState : accountpb .TokenAccountInfo_CLAIM_STATE_CLAIMED ,
364364 },
365365 } {
366- ownerAccount := testutil .NewRandomAccount (t )
367- timelockAccounts , err := ownerAccount .GetTimelockAccounts (common .CodeVmAccount , common .CoreMintAccount )
368- require .NoError (t , err )
366+ giftCardIssuerOwnerAccount := testutil .NewRandomAccount (t )
367+ giftCardOwnerAccount := testutil .NewRandomAccount (t )
369368
370- req := & accountpb.GetTokenAccountInfosRequest {
371- Owner : ownerAccount .ToProto (),
372- }
373- reqBytes , err := proto .Marshal (req )
374- require .NoError (t , err )
375- req .Signature = & commonpb.Signature {
376- Value : ed25519 .Sign (ownerAccount .PrivateKey ().ToBytes (), reqBytes ),
377- }
378-
379- accountRecords := setupAccountRecords (t , env , ownerAccount , ownerAccount , 0 , commonpb .AccountType_REMOTE_SEND_GIFT_CARD )
369+ accountRecords := setupAccountRecords (t , env , giftCardOwnerAccount , giftCardOwnerAccount , 0 , commonpb .AccountType_REMOTE_SEND_GIFT_CARD )
380370
381371 giftCardIssuedIntentRecord := & intent.Record {
382372 IntentId : testutil .NewRandomAccount (t ).PublicKey ().ToBase58 (),
383373 IntentType : intent .SendPublicPayment ,
384374
385- InitiatorOwnerAccount : testutil . NewRandomAccount ( t ). PrivateKey ().ToBase58 (),
375+ InitiatorOwnerAccount : giftCardIssuerOwnerAccount . PublicKey ().ToBase58 (),
386376
387377 SendPublicPaymentMetadata : & intent.SendPublicPaymentMetadata {
388378 DestinationTokenAccount : accountRecords .General .TokenAccount ,
@@ -444,43 +434,73 @@ func TestGetTokenAccountInfos_RemoteSendGiftCard_HappyPath(t *testing.T) {
444434 accountRecords .Timelock .Block += 1
445435 require .NoError (t , env .data .SaveTimelock (env .ctx , accountRecords .Timelock ))
446436
447- resp , err := env .client .GetTokenAccountInfos (env .ctx , req )
448- require .NoError (t , err )
449- assert .Equal (t , accountpb .GetTokenAccountInfosResponse_OK , resp .Result )
450- assert .Len (t , resp .TokenAccountInfos , 1 )
437+ for _ , requestingOwnerAccount := range []* common.Account {
438+ nil ,
439+ testutil .NewRandomAccount (t ),
440+ giftCardIssuerOwnerAccount ,
441+ } {
442+ timelockAccounts , err := giftCardOwnerAccount .GetTimelockAccounts (common .CodeVmAccount , common .CoreMintAccount )
443+ require .NoError (t , err )
451444
452- accountInfo , ok := resp .TokenAccountInfos [timelockAccounts .Vault .PublicKey ().ToBase58 ()]
453- require .True (t , ok )
445+ req := & accountpb.GetTokenAccountInfosRequest {
446+ Owner : giftCardOwnerAccount .ToProto (),
447+ }
448+ if requestingOwnerAccount != nil {
449+ req .RequestingOwner = requestingOwnerAccount .ToProto ()
450+ }
451+ reqBytes , err := proto .Marshal (req )
452+ require .NoError (t , err )
453+ sig1 := & commonpb.Signature {
454+ Value : ed25519 .Sign (giftCardOwnerAccount .PrivateKey ().ToBytes (), reqBytes ),
455+ }
456+ if requestingOwnerAccount != nil {
457+ sig2 := & commonpb.Signature {
458+ Value : ed25519 .Sign (requestingOwnerAccount .PrivateKey ().ToBytes (), reqBytes ),
459+ }
460+ req .RequestingOwnerSignature = sig2
461+ }
462+ req .Signature = sig1
454463
455- assert .Equal (t , commonpb .AccountType_REMOTE_SEND_GIFT_CARD , accountInfo .AccountType )
456- assert .Equal (t , ownerAccount .PublicKey ().ToBytes (), accountInfo .Owner .Value )
457- assert .Equal (t , ownerAccount .PublicKey ().ToBytes (), accountInfo .Authority .Value )
458- assert .Equal (t , timelockAccounts .Vault .PublicKey ().ToBytes (), accountInfo .Address .Value )
459- assert .Equal (t , common .CoreMintAccount .PublicKey ().ToBytes (), accountInfo .Mint .Value )
460- assert .EqualValues (t , 0 , accountInfo .Index )
464+ resp , err := env .client .GetTokenAccountInfos (env .ctx , req )
465+ require .NoError (t , err )
466+ assert .Equal (t , accountpb .GetTokenAccountInfosResponse_OK , resp .Result )
467+ assert .Len (t , resp .TokenAccountInfos , 1 )
461468
462- assert .Equal (t , tc .expectedBalanceSource , accountInfo .BalanceSource )
463- if tc .simulateClaimInCode || tc .simulateAutoReturnInCode || tc .expectedClaimState == accountpb .TokenAccountInfo_CLAIM_STATE_CLAIMED || tc .expectedClaimState == accountpb .TokenAccountInfo_CLAIM_STATE_EXPIRED {
464- assert .EqualValues (t , 0 , accountInfo .Balance )
465- } else if tc .expectedBalanceSource == accountpb .TokenAccountInfo_BALANCE_SOURCE_CACHE {
466- assert .EqualValues (t , tc .balance , accountInfo .Balance )
467- } else {
468- assert .EqualValues (t , 0 , accountInfo .Balance )
469- }
469+ accountInfo , ok := resp .TokenAccountInfos [timelockAccounts .Vault .PublicKey ().ToBase58 ()]
470+ require .True (t , ok )
470471
471- assert .Equal (t , tc .expectedManagementState , accountInfo .ManagementState )
472- assert .Equal (t , tc .expectedBlockchainState , accountInfo .BlockchainState )
473- assert .Equal (t , tc .expectedClaimState , accountInfo .ClaimState )
472+ assert .Equal (t , commonpb .AccountType_REMOTE_SEND_GIFT_CARD , accountInfo .AccountType )
473+ assert .Equal (t , giftCardOwnerAccount .PublicKey ().ToBytes (), accountInfo .Owner .Value )
474+ assert .Equal (t , giftCardOwnerAccount .PublicKey ().ToBytes (), accountInfo .Authority .Value )
475+ assert .Equal (t , timelockAccounts .Vault .PublicKey ().ToBytes (), accountInfo .Address .Value )
476+ assert .Equal (t , common .CoreMintAccount .PublicKey ().ToBytes (), accountInfo .Mint .Value )
477+ assert .EqualValues (t , 0 , accountInfo .Index )
474478
475- require .NotNil (t , accountInfo .OriginalExchangeData )
476- assert .EqualValues (t , giftCardIssuedIntentRecord .SendPublicPaymentMetadata .ExchangeCurrency , accountInfo .OriginalExchangeData .Currency )
477- assert .Equal (t , giftCardIssuedIntentRecord .SendPublicPaymentMetadata .ExchangeRate , accountInfo .OriginalExchangeData .ExchangeRate )
478- assert .Equal (t , giftCardIssuedIntentRecord .SendPublicPaymentMetadata .NativeAmount , accountInfo .OriginalExchangeData .NativeAmount )
479- assert .Equal (t , giftCardIssuedIntentRecord .SendPublicPaymentMetadata .Quantity , accountInfo .OriginalExchangeData .Quarks )
479+ assert .Equal (t , tc .expectedBalanceSource , accountInfo .BalanceSource )
480+ if tc .simulateClaimInCode || tc .simulateAutoReturnInCode || tc .expectedClaimState == accountpb .TokenAccountInfo_CLAIM_STATE_CLAIMED || tc .expectedClaimState == accountpb .TokenAccountInfo_CLAIM_STATE_EXPIRED {
481+ assert .EqualValues (t , 0 , accountInfo .Balance )
482+ } else if tc .expectedBalanceSource == accountpb .TokenAccountInfo_BALANCE_SOURCE_CACHE {
483+ assert .EqualValues (t , tc .balance , accountInfo .Balance )
484+ } else {
485+ assert .EqualValues (t , 0 , accountInfo .Balance )
486+ }
480487
481- accountInfoRecord , err := env .data .GetLatestAccountInfoByOwnerAddressAndType (env .ctx , ownerAccount .PublicKey ().ToBase58 (), commonpb .AccountType_REMOTE_SEND_GIFT_CARD )
482- require .NoError (t , err )
483- assert .False (t , accountInfoRecord .RequiresDepositSync )
488+ assert .Equal (t , tc .expectedManagementState , accountInfo .ManagementState )
489+ assert .Equal (t , tc .expectedBlockchainState , accountInfo .BlockchainState )
490+ assert .Equal (t , tc .expectedClaimState , accountInfo .ClaimState )
491+
492+ require .NotNil (t , accountInfo .OriginalExchangeData )
493+ assert .EqualValues (t , giftCardIssuedIntentRecord .SendPublicPaymentMetadata .ExchangeCurrency , accountInfo .OriginalExchangeData .Currency )
494+ assert .Equal (t , giftCardIssuedIntentRecord .SendPublicPaymentMetadata .ExchangeRate , accountInfo .OriginalExchangeData .ExchangeRate )
495+ assert .Equal (t , giftCardIssuedIntentRecord .SendPublicPaymentMetadata .NativeAmount , accountInfo .OriginalExchangeData .NativeAmount )
496+ assert .Equal (t , giftCardIssuedIntentRecord .SendPublicPaymentMetadata .Quantity , accountInfo .OriginalExchangeData .Quarks )
497+
498+ assert .Equal (t , requestingOwnerAccount != nil && requestingOwnerAccount == giftCardIssuerOwnerAccount , accountInfo .IsGiftCardIssuer )
499+
500+ accountInfoRecord , err := env .data .GetLatestAccountInfoByOwnerAddressAndType (env .ctx , giftCardOwnerAccount .PublicKey ().ToBase58 (), commonpb .AccountType_REMOTE_SEND_GIFT_CARD )
501+ require .NoError (t , err )
502+ assert .False (t , accountInfoRecord .RequiresDepositSync )
503+ }
484504 }
485505}
486506
@@ -618,7 +638,7 @@ func TestUnauthenticatedRPC(t *testing.T) {
618638 defer cleanup ()
619639
620640 ownerAccount := testutil .NewRandomAccount (t )
621- // swapAuthorityAccount := testutil.NewRandomAccount(t)
641+ requestingOwnerAccount := testutil .NewRandomAccount (t )
622642 maliciousAccount := testutil .NewRandomAccount (t )
623643
624644 isCodeAccountReq := & accountpb.IsCodeAccountRequest {
@@ -644,6 +664,37 @@ func TestUnauthenticatedRPC(t *testing.T) {
644664
645665 _ , err = env .client .GetTokenAccountInfos (env .ctx , getTokenAccountInfosReq )
646666 testutil .AssertStatusErrorWithCode (t , err , codes .Unauthenticated )
667+
668+ getTokenAccountInfosReq = & accountpb.GetTokenAccountInfosRequest {
669+ Owner : ownerAccount .ToProto (),
670+ RequestingOwner : requestingOwnerAccount .ToProto (),
671+ }
672+ reqBytes , err = proto .Marshal (getTokenAccountInfosReq )
673+ require .NoError (t , err )
674+ getTokenAccountInfosReq .Signature = & commonpb.Signature {
675+ Value : ed25519 .Sign (ownerAccount .PrivateKey ().ToBytes (), reqBytes ),
676+ }
677+
678+ _ , err = env .client .GetTokenAccountInfos (env .ctx , getTokenAccountInfosReq )
679+ testutil .AssertStatusErrorWithCode (t , err , codes .Unauthenticated )
680+
681+ getTokenAccountInfosReq = & accountpb.GetTokenAccountInfosRequest {
682+ Owner : ownerAccount .ToProto (),
683+ RequestingOwner : requestingOwnerAccount .ToProto (),
684+ }
685+ reqBytes , err = proto .Marshal (getTokenAccountInfosReq )
686+ require .NoError (t , err )
687+ sig1 := & commonpb.Signature {
688+ Value : ed25519 .Sign (ownerAccount .PrivateKey ().ToBytes (), reqBytes ),
689+ }
690+ sig2 := & commonpb.Signature {
691+ Value : ed25519 .Sign (maliciousAccount .PrivateKey ().ToBytes (), reqBytes ),
692+ }
693+ getTokenAccountInfosReq .Signature = sig1
694+ getTokenAccountInfosReq .RequestingOwnerSignature = sig2
695+
696+ _ , err = env .client .GetTokenAccountInfos (env .ctx , getTokenAccountInfosReq )
697+ testutil .AssertStatusErrorWithCode (t , err , codes .Unauthenticated )
647698}
648699
649700func setupAccountRecords (t * testing.T , env testEnv , ownerAccount , authorityAccount * common.Account , index uint64 , accountType commonpb.AccountType ) * common.AccountRecords {
@@ -722,18 +773,3 @@ func setupCachedBalance(t *testing.T, env testEnv, accountRecords *common.Accoun
722773 }
723774 require .NoError (t , env .data .SaveExternalDeposit (env .ctx , depositRecord ))
724775}
725-
726- func setupOpenAccountsIntent (t * testing.T , env testEnv , ownerAccount * common.Account ) {
727- intentRecord := & intent.Record {
728- IntentId : testutil .NewRandomAccount (t ).PublicKey ().ToBase58 (),
729- IntentType : intent .OpenAccounts ,
730-
731- InitiatorOwnerAccount : ownerAccount .PublicKey ().ToBase58 (),
732-
733- OpenAccountsMetadata : & intent.OpenAccountsMetadata {},
734-
735- State : intent .StatePending ,
736- }
737-
738- require .NoError (t , env .data .SaveIntent (env .ctx , intentRecord ))
739- }
0 commit comments