@@ -3,6 +3,8 @@ import { expect, use } from 'chai';
3
3
import {
4
4
ASSOCIATED_TOKEN_PROGRAM_ID ,
5
5
createAssociatedTokenAccountInstruction ,
6
+ createAssociatedTokenAccountIdempotentInstruction ,
7
+ createAssociatedTokenAccountIdempotentInstructionWithDerivation ,
6
8
createReallocateInstruction ,
7
9
createInitializeMintInstruction ,
8
10
createInitializeMint2Instruction ,
@@ -167,6 +169,37 @@ describe('spl-associated-token-account instructions', () => {
167
169
expect ( ix . programId ) . to . eql ( ASSOCIATED_TOKEN_PROGRAM_ID ) ;
168
170
expect ( ix . keys ) . to . have . length ( 6 ) ;
169
171
} ) ;
172
+
173
+ it ( 'create idempotent' , ( ) => {
174
+ const ix = createAssociatedTokenAccountIdempotentInstruction (
175
+ Keypair . generate ( ) . publicKey ,
176
+ Keypair . generate ( ) . publicKey ,
177
+ Keypair . generate ( ) . publicKey ,
178
+ Keypair . generate ( ) . publicKey ,
179
+ ) ;
180
+ expect ( ix . programId ) . to . eql ( ASSOCIATED_TOKEN_PROGRAM_ID ) ;
181
+ expect ( ix . keys ) . to . have . length ( 6 ) ;
182
+ } ) ;
183
+
184
+ it ( 'create idempotent with derivation' , ( ) => {
185
+ const ix = createAssociatedTokenAccountIdempotentInstructionWithDerivation (
186
+ Keypair . generate ( ) . publicKey ,
187
+ Keypair . generate ( ) . publicKey ,
188
+ Keypair . generate ( ) . publicKey ,
189
+ ) ;
190
+ expect ( ix . programId ) . to . eql ( ASSOCIATED_TOKEN_PROGRAM_ID ) ;
191
+ expect ( ix . keys ) . to . have . length ( 6 ) ;
192
+ } ) ;
193
+
194
+ it ( 'create idempotent with derivation same without' , ( ) => {
195
+ const payer = Keypair . generate ( ) . publicKey ;
196
+ const owner = Keypair . generate ( ) . publicKey ;
197
+ const mint = Keypair . generate ( ) . publicKey ;
198
+ const associatedToken = getAssociatedTokenAddressSync ( mint , owner , true ) ;
199
+ const ix = createAssociatedTokenAccountIdempotentInstruction ( payer , associatedToken , owner , mint ) ;
200
+ const ixDerivation = createAssociatedTokenAccountIdempotentInstructionWithDerivation ( payer , owner , mint ) ;
201
+ expect ( ix ) . to . deep . eq ( ixDerivation ) ;
202
+ } ) ;
170
203
} ) ;
171
204
172
205
describe ( 'state' , ( ) => {
0 commit comments