@@ -162,22 +162,22 @@ describe("check fee analyzer", () => {
162
162
perWeightUnitFee : 0n ,
163
163
methods : {
164
164
"TestModule1.Method_1" : {
165
- baseFee : 10n ,
165
+ baseFee : 9n ,
166
166
weight : 0n ,
167
167
perWeightUnitFee : 0n ,
168
168
} ,
169
169
"TestModule1.Method_10" : {
170
- baseFee : 10n ,
170
+ baseFee : 8n ,
171
171
weight : 0n ,
172
172
perWeightUnitFee : 0n ,
173
173
} ,
174
174
"TestModule2.Method_4" : {
175
- baseFee : 10n ,
175
+ baseFee : 7n ,
176
176
weight : 0n ,
177
177
perWeightUnitFee : 0n ,
178
178
} ,
179
179
"TestModule2.Method_7" : {
180
- baseFee : 10n ,
180
+ baseFee : 6n ,
181
181
weight : 0n ,
182
182
perWeightUnitFee : 0n ,
183
183
} ,
@@ -191,63 +191,93 @@ describe("check fee analyzer", () => {
191
191
} ) ;
192
192
193
193
it ( "with multiple zk programs" , async ( ) => {
194
- expect . assertions ( 4 ) ;
194
+ expect . assertions ( 12 ) ;
195
195
const testModule1 = appChain . runtime . resolve ( "TestModule1" ) ;
196
196
const testModule2 = appChain . runtime . resolve ( "TestModule2" ) ;
197
197
const faucet = appChain . runtime . resolve ( "Faucet" ) ;
198
+ const transactionFeeModule = appChain . protocol . resolve ( "TransactionFee" ) ;
198
199
199
200
const tx1 = await appChain . transaction (
200
201
senderKey . toPublicKey ( ) ,
201
202
async ( ) => {
202
203
await faucet . drip ( ) ;
203
- }
204
+ } ,
205
+ { nonce : 0 }
204
206
) ;
205
207
206
208
await tx1 . sign ( ) ;
207
209
await tx1 . send ( ) ;
208
210
209
- await appChain . produceBlock ( ) ;
210
-
211
211
const tx2 = await appChain . transaction (
212
212
senderKey . toPublicKey ( ) ,
213
213
async ( ) => {
214
214
await testModule1 . Method_1 ( ) ;
215
- }
215
+ } ,
216
+ { nonce : 4 }
216
217
) ;
217
218
218
219
await tx2 . sign ( ) ;
219
220
await tx2 . send ( ) ;
221
+ const methodId2 = tx2 . transaction ?. methodId . toBigInt ( ) ;
222
+ expectDefined ( methodId2 ) ;
223
+ const transactionFeeConfig2 =
224
+ transactionFeeModule . feeAnalyzer . getFeeConfig ( methodId2 ) ;
225
+ const transactionFee2 = transactionFeeModule . getFee ( transactionFeeConfig2 ) ;
226
+ expect ( transactionFee2 . toString ( ) ) . toEqual ( "9" ) ;
220
227
221
228
const tx3 = await appChain . transaction (
222
229
senderKey . toPublicKey ( ) ,
223
230
async ( ) => {
224
231
await testModule2 . Method_4 ( ) ;
225
- }
232
+ } ,
233
+ { nonce : 1 }
226
234
) ;
227
235
228
236
await tx3 . sign ( ) ;
229
237
await tx3 . send ( ) ;
238
+ const methodId3 = tx3 . transaction ?. methodId . toBigInt ( ) ;
239
+ expectDefined ( methodId3 ) ;
240
+ const transactionFeeConfig3 =
241
+ transactionFeeModule . feeAnalyzer . getFeeConfig ( methodId3 ) ;
242
+ const transactionFee3 = transactionFeeModule . getFee ( transactionFeeConfig3 ) ;
243
+ expect ( transactionFee3 . toString ( ) ) . toEqual ( "7" ) ;
230
244
231
245
const tx4 = await appChain . transaction (
232
246
senderKey . toPublicKey ( ) ,
233
247
async ( ) => {
234
248
await testModule2 . Method_7 ( ) ;
235
- }
249
+ } ,
250
+ { nonce : 2 }
236
251
) ;
237
252
238
253
await tx4 . sign ( ) ;
239
254
await tx4 . send ( ) ;
240
255
256
+ const methodId4 = tx4 . transaction ?. methodId . toBigInt ( ) ;
257
+ expectDefined ( methodId4 ) ;
258
+ const transactionFeeConfig4 =
259
+ transactionFeeModule . feeAnalyzer . getFeeConfig ( methodId4 ) ;
260
+ const transactionFee4 = transactionFeeModule . getFee ( transactionFeeConfig4 ) ;
261
+ expect ( transactionFee4 . toString ( ) ) . toEqual ( "6" ) ;
262
+
241
263
const tx5 = await appChain . transaction (
242
264
senderKey . toPublicKey ( ) ,
243
265
async ( ) => {
244
266
await testModule1 . Method_10 ( ) ;
245
- }
267
+ } ,
268
+ { nonce : 3 }
246
269
) ;
247
270
248
271
await tx5 . sign ( ) ;
249
272
await tx5 . send ( ) ;
250
273
274
+ const methodId5 = tx5 . transaction ?. methodId . toBigInt ( ) ;
275
+ expectDefined ( methodId5 ) ;
276
+ const transactionFeeConfig5 =
277
+ transactionFeeModule . feeAnalyzer . getFeeConfig ( methodId5 ) ;
278
+ const transactionFee5 = transactionFeeModule . getFee ( transactionFeeConfig5 ) ;
279
+ expect ( transactionFee5 . toString ( ) ) . toEqual ( "8" ) ;
280
+
251
281
await appChain . produceBlock ( ) ;
252
282
253
283
const senderBalance = await appChain . query . runtime . Balances . balances . get (
@@ -266,9 +296,9 @@ describe("check fee analyzer", () => {
266
296
) ;
267
297
268
298
expectDefined ( senderBalance ) ;
269
- expect ( senderBalance . toString ( ) ) . toBe ( "990 " ) ;
299
+ expect ( senderBalance . toString ( ) ) . toBe ( "970 " ) ;
270
300
271
301
expectDefined ( feeRecipientBalance ) ;
272
- expect ( feeRecipientBalance . toString ( ) ) . toBe ( "10 " ) ;
302
+ expect ( feeRecipientBalance . toString ( ) ) . toBe ( "30 " ) ;
273
303
} ) ;
274
304
} ) ;
0 commit comments