@@ -1565,9 +1565,9 @@ where
15651565 let ( _, pk) = PrivateKey :: new_from_rng ( & mut rng, KeyKind :: Secp256k1Schnorr ) ;
15661566 let random_destination = Destination :: PublicKeyHash ( PublicKeyHash :: from ( & pk) ) ;
15671567
1568- let token_ticker = "XXXX" . as_bytes ( ) . to_vec ( ) ;
1568+ let token_ticker = String :: from ( "AB \\ CD" ) ;
15691569 let token_data = FungibleTokenData {
1570- token_ticker : token_ticker. clone ( ) ,
1570+ token_ticker : token_ticker. as_bytes ( ) . to_vec ( ) . clone ( ) ,
15711571 number_of_decimals : rng. gen_range ( 1 ..18 ) ,
15721572 metadata_uri : "http://uri" . as_bytes ( ) . to_vec ( ) ,
15731573 circulating_supply : Amount :: ZERO ,
@@ -1602,7 +1602,7 @@ where
16021602 creator : None ,
16031603 name : "Name" . as_bytes ( ) . to_vec ( ) ,
16041604 description : "SomeNFT" . as_bytes ( ) . to_vec ( ) ,
1605- ticker : token_ticker. clone ( ) ,
1605+ ticker : token_ticker. as_bytes ( ) . to_vec ( ) . clone ( ) ,
16061606 icon_uri : DataOrNoVec :: from ( None ) ,
16071607 additional_metadata_uri : DataOrNoVec :: from ( None ) ,
16081608 media_uri : DataOrNoVec :: from ( None ) ,
@@ -1629,24 +1629,20 @@ where
16291629 . unwrap ( ) ;
16301630
16311631 // will return all token and nft ids
1632- let ids = db_tx. get_token_ids ( 6 , 0 ) . await . unwrap ( ) ;
1633- assert ! ( ids . contains( & random_token_id1) ) ;
1634- assert ! ( ids . contains( & random_token_id2) ) ;
1635- assert ! ( ids . contains( & random_token_id3) ) ;
1632+ let all_ids = db_tx. get_token_ids ( 6 , 0 ) . await . unwrap ( ) ;
1633+ assert ! ( all_ids . contains( & random_token_id1) ) ;
1634+ assert ! ( all_ids . contains( & random_token_id2) ) ;
1635+ assert ! ( all_ids . contains( & random_token_id3) ) ;
16361636
1637- assert ! ( ids . contains( & random_token_id4) ) ;
1638- assert ! ( ids . contains( & random_token_id5) ) ;
1639- assert ! ( ids . contains( & random_token_id6) ) ;
1637+ assert ! ( all_ids . contains( & random_token_id4) ) ;
1638+ assert ! ( all_ids . contains( & random_token_id5) ) ;
1639+ assert ! ( all_ids . contains( & random_token_id6) ) ;
16401640
16411641 // will return all token and nft ids
16421642 let ids = db_tx. get_token_ids_by_ticker ( 6 , 0 , & token_ticker) . await . unwrap ( ) ;
1643- assert ! ( ids. contains( & random_token_id1) ) ;
1644- assert ! ( ids. contains( & random_token_id2) ) ;
1645- assert ! ( ids. contains( & random_token_id3) ) ;
1646-
1647- assert ! ( ids. contains( & random_token_id4) ) ;
1648- assert ! ( ids. contains( & random_token_id5) ) ;
1649- assert ! ( ids. contains( & random_token_id6) ) ;
1643+ for id in & all_ids {
1644+ assert ! ( ids. contains( id) ) ;
1645+ }
16501646
16511647 // will return the tokens first
16521648 let ids = db_tx. get_token_ids ( 3 , 0 ) . await . unwrap ( ) ;
@@ -1672,8 +1668,34 @@ where
16721668 assert ! ( ids. contains( & random_token_id5) ) ;
16731669 assert ! ( ids. contains( & random_token_id6) ) ;
16741670
1675- let ids = db_tx. get_token_ids_by_ticker ( 0 , 6 , "NOT_FOUND" . as_bytes ( ) ) . await . unwrap ( ) ;
1671+ let ids = db_tx. get_token_ids_by_ticker ( 0 , 6 , "NOT_FOUND" ) . await . unwrap ( ) ;
16761672 assert ! ( ids. is_empty( ) ) ;
1673+
1674+ // will return all token and nft ids for partial match
1675+ for partial_ticker in get_all_substrings ( & token_ticker) {
1676+ let ids = db_tx. get_token_ids_by_ticker ( 6 , 0 , partial_ticker) . await . unwrap ( ) ;
1677+ for id in & all_ids {
1678+ assert ! ( ids. contains( id) ) ;
1679+ }
1680+
1681+ // check lowercase as well
1682+ let lowercase_partial_ticker = partial_ticker. to_ascii_lowercase ( ) ;
1683+ let ids2 =
1684+ db_tx. get_token_ids_by_ticker ( 6 , 0 , & lowercase_partial_ticker) . await . unwrap ( ) ;
1685+ assert_eq ! ( ids, ids2) ;
1686+ }
1687+
1688+ // Try out patterns inside the ticker string, they should be escaped and not work
1689+ let ids = db_tx. get_token_ids_by_ticker ( 6 , 0 , "A%D" ) . await . unwrap ( ) ;
1690+ assert ! ( ids. is_empty( ) ) ;
1691+
1692+ let ids = db_tx. get_token_ids_by_ticker ( 6 , 0 , "A_" ) . await . unwrap ( ) ;
1693+ assert ! ( ids. is_empty( ) ) ;
1694+
1695+ for c in [ '*' , '+' , '?' ] {
1696+ let ids = db_tx. get_token_ids_by_ticker ( 6 , 0 , & format ! ( "A{c}" ) ) . await . unwrap ( ) ;
1697+ assert ! ( ids. is_empty( ) ) ;
1698+ }
16771699 }
16781700
16791701 // test coin and token statistics
@@ -2006,3 +2028,13 @@ where
20062028 ]
20072029 . into_iter ( )
20082030}
2031+
2032+ fn get_all_substrings ( s : & str ) -> Vec < & str > {
2033+ let mut substrings = Vec :: new ( ) ;
2034+ for i in 0 ..s. len ( ) {
2035+ for j in i..s. len ( ) {
2036+ substrings. push ( s. get ( i..=j) . unwrap ( ) ) ;
2037+ }
2038+ }
2039+ substrings
2040+ }
0 commit comments