1
1
import { Asset , Cardano } from '@cardano-sdk/core' ;
2
2
import { Buffer } from 'buffer' ;
3
+ import { CIP67Assets , withCIP67 , withHandles , withMint , withUtxo } from '../../../src/operators/Mappers' ;
3
4
import { Mappers , ProjectionEvent } from '../../../src' ;
4
5
import {
5
6
NFTSubHandleOutput ,
6
7
assetIdFromHandle ,
7
8
bobAddress ,
8
9
bobHandleOne ,
9
10
bobHandleTwo ,
11
+ handleDatum ,
10
12
handleOutputs ,
11
13
handlePolicyId ,
14
+ invalidHandle ,
12
15
maryAddress ,
13
16
maryHandleOne ,
14
17
referenceNftOutput ,
@@ -19,7 +22,6 @@ import {
19
22
} from './handleUtil' ;
20
23
import { firstValueFrom , of } from 'rxjs' ;
21
24
import { logger , mockProviders } from '@cardano-sdk/util-dev' ;
22
- import { withCIP67 , withHandles , withMint , withUtxo } from '../../../src/operators/Mappers' ;
23
25
24
26
type In = Mappers . WithMint & Mappers . WithCIP67 & Mappers . WithNftMetadata ;
25
27
@@ -174,8 +176,23 @@ describe('withHandles', () => {
174
176
} ) ;
175
177
176
178
describe ( 'assets with invalid asset names' , ( ) => {
177
- const invalidAssetName = Asset . AssetNameLabel . encode ( Cardano . AssetName ( 'abc' ) , Asset . AssetNameLabelNum . UserFT ) ;
179
+ const invalidAssetName = Cardano . AssetName ( Buffer . from ( invalidHandle , 'utf8' ) . toString ( 'hex' ) ) ;
178
180
const invalidAssetId = Cardano . AssetId . fromParts ( handlePolicyId , invalidAssetName ) ;
181
+ const decodedInvalidAssetName = Cardano . AssetName ( Buffer . from ( `${ invalidHandle } other` , 'utf8' ) . toString ( 'hex' ) ) ;
182
+ const invalidAssetCip67AssetName = Asset . AssetNameLabel . encode (
183
+ decodedInvalidAssetName ,
184
+ Asset . AssetNameLabelNum . UserNFT
185
+ ) ;
186
+ const invalidAssetCip67ReferenceNftAssetName = Asset . AssetNameLabel . encode (
187
+ decodedInvalidAssetName ,
188
+ Asset . AssetNameLabelNum . ReferenceNFT
189
+ ) ;
190
+ const invalidCip67AssetId = Cardano . AssetId . fromParts ( handlePolicyId , invalidAssetCip67AssetName ) ;
191
+ const invalidCip67ReferenceNftAssetId = Cardano . AssetId . fromParts (
192
+ handlePolicyId ,
193
+ invalidAssetCip67ReferenceNftAssetName
194
+ ) ;
195
+
179
196
const outputsWithInvalidHandles = {
180
197
invalidAssetName : {
181
198
address : 'addr_test1vptwv4jvaqt635jvthpa29lww3vkzypm8l6vk4lv4tqfhhgajdgwf' ,
@@ -184,17 +201,58 @@ describe('withHandles', () => {
184
201
coins : 1n
185
202
}
186
203
} ,
187
- oneValidAndOneInvalidAssetName : {
188
- address : 'addr_test1vptwv4jvaqt635jvthpa29lww3vkzypm8l6vk4lv4tqfhhgajdgwf' ,
204
+ oneValidTwoInvalidAssetName : {
205
+ address : Cardano . PaymentAddress ( 'addr_test1vptwv4jvaqt635jvthpa29lww3vkzypm8l6vk4lv4tqfhhgajdgwf' ) ,
206
+ datum : handleDatum ,
189
207
value : {
190
208
assets : new Map ( [
191
209
[ invalidAssetId , 1n ] ,
192
- [ assetIdFromHandle ( bobHandleTwo ) , 1n ]
193
- ] )
210
+ [ assetIdFromHandle ( bobHandleTwo ) , 1n ] ,
211
+ [ invalidCip67AssetId , 1n ] ,
212
+ [ invalidCip67ReferenceNftAssetId , 1n ]
213
+ ] ) ,
214
+ coins : 123n
194
215
}
195
216
}
196
217
} ;
197
218
219
+ const txId = Cardano . TransactionId ( '0000000000000000000000000000000000000000000000000000000000000000' ) ;
220
+ const utxo : [ Cardano . TxIn , Cardano . TxOut ] = [
221
+ { index : 0 , txId } ,
222
+ outputsWithInvalidHandles . oneValidTwoInvalidAssetName
223
+ ] ;
224
+ const userNftCip67Asset = {
225
+ assetId : invalidCip67ReferenceNftAssetId ,
226
+ assetName : invalidAssetCip67ReferenceNftAssetName ,
227
+ decoded : {
228
+ content : decodedInvalidAssetName ,
229
+ label : Asset . AssetNameLabelNum . ReferenceNFT
230
+ } ,
231
+ policyId : handlePolicyId ,
232
+ utxo
233
+ } ;
234
+ const referenceNftCip67Asset = {
235
+ assetId : invalidCip67AssetId ,
236
+ assetName : invalidAssetCip67AssetName ,
237
+ decoded : {
238
+ content : decodedInvalidAssetName ,
239
+ label : Asset . AssetNameLabelNum . UserNFT
240
+ } ,
241
+ policyId : handlePolicyId ,
242
+ utxo
243
+ } ;
244
+
245
+ const cip67 : CIP67Assets = {
246
+ byAssetId : {
247
+ [ invalidAssetCip67ReferenceNftAssetName ] : userNftCip67Asset ,
248
+ [ invalidCip67AssetId ] : referenceNftCip67Asset
249
+ } ,
250
+ byLabel : {
251
+ [ Asset . AssetNameLabelNum . UserNFT ] : [ userNftCip67Asset ] ,
252
+ [ Asset . AssetNameLabelNum . ReferenceNFT ] : [ referenceNftCip67Asset ]
253
+ }
254
+ } ;
255
+
198
256
it ( 'it returns no handles when output only contain invalid assetId' , async ( ) => {
199
257
const validTxSource$ = of ( {
200
258
block : {
@@ -222,12 +280,12 @@ describe('withHandles', () => {
222
280
body : [
223
281
{
224
282
body : {
225
- outputs : [ outputsWithInvalidHandles . oneValidAndOneInvalidAssetName ]
283
+ outputs : [ outputsWithInvalidHandles . oneValidTwoInvalidAssetName ]
226
284
}
227
285
}
228
286
]
229
287
} ,
230
- cip67 : { byAssetId : { } , byLabel : { } }
288
+ cip67
231
289
} as ProjectionEvent < In > ) ;
232
290
233
291
const { handles } = await firstValueFrom (
@@ -243,7 +301,7 @@ describe('withHandles', () => {
243
301
body : [
244
302
{
245
303
body : {
246
- outputs : [ outputsWithInvalidHandles . oneValidAndOneInvalidAssetName ]
304
+ outputs : [ outputsWithInvalidHandles . oneValidTwoInvalidAssetName ]
247
305
}
248
306
} ,
249
307
{
@@ -253,7 +311,7 @@ describe('withHandles', () => {
253
311
}
254
312
]
255
313
} ,
256
- cip67 : { byAssetId : { } , byLabel : { } }
314
+ cip67
257
315
} as ProjectionEvent < In > ) ;
258
316
259
317
const { handles } = await firstValueFrom (
0 commit comments