@@ -5,6 +5,7 @@ import { createTestProviderTools } from '../../test/stub/provider';
5
5
import {
6
6
buildApproveTransactionData ,
7
7
buildIncreaseAllowanceTransactionData ,
8
+ buildPermit2ApproveTransactionData ,
8
9
} from '../../test/data/confirmations/token-approve' ;
9
10
import { buildSetApproveForAllTransactionData } from '../../test/data/confirmations/set-approval-for-all' ;
10
11
import {
@@ -19,6 +20,8 @@ import {
19
20
20
21
const DATA_MOCK = '0x12345678' ;
21
22
const ADDRESS_MOCK = '0x1234567890123456789012345678901234567890' ;
23
+ const ADDRESS_2_MOCK = '0x1234567890123456789012345678901234567891' ;
24
+ const EXPIRATION_MOCK = 1234567890 ;
22
25
const AMOUNT_MOCK = 123 ;
23
26
24
27
describe ( 'Transaction.utils' , function ( ) {
@@ -39,7 +42,29 @@ describe('Transaction.utils', function () {
39
42
it ( 'should not throw errors when called without arguments' , ( ) => {
40
43
expect ( ( ) => parseStandardTokenTransactionData ( ) ) . not . toThrow ( ) ;
41
44
} ) ;
45
+
46
+ it ( 'decodes Permit2 function' , ( ) => {
47
+ const result = parseStandardTokenTransactionData (
48
+ buildPermit2ApproveTransactionData (
49
+ ADDRESS_MOCK ,
50
+ ADDRESS_2_MOCK ,
51
+ AMOUNT_MOCK ,
52
+ EXPIRATION_MOCK ,
53
+ ) ,
54
+ ) ;
55
+
56
+ expect ( result . name ) . toBe ( 'approve' ) ;
57
+ expect ( result . args ) . toStrictEqual (
58
+ expect . objectContaining ( {
59
+ token : ADDRESS_MOCK ,
60
+ spender : ADDRESS_2_MOCK ,
61
+ expiration : EXPIRATION_MOCK ,
62
+ } ) ,
63
+ ) ;
64
+ expect ( result . args . amount . toString ( ) ) . toBe ( AMOUNT_MOCK . toString ( ) ) ;
65
+ } ) ;
42
66
} ) ;
67
+
43
68
describe ( 'isEIP1559Transaction' , function ( ) {
44
69
it ( 'should return true if both maxFeePerGas and maxPriorityFeePerGas are hex strings' , ( ) => {
45
70
expect (
@@ -458,6 +483,8 @@ describe('Transaction.utils', function () {
458
483
amountOrTokenId : new BigNumber ( AMOUNT_MOCK ) ,
459
484
isApproveAll : false ,
460
485
isRevokeAll : false ,
486
+ name : 'approve' ,
487
+ tokenAddress : undefined ,
461
488
} ) ;
462
489
} ) ;
463
490
@@ -470,6 +497,8 @@ describe('Transaction.utils', function () {
470
497
amountOrTokenId : new BigNumber ( AMOUNT_MOCK ) ,
471
498
isApproveAll : false ,
472
499
isRevokeAll : false ,
500
+ name : 'increaseAllowance' ,
501
+ tokenAddress : undefined ,
473
502
} ) ;
474
503
} ) ;
475
504
@@ -482,6 +511,8 @@ describe('Transaction.utils', function () {
482
511
amountOrTokenId : undefined ,
483
512
isApproveAll : true ,
484
513
isRevokeAll : false ,
514
+ name : 'setApprovalForAll' ,
515
+ tokenAddress : undefined ,
485
516
} ) ;
486
517
} ) ;
487
518
@@ -494,6 +525,27 @@ describe('Transaction.utils', function () {
494
525
amountOrTokenId : undefined ,
495
526
isApproveAll : false ,
496
527
isRevokeAll : true ,
528
+ name : 'setApprovalForAll' ,
529
+ tokenAddress : undefined ,
530
+ } ) ;
531
+ } ) ;
532
+
533
+ it ( 'returns parsed data if Permit2 approve' , ( ) => {
534
+ expect (
535
+ parseApprovalTransactionData (
536
+ buildPermit2ApproveTransactionData (
537
+ ADDRESS_MOCK ,
538
+ ADDRESS_2_MOCK ,
539
+ AMOUNT_MOCK ,
540
+ EXPIRATION_MOCK ,
541
+ ) ,
542
+ ) ,
543
+ ) . toStrictEqual ( {
544
+ amountOrTokenId : new BigNumber ( AMOUNT_MOCK ) ,
545
+ isApproveAll : false ,
546
+ isRevokeAll : false ,
547
+ name : 'approve' ,
548
+ tokenAddress : ADDRESS_MOCK ,
497
549
} ) ;
498
550
} ) ;
499
551
} ) ;
0 commit comments