@@ -301,5 +301,164 @@ describe('SBT', () => {
301301 { trait_type : 'Gas fee used' , value : '12342' , display_type : 'number' } ,
302302 ] )
303303 } )
304+
305+ it ( 'The setTokenURI function should function correctly for only 1 string attribute and 1 number attribute' , async ( ) => {
306+ const sbt = await init ( )
307+ const signers = await getSigners ( )
308+
309+ const metadata = {
310+ name : 'Proof of service NFT' ,
311+ description :
312+ 'This is a proof of service NFT, which indicates your contribution to the project' ,
313+ tokenURIImage :
314+ 'https://i.guim.co.uk/img/media/ef8492feb3715ed4de705727d9f513c168a8b196/37_0_1125_675/master/1125.jpg?width=1200&height=1200&quality=85&auto=format&fit=crop&s=d456a2af571d980d8b2985472c262b31' ,
315+ stringAttributes : [
316+ { trait_type : 'Category' , value : 'Category A' } ,
317+ ] ,
318+ numberAttributes : [
319+ {
320+ trait_type : 'No. of contributions' ,
321+ value : 1 ,
322+ display_type : 'number' ,
323+ } ,
324+ ] ,
325+ }
326+ const encodedMetadata = await getEncodedMetadata ( sbt , metadata )
327+ await expect (
328+ sbt
329+ . connect ( signers . minterA )
330+ . mint ( signers . userA . address , encodedMetadata )
331+ )
332+ . to . emit ( sbt , 'Minted' )
333+ . withArgs ( 0 , signers . userA . address )
334+
335+ const uri = await sbt . tokenURI ( 0 )
336+ const uriInfo : string [ ] = uri . split ( ',' )
337+ expect ( uriInfo [ 0 ] ) . to . equal ( 'data:application/json;base64' )
338+ const decodedData = JSON . parse (
339+ Buffer . from ( uriInfo [ 1 ] , 'base64' ) . toString ( )
340+ ) as {
341+ name : string
342+ description : string
343+ image : string
344+ attributes : any [ ]
345+ }
346+ expect ( decodedData . name ) . to . eq ( metadata . name )
347+ expect ( decodedData . description ) . to . eq ( metadata . description )
348+ expect ( decodedData . image ) . to . eq ( metadata . tokenURIImage )
349+ expect ( decodedData . attributes . length ) . to . eq ( 2 )
350+ expect ( decodedData . attributes [ 0 ] ) . to . deep . equal ( { trait_type : 'Category' , value : 'Category A' } )
351+ expect ( decodedData . attributes [ 1 ] ) . to . deep . equal ( {
352+ trait_type : 'No. of contributions' ,
353+ value : '1' ,
354+ display_type : 'number' ,
355+ } )
356+ expect ( decodedData . attributes ) . to . deep . equal ( [
357+ { trait_type : 'Category' , value : 'Category A' } ,
358+ {
359+ trait_type : 'No. of contributions' ,
360+ value : '1' ,
361+ display_type : 'number' ,
362+ }
363+ ] )
364+ } )
365+
366+ it ( 'The setTokenURI function should function correctly for only 1+ string attribute and 1+ number attribute' , async ( ) => {
367+ const sbt = await init ( )
368+ const signers = await getSigners ( )
369+
370+ const metadata = {
371+ name : 'Proof of service NFT' ,
372+ description :
373+ 'This is a proof of service NFT, which indicates your contribution to the project' ,
374+ tokenURIImage :
375+ 'https://i.guim.co.uk/img/media/ef8492feb3715ed4de705727d9f513c168a8b196/37_0_1125_675/master/1125.jpg?width=1200&height=1200&quality=85&auto=format&fit=crop&s=d456a2af571d980d8b2985472c262b31' ,
376+ stringAttributes : [
377+ { trait_type : 'Category' , value : 'Category A' } ,
378+ { trait_type : 'Location' , value : 'Shibuya' } ,
379+ { trait_type : 'Entity' , value : 'Corporation' } ,
380+ ] ,
381+ numberAttributes : [
382+ {
383+ trait_type : 'No. of contributions' ,
384+ value : 1 ,
385+ display_type : 'number' ,
386+ } ,
387+ {
388+ trait_type : 'No. of locations' ,
389+ value : 1000 ,
390+ display_type : 'number' ,
391+ } ,
392+ { trait_type : 'Gas fee used' , value : 12342 , display_type : 'number' } ,
393+ ] ,
394+ }
395+ const encodedMetadata = await getEncodedMetadata ( sbt , metadata )
396+ await expect (
397+ sbt
398+ . connect ( signers . minterA )
399+ . mint ( signers . userA . address , encodedMetadata )
400+ )
401+ . to . emit ( sbt , 'Minted' )
402+ . withArgs ( 0 , signers . userA . address )
403+
404+ const uri = await sbt . tokenURI ( 0 )
405+ const uriInfo : string [ ] = uri . split ( ',' )
406+ expect ( uriInfo [ 0 ] ) . to . equal ( 'data:application/json;base64' )
407+ const decodedData = JSON . parse (
408+ Buffer . from ( uriInfo [ 1 ] , 'base64' ) . toString ( )
409+ ) as {
410+ name : string
411+ description : string
412+ image : string
413+ attributes : any [ ]
414+ }
415+ expect ( decodedData . name ) . to . eq ( metadata . name )
416+ expect ( decodedData . description ) . to . eq ( metadata . description )
417+ expect ( decodedData . image ) . to . eq ( metadata . tokenURIImage )
418+ expect ( decodedData . attributes . length ) . to . eq ( 6 )
419+ expect ( decodedData . attributes [ 0 ] ) . to . deep . equal ( {
420+ trait_type : 'Category' ,
421+ value : 'Category A' ,
422+ } )
423+ expect ( decodedData . attributes [ 1 ] ) . to . deep . equal ( {
424+ trait_type : 'Location' ,
425+ value : 'Shibuya' ,
426+ } )
427+ expect ( decodedData . attributes [ 2 ] ) . to . deep . equal ( {
428+ trait_type : 'Entity' ,
429+ value : 'Corporation' ,
430+ } )
431+ expect ( decodedData . attributes [ 3 ] ) . to . deep . equal ( {
432+ trait_type : 'No. of contributions' ,
433+ value : '1' ,
434+ display_type : 'number' ,
435+ } )
436+ expect ( decodedData . attributes [ 4 ] ) . to . deep . equal ( {
437+ trait_type : 'No. of locations' ,
438+ value : '1000' ,
439+ display_type : 'number' ,
440+ } )
441+ expect ( decodedData . attributes [ 5 ] ) . to . deep . equal ( {
442+ trait_type : 'Gas fee used' ,
443+ value : '12342' ,
444+ display_type : 'number' ,
445+ } )
446+ expect ( decodedData . attributes ) . to . deep . equal ( [
447+ { trait_type : 'Category' , value : 'Category A' } ,
448+ { trait_type : 'Location' , value : 'Shibuya' } ,
449+ { trait_type : 'Entity' , value : 'Corporation' } ,
450+ {
451+ trait_type : 'No. of contributions' ,
452+ value : "1" ,
453+ display_type : 'number' ,
454+ } ,
455+ {
456+ trait_type : 'No. of locations' ,
457+ value : "1000" ,
458+ display_type : 'number' ,
459+ } ,
460+ { trait_type : 'Gas fee used' , value : "12342" , display_type : 'number' }
461+ ] )
462+ } )
304463 } )
305464} )
0 commit comments