Skip to content

Instantly share code, notes, and snippets.

@davoclavo
Created October 6, 2021 04:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davoclavo/742a05d6273368e863967fb38a190331 to your computer and use it in GitHub Desktop.
Save davoclavo/742a05d6273368e863967fb38a190331 to your computer and use it in GitHub Desktop.
diff --git a/tests/misc/programs/misc/src/context.rs b/tests/misc/programs/misc/src/context.rs
index a095fdf..284833e 100644
--- a/tests/misc/programs/misc/src/context.rs
+++ b/tests/misc/programs/misc/src/context.rs
@@ -49,6 +49,17 @@ pub struct TestInitAssociatedToken<'info> {
pub associated_token_program: Program<'info, AssociatedToken>,
}
+#[derive(Accounts)]
+pub struct TestValidateAssociatedToken<'info> {
+ #[account(
+ associated_token::mint = mint,
+ associated_token::authority = payer,
+ )]
+ pub token: Account<'info, TokenAccount>,
+ pub mint: Account<'info, Mint>,
+ pub wallet: AccountInfo<'info>
+}
+
#[derive(Accounts)]
#[instruction(nonce: u8)]
pub struct TestInstructionConstraint<'info> {
diff --git a/tests/misc/programs/misc/src/lib.rs b/tests/misc/programs/misc/src/lib.rs
index 1ace4df..10fc812 100644
--- a/tests/misc/programs/misc/src/lib.rs
+++ b/tests/misc/programs/misc/src/lib.rs
@@ -165,6 +165,10 @@ pub mod misc {
Ok(())
}
+ pub fn test_validate_associated_token(ctx: Context<TestValidateAssociatedToken>) -> ProgramResult {
+ Ok(())
+ }
+
pub fn test_fetch_all(ctx: Context<TestFetchAll>, filterable: Pubkey) -> ProgramResult {
ctx.accounts.data.authority = ctx.accounts.authority.key();
ctx.accounts.data.filterable = filterable;
diff --git a/tests/misc/tests/misc.js b/tests/misc/tests/misc.js
index 49ca1f7..c746edc 100644
--- a/tests/misc/tests/misc.js
+++ b/tests/misc/tests/misc.js
@@ -612,8 +612,10 @@ describe("misc", () => {
assert.equal(account2.idata, 3);
});
+ let associatedToken = null;
+
it("Can create an associated token account", async () => {
- const token = await Token.getAssociatedTokenAddress(
+ associatedToken = await Token.getAssociatedTokenAddress(
ASSOCIATED_TOKEN_PROGRAM_ID,
TOKEN_PROGRAM_ID,
mint.publicKey,
@@ -622,7 +624,7 @@ describe("misc", () => {
await program.rpc.testInitAssociatedToken({
accounts: {
- token,
+ associatedToken,
mint: mint.publicKey,
payer: program.provider.wallet.publicKey,
rent: anchor.web3.SYSVAR_RENT_PUBKEY,
@@ -645,6 +647,16 @@ describe("misc", () => {
assert.ok(account.mint.equals(mint.publicKey));
});
+ it("Can create an associated token account", async () => {
+ await program.rpc.testInitAssociatedToken({
+ accounts: {
+ associatedToken,
+ mint: mint.publicKey,
+ wallet: program.provider.wallet.publicKey
+ },
+ });
+ });
+
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment