|
1 | 1 | import * as anchor from "@coral-xyz/anchor"; |
2 | 2 | import { BN } from "@coral-xyz/anchor"; |
| 3 | +import { |
| 4 | + address, |
| 5 | + appendTransactionMessageInstruction, |
| 6 | + createKeyPairFromBytes, |
| 7 | + createSignerFromKeyPair, |
| 8 | + getProgramDerivedAddress, |
| 9 | + pipe, |
| 10 | +} from "@solana/kit"; |
3 | 11 | import { ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_PROGRAM_ID, createMint, getAccount } from "@solana/spl-token"; |
4 | | -import { PublicKey, Keypair } from "@solana/web3.js"; |
| 12 | +import { Keypair, PublicKey } from "@solana/web3.js"; |
5 | 13 | import { assert } from "chai"; |
6 | | -import { common } from "./SvmSpoke.common"; |
| 14 | +import { SvmSpokeClient } from "../../src/svm"; |
| 15 | +import { SetEnableRouteInput } from "../../src/svm/clients/SvmSpoke"; |
7 | 16 | import { readEventsUntilFound } from "../../src/svm/web3-v1"; |
| 17 | +import { common } from "./SvmSpoke.common"; |
| 18 | +import { createDefaultSolanaClient, createDefaultTransaction, signAndSendTransaction } from "./utils"; |
8 | 19 |
|
9 | 20 | const { provider, program, owner, initializeState, createRoutePda, getVaultAta } = common; |
10 | 21 |
|
@@ -116,4 +127,56 @@ describe("svm_spoke.routes", () => { |
116 | 127 | assert.strictEqual(err.error.errorCode.code, "InvalidMint", "Expected error code InvalidMint"); |
117 | 128 | } |
118 | 129 | }); |
| 130 | + |
| 131 | + describe("codama client and solana kit", () => { |
| 132 | + it("Sets and retrieves route enablement with codama", async () => { |
| 133 | + const rpcClient = createDefaultSolanaClient(); |
| 134 | + const signer = await createSignerFromKeyPair( |
| 135 | + await createKeyPairFromBytes((anchor.AnchorProvider.env().wallet as anchor.Wallet).payer.secretKey) |
| 136 | + ); |
| 137 | + |
| 138 | + const [eventAuthority] = await getProgramDerivedAddress({ |
| 139 | + programAddress: address(program.programId.toString()), |
| 140 | + seeds: ["__event_authority"], |
| 141 | + }); |
| 142 | + |
| 143 | + const input: SetEnableRouteInput = { |
| 144 | + signer: signer, |
| 145 | + payer: signer, |
| 146 | + state: address(state.toString()), |
| 147 | + route: address(routePda.toString()), |
| 148 | + vault: address(vault.toString()), |
| 149 | + originTokenMint: address(tokenMint.toString()), |
| 150 | + tokenProgram: address(TOKEN_PROGRAM_ID.toString()), |
| 151 | + associatedTokenProgram: address(ASSOCIATED_TOKEN_PROGRAM_ID.toString()), |
| 152 | + systemProgram: address(anchor.web3.SystemProgram.programId.toString()), |
| 153 | + eventAuthority: address(eventAuthority.toString()), |
| 154 | + program: address(program.programId.toString()), |
| 155 | + originToken: address(tokenMint.toString()), |
| 156 | + destinationChainId: routeChainId.toNumber(), |
| 157 | + enabled: true, |
| 158 | + }; |
| 159 | + const instructions = SvmSpokeClient.getSetEnableRouteInstruction(input); |
| 160 | + const tx = await pipe( |
| 161 | + await createDefaultTransaction(rpcClient, signer), |
| 162 | + (tx) => appendTransactionMessageInstruction(instructions, tx), |
| 163 | + (tx) => signAndSendTransaction(rpcClient, tx) |
| 164 | + ); |
| 165 | + |
| 166 | + // Retrieve and verify the route is enabled |
| 167 | + let routeAccount = await SvmSpokeClient.fetchRoute(rpcClient.rpc, address(routePda.toString())); |
| 168 | + assert.isTrue(routeAccount.data.enabled, "Route should be enabled"); |
| 169 | + |
| 170 | + // Verify the enabledDepositRoute event |
| 171 | + let events = await readEventsUntilFound(provider.connection, tx, [program]); |
| 172 | + let event = events[0].data; |
| 173 | + assert.strictEqual(event.originToken.toString(), tokenMint.toString(), "originToken event match"); |
| 174 | + assert.strictEqual( |
| 175 | + event.destinationChainId.toString(), |
| 176 | + routeChainId.toString(), |
| 177 | + "destinationChainId should match" |
| 178 | + ); |
| 179 | + assert.isTrue(event.enabled, "enabledDepositRoute enabled"); |
| 180 | + }); |
| 181 | + }); |
119 | 182 | }); |
0 commit comments