@@ -71,6 +71,107 @@ function getSubscriptionStreamFromFetch(streamHolder: { stream: ReadableStream<U
71
71
* @group browser
72
72
*/
73
73
describe ( 'TransactionResponse' , ( ) => {
74
+ beforeEach ( ( ) => {
75
+ vi . resetAllMocks ( ) ;
76
+ } ) ;
77
+
78
+ it ( 'builds tx response from active sendAndAwaitStatus subscription' , async ( ) => {
79
+ using launched = await launchTestNode ( ) ;
80
+
81
+ const {
82
+ provider,
83
+ wallets : [ adminWallet ] ,
84
+ } = launched ;
85
+
86
+ const submitAndAwaitStatusSpy = vi . spyOn ( provider . operations , 'submitAndAwaitStatus' ) ;
87
+ const statusChangeSpy = vi . spyOn ( provider . operations , 'statusChange' ) ;
88
+ const getTransactionWithReceiptsSpy = vi . spyOn (
89
+ provider . operations ,
90
+ 'getTransactionWithReceipts'
91
+ ) ;
92
+
93
+ const transferTx = await adminWallet . transfer (
94
+ Wallet . generate ( ) . address ,
95
+ 100 ,
96
+ await provider . getBaseAssetId ( )
97
+ ) ;
98
+ const result = await transferTx . waitForResult ( ) ;
99
+
100
+ expect ( transferTx . id ) . toEqual ( result . id ) ;
101
+ expect ( result . receipts . length ) . toBe ( 2 ) ;
102
+
103
+ expect ( submitAndAwaitStatusSpy ) . toHaveBeenCalledTimes ( 1 ) ; // sends tx and gets result
104
+ expect ( statusChangeSpy ) . toHaveBeenCalledTimes ( 0 ) ; // we already have the status
105
+ expect ( getTransactionWithReceiptsSpy ) . toHaveBeenCalledTimes ( 0 ) ; // we already have the raw tx
106
+ } ) ;
107
+
108
+ it ( 'builds tx response from transaction ID' , async ( ) => {
109
+ using launched = await launchTestNode ( ) ;
110
+
111
+ const {
112
+ provider,
113
+ wallets : [ adminWallet ] ,
114
+ } = launched ;
115
+
116
+ const submitAndAwaitStatusSpy = vi . spyOn ( provider . operations , 'submitAndAwaitStatus' ) ;
117
+ const statusChangeSpy = vi . spyOn ( provider . operations , 'statusChange' ) ;
118
+ const getTransactionWithReceiptsSpy = vi . spyOn (
119
+ provider . operations ,
120
+ 'getTransactionWithReceipts'
121
+ ) ;
122
+
123
+ const transferTx = await adminWallet . transfer (
124
+ Wallet . generate ( ) . address ,
125
+ 100 ,
126
+ await provider . getBaseAssetId ( )
127
+ ) ;
128
+ const response = new TransactionResponse ( transferTx . id , provider , await provider . getChainId ( ) ) ;
129
+ const result = await response . waitForResult ( ) ;
130
+
131
+ expect ( transferTx . id ) . toEqual ( result . id ) ;
132
+ expect ( result . receipts . length ) . toBe ( 2 ) ;
133
+
134
+ expect ( submitAndAwaitStatusSpy ) . toHaveBeenCalledTimes ( 1 ) ; // sends tx
135
+ expect ( statusChangeSpy ) . toHaveBeenCalledTimes ( 1 ) ; // awaits result (can get receipts)
136
+ expect ( getTransactionWithReceiptsSpy ) . toHaveBeenCalledTimes ( 1 ) ; // gets raw transaction and receipts
137
+ } ) ;
138
+
139
+ it ( 'builds tx response from transaction request instance' , async ( ) => {
140
+ using launched = await launchTestNode ( ) ;
141
+
142
+ const {
143
+ provider,
144
+ wallets : [ adminWallet ] ,
145
+ } = launched ;
146
+
147
+ const submitAndAwaitStatusSpy = vi . spyOn ( provider . operations , 'submitAndAwaitStatus' ) ;
148
+ const statusChangeSpy = vi . spyOn ( provider . operations , 'statusChange' ) ;
149
+ const getTransactionWithReceiptsSpy = vi . spyOn (
150
+ provider . operations ,
151
+ 'getTransactionWithReceipts'
152
+ ) ;
153
+
154
+ const transferTxRequest = await adminWallet . createTransfer (
155
+ Wallet . generate ( ) . address ,
156
+ 100 ,
157
+ await provider . getBaseAssetId ( )
158
+ ) ;
159
+ const transferTx = await adminWallet . sendTransaction ( transferTxRequest ) ;
160
+ const response = new TransactionResponse (
161
+ transferTxRequest ,
162
+ provider ,
163
+ await provider . getChainId ( )
164
+ ) ;
165
+ const result = await response . waitForResult ( ) ;
166
+
167
+ expect ( transferTx . id ) . toEqual ( result . id ) ;
168
+ expect ( result . receipts . length ) . toBe ( 2 ) ;
169
+
170
+ expect ( submitAndAwaitStatusSpy ) . toHaveBeenCalledTimes ( 1 ) ; // sends tx
171
+ expect ( statusChangeSpy ) . toHaveBeenCalledTimes ( 1 ) ; // awaits result and gets receipts
172
+ expect ( getTransactionWithReceiptsSpy ) . toHaveBeenCalledTimes ( 0 ) ; // we already have raw tx
173
+ } ) ;
174
+
74
175
it ( 'should ensure create method waits till a transaction response is given' , async ( ) => {
75
176
using launched = await launchTestNode ( ) ;
76
177
0 commit comments