@@ -5,112 +5,121 @@ import { ProcessMode } from '~/rest/common';
55import { Identity } from '~/rest/identities/interfaces' ;
66import { RestSuccessResult } from '~/rest/interfaces' ;
77import { fungibleInstructionParams } from '~/rest/settlements/params' ;
8+
89import { expectBasicTxInfo } from '../utils' ;
910
1011const handles = [ 'issuer' , 'holder' ] ;
1112let factory : TestFactory ;
1213
1314describe ( 'Fungible AssetController transfer' , ( ) => {
14- let restClient : RestClient ;
15- let signer : string ;
16- let issuer : Identity ;
17- let holder : Identity ;
18- let assetParams : ReturnType < typeof createAssetParams > ;
19- let assetId : string ;
20-
21- beforeAll ( async ( ) => {
22- factory = await TestFactory . create ( { handles } ) ;
23- ( { restClient } = factory ) ;
24- issuer = factory . getSignerIdentity ( handles [ 0 ] ) ;
25- holder = factory . getSignerIdentity ( handles [ 1 ] ) ;
26-
27- signer = issuer . signer ;
28-
29- assetParams = createAssetParams ( {
30- options : { processMode : ProcessMode . Submit , signer } ,
31- } ) ;
15+ let restClient : RestClient ;
16+ let signer : string ;
17+ let issuer : Identity ;
18+ let holder : Identity ;
19+ let assetParams : ReturnType < typeof createAssetParams > ;
20+ let assetId : string ;
21+
22+ beforeAll ( async ( ) => {
23+ factory = await TestFactory . create ( { handles } ) ;
24+ ( { restClient } = factory ) ;
25+ issuer = factory . getSignerIdentity ( handles [ 0 ] ) ;
26+ holder = factory . getSignerIdentity ( handles [ 1 ] ) ;
27+
28+ signer = issuer . signer ;
29+
30+ assetParams = createAssetParams ( {
31+ options : { processMode : ProcessMode . Submit , signer } ,
3232 } ) ;
33+ } ) ;
3334
34- afterAll ( async ( ) => {
35- await factory . close ( ) ;
36- } ) ;
35+ afterAll ( async ( ) => {
36+ await factory . close ( ) ;
37+ } ) ;
3738
38- it ( 'should create and fetch the Asset' , async ( ) => {
39- assetId = await restClient . assets . createAndGetAssetId ( assetParams ) ;
39+ it ( 'should create and fetch the Asset' , async ( ) => {
40+ assetId = await restClient . assets . createAndGetAssetId ( assetParams ) ;
4041
41- const asset = await restClient . assets . getAsset ( assetId ) ;
42+ const asset = await restClient . assets . getAsset ( assetId ) ;
4243
43- expect ( asset ) . toMatchObject ( {
44- name : assetParams . name ,
45- assetType : assetParams . assetType ,
46- } ) ;
44+ expect ( asset ) . toMatchObject ( {
45+ name : assetParams . name ,
46+ assetType : assetParams . assetType ,
4747 } ) ;
48-
49- it ( 'should transfer the asset to holder' , async ( ) => {
50- const transferToHolderTx = await restClient . settlements . createDirectInstruction ( fungibleInstructionParams ( assetId , issuer . did , holder . did , {
51- options : { processMode : ProcessMode . Submit , signer } ,
52- } ) ) ;
53-
54- // should have created an instruction
55- expect ( ( transferToHolderTx as RestSuccessResult ) . instruction ) . toBeDefined ( ) ;
56-
57- const txData = await restClient . settlements . affirmInstruction (
58- // eslint-disable-next-line @typescript-eslint/no-explicit-any
59- ( transferToHolderTx as any ) . instruction ,
60- {
61- options : { processMode : ProcessMode . Submit , signer : holder . signer } ,
62- }
63- ) ;
64-
65- expect ( txData ) . toMatchObject ( {
66- transactions : expect . arrayContaining ( [
67- {
68- transactionTag : 'settlement.affirmInstructionWithCount' ,
69- type : 'single' ,
70- ...expectBasicTxInfo ,
71- } ,
72- ] ) ,
73- } ) ;
74-
75- const { results } = await restClient . assets . getAssetHolders ( assetId ) ;
76-
77- expect ( results . length ) . toEqual ( 2 ) ;
78- expect ( results ) . toContainEqual ( expect . objectContaining ( {
79- identity : issuer . did ,
80- balance : '99990' ,
81- } ) ) ;
82- expect ( results ) . toContainEqual ( expect . objectContaining ( {
83- identity : holder . did ,
84- balance : '10' ,
85- } ) ) ;
48+ } ) ;
49+
50+ it ( 'should transfer the asset to holder' , async ( ) => {
51+ const transferToHolderTx = await restClient . settlements . createDirectInstruction (
52+ fungibleInstructionParams ( assetId , issuer . did , holder . did , {
53+ options : { processMode : ProcessMode . Submit , signer } ,
54+ } )
55+ ) ;
56+
57+ // should have created an instruction
58+ expect ( ( transferToHolderTx as RestSuccessResult ) . instruction ) . toBeDefined ( ) ;
59+
60+ const txData = await restClient . settlements . affirmInstruction (
61+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
62+ ( transferToHolderTx as any ) . instruction ,
63+ {
64+ options : { processMode : ProcessMode . Submit , signer : holder . signer } ,
65+ }
66+ ) ;
67+
68+ expect ( txData ) . toMatchObject ( {
69+ transactions : expect . arrayContaining ( [
70+ {
71+ transactionTag : 'settlement.affirmInstructionWithCount' ,
72+ type : 'single' ,
73+ ...expectBasicTxInfo ,
74+ } ,
75+ ] ) ,
8676 } ) ;
8777
88- it ( 'should run controller transfer and return the asset back to the issuer' , async ( ) => {
89- const controllerTransferTx = await restClient . assets . controllerTransfer ( assetId , controllerTransferParams ( { did : holder . did , id : '0' } , 10 , {
90- options : { processMode : ProcessMode . Submit , signer } ,
91- } ) ) as RestSuccessResult ;
92-
93- expect ( controllerTransferTx ) . toMatchObject ( {
94- transactions : expect . arrayContaining ( [
95- {
96- transactionTag : 'asset.controllerTransfer' ,
97- type : 'single' ,
98- ...expectBasicTxInfo ,
99- } ,
100- ] ) ,
101- } ) ;
102-
103-
104- const { results } = await restClient . assets . getAssetHolders ( assetId ) ;
105-
106- expect ( results . length ) . toEqual ( 1 ) ;
107- expect ( results ) . toContainEqual ( expect . objectContaining ( {
108- identity : expect . objectContaining ( {
109- did : issuer . did ,
110- } ) ,
111- balance : expect . objectContaining ( {
112- amount : '100000' ,
113- } ) ,
114- } ) ) ;
78+ const { results } = await restClient . assets . getAssetHolders ( assetId ) ;
79+
80+ expect ( results . length ) . toEqual ( 2 ) ;
81+ expect ( results ) . toContainEqual (
82+ expect . objectContaining ( {
83+ identity : issuer . did ,
84+ balance : '99990' ,
85+ } )
86+ ) ;
87+ expect ( results ) . toContainEqual (
88+ expect . objectContaining ( {
89+ identity : holder . did ,
90+ balance : '10' ,
91+ } )
92+ ) ;
93+ } ) ;
94+
95+ it ( 'should run controller transfer and return the asset back to the issuer' , async ( ) => {
96+ const controllerTransferTx = ( await restClient . assets . controllerTransfer (
97+ assetId ,
98+ controllerTransferParams ( { did : holder . did , id : '0' } , 10 , {
99+ options : { processMode : ProcessMode . Submit , signer } ,
100+ } )
101+ ) ) as RestSuccessResult ;
102+
103+ expect ( controllerTransferTx ) . toMatchObject ( {
104+ transactions : expect . arrayContaining ( [
105+ {
106+ transactionTag : 'asset.controllerTransfer' ,
107+ type : 'single' ,
108+ ...expectBasicTxInfo ,
109+ } ,
110+ ] ) ,
115111 } ) ;
112+
113+ const { results } = await restClient . assets . getAssetHolders ( assetId ) ;
114+
115+ expect ( results . length ) . toBeGreaterThan ( 1 ) ;
116+ expect ( results ) . toEqual (
117+ expect . arrayContaining ( [
118+ {
119+ identity : issuer . did ,
120+ balance : '100000' ,
121+ } ,
122+ ] )
123+ ) ;
124+ } ) ;
116125} ) ;
0 commit comments