@@ -2,31 +2,33 @@ import { Test, TestingModule } from '@nestjs/testing';
2
2
import { BigNumber } from '@polymathnetwork/polymesh-sdk' ;
3
3
import {
4
4
ClaimType ,
5
- KnownTokenType ,
6
- TokenIdentifierType ,
5
+ KnownAssetType ,
6
+ SecurityIdentifierType ,
7
7
} from '@polymathnetwork/polymesh-sdk/types' ;
8
8
9
9
import { MAX_CONTENT_HASH_LENGTH } from '~/assets/assets.consts' ;
10
10
import { AssetsController } from '~/assets/assets.controller' ;
11
11
import { AssetsService } from '~/assets/assets.service' ;
12
- import { MockComplianceRequirements } from '~/assets/mocks/compliance-requirements.mock' ;
13
- import { ComplianceRequirementsModel } from '~/assets/models/compliance-requirements.model' ;
14
12
import { PaginatedResultsModel } from '~/common/models/paginated-results.model' ;
15
- import { MockSecurityToken } from '~/test-utils/mocks' ;
16
- import { MockAssetService } from '~/test-utils/service-mocks' ;
13
+ import { ComplianceService } from '~/compliance/compliance.service' ;
14
+ import { MockAsset } from '~/test-utils/mocks' ;
15
+ import { MockAssetService , MockComplianceService } from '~/test-utils/service-mocks' ;
17
16
18
17
describe ( 'AssetsController' , ( ) => {
19
18
let controller : AssetsController ;
20
19
21
20
const mockAssetsService = new MockAssetService ( ) ;
21
+ const mockComplianceService = new MockComplianceService ( ) ;
22
22
23
23
beforeEach ( async ( ) => {
24
24
const module : TestingModule = await Test . createTestingModule ( {
25
25
controllers : [ AssetsController ] ,
26
- providers : [ AssetsService ] ,
26
+ providers : [ AssetsService , ComplianceService ] ,
27
27
} )
28
28
. overrideProvider ( AssetsService )
29
29
. useValue ( mockAssetsService )
30
+ . overrideProvider ( ComplianceService )
31
+ . useValue ( mockComplianceService )
30
32
. compile ( ) ;
31
33
32
34
controller = module . get < AssetsController > ( AssetsController ) ;
@@ -38,8 +40,8 @@ describe('AssetsController', () => {
38
40
39
41
describe ( 'getDetails' , ( ) => {
40
42
it ( 'should return the details' , async ( ) => {
41
- const mockTokenDetails = {
42
- assetType : KnownTokenType . EquityCommon ,
43
+ const mockAssetDetails = {
44
+ assetType : KnownAssetType . EquityCommon ,
43
45
isDivisible : false ,
44
46
name : 'NAME' ,
45
47
owner : {
@@ -49,24 +51,24 @@ describe('AssetsController', () => {
49
51
} ;
50
52
const mockIdentifiers = [
51
53
{
52
- type : TokenIdentifierType . Isin ,
54
+ type : SecurityIdentifierType . Isin ,
53
55
value : 'US000000000' ,
54
56
} ,
55
57
] ;
56
- const mockSecurityToken = new MockSecurityToken ( ) ;
57
- mockSecurityToken . details . mockResolvedValue ( mockTokenDetails ) ;
58
- mockSecurityToken . getIdentifiers . mockResolvedValue ( mockIdentifiers ) ;
58
+ const mockAsset = new MockAsset ( ) ;
59
+ mockAsset . details . mockResolvedValue ( mockAssetDetails ) ;
60
+ mockAsset . getIdentifiers . mockResolvedValue ( mockIdentifiers ) ;
59
61
60
62
const mockFundingRound = 'Series A' ;
61
- mockSecurityToken . currentFundingRound . mockResolvedValue ( mockFundingRound ) ;
63
+ mockAsset . currentFundingRound . mockResolvedValue ( mockFundingRound ) ;
62
64
63
- mockAssetsService . findOne . mockResolvedValue ( mockSecurityToken ) ;
65
+ mockAssetsService . findOne . mockResolvedValue ( mockAsset ) ;
64
66
65
67
const result = await controller . getDetails ( { ticker : 'SOME_TICKER' } ) ;
66
68
67
69
const mockResult = {
68
- ...mockTokenDetails ,
69
- identifiers : mockIdentifiers ,
70
+ ...mockAssetDetails ,
71
+ securityIdentifiers : mockIdentifiers ,
70
72
fundingRound : mockFundingRound ,
71
73
} ;
72
74
@@ -83,21 +85,24 @@ describe('AssetsController', () => {
83
85
} ,
84
86
] ,
85
87
next : '0xddddd' ,
86
- count : 2 ,
88
+ count : new BigNumber ( 2 ) ,
87
89
} ;
88
90
89
91
it ( 'should return the list of Asset holders' , async ( ) => {
90
92
mockAssetsService . findHolders . mockResolvedValue ( mockHolders ) ;
91
93
92
- const result = await controller . getHolders ( { ticker : 'SOME_TICKER' } , { size : 1 } ) ;
94
+ const result = await controller . getHolders (
95
+ { ticker : 'SOME_TICKER' } ,
96
+ { size : new BigNumber ( 1 ) }
97
+ ) ;
93
98
const expectedResults = mockHolders . data . map ( holder => {
94
99
return { identity : holder . identity . did , balance : holder . balance } ;
95
100
} ) ;
96
101
97
102
expect ( result ) . toEqual (
98
103
new PaginatedResultsModel ( {
99
104
results : expectedResults ,
100
- total : mockHolders . count ,
105
+ total : new BigNumber ( mockHolders . count ) ,
101
106
next : mockHolders . next ,
102
107
} )
103
108
) ;
@@ -108,7 +113,7 @@ describe('AssetsController', () => {
108
113
109
114
const result = await controller . getHolders (
110
115
{ ticker : 'SOME_TICKER' } ,
111
- { size : 1 , start : 'SOME_START_KEY' }
116
+ { size : new BigNumber ( 1 ) , start : 'SOME_START_KEY' }
112
117
) ;
113
118
114
119
const expectedResults = mockHolders . data . map ( holder => {
@@ -118,7 +123,7 @@ describe('AssetsController', () => {
118
123
expect ( result ) . toEqual (
119
124
new PaginatedResultsModel ( {
120
125
results : expectedResults ,
121
- total : mockHolders . count ,
126
+ total : new BigNumber ( mockHolders . count ) ,
122
127
next : mockHolders . next ,
123
128
} )
124
129
) ;
@@ -135,18 +140,21 @@ describe('AssetsController', () => {
135
140
} ,
136
141
] ,
137
142
next : '0xddddd' ,
138
- count : 2 ,
143
+ count : new BigNumber ( 2 ) ,
139
144
} ;
140
145
141
146
it ( 'should return the list of Asset documents' , async ( ) => {
142
147
mockAssetsService . findDocuments . mockResolvedValue ( mockDocuments ) ;
143
148
144
- const result = await controller . getDocuments ( { ticker : 'SOME_TICKER' } , { size : 1 } ) ;
149
+ const result = await controller . getDocuments (
150
+ { ticker : 'SOME_TICKER' } ,
151
+ { size : new BigNumber ( 1 ) }
152
+ ) ;
145
153
146
154
expect ( result ) . toEqual (
147
155
new PaginatedResultsModel ( {
148
156
results : mockDocuments . data ,
149
- total : mockDocuments . count ,
157
+ total : new BigNumber ( mockDocuments . count ) ,
150
158
next : mockDocuments . next ,
151
159
} )
152
160
) ;
@@ -157,63 +165,53 @@ describe('AssetsController', () => {
157
165
158
166
const result = await controller . getDocuments (
159
167
{ ticker : 'SOME_TICKER' } ,
160
- { size : 1 , start : 'SOME_START_KEY' }
168
+ { size : new BigNumber ( 1 ) , start : 'SOME_START_KEY' }
161
169
) ;
162
170
163
171
expect ( result ) . toEqual (
164
172
new PaginatedResultsModel ( {
165
173
results : mockDocuments . data ,
166
- total : mockDocuments . count ,
174
+ total : new BigNumber ( mockDocuments . count ) ,
167
175
next : mockDocuments . next ,
168
176
} )
169
177
) ;
170
178
} ) ;
171
179
} ) ;
172
180
173
- describe ( 'getComplianceRequirements' , ( ) => {
174
- it ( 'should return the list of all compliance requirements of an Asset' , async ( ) => {
175
- const mockComplianceRequirements = new MockComplianceRequirements ( ) ;
176
- mockAssetsService . findComplianceRequirements . mockResolvedValue ( mockComplianceRequirements ) ;
177
-
178
- const result = await controller . getComplianceRequirements ( { ticker : 'SOME_TICKER' } ) ;
179
-
180
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
181
- expect ( result ) . toEqual ( new ComplianceRequirementsModel ( mockComplianceRequirements as any ) ) ;
182
- } ) ;
183
- } ) ;
184
-
185
181
describe ( 'getTrustedClaimIssuers' , ( ) => {
186
182
it ( 'should return the list of all trusted Claim Issuers of an Asset' , async ( ) => {
187
183
const mockClaimIssuers = [
188
184
{
189
- did : 'Ox6' . padEnd ( 66 , '0' ) ,
185
+ identity : {
186
+ did : 'Ox6' . padEnd ( 66 , '0' ) ,
187
+ } ,
190
188
trustedFor : [ ClaimType . Accredited , ClaimType . InvestorUniqueness ] ,
191
189
} ,
192
190
] ;
193
- mockAssetsService . findTrustedClaimIssuers . mockResolvedValue ( mockClaimIssuers ) ;
191
+ mockComplianceService . findTrustedClaimIssuers . mockResolvedValue ( mockClaimIssuers ) ;
194
192
195
193
const result = await controller . getTrustedClaimIssuers ( { ticker : 'SOME_TICKER' } ) ;
196
194
197
- expect ( result ) . toEqual ( { results : mockClaimIssuers } ) ;
195
+ expect ( result ) . toEqual ( {
196
+ results : [
197
+ {
198
+ did : 'Ox6' . padEnd ( 66 , '0' ) ,
199
+ trustedFor : [ ClaimType . Accredited , ClaimType . InvestorUniqueness ] ,
200
+ } ,
201
+ ] ,
202
+ } ) ;
198
203
} ) ;
199
204
} ) ;
200
205
201
206
describe ( 'reserveTicker' , ( ) => {
202
207
it ( 'should call the service and return the results' , async ( ) => {
203
208
const input = { ticker : 'SOME_TICKER' , signer : '0x6000' } ;
204
- const response = {
205
- transactions : [
206
- {
207
- blockHash : '0xfb3f745444ae63e66240d57eb9d769b0152af23214600425fe7c01f02512d960' ,
208
- transactionHash : '0xe16c51097d10e712b9f6ff572ca0c8c77ffcab0af8a8cb0598f8b891ab3ce46a' ,
209
- transactionTag : 'asset.reserveTicker' ,
210
- } ,
211
- ] ,
212
- } ;
213
- mockAssetsService . registerTicker . mockResolvedValue ( response ) ;
209
+ mockAssetsService . registerTicker . mockResolvedValue ( { transactions : [ 'transaction' ] } ) ;
214
210
215
211
const result = await controller . registerTicker ( input ) ;
216
- expect ( result ) . toEqual ( response ) ;
212
+ expect ( result ) . toEqual ( {
213
+ transactions : [ 'transaction' ] ,
214
+ } ) ;
217
215
expect ( mockAssetsService . registerTicker ) . toHaveBeenCalledWith ( input ) ;
218
216
} ) ;
219
217
@@ -224,22 +222,13 @@ describe('AssetsController', () => {
224
222
name : 'Berkshire Class A' ,
225
223
ticker : 'BRK.A' ,
226
224
isDivisible : false ,
227
- assetType : KnownTokenType . EquityCommon ,
225
+ assetType : KnownAssetType . EquityCommon ,
228
226
requireInvestorUniqueness : false ,
229
227
} ;
230
- const response = {
231
- transactions : [
232
- {
233
- blockHash : '0xfb3f745444ae63e66240d57eb9d769b0152af23214600425fe7c01f02512d960' ,
234
- transactionHash : '0xe16c51097d10e712b9f6ff572ca0c8c77ffcab0af8a8cb0598f8b891ab3ce46a' ,
235
- transactionTag : 'asset.createAsset' ,
236
- } ,
237
- ] ,
238
- } ;
239
- mockAssetsService . createAsset . mockResolvedValue ( response ) ;
228
+ mockAssetsService . createAsset . mockResolvedValue ( { transactions : [ 'transaction' ] } ) ;
240
229
241
230
const result = await controller . createAsset ( input ) ;
242
- expect ( result ) . toEqual ( response ) ;
231
+ expect ( result ) . toEqual ( { transactions : [ 'transaction' ] } ) ;
243
232
expect ( mockAssetsService . createAsset ) . toHaveBeenCalledWith ( input ) ;
244
233
} ) ;
245
234
} ) ;
@@ -248,20 +237,11 @@ describe('AssetsController', () => {
248
237
it ( 'should call the service and return the results' , async ( ) => {
249
238
const signer = '0x6000' ;
250
239
const ticker = 'TICKER' ;
251
- const amount = new BigNumber ( '1000' ) ;
252
- const response = {
253
- transactions : [
254
- {
255
- blockHash : '0xfb3f745444ae63e66240d57eb9d769b0152af23214600425fe7c01f02512d960' ,
256
- transactionHash : '0xe16c51097d10e712b9f6ff572ca0c8c77ffcab0af8a8cb0598f8b891ab3ce46a' ,
257
- transactionTag : 'asset.issue' ,
258
- } ,
259
- ] ,
260
- } ;
261
- mockAssetsService . issue . mockResolvedValue ( response ) ;
240
+ const amount = new BigNumber ( 1000 ) ;
241
+ mockAssetsService . issue . mockResolvedValue ( { transactions : [ 'transaction' ] } ) ;
262
242
263
243
const result = await controller . issue ( { ticker } , { signer, amount } ) ;
264
- expect ( result ) . toEqual ( response ) ;
244
+ expect ( result ) . toEqual ( { transactions : [ 'transaction' ] } ) ;
265
245
expect ( mockAssetsService . issue ) . toHaveBeenCalledWith ( ticker , { signer, amount } ) ;
266
246
} ) ;
267
247
} ) ;
0 commit comments