@@ -12,6 +12,7 @@ import {
12
12
pipe ,
13
13
} from "@solana/kit" ;
14
14
import {
15
+ ASSOCIATED_TOKEN_PROGRAM_ID ,
15
16
ExtensionType ,
16
17
NATIVE_MINT ,
17
18
TOKEN_2022_PROGRAM_ID ,
@@ -163,9 +164,13 @@ describe("svm_spoke.deposit", () => {
163
164
. accounts ( calledDepositAccounts )
164
165
. instruction ( ) ;
165
166
const depositTx = new Transaction ( ) . add ( approveIx , depositIx ) ;
166
- return sendAndConfirmTransaction ( connection , depositTx , [ payer , depositor ] ) ;
167
+ return sendAndConfirmTransaction ( connection , depositTx , [ depositor ] ) ;
167
168
} ;
168
169
170
+ before ( async ( ) => {
171
+ await connection . requestAirdrop ( depositor . publicKey , 10_000_000_000 ) ; // 10 SOL
172
+ } ) ;
173
+
169
174
beforeEach ( async ( ) => {
170
175
( { state, seed } = await initializeState ( ) ) ;
171
176
@@ -730,6 +735,44 @@ describe("svm_spoke.deposit", () => {
730
735
) ;
731
736
} ) ;
732
737
738
+ it ( "Deposits tokens to a new vault" , async ( ) => {
739
+ // Create new input token without creating a new vault for it.
740
+ await setupInputToken ( ) ;
741
+ const inputTokenAccount = await provider . connection . getAccountInfo ( inputToken ) ;
742
+ if ( inputTokenAccount === null ) throw new Error ( "Input mint account not found" ) ;
743
+ vault = getAssociatedTokenAddressSync (
744
+ inputToken ,
745
+ state ,
746
+ true ,
747
+ inputTokenAccount . owner ,
748
+ ASSOCIATED_TOKEN_PROGRAM_ID
749
+ ) ;
750
+
751
+ // Update global variables using the new input token.
752
+ depositData . inputToken = inputToken ;
753
+ depositAccounts . depositorTokenAccount = depositorTA ;
754
+ depositAccounts . vault = vault ;
755
+ depositAccounts . mint = inputToken ;
756
+
757
+ // Verify there is no vault account before the deposit.
758
+ assert . isNull ( await provider . connection . getAccountInfo ( vault ) , "Vault should not exist before the deposit" ) ;
759
+
760
+ // Execute the deposit call
761
+ await approvedDeposit ( depositData ) ;
762
+
763
+ // Verify tokens leave the depositor's account
764
+ const depositorAccount = await getAccount ( connection , depositorTA ) ;
765
+ assertSE (
766
+ depositorAccount . amount ,
767
+ seedBalance - depositData . inputAmount . toNumber ( ) ,
768
+ "Depositor's balance should be reduced by the deposited amount"
769
+ ) ;
770
+
771
+ // Verify tokens are credited into the new vault
772
+ const vaultAccount = await getAccount ( connection , vault ) ;
773
+ assertSE ( vaultAccount . amount , depositData . inputAmount , "Vault balance should equal the deposited amount" ) ;
774
+ } ) ;
775
+
733
776
describe ( "codama client and solana kit" , ( ) => {
734
777
it ( "Deposit with with solana kit and codama client" , async ( ) => {
735
778
// typescript is not happy with the depositData object
0 commit comments