examples: Import TOKEN_PROGRAM_ID from @solana/spl-token (#415)

This commit is contained in:
Haik Dulgarian 2021-06-26 12:27:14 -05:00 committed by GitHub
parent b3ce642454
commit 24824ca9f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 25 deletions

View File

@ -1,7 +1,9 @@
const anchor = require("@project-serum/anchor");
const serumCmn = require("@project-serum/common");
const TokenInstructions = require("@project-serum/serum").TokenInstructions;
const assert = require("assert");
const { TOKEN_PROGRAM_ID } = require("@solana/spl-token");
describe("cashiers-check", () => {
// Configure the client to use the local cluster.
@ -48,7 +50,7 @@ describe("cashiers-check", () => {
from: god,
to: receiver,
owner: program.provider.wallet.publicKey,
tokenProgram: TokenInstructions.TOKEN_PROGRAM_ID,
tokenProgram: TOKEN_PROGRAM_ID,
rent: anchor.web3.SYSVAR_RENT_PUBKEY,
},
signers: [check, vault],
@ -87,7 +89,7 @@ describe("cashiers-check", () => {
checkSigner: checkSigner,
to: receiver,
owner: program.provider.wallet.publicKey,
tokenProgram: TokenInstructions.TOKEN_PROGRAM_ID,
tokenProgram: TOKEN_PROGRAM_ID,
},
});

View File

@ -1,7 +1,8 @@
const assert = require("assert");
const anchor = require("@project-serum/anchor");
const serumCmn = require("@project-serum/common");
const TokenInstructions = require("@project-serum/serum").TokenInstructions;
const { TOKEN_PROGRAM_ID } = require("@solana/spl-token");
const utils = require("./utils");
describe("Lockup and Registry", () => {
@ -130,7 +131,7 @@ describe("Lockup and Registry", () => {
},
});
let lockupAccount = await lockup.state.fetch();
assert.deepEqual(lockupAccount.whitelist, entries.slice(1));
assert.deepStrictEqual(lockupAccount.whitelist, entries.slice(1));
});
const vesting = anchor.web3.Keypair.generate();
@ -168,7 +169,7 @@ describe("Lockup and Registry", () => {
vault: vault.publicKey,
depositor: god,
depositorAuthority: provider.wallet.publicKey,
tokenProgram: TokenInstructions.TOKEN_PROGRAM_ID,
tokenProgram: TOKEN_PROGRAM_ID,
rent: anchor.web3.SYSVAR_RENT_PUBKEY,
clock: anchor.web3.SYSVAR_CLOCK_PUBKEY,
},
@ -210,7 +211,7 @@ describe("Lockup and Registry", () => {
token: god,
vault: vestingAccount.vault,
vestingSigner: vestingSigner,
tokenProgram: TokenInstructions.TOKEN_PROGRAM_ID,
tokenProgram: TOKEN_PROGRAM_ID,
clock: anchor.web3.SYSVAR_CLOCK_PUBKEY,
},
});
@ -241,7 +242,7 @@ describe("Lockup and Registry", () => {
token,
vault: vestingAccount.vault,
vestingSigner,
tokenProgram: TokenInstructions.TOKEN_PROGRAM_ID,
tokenProgram: TOKEN_PROGRAM_ID,
clock: anchor.web3.SYSVAR_CLOCK_PUBKEY,
},
});
@ -373,7 +374,7 @@ describe("Lockup and Registry", () => {
memberSigner,
balances,
balancesLocked,
tokenProgram: TokenInstructions.TOKEN_PROGRAM_ID,
tokenProgram: TOKEN_PROGRAM_ID,
rent: anchor.web3.SYSVAR_RENT_PUBKEY,
},
instructions: [await registry.account.member.createInstruction(member)],
@ -408,7 +409,7 @@ describe("Lockup and Registry", () => {
accounts: {
depositor: god,
depositorAuthority: provider.wallet.publicKey,
tokenProgram: TokenInstructions.TOKEN_PROGRAM_ID,
tokenProgram: TOKEN_PROGRAM_ID,
vault: memberAccount.balances.vault,
beneficiary: provider.wallet.publicKey,
member: member.publicKey,
@ -440,7 +441,7 @@ describe("Lockup and Registry", () => {
registrarSigner,
// Misc.
clock: anchor.web3.SYSVAR_CLOCK_PUBKEY,
tokenProgram: TokenInstructions.TOKEN_PROGRAM_ID,
tokenProgram: TOKEN_PROGRAM_ID,
},
});
@ -499,7 +500,7 @@ describe("Lockup and Registry", () => {
depositor: god,
depositorAuthority: provider.wallet.publicKey,
tokenProgram: TokenInstructions.TOKEN_PROGRAM_ID,
tokenProgram: TOKEN_PROGRAM_ID,
clock: anchor.web3.SYSVAR_CLOCK_PUBKEY,
rent: anchor.web3.SYSVAR_RENT_PUBKEY,
},
@ -562,7 +563,7 @@ describe("Lockup and Registry", () => {
vault: unlockedVendorVault.publicKey,
vendorSigner: unlockedVendorSigner,
tokenProgram: TokenInstructions.TOKEN_PROGRAM_ID,
tokenProgram: TOKEN_PROGRAM_ID,
clock: anchor.web3.SYSVAR_CLOCK_PUBKEY,
},
},
@ -618,7 +619,7 @@ describe("Lockup and Registry", () => {
depositor: god,
depositorAuthority: provider.wallet.publicKey,
tokenProgram: TokenInstructions.TOKEN_PROGRAM_ID,
tokenProgram: TOKEN_PROGRAM_ID,
clock: anchor.web3.SYSVAR_CLOCK_PUBKEY,
rent: anchor.web3.SYSVAR_RENT_PUBKEY,
},
@ -684,7 +685,7 @@ describe("Lockup and Registry", () => {
vault: vendoredVestingVault.publicKey,
depositor: lockedVendorVault.publicKey,
depositorAuthority: lockedVendorSigner,
tokenProgram: TokenInstructions.TOKEN_PROGRAM_ID,
tokenProgram: TOKEN_PROGRAM_ID,
rent: anchor.web3.SYSVAR_RENT_PUBKEY,
clock: anchor.web3.SYSVAR_CLOCK_PUBKEY,
})
@ -710,7 +711,7 @@ describe("Lockup and Registry", () => {
vault: lockedVendorVault.publicKey,
vendorSigner: lockedVendorSigner,
tokenProgram: TokenInstructions.TOKEN_PROGRAM_ID,
tokenProgram: TOKEN_PROGRAM_ID,
clock: anchor.web3.SYSVAR_CLOCK_PUBKEY,
},
},
@ -765,7 +766,7 @@ describe("Lockup and Registry", () => {
token,
vault: vendoredVestingVault.publicKey,
vestingSigner: vendoredVestingSigner,
tokenProgram: TokenInstructions.TOKEN_PROGRAM_ID,
tokenProgram: TOKEN_PROGRAM_ID,
clock: anchor.web3.SYSVAR_CLOCK_PUBKEY,
},
// TODO: trait methods generated on the client. Until then, we need to manually
@ -807,7 +808,7 @@ describe("Lockup and Registry", () => {
memberSigner,
tokenProgram: TokenInstructions.TOKEN_PROGRAM_ID,
tokenProgram: TOKEN_PROGRAM_ID,
clock: anchor.web3.SYSVAR_CLOCK_PUBKEY,
rent: anchor.web3.SYSVAR_RENT_PUBKEY,
},
@ -852,7 +853,7 @@ describe("Lockup and Registry", () => {
memberSigner,
clock: anchor.web3.SYSVAR_CLOCK_PUBKEY,
tokenProgram: TokenInstructions.TOKEN_PROGRAM_ID,
tokenProgram: TOKEN_PROGRAM_ID,
},
});
};
@ -905,7 +906,7 @@ describe("Lockup and Registry", () => {
vault: memberAccount.balances.vault,
memberSigner,
depositor: token,
tokenProgram: TokenInstructions.TOKEN_PROGRAM_ID,
tokenProgram: TOKEN_PROGRAM_ID,
},
});
@ -928,7 +929,7 @@ describe("Lockup and Registry", () => {
token,
vault: vendoredVestingVault.publicKey,
vestingSigner: vendoredVestingSigner,
tokenProgram: TokenInstructions.TOKEN_PROGRAM_ID,
tokenProgram: TOKEN_PROGRAM_ID,
clock: anchor.web3.SYSVAR_CLOCK_PUBKEY,
},
// TODO: trait methods generated on the client. Until then, we need to manually

View File

@ -1,7 +1,9 @@
//! This example demonstrates the use of zero copy deserialization for accounts.
//! The main noticeable benefit one achieves using zero copy is the ability
//! to create accounts larger than the size of the stack or heap, as is
//! demonstrated by the event queue in this example.
//! This example demonstrates the use of zero-copy deserialization for accounts.
//! Zero-copy is a deserialization technique that creates data structures by borrowing
//! (not copying!) from the array holding the input, avoiding the expensive memory
//! allocation and processing of traditional deserialization.
//! With zero-copy, we can create accounts larger than the size of the stack or heap,
//! as is demonstrated by the event queue in this example.
use anchor_lang::prelude::*;