@@ -1546,4 +1546,45 @@ func TGetDeletedTokensPendingSKICleanup(t *testing.T, db TestTokenDB) {
15461546
15471547 assert .Equal (t , 3 , count , "should return all indices for the same transaction" )
15481548 })
1549+
1550+ // Test 12: Non-owned tokens (auditor-only, issuer-only) must be excluded,
1551+ // since this node never holds the secret keys for tokens it does not own.
1552+ t .Run ("ExcludeNonOwnedTokens" , func (t * testing.T ) {
1553+ createAndDeleteNonOwnedToken := func (txID string , index uint64 , ownerType string , auditor , issuer bool ) {
1554+ tr := driver2.TokenRecord {
1555+ TxID : txID ,
1556+ Index : index ,
1557+ OwnerRaw : []byte {1 , 2 , 3 },
1558+ OwnerType : ownerType ,
1559+ OwnerIdentity : fmt .Appendf (nil , "owner_%s_%d" , txID , index ),
1560+ Ledger : []byte ("ledger" ),
1561+ LedgerMetadata : []byte {},
1562+ Quantity : "0x01" ,
1563+ Type : ABC ,
1564+ Amount : 1 ,
1565+ Owner : false ,
1566+ Auditor : auditor ,
1567+ Issuer : issuer ,
1568+ }
1569+ require .NoError (t , db .StoreToken (ctx , tr , nil ))
1570+ require .NoError (t , db .DeleteTokens (ctx , "deleter_tx" , & token.ID {TxId : txID , Index : index }))
1571+ }
1572+
1573+ createAndDeleteNonOwnedToken ("auditor_only" , 0 , "idemix" , true , false )
1574+ createAndDeleteNonOwnedToken ("issuer_only" , 0 , "idemix" , false , true )
1575+ createAndDeleteToken ("owned_control" , 0 , "idemix" )
1576+
1577+ tokens , err := db .GetDeletedTokensPendingSKICleanup (ctx , 0 , 100 )
1578+ require .NoError (t , err , "query should not error" )
1579+
1580+ foundOwnedControl := false
1581+ for _ , tok := range tokens {
1582+ assert .NotEqual (t , "auditor_only" , tok .TxID , "auditor-only token should not be returned" )
1583+ assert .NotEqual (t , "issuer_only" , tok .TxID , "issuer-only token should not be returned" )
1584+ if tok .TxID == "owned_control" {
1585+ foundOwnedControl = true
1586+ }
1587+ }
1588+ assert .True (t , foundOwnedControl , "owned token should still be returned" )
1589+ })
15491590}
0 commit comments