|
9 | 9 | stakingWithdrawInstructionsIndexes, |
10 | 10 | } from '../../src/lib/constants'; |
11 | 11 | import BigNumber from 'bignumber.js'; |
12 | | -import { TOKEN_2022_PROGRAM_ID } from '@solana/spl-token'; |
| 12 | +import { TOKEN_2022_PROGRAM_ID, ASSOCIATED_TOKEN_PROGRAM_ID } from '@solana/spl-token'; |
13 | 13 |
|
14 | 14 | describe('SOL util library', function () { |
15 | 15 | describe('isValidAddress', function () { |
@@ -547,4 +547,56 @@ describe('SOL util library', function () { |
547 | 547 | }); |
548 | 548 | }); |
549 | 549 | }); |
| 550 | + |
| 551 | + describe('isIdempotentAtaInstruction', function () { |
| 552 | + const mockKeys = [ |
| 553 | + { pubkey: new PublicKey('9i8CSiz2un7rfuNvTMt1tTXbHSaMkPZyJ4MexY1yeZBD'), isSigner: true, isWritable: true }, |
| 554 | + { pubkey: new PublicKey('3F7X7ifwMR29Z3t1YamFg6yzCcsSkjAZpZF8yU1kWURh'), isSigner: false, isWritable: true }, |
| 555 | + ]; |
| 556 | + |
| 557 | + it('should return true for idempotent ATA instruction with discriminator byte 1', function () { |
| 558 | + const instruction = new TransactionInstruction({ |
| 559 | + programId: ASSOCIATED_TOKEN_PROGRAM_ID, |
| 560 | + keys: mockKeys, |
| 561 | + data: Buffer.from([1]), |
| 562 | + }); |
| 563 | + Utils.isIdempotentAtaInstruction(instruction).should.equal(true); |
| 564 | + }); |
| 565 | + |
| 566 | + it('should return true for idempotent ATA instruction from base64 "AQ=="', function () { |
| 567 | + const instruction = new TransactionInstruction({ |
| 568 | + programId: ASSOCIATED_TOKEN_PROGRAM_ID, |
| 569 | + keys: mockKeys, |
| 570 | + data: Buffer.from('AQ==', 'base64'), |
| 571 | + }); |
| 572 | + Utils.isIdempotentAtaInstruction(instruction).should.equal(true); |
| 573 | + }); |
| 574 | + |
| 575 | + it('should return false for legacy ATA instruction with empty data', function () { |
| 576 | + const instruction = new TransactionInstruction({ |
| 577 | + programId: ASSOCIATED_TOKEN_PROGRAM_ID, |
| 578 | + keys: mockKeys, |
| 579 | + data: Buffer.from([]), |
| 580 | + }); |
| 581 | + Utils.isIdempotentAtaInstruction(instruction).should.equal(false); |
| 582 | + }); |
| 583 | + |
| 584 | + it('should return false for instruction with wrong discriminator', function () { |
| 585 | + const instruction = new TransactionInstruction({ |
| 586 | + programId: ASSOCIATED_TOKEN_PROGRAM_ID, |
| 587 | + keys: mockKeys, |
| 588 | + data: Buffer.from([2]), |
| 589 | + }); |
| 590 | + Utils.isIdempotentAtaInstruction(instruction).should.equal(false); |
| 591 | + }); |
| 592 | + |
| 593 | + it('should return false for instruction with multiple bytes', function () { |
| 594 | + const instruction = new TransactionInstruction({ |
| 595 | + programId: ASSOCIATED_TOKEN_PROGRAM_ID, |
| 596 | + keys: mockKeys, |
| 597 | + data: Buffer.from([1, 2]), |
| 598 | + }); |
| 599 | + Utils.isIdempotentAtaInstruction(instruction).should.equal(false); |
| 600 | + }); |
| 601 | + }); |
550 | 602 | }); |
0 commit comments