@@ -7,7 +7,7 @@ import { newExportTxFromBaseFee, newImportTxFromBaseFee } from '../vms/evm';
7
7
import { getBurnedAmountByTx } from './getBurnedAmountByTx' ;
8
8
import { testContext } from '../fixtures/context' ;
9
9
import { testEthAddress1 , testAddress1 , testAddress2 } from '../fixtures/vms' ;
10
- import { nodeId } from '../fixtures/common' ;
10
+ import { id , nodeId } from '../fixtures/common' ;
11
11
import { Utxo } from '../serializable/avax/utxo' ;
12
12
import { OutputOwners , TransferOutput } from '../serializable/fxs/secp256k1' ;
13
13
import { Address , Id } from '../serializable/fxs/common' ;
@@ -30,6 +30,18 @@ import type { EVMTx } from '../serializable/evm/abstractTx';
30
30
import { testUTXOID1 , testUTXOID2 } from '../fixtures/transactions' ;
31
31
import { costCorethTx } from './costs' ;
32
32
import { StakeableLockOut } from '../serializable/pvm' ;
33
+ import {
34
+ newConvertSubnetToL1Tx ,
35
+ newIncreaseL1ValidatorBalanceTx ,
36
+ newRegisterL1ValidatorTx ,
37
+ } from '../vms/pvm/etna-builder' ;
38
+ import { feeState , l1Validator } from '../fixtures/pvm' ;
39
+ import {
40
+ bigIntPr ,
41
+ blsSignatureBytes ,
42
+ bytesBytes ,
43
+ stringPr ,
44
+ } from '../fixtures/primitives' ;
33
45
34
46
const getUtxoMock = (
35
47
utxoId : Id ,
@@ -95,7 +107,7 @@ describe('getBurnedAmountByTx', () => {
95
107
1n ,
96
108
) ;
97
109
98
- const amounts = getBurnedAmountByTx ( tx . getTx ( ) as EVMTx ) ;
110
+ const amounts = getBurnedAmountByTx ( tx . getTx ( ) as EVMTx , testContext ) ;
99
111
expect ( amounts . size ) . toEqual ( 1 ) ;
100
112
expect ( amounts . get ( testContext . avaxAssetID ) ) . toEqual (
101
113
baseFee * costCorethTx ( tx ) ,
@@ -116,7 +128,7 @@ describe('getBurnedAmountByTx', () => {
116
128
baseFee ,
117
129
) ;
118
130
119
- const amounts = getBurnedAmountByTx ( tx . getTx ( ) as EVMTx ) ;
131
+ const amounts = getBurnedAmountByTx ( tx . getTx ( ) as EVMTx , testContext ) ;
120
132
expect ( amounts . size ) . toEqual ( 1 ) ;
121
133
expect ( amounts . get ( testContext . avaxAssetID ) ) . toEqual (
122
134
baseFee * costCorethTx ( tx ) ,
@@ -139,7 +151,7 @@ describe('getBurnedAmountByTx', () => {
139
151
[ output ] ,
140
152
) . getTx ( ) as AvaxTx ;
141
153
142
- const amounts = getBurnedAmountByTx ( tx ) ;
154
+ const amounts = getBurnedAmountByTx ( tx , testContext ) ;
143
155
expect ( amounts . size ) . toEqual ( 1 ) ;
144
156
expect ( amounts . get ( testContext . avaxAssetID ) ) . toEqual (
145
157
testContext . baseTxFee ,
@@ -164,7 +176,7 @@ describe('getBurnedAmountByTx', () => {
164
176
[ output1 , output2 , output3 ] ,
165
177
) . getTx ( ) as AvaxTx ;
166
178
167
- const amounts = getBurnedAmountByTx ( tx ) ;
179
+ const amounts = getBurnedAmountByTx ( tx , testContext ) ;
168
180
expect ( amounts . size ) . toEqual ( 1 ) ;
169
181
expect ( amounts . get ( testContext . avaxAssetID ) ) . toEqual (
170
182
testContext . baseTxFee ,
@@ -192,7 +204,7 @@ describe('getBurnedAmountByTx', () => {
192
204
[ output1 , output2 , output3 ] ,
193
205
) . getTx ( ) as AvaxTx ;
194
206
195
- const amounts = getBurnedAmountByTx ( tx ) ;
207
+ const amounts = getBurnedAmountByTx ( tx , testContext ) ;
196
208
expect ( amounts . size ) . toEqual ( 1 ) ;
197
209
expect ( amounts . get ( testContext . avaxAssetID ) ) . toEqual (
198
210
testContext . baseTxFee ,
@@ -221,7 +233,7 @@ describe('getBurnedAmountByTx', () => {
221
233
[ output ] ,
222
234
) . getTx ( ) as AvaxTx ;
223
235
224
- const amounts = getBurnedAmountByTx ( tx ) ;
236
+ const amounts = getBurnedAmountByTx ( tx , testContext ) ;
225
237
expect ( amounts . size ) . toEqual ( 1 ) ;
226
238
expect ( amounts . get ( testContext . avaxAssetID ) ) . toEqual (
227
239
testContext . baseTxFee ,
@@ -243,7 +255,7 @@ describe('getBurnedAmountByTx', () => {
243
255
[ output1 , output2 , output3 ] ,
244
256
) . getTx ( ) as AvaxTx ;
245
257
246
- const amounts = getBurnedAmountByTx ( tx ) ;
258
+ const amounts = getBurnedAmountByTx ( tx , testContext ) ;
247
259
expect ( amounts . size ) . toEqual ( 1 ) ;
248
260
expect ( amounts . get ( testContext . avaxAssetID ) ) . toEqual (
249
261
testContext . baseTxFee ,
@@ -266,7 +278,7 @@ describe('getBurnedAmountByTx', () => {
266
278
[ output1 , output2 , output3 ] ,
267
279
) . getTx ( ) as AvaxTx ;
268
280
269
- const amounts = getBurnedAmountByTx ( tx ) ;
281
+ const amounts = getBurnedAmountByTx ( tx , testContext ) ;
270
282
expect ( amounts . size ) . toEqual ( 1 ) ;
271
283
expect ( amounts . get ( testContext . avaxAssetID ) ) . toEqual (
272
284
testContext . baseTxFee ,
@@ -288,7 +300,7 @@ describe('getBurnedAmountByTx', () => {
288
300
[ testAddress1 ] ,
289
301
) . getTx ( ) as AvaxTx ;
290
302
291
- const amounts = getBurnedAmountByTx ( tx ) ;
303
+ const amounts = getBurnedAmountByTx ( tx , testContext ) ;
292
304
expect ( amounts . size ) . toEqual ( 1 ) ;
293
305
expect ( amounts . get ( testContext . avaxAssetID ) ) . toEqual (
294
306
testContext . baseTxFee ,
@@ -313,7 +325,7 @@ describe('getBurnedAmountByTx', () => {
313
325
[ output ] ,
314
326
) . getTx ( ) as AvaxTx ;
315
327
316
- const amounts = getBurnedAmountByTx ( tx ) ;
328
+ const amounts = getBurnedAmountByTx ( tx , testContext ) ;
317
329
expect ( amounts . size ) . toEqual ( 1 ) ;
318
330
expect ( amounts . get ( testContext . avaxAssetID ) ) . toEqual (
319
331
testContext . baseTxFee ,
@@ -335,7 +347,7 @@ describe('getBurnedAmountByTx', () => {
335
347
[ output1 , output2 , output3 ] ,
336
348
) . getTx ( ) as AvaxTx ;
337
349
338
- const amounts = getBurnedAmountByTx ( tx ) ;
350
+ const amounts = getBurnedAmountByTx ( tx , testContext ) ;
339
351
expect ( amounts . size ) . toEqual ( 1 ) ;
340
352
expect ( amounts . get ( testContext . avaxAssetID ) ) . toEqual (
341
353
testContext . baseTxFee ,
@@ -358,7 +370,7 @@ describe('getBurnedAmountByTx', () => {
358
370
[ output1 , output2 , output3 ] ,
359
371
) . getTx ( ) as AvaxTx ;
360
372
361
- const amounts = getBurnedAmountByTx ( tx ) ;
373
+ const amounts = getBurnedAmountByTx ( tx , testContext ) ;
362
374
expect ( amounts . size ) . toEqual ( 1 ) ;
363
375
expect ( amounts . get ( testContext . avaxAssetID ) ) . toEqual (
364
376
testContext . baseTxFee ,
@@ -380,7 +392,7 @@ describe('getBurnedAmountByTx', () => {
380
392
[ testAddress1 ] ,
381
393
) . getTx ( ) as AvaxTx ;
382
394
383
- const amounts = getBurnedAmountByTx ( tx ) ;
395
+ const amounts = getBurnedAmountByTx ( tx , testContext ) ;
384
396
expect ( amounts . size ) . toEqual ( 1 ) ;
385
397
expect ( amounts . get ( testContext . avaxAssetID ) ) . toEqual (
386
398
testContext . baseTxFee ,
@@ -407,7 +419,7 @@ describe('getBurnedAmountByTx', () => {
407
419
3 ,
408
420
) . getTx ( ) as AvaxTx ;
409
421
410
- const amounts = getBurnedAmountByTx ( tx ) ;
422
+ const amounts = getBurnedAmountByTx ( tx , testContext ) ;
411
423
expect ( amounts . size ) . toEqual ( 1 ) ;
412
424
expect ( amounts . get ( testContext . avaxAssetID ) ) . toEqual (
413
425
testContext . addPrimaryNetworkValidatorFee ,
@@ -442,7 +454,7 @@ describe('getBurnedAmountByTx', () => {
442
454
3 ,
443
455
) . getTx ( ) as AvaxTx ;
444
456
445
- const amounts = getBurnedAmountByTx ( tx ) ;
457
+ const amounts = getBurnedAmountByTx ( tx , testContext ) ;
446
458
expect ( amounts . size ) . toEqual ( 1 ) ;
447
459
expect ( amounts . get ( testContext . avaxAssetID ) ) . toEqual (
448
460
testContext . addPrimaryNetworkValidatorFee ,
@@ -473,7 +485,7 @@ describe('getBurnedAmountByTx', () => {
473
485
3 ,
474
486
) . getTx ( ) as AvaxTx ;
475
487
476
- const amounts = getBurnedAmountByTx ( tx ) ;
488
+ const amounts = getBurnedAmountByTx ( tx , testContext ) ;
477
489
expect ( amounts . size ) . toEqual ( 1 ) ;
478
490
expect ( amounts . get ( testContext . avaxAssetID ) ) . toEqual (
479
491
testContext . addPrimaryNetworkValidatorFee ,
@@ -499,7 +511,7 @@ describe('getBurnedAmountByTx', () => {
499
511
[ testAddress1 ] ,
500
512
) . getTx ( ) as AvaxTx ;
501
513
502
- const amounts = getBurnedAmountByTx ( tx ) ;
514
+ const amounts = getBurnedAmountByTx ( tx , testContext ) ;
503
515
expect ( amounts . size ) . toEqual ( 1 ) ;
504
516
expect ( amounts . get ( testContext . avaxAssetID ) ) . toEqual (
505
517
testContext . addPrimaryNetworkDelegatorFee ,
@@ -533,7 +545,7 @@ describe('getBurnedAmountByTx', () => {
533
545
[ testAddress1 ] ,
534
546
) . getTx ( ) as AvaxTx ;
535
547
536
- const amounts = getBurnedAmountByTx ( tx ) ;
548
+ const amounts = getBurnedAmountByTx ( tx , testContext ) ;
537
549
expect ( amounts . size ) . toEqual ( 1 ) ;
538
550
expect ( amounts . get ( testContext . avaxAssetID ) ) . toEqual (
539
551
testContext . addPrimaryNetworkDelegatorFee ,
@@ -563,7 +575,7 @@ describe('getBurnedAmountByTx', () => {
563
575
[ testAddress1 ] ,
564
576
) . getTx ( ) as AvaxTx ;
565
577
566
- const amounts = getBurnedAmountByTx ( tx ) ;
578
+ const amounts = getBurnedAmountByTx ( tx , testContext ) ;
567
579
expect ( amounts . size ) . toEqual ( 1 ) ;
568
580
expect ( amounts . get ( testContext . avaxAssetID ) ) . toEqual (
569
581
testContext . addPrimaryNetworkDelegatorFee ,
@@ -584,7 +596,7 @@ describe('getBurnedAmountByTx', () => {
584
596
[ testAddress1 ] ,
585
597
) . getTx ( ) as AvaxTx ;
586
598
587
- const amounts = getBurnedAmountByTx ( tx ) ;
599
+ const amounts = getBurnedAmountByTx ( tx , testContext ) ;
588
600
expect ( amounts . size ) . toEqual ( 1 ) ;
589
601
expect ( amounts . get ( testContext . avaxAssetID ) ) . toEqual (
590
602
testContext . createSubnetTxFee ,
@@ -610,7 +622,7 @@ describe('getBurnedAmountByTx', () => {
610
622
[ 0 ] ,
611
623
) . getTx ( ) as AvaxTx ;
612
624
613
- const amounts = getBurnedAmountByTx ( tx ) ;
625
+ const amounts = getBurnedAmountByTx ( tx , testContext ) ;
614
626
expect ( amounts . size ) . toEqual ( 1 ) ;
615
627
expect ( amounts . get ( testContext . avaxAssetID ) ) . toEqual (
616
628
testContext . createBlockchainTxFee ,
@@ -637,12 +649,76 @@ describe('getBurnedAmountByTx', () => {
637
649
[ 0 ] ,
638
650
) . getTx ( ) as AvaxTx ;
639
651
640
- const amounts = getBurnedAmountByTx ( tx ) ;
652
+ const amounts = getBurnedAmountByTx ( tx , testContext ) ;
641
653
expect ( amounts . size ) . toEqual ( 1 ) ;
642
654
expect ( amounts . get ( testContext . avaxAssetID ) ) . toEqual (
643
655
testContext . addSubnetValidatorFee ,
644
656
) ;
645
657
} ) ;
646
658
} ) ;
659
+
660
+ it ( 'calculates the burned amount of ConvertSubnetToL1 tx correctly' , ( ) => {
661
+ const utxo1 = getUtxoMock ( testUTXOID1 , 5000000n ) ;
662
+ const utxo2 = getUtxoMock ( testUTXOID2 , 6000000n ) ;
663
+
664
+ const tx = newConvertSubnetToL1Tx (
665
+ {
666
+ address : testAddress1 ,
667
+ chainId : id ( ) . toString ( ) ,
668
+ feeState : feeState ( ) ,
669
+ fromAddressesBytes : [ testAddress1 ] ,
670
+ subnetAuth : [ 0 ] ,
671
+ subnetId : id ( ) . toString ( ) ,
672
+ utxos : [ utxo1 , utxo2 ] ,
673
+ validators : [ l1Validator ( ) ] ,
674
+ } ,
675
+ testContext ,
676
+ ) . getTx ( ) as AvaxTx ;
677
+
678
+ const amounts = getBurnedAmountByTx ( tx , testContext ) ;
679
+ expect ( amounts . size ) . toEqual ( 1 ) ;
680
+ expect ( amounts . get ( testContext . avaxAssetID ) ) . toEqual ( 749n ) ;
681
+ } ) ;
682
+ } ) ;
683
+
684
+ it ( 'calculates the burned amount of RegisterL1Validator tx correctly' , ( ) => {
685
+ const utxo1 = getUtxoMock ( testUTXOID1 , 5000000n ) ;
686
+ const utxo2 = getUtxoMock ( testUTXOID2 , 6000000n ) ;
687
+
688
+ const tx = newRegisterL1ValidatorTx (
689
+ {
690
+ feeState : feeState ( ) ,
691
+ fromAddressesBytes : [ testAddress1 ] ,
692
+ utxos : [ utxo1 , utxo2 ] ,
693
+ balance : bigIntPr ( ) . value ( ) ,
694
+ blsSignature : blsSignatureBytes ( ) ,
695
+ message : bytesBytes ( ) ,
696
+ } ,
697
+ testContext ,
698
+ ) . getTx ( ) as AvaxTx ;
699
+
700
+ const amounts = getBurnedAmountByTx ( tx , testContext ) ;
701
+ expect ( amounts . size ) . toEqual ( 1 ) ;
702
+ expect ( amounts . get ( testContext . avaxAssetID ) ) . toEqual ( 416n ) ;
703
+ } ) ;
704
+
705
+ it ( 'calculates the burned amount of RegisterL1Validator tx correctly' , ( ) => {
706
+ const utxo1 = getUtxoMock ( testUTXOID1 , 5000000n ) ;
707
+ const utxo2 = getUtxoMock ( testUTXOID2 , 6000000n ) ;
708
+
709
+ const tx = newIncreaseL1ValidatorBalanceTx (
710
+ {
711
+ feeState : feeState ( ) ,
712
+ fromAddressesBytes : [ testAddress1 ] ,
713
+ utxos : [ utxo1 , utxo2 ] ,
714
+ balance : bigIntPr ( ) . value ( ) ,
715
+ validationId : stringPr ( ) . value ( ) ,
716
+ } ,
717
+ testContext ,
718
+ ) . getTx ( ) as AvaxTx ;
719
+
720
+ const amounts = getBurnedAmountByTx ( tx , testContext ) ;
721
+ expect ( amounts . size ) . toEqual ( 1 ) ;
722
+ expect ( amounts . get ( testContext . avaxAssetID ) ) . toEqual ( 342n ) ;
647
723
} ) ;
648
724
} ) ;
0 commit comments