@@ -5,112 +5,121 @@ import { ProcessMode } from '~/rest/common';
5
5
import { Identity } from '~/rest/identities/interfaces' ;
6
6
import { RestSuccessResult } from '~/rest/interfaces' ;
7
7
import { fungibleInstructionParams } from '~/rest/settlements/params' ;
8
+
8
9
import { expectBasicTxInfo } from '../utils' ;
9
10
10
11
const handles = [ 'issuer' , 'holder' ] ;
11
12
let factory : TestFactory ;
12
13
13
14
describe ( '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 } ,
32
32
} ) ;
33
+ } ) ;
33
34
34
- afterAll ( async ( ) => {
35
- await factory . close ( ) ;
36
- } ) ;
35
+ afterAll ( async ( ) => {
36
+ await factory . close ( ) ;
37
+ } ) ;
37
38
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 ) ;
40
41
41
- const asset = await restClient . assets . getAsset ( assetId ) ;
42
+ const asset = await restClient . assets . getAsset ( assetId ) ;
42
43
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 ,
47
47
} ) ;
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
+ ] ) ,
86
76
} ) ;
87
77
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
+ ] ) ,
115
111
} ) ;
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
+ } ) ;
116
125
} ) ;
0 commit comments