@@ -20,6 +20,7 @@ func RunTests(t *testing.T, s currency.Store, teardown func()) {
2020 testMetadataRoundTrip ,
2121 testMetadataSaveWithVersioning ,
2222 testMetadataUniqueNameConstraint ,
23+ testIsNameAvailable ,
2324 testGetAllMetadataByState ,
2425 testGetAllMints ,
2526 testCountMints ,
@@ -282,6 +283,72 @@ func testMetadataUniqueNameConstraint(t *testing.T, s currency.Store) {
282283 assert .Equal (t , currency .ErrDuplicateCurrency , s .SaveMetadata (context .Background (), record2 ))
283284}
284285
286+ func testIsNameAvailable (t * testing.T , s currency.Store ) {
287+ ctx := context .Background ()
288+
289+ // Name should be available when no records exist
290+ available , err := s .IsNameAvailable (ctx , "TestCurrency" )
291+ require .NoError (t , err )
292+ assert .True (t , available )
293+
294+ // Save a metadata record
295+ record := & currency.MetadataRecord {
296+ Name : "TestCurrency" ,
297+ Symbol : "TC" ,
298+ Description : "A test currency" ,
299+ ImageUrl : "https://example.com/tc.png" ,
300+ BillColors : []string {"#000000" },
301+ SocialLinks : []currency.SocialLink {{Type : currency .SocialLinkTypeWebsite , Value : "https://example.com" }},
302+
303+ Seed : "nameseed1" ,
304+ Authority : "nameauth1" ,
305+
306+ Mint : "namemint11111111111111111111111111111111111111" ,
307+ MintBump : 255 ,
308+ Decimals : currencycreator .DefaultMintDecimals ,
309+
310+ CurrencyConfig : "nameconfig111111111111111111111111111111111" ,
311+ CurrencyConfigBump : 255 ,
312+
313+ LiquidityPool : "namepool11111111111111111111111111111111111" ,
314+ LiquidityPoolBump : 255 ,
315+
316+ VaultMint : "namevmint1111111111111111111111111111111111" ,
317+ VaultMintBump : 255 ,
318+
319+ VaultCore : "namevcore1111111111111111111111111111111111" ,
320+ VaultCoreBump : 255 ,
321+
322+ SellFeeBps : currencycreator .DefaultSellFeeBps ,
323+
324+ Alt : "namealt111111111111111111111111111111111111111" ,
325+
326+ CreatedBy : "namecreator1" ,
327+ CreatedAt : time .Now (),
328+ }
329+
330+ require .NoError (t , s .SaveMetadata (ctx , record ))
331+
332+ // Exact name should not be available
333+ available , err = s .IsNameAvailable (ctx , "TestCurrency" )
334+ require .NoError (t , err )
335+ assert .False (t , available )
336+
337+ // Case-insensitive match should not be available
338+ available , err = s .IsNameAvailable (ctx , "testcurrency" )
339+ require .NoError (t , err )
340+ assert .False (t , available )
341+
342+ available , err = s .IsNameAvailable (ctx , "TESTCURRENCY" )
343+ require .NoError (t , err )
344+ assert .False (t , available )
345+
346+ // Different name should be available
347+ available , err = s .IsNameAvailable (ctx , "OtherCurrency" )
348+ require .NoError (t , err )
349+ assert .True (t , available )
350+ }
351+
285352func testGetAllMetadataByState (t * testing.T , s currency.Store ) {
286353 t .Run ("testGetAllMetadataByState" , func (t * testing.T ) {
287354 ctx := context .Background ()
0 commit comments