@@ -25,20 +25,19 @@ describe('Asset metadata service', () => {
2525 } ) ;
2626
2727 it ( 'should not fetch coin from custom coin factory when useAms is false' , async ( ) => {
28- const bitgo = TestBitGo . decorate ( BitGo , { env : 'mock' , microservicesUri, useAms : false } as any ) ;
29- bitgo . initializeTestVars ( ) ;
30- bitgo . initCoinFactory ( reducedAmsTokenConfig ) ;
28+ const bitgoNoAms = TestBitGo . decorate ( BitGo , { env : 'mock' , microservicesUri, useAms : false } as any ) ;
29+ bitgoNoAms . initializeTestVars ( ) ;
30+ bitgoNoAms . initCoinFactory ( reducedAmsTokenConfig ) ;
3131 ( ( ) => {
32- bitgo . coin ( 'hteth:faketoken' ) ;
32+ bitgoNoAms . coin ( 'hteth:faketoken' ) ;
3333 } ) . should . throw (
3434 'Coin or token type hteth:faketoken not supported or not compiled. Please be sure that you are using the latest version of BitGoJS. If using @bitgo/sdk-api, please confirm you have registered hteth:faketoken first.'
3535 ) ;
3636 } ) ;
3737
3838 it ( 'should be able to register a token in the coin factory' , ( ) => {
3939 const tokenName = 'hteth:faketoken' ;
40- const amsToken = reducedAmsTokenConfig [ tokenName ] [ 0 ] ;
41- bitgo . registerToken ( amsToken ) ;
40+ bitgo . registerToken ( tokenName ) ;
4241 const coin = bitgo . coin ( tokenName ) ;
4342 should . exist ( coin ) ;
4443 coin . type . should . equal ( tokenName ) ;
@@ -47,6 +46,53 @@ describe('Asset metadata service', () => {
4746 coin . tokenContractAddress . should . equal ( '0x89a959b9184b4f8c8633646d5dfd049d2ebc983a' ) ;
4847 } ) ;
4948
49+ describe ( 'ERC721 NFTs' , ( ) => {
50+ it ( 'should create a custom coin factory from ams response' , async ( ) => {
51+ bitgo . initCoinFactory ( reducedAmsTokenConfig ) ;
52+ const coin = bitgo . coin ( 'erc721:unsteth' ) ;
53+ should . exist ( coin ) ;
54+ coin . type . should . equal ( 'erc721:unsteth' ) ;
55+ coin . name . should . equal ( 'Lido: stETH Withdrawal NFT' ) ;
56+ coin . decimalPlaces . should . equal ( 0 ) ;
57+ coin . tokenContractAddress . should . equal ( '0x889edc2edab5f40e902b864ad4d7ade8e412f9b1' ) ;
58+ } ) ;
59+
60+ it ( 'should be able to register an nft in the coin factory' , ( ) => {
61+ const nftName = 'terc721:unsteth' ;
62+ bitgo . registerToken ( nftName ) ;
63+ const coin = bitgo . coin ( nftName ) ;
64+ should . exist ( coin ) ;
65+ coin . type . should . equal ( nftName ) ;
66+ coin . name . should . equal ( 'Test Lido: stETH Withdrawal NFT' ) ;
67+ coin . decimalPlaces . should . equal ( 0 ) ;
68+ coin . tokenContractAddress . should . equal ( '0xfe56573178f1bcdf53f01a6e9977670dcbbd9186' ) ;
69+ } ) ;
70+
71+ it ( 'should fetch all assets from AMS and initialize the coin factory' , async ( ) => {
72+ const bitgo = TestBitGo . decorate ( BitGo , { env : 'mock' , microservicesUri, useAms : true } as BitGoOptions ) ;
73+ bitgo . initializeTestVars ( ) ;
74+
75+ // Setup nocks
76+ nock ( microservicesUri ) . get ( '/api/v1/assets/list/testnet' ) . reply ( 200 , reducedAmsTokenConfig ) ;
77+
78+ await bitgo . registerAllTokens ( ) ;
79+ const coin = bitgo . coin ( 'terc721:unsteth' ) ;
80+ should . exist ( coin ) ;
81+ } ) ;
82+
83+ it ( 'should fetch nft from default coin factory when useAms is false' , ( ) => {
84+ const bitgoNoAms = TestBitGo . decorate ( BitGo , { env : 'mock' , microservicesUri, useAms : false } as BitGoOptions ) ;
85+ bitgoNoAms . initializeTestVars ( ) ;
86+ bitgoNoAms . initCoinFactory ( reducedAmsTokenConfig ) ;
87+ const coin : any = bitgoNoAms . coin ( 'erc721:unsteth' ) ;
88+ should . exist ( coin ) ;
89+ coin . type . should . equal ( 'erc721:unsteth' ) ;
90+ coin . name . should . equal ( 'Lido: stETH Withdrawal NFT' ) ;
91+ coin . decimalPlaces . should . equal ( 0 ) ;
92+ coin . tokenContractAddress . should . equal ( '0x889edc2edab5f40e902b864ad4d7ade8e412f9b1' ) ;
93+ } ) ;
94+ } ) ;
95+
5096 it ( 'should fetch all assets from AMS and initialize the coin factory' , async ( ) => {
5197 const bitgo = TestBitGo . decorate ( BitGo , { env : 'mock' , microservicesUri, useAms : true } as BitGoOptions ) ;
5298 bitgo . initializeTestVars ( ) ;
@@ -61,10 +107,10 @@ describe('Asset metadata service', () => {
61107
62108 describe ( 'registerToken' , ( ) => {
63109 it ( 'should throw an error when useAms is false' , async ( ) => {
64- const bitgo = TestBitGo . decorate ( BitGo , { env : 'mock' , microservicesUri, useAms : false } as BitGoOptions ) ;
65- bitgo . initializeTestVars ( ) ;
110+ const bitgoNoAms = TestBitGo . decorate ( BitGo , { env : 'mock' , microservicesUri, useAms : false } as BitGoOptions ) ;
111+ bitgoNoAms . initializeTestVars ( ) ;
66112
67- await bitgo
113+ await bitgoNoAms
68114 . registerToken ( 'hteth:faketoken' )
69115 . should . be . rejectedWith ( 'registerToken is only supported when useAms is set to true' ) ;
70116 } ) ;
0 commit comments