@@ -10,6 +10,7 @@ package token
1010import (
1111 "context"
1212 "testing"
13+ "time"
1314
1415 "github.com/hyperledger-labs/fabric-smart-client/pkg/utils/errors"
1516 "github.com/hyperledger-labs/fabric-token-sdk/token/driver"
@@ -572,7 +573,7 @@ func TestOwnerWallet_Balance(t *testing.T) {
572573 wallet := & OwnerWallet {w : mockOW }
573574 ctx := context .Background ()
574575
575- balance , err := wallet .Balance (ctx , WithBalanceType ("USD" ))
576+ balance , err := wallet .Balance (ctx , WithBalanceTokenType ("USD" ))
576577
577578 require .NoError (t , err )
578579 assert .Equal (t , uint64 (1000 ), balance )
@@ -623,6 +624,51 @@ func TestIssuerWallet_ListIssuedTokens(t *testing.T) {
623624 assert .Equal (t , expectedTokens , tokens )
624625}
625626
627+ // TestIssuerWallet_ListIssuedTokens_WithSortBy verifies that WithSortBy passes the sort
628+ // field and direction through to the driver.
629+ func TestIssuerWallet_ListIssuedTokens_WithSortBy (t * testing.T ) {
630+ mockIW := & mock.IssuerWallet {}
631+ expectedTokens := & token.IssuedTokens {}
632+ mockIW .HistoryTokensReturns (expectedTokens , nil )
633+
634+ wallet := & IssuerWallet {w : mockIW }
635+ ctx := context .Background ()
636+
637+ tokens , err := wallet .ListIssuedTokens (ctx , WithType ("USD" ), WithSortBy (driver .SortByQuantity , driver .SortDescending ))
638+
639+ require .NoError (t , err )
640+ assert .Equal (t , expectedTokens , tokens )
641+
642+ // Verify the compiled options include sort fields.
643+ _ , opts := mockIW .HistoryTokensArgsForCall (0 )
644+ assert .Equal (t , driver .SortByQuantity , opts .SortBy )
645+ assert .Equal (t , driver .SortDescending , opts .SortDirection )
646+ }
647+
648+ // TestOwnerWallet_Balance_WithTimeRange verifies that WithTimeRange passes the
649+ // time bounds through to the driver.
650+ func TestOwnerWallet_Balance_WithTimeRange (t * testing.T ) {
651+ mockOW := & mock.OwnerWallet {}
652+ mockOW .BalanceReturns (uint64 (500 ), nil )
653+
654+ wallet := & OwnerWallet {w : mockOW }
655+ ctx := context .Background ()
656+
657+ from := time .Date (2025 , 1 , 1 , 0 , 0 , 0 , 0 , time .UTC )
658+ to := time .Date (2025 , 12 , 31 , 23 , 59 , 59 , 0 , time .UTC )
659+
660+ balance , err := wallet .Balance (ctx , WithBalanceTokenType ("USD" ), WithTimeRange (& from , & to ))
661+
662+ require .NoError (t , err )
663+ assert .Equal (t , uint64 (500 ), balance )
664+
665+ // Verify the compiled options include time range.
666+ _ , opts := mockOW .BalanceArgsForCall (0 )
667+ assert .Equal (t , & from , opts .From )
668+ assert .Equal (t , & to , opts .To )
669+ assert .Equal (t , token .Type ("USD" ), opts .TokenType )
670+ }
671+
626672// TestWalletManager_OwnerWalletIDs_Error verifies error handling
627673func TestWalletManager_OwnerWalletIDs_Error (t * testing.T ) {
628674 mockWS := & mock.WalletService {}
@@ -763,7 +809,7 @@ func TestOwnerWallet_Balance_Error(t *testing.T) {
763809 wallet := & OwnerWallet {w : mockOW }
764810 ctx := context .Background ()
765811
766- balance , err := wallet .Balance (ctx , WithBalanceType ("USD" ))
812+ balance , err := wallet .Balance (ctx , WithBalanceTokenType ("USD" ))
767813
768814 require .Error (t , err )
769815 assert .Equal (t , expectedErr , err )
0 commit comments