@@ -10,6 +10,7 @@ import {
10
10
import {
11
11
ASSOCIATED_TOKEN_PROGRAM_ID ,
12
12
createAssociatedTokenAccountIdempotentInstruction ,
13
+ createAssociatedTokenAccountInstruction ,
13
14
createInitializeMintInstruction ,
14
15
createMintToInstruction ,
15
16
createTransferCheckedInstruction ,
@@ -77,12 +78,15 @@ describe("vesting", () => {
77
78
const vesterWithoutAccount = Keypair . generate ( ) ;
78
79
const seed = new BN ( randomBytes ( 8 ) ) ;
79
80
const seed2 = new BN ( randomBytes ( 8 ) ) ;
81
+ const seed3 = new BN ( randomBytes ( 8 ) ) ;
80
82
81
83
let accounts ,
82
84
config ,
83
85
config2 ,
86
+ config3 ,
84
87
vault ,
85
88
vault2 ,
89
+ vault3 ,
86
90
vesterTa ,
87
91
vester2Ta ,
88
92
vester3Ta ,
@@ -161,6 +165,14 @@ describe("vesting", () => {
161
165
] ,
162
166
stakeConnection . program . programId ,
163
167
) [ 0 ] ;
168
+ config3 = PublicKey . findProgramAddressSync (
169
+ [
170
+ Buffer . from ( wasm . Constants . VESTING_CONFIG_SEED ( ) ) ,
171
+ whMintAccount . publicKey . toBuffer ( ) ,
172
+ seed3 . toBuffer ( "le" , 8 ) ,
173
+ ] ,
174
+ stakeConnection . program . programId ,
175
+ ) [ 0 ] ;
164
176
vault = getAssociatedTokenAddressSync (
165
177
whMintAccount . publicKey ,
166
178
config ,
@@ -173,6 +185,12 @@ describe("vesting", () => {
173
185
true ,
174
186
TOKEN_PROGRAM_ID ,
175
187
) ;
188
+ vault3 = getAssociatedTokenAddressSync (
189
+ whMintAccount . publicKey ,
190
+ config3 ,
191
+ true ,
192
+ TOKEN_PROGRAM_ID ,
193
+ ) ;
176
194
vesterTa = getAssociatedTokenAddressSync (
177
195
whMintAccount . publicKey ,
178
196
vester . publicKey ,
@@ -670,6 +688,34 @@ describe("vesting", () => {
670
688
}
671
689
} ) ;
672
690
691
+ it ( "should successfully initialize vesting config if vault ATA is pre-created by another user" , async ( ) => {
692
+ const tx = new Transaction ( ) ;
693
+ tx . add (
694
+ createAssociatedTokenAccountInstruction (
695
+ vester . publicKey , // payer
696
+ vault3 , // associatedToken
697
+ config3 , // owner
698
+ whMintAccount . publicKey , // mint
699
+ TOKEN_PROGRAM_ID ,
700
+ ASSOCIATED_TOKEN_PROGRAM_ID ,
701
+ ) ,
702
+ ) ;
703
+ await vesterStakeConnection . provider . sendAndConfirm ( tx , [ vester ] )
704
+ . then ( confirm ) ;
705
+ await sleep ( 1500 ) ;
706
+
707
+ await stakeConnection . program . methods
708
+ . initializeVestingConfig ( seed3 )
709
+ . accounts ( {
710
+ ...accounts ,
711
+ config : config3 ,
712
+ vault : vault3 ,
713
+ } )
714
+ . signers ( [ whMintAuthority ] )
715
+ . rpc ( )
716
+ . then ( confirm ) ;
717
+ } ) ;
718
+
673
719
it ( "Initialize config" , async ( ) => {
674
720
await stakeConnection . program . methods
675
721
. initializeVestingConfig ( seed )
0 commit comments