@@ -25,20 +25,19 @@ describe('Asset metadata service', () => {
25
25
} ) ;
26
26
27
27
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 ) ;
31
31
( ( ) => {
32
- bitgo . coin ( 'hteth:faketoken' ) ;
32
+ bitgoNoAms . coin ( 'hteth:faketoken' ) ;
33
33
} ) . should . throw (
34
34
'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.'
35
35
) ;
36
36
} ) ;
37
37
38
38
it ( 'should be able to register a token in the coin factory' , ( ) => {
39
39
const tokenName = 'hteth:faketoken' ;
40
- const amsToken = reducedAmsTokenConfig [ tokenName ] [ 0 ] ;
41
- bitgo . registerToken ( amsToken ) ;
40
+ bitgo . registerToken ( tokenName ) ;
42
41
const coin = bitgo . coin ( tokenName ) ;
43
42
should . exist ( coin ) ;
44
43
coin . type . should . equal ( tokenName ) ;
@@ -47,6 +46,53 @@ describe('Asset metadata service', () => {
47
46
coin . tokenContractAddress . should . equal ( '0x89a959b9184b4f8c8633646d5dfd049d2ebc983a' ) ;
48
47
} ) ;
49
48
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
+
50
96
it ( 'should fetch all assets from AMS and initialize the coin factory' , async ( ) => {
51
97
const bitgo = TestBitGo . decorate ( BitGo , { env : 'mock' , microservicesUri, useAms : true } as BitGoOptions ) ;
52
98
bitgo . initializeTestVars ( ) ;
@@ -61,10 +107,10 @@ describe('Asset metadata service', () => {
61
107
62
108
describe ( 'registerToken' , ( ) => {
63
109
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 ( ) ;
66
112
67
- await bitgo
113
+ await bitgoNoAms
68
114
. registerToken ( 'hteth:faketoken' )
69
115
. should . be . rejectedWith ( 'registerToken is only supported when useAms is set to true' ) ;
70
116
} ) ;
0 commit comments