@@ -6,7 +6,11 @@ import { InstructionParams } from '../../src/lib/iface';
66import { InstructionBuilderTypes , MEMO_PROGRAM_PK } from '../../src/lib/constants' ;
77import { PublicKey , SystemProgram , TransactionInstruction } from '@solana/web3.js' ;
88import BigNumber from 'bignumber.js' ;
9- import { createAssociatedTokenAccountInstruction , createTransferCheckedInstruction } from '@solana/spl-token' ;
9+ import {
10+ createAssociatedTokenAccountInstruction ,
11+ createTransferCheckedInstruction ,
12+ TOKEN_2022_PROGRAM_ID ,
13+ } from '@solana/spl-token' ;
1014
1115describe ( 'Instruction Parser Tests: ' , function ( ) {
1216 describe ( 'Succeed ' , function ( ) {
@@ -135,6 +139,67 @@ describe('Instruction Parser Tests: ', function () {
135139 should . deepEqual ( result , instructionsData ) ;
136140 } ) ;
137141
142+ it ( 'Send sol 2022 token tx instructions' , ( ) => {
143+ const authAccount = testData . authAccount . pub ;
144+ const nonceAccount = testData . nonceAccount . pub ;
145+ const amount = testData . sol2022TokenTransfers . amount ;
146+ const memo = testData . sol2022TokenTransfers . memo ;
147+ const decimals = testData . sol2022TokenTransfers . decimals ;
148+ const name = testData . sol2022TokenTransfers . name ;
149+ const mint = testData . sol2022TokenTransfers . mint ;
150+ const owner = testData . sol2022TokenTransfers . owner ;
151+ const source = testData . sol2022TokenTransfers . source ;
152+
153+ // nonce
154+ const nonceAdvanceParams : InstructionParams = {
155+ type : InstructionBuilderTypes . NonceAdvance ,
156+ params : { walletNonceAddress : nonceAccount , authWalletAddress : authAccount } ,
157+ } ;
158+ const nonceAdvanceInstruction = SystemProgram . nonceAdvance ( {
159+ noncePubkey : new PublicKey ( nonceAccount ) ,
160+ authorizedPubkey : new PublicKey ( authAccount ) ,
161+ } ) ;
162+
163+ // token transfer
164+ const transferParams = {
165+ type : InstructionBuilderTypes . TokenTransfer ,
166+ params : {
167+ fromAddress : owner ,
168+ toAddress : nonceAccount ,
169+ amount : amount . toString ( ) ,
170+ tokenName : name ,
171+ sourceAddress : source ,
172+ } ,
173+ } ;
174+ const transferInstruction = createTransferCheckedInstruction (
175+ new PublicKey ( source ) ,
176+ new PublicKey ( mint ) ,
177+ new PublicKey ( nonceAccount ) ,
178+ new PublicKey ( owner ) ,
179+ amount ,
180+ decimals ,
181+ [ ] ,
182+ TOKEN_2022_PROGRAM_ID
183+ ) ;
184+
185+ // memo
186+ const memoParams : InstructionParams = {
187+ type : InstructionBuilderTypes . Memo ,
188+ params : { memo } ,
189+ } ;
190+
191+ const memoInstruction = new TransactionInstruction ( {
192+ keys : [ ] ,
193+ programId : new PublicKey ( MEMO_PROGRAM_PK ) ,
194+ data : Buffer . from ( memo ) ,
195+ } ) ;
196+
197+ const instructions = [ nonceAdvanceInstruction , transferInstruction , memoInstruction ] ;
198+ const instructionsData = [ nonceAdvanceParams , transferParams , memoParams ] ;
199+ const result = instructionParamsFactory ( TransactionType . Send , instructions ) ;
200+ should . deepEqual ( result , instructionsData ) ;
201+ } ) ;
202+
138203 it ( 'multi ATA init tx instructions' , ( ) => {
139204 const ataParams = [
140205 {
@@ -172,6 +237,38 @@ describe('Instruction Parser Tests: ', function () {
172237 const result = instructionParamsFactory ( TransactionType . AssociatedTokenAccountInitialization , ataInstructions ) ;
173238 should . deepEqual ( result , createATAParams ) ;
174239 } ) ;
240+ it ( 'sol 2022 ATA init tx instructions' , ( ) => {
241+ const ataParams = [
242+ {
243+ mintAddress : testData . associatedTokenAccountsForSol2022 . mintId ,
244+ ownerAddress : testData . associatedTokenAccountsForSol2022 . accounts [ 0 ] . pub ,
245+ payerAddress : testData . associatedTokenAccountsForSol2022 . accounts [ 0 ] . pub ,
246+ ataAddress : testData . associatedTokenAccountsForSol2022 . accounts [ 0 ] . ata ,
247+ } ,
248+ ] ;
249+
250+ const ataInstructions : TransactionInstruction [ ] = [ ] ;
251+ const createATAParams : InstructionParams [ ] = [ ] ;
252+
253+ ataParams . forEach ( ( param ) => {
254+ ataInstructions . push (
255+ createAssociatedTokenAccountInstruction (
256+ new PublicKey ( param . payerAddress ) ,
257+ new PublicKey ( param . ataAddress ) ,
258+ new PublicKey ( param . ownerAddress ) ,
259+ new PublicKey ( param . mintAddress ) ,
260+ TOKEN_2022_PROGRAM_ID
261+ )
262+ ) ;
263+
264+ createATAParams . push ( {
265+ type : InstructionBuilderTypes . CreateAssociatedTokenAccount ,
266+ params : { ...param , tokenName : 'tsol:t22mint' } ,
267+ } ) ;
268+ } ) ;
269+ const result = instructionParamsFactory ( TransactionType . AssociatedTokenAccountInitialization , ataInstructions ) ;
270+ should . deepEqual ( result , createATAParams ) ;
271+ } ) ;
175272 } ) ;
176273 describe ( 'Fail ' , function ( ) {
177274 it ( 'Invalid type' , ( ) => {
0 commit comments