Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade @solana/spl-token to "0.4.9" #3447

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
33 changes: 19 additions & 14 deletions tests/anchor-cli-account/tests/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { Program } from "@coral-xyz/anchor";
import { AccountCommand } from "../target/types/account_command";
import { assert } from "chai";
import { execSync } from "child_process";
import { sleep } from "@project-serum/common";

describe("Test CLI account commands", () => {
// Configure the client to use the local cluster.
Expand All @@ -24,11 +23,11 @@ describe("Test CLI account commands", () => {
await program.methods
.initialize(
balance,
new anchor.BN(amount),
amount,
memo,
values.map((x) => new anchor.BN(x))
)
.accounts({
.accountsPartial({
myAccount: myAccount.publicKey,
user: provider.wallet.publicKey,
systemProgram: anchor.web3.SystemProgram.programId,
Expand All @@ -51,26 +50,32 @@ describe("Test CLI account commands", () => {
throw e;
}
}

await sleep(5000);
}

assert(output.balance === balance, "Balance deserialized incorrectly");
assert(
output.delegate_pubkey === provider.wallet.publicKey.toBase58(),
assert.strictEqual(
output.balance,
balance,
"Balance deserialized incorrectly"
);
assert.strictEqual(
output.delegate_pubkey,
provider.wallet.publicKey.toBase58(),
"delegatePubkey deserialized incorrectly"
);
assert(
output.sub.state.Confirmed.amount === amount,
assert.strictEqual(
output.sub.state.Confirmed.amount,
amount,
"Amount deserialized incorrectly"
);
assert(
output.sub.state.Confirmed.memo === memo,
assert.strictEqual(
output.sub.state.Confirmed.memo,
memo,
"Memo deserialized incorrectly"
);
for (let i = 0; i < values.length; i++) {
assert(
output.sub.values[i] == values[i],
assert.equal(
output.sub.values[i],
values[i],
"Values deserialized incorrectly"
);
}
Expand Down
9 changes: 1 addition & 8 deletions tests/anchor-cli-account/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
{
"compilerOptions": {
"types": ["mocha", "chai"],
"typeRoots": ["./node_modules/@types"],
"lib": ["es2015"],
"module": "commonjs",
"target": "es6",
"esModuleInterop": true
}
"extends": "../tsconfig.json"
}
9 changes: 1 addition & 8 deletions tests/anchor-cli-idl/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
{
"compilerOptions": {
"types": ["mocha", "chai"],
"typeRoots": ["./node_modules/@types"],
"lib": ["es2015"],
"module": "commonjs",
"target": "es6",
"esModuleInterop": true
}
"extends": "../tsconfig.json"
}
2 changes: 2 additions & 0 deletions tests/auction-house/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
"test": "anchor test --skip-lint"
},
"dependencies": {
"@solana/spl-token": "^0.1.8",
"@solana/web3.js": "^1.68.0",
"@metaplex/js": "^4.4.1"
}
}
10 changes: 1 addition & 9 deletions tests/bpf-upgradeable-state/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
{
"compilerOptions": {
"types": ["mocha", "chai"],
"typeRoots": ["./node_modules/@types"],
"lib": ["es2015"],
"module": "commonjs",
"target": "es6",
"esModuleInterop": true,
"skipLibCheck": true
}
"extends": "../tsconfig.json"
}
92 changes: 56 additions & 36 deletions tests/cashiers-check/tests/cashiers-check.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,50 @@
const anchor = require("@coral-xyz/anchor");
const serumCmn = require("@project-serum/common");
const { Keypair, SystemProgram, PublicKey } = require("@solana/web3.js");
const { assert } = require("chai");
const { TOKEN_PROGRAM_ID } = require("@solana/spl-token");
const {
TOKEN_PROGRAM_ID,
createMint,
createAccount,
mintTo,
getAccount,
createInitializeAccountInstruction,
} = require("@solana/spl-token");
const TOKEN_ACCOUNT_SIZE = 165;

describe("cashiers-check", () => {
// Configure the client to use the local cluster.
const provider = anchor.AnchorProvider.env();
// hack so we don't have to update serum-common library
// to the new AnchorProvider class and Provider interface
provider.send = provider.sendAndConfirm;
anchor.setProvider(provider);

const program = anchor.workspace.CashiersCheck;
const connection = provider.connection;
const payer = provider.wallet.payer;
const walletKey = provider.wallet.publicKey;

let mint = null;
let god = null;
let receiver = null;

it("Sets up initial test state", async () => {
const [_mint, _god] = await serumCmn.createMintAndVault(
program.provider,
new anchor.BN(1000000)
mint = await createMint(connection, payer, walletKey, walletKey, 6);

god = await createAccount(
connection,
payer,
mint,
walletKey,
Keypair.generate()
);
mint = _mint;
god = _god;
// Mint tokens to god account
await mintTo(connection, payer, mint, god, payer, 1_000_000);

receiver = await serumCmn.createTokenAccount(
program.provider,
receiver = await createAccount(
connection,
payer,
mint,
program.provider.wallet.publicKey
walletKey,
Keypair.generate()
);
});

Expand All @@ -38,11 +54,14 @@ describe("cashiers-check", () => {
let checkSigner = null;

it("Creates a check!", async () => {
let [_checkSigner, nonce] = await anchor.web3.PublicKey.findProgramAddress(
let [_checkSigner, nonce] = PublicKey.findProgramAddressSync(
[check.publicKey.toBuffer()],
program.programId
);
checkSigner = _checkSigner;
const token_lamports = await connection.getMinimumBalanceForRentExemption(
TOKEN_ACCOUNT_SIZE
);

await program.rpc.createCheck(new anchor.BN(100), "Hello world", nonce, {
accounts: {
Expand All @@ -51,19 +70,29 @@ describe("cashiers-check", () => {
checkSigner,
from: god,
to: receiver,
owner: program.provider.wallet.publicKey,
owner: walletKey,
tokenProgram: TOKEN_PROGRAM_ID,
rent: anchor.web3.SYSVAR_RENT_PUBKEY,
},
signers: [check, vault],
instructions: [
await program.account.check.createInstruction(check, 300),
...(await serumCmn.createTokenAccountInstrs(
program.provider,
vault.publicKey,
mint,
checkSigner
)),
await program.account.check.createInstruction(
check,
TOKEN_ACCOUNT_SIZE
),
SystemProgram.createAccount({
fromPubkey: walletKey,
newAccountPubkey: vault.publicKey,
space: TOKEN_ACCOUNT_SIZE,
programId: TOKEN_PROGRAM_ID,
lamports: token_lamports,
}),

createInitializeAccountInstruction(
vault.publicKey, // account
mint, // mint
checkSigner // owner
),
],
});

Expand All @@ -76,11 +105,8 @@ describe("cashiers-check", () => {
assert.strictEqual(checkAccount.nonce, nonce);
assert.isFalse(checkAccount.burned);

let vaultAccount = await serumCmn.getTokenAccount(
program.provider,
checkAccount.vault
);
assert.isTrue(vaultAccount.amount.eq(new anchor.BN(100)));
let vaultAccount = await getAccount(connection, checkAccount.vault);
assert.equal(vaultAccount.amount, BigInt(100));
});

it("Cashes a check", async () => {
Expand All @@ -98,16 +124,10 @@ describe("cashiers-check", () => {
const checkAccount = await program.account.check.fetch(check.publicKey);
assert.isTrue(checkAccount.burned);

let vaultAccount = await serumCmn.getTokenAccount(
program.provider,
checkAccount.vault
);
assert.isTrue(vaultAccount.amount.eq(new anchor.BN(0)));
let vaultAccount = await getAccount(connection, checkAccount.vault);
assert.equal(vaultAccount.amount, BigInt(0));

let receiverAccount = await serumCmn.getTokenAccount(
program.provider,
receiver
);
assert.isTrue(receiverAccount.amount.eq(new anchor.BN(100)));
let receiverAccount = await getAccount(connection, receiver);
assert.equal(receiverAccount.amount, BigInt(100));
});
});
17 changes: 10 additions & 7 deletions tests/cpi-returns/tests/cpi-return.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,15 @@ describe("CPI return", () => {

const cpiReturn = anchor.web3.Keypair.generate();

const confirmOptions: ConfirmOptions = { commitment: "confirmed" };
const confirmOptions: ConfirmOptions = {
commitment: "confirmed",
maxRetries: 5,
};

it("can initialize", async () => {
await calleeProgram.methods
.initialize()
.accounts({
.accountsPartial({
account: cpiReturn.publicKey,
user: provider.wallet.publicKey,
systemProgram: SystemProgram.programId,
Expand All @@ -45,7 +48,7 @@ describe("CPI return", () => {
it("can return u64 from a cpi", async () => {
const tx = await callerProgram.methods
.cpiCallReturnU64()
.accounts({
.accountsPartial({
cpiReturn: cpiReturn.publicKey,
cpiReturnProgram: calleeProgram.programId,
})
Expand Down Expand Up @@ -86,7 +89,7 @@ describe("CPI return", () => {
it("can return a struct from a cpi", async () => {
const tx = await callerProgram.methods
.cpiCallReturnStruct()
.accounts({
.accountsPartial({
cpiReturn: cpiReturn.publicKey,
cpiReturnProgram: calleeProgram.programId,
})
Expand Down Expand Up @@ -124,7 +127,7 @@ describe("CPI return", () => {
it("can return a vec from a cpi", async () => {
const tx = await callerProgram.methods
.cpiCallReturnVec()
.accounts({
.accountsPartial({
cpiReturn: cpiReturn.publicKey,
cpiReturnProgram: calleeProgram.programId,
})
Expand All @@ -134,7 +137,7 @@ describe("CPI return", () => {
});

const [key, data, buffer] = getReturnLog(t);
assert.equal(key, calleeProgram.programId);
assert.strictEqual(key, calleeProgram.programId.toBase58());

// Check for matching log on receive side
let receiveLog = t.meta.logMessages.find(
Expand Down Expand Up @@ -213,7 +216,7 @@ describe("CPI return", () => {
try {
await calleeProgram.methods
.initialize()
.accounts({
.accountsPartial({
account: cpiReturn.publicKey,
user: provider.wallet.publicKey,
systemProgram: SystemProgram.programId,
Expand Down
9 changes: 1 addition & 8 deletions tests/cpi-returns/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
{
"compilerOptions": {
"types": ["mocha", "chai"],
"lib": ["es2015"],
"module": "commonjs",
"target": "es6",
"esModuleInterop": true,
"skipLibCheck": true
}
"extends": "../tsconfig.json"
}
4 changes: 2 additions & 2 deletions tests/custom-coder/tests/spl-associated-token-coder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe("spl-associated-token-coder", () => {
// act
await program.methods
.create()
.accounts({
.accountsPartial({
associatedAccountAddress: associatedToken,
fundingAddress: provider.wallet.publicKey,
systemProgram: systemProgram.programId,
Expand All @@ -47,7 +47,7 @@ describe("spl-associated-token-coder", () => {
tokenProgram.account.mint.createInstruction(mintKeypair),
tokenProgram.methods
.initializeMint(mintDecimals, provider.wallet.publicKey, null)
.accounts({
.accountsPartial({
mint: mintKeypair.publicKey,
rent: SYSVAR_RENT_PUBKEY,
})
Expand Down
6 changes: 3 additions & 3 deletions tests/custom-coder/tests/spl-token-coder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe("spl-token", () => {
it("Creates a mint", async () => {
await program.methods
.initializeMint(6, provider.wallet.publicKey, null)
.accounts({
.accountsPartial({
mint: mintKeypair.publicKey,
rent,
})
Expand All @@ -45,7 +45,7 @@ describe("spl-token", () => {
it("Creates a token account for alice", async () => {
await program.methods
.initializeAccount()
.accounts({
.accountsPartial({
account: aliceTokenKeypair.publicKey,
mint: mintKeypair.publicKey,
owner: provider.wallet.publicKey,
Expand Down Expand Up @@ -90,7 +90,7 @@ describe("spl-token", () => {
it("Creates a token for bob", async () => {
await program.methods
.initializeAccount()
.accounts({
.accountsPartial({
account: bobTokenKeypair.publicKey,
mint: mintKeypair.publicKey,
owner: provider.wallet.publicKey,
Expand Down
10 changes: 1 addition & 9 deletions tests/custom-coder/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
{
"compilerOptions": {
"types": ["mocha", "chai"],
"typeRoots": ["./node_modules/@types"],
"lib": ["es2015"],
"module": "commonjs",
"target": "es6",
"esModuleInterop": true,
"skipLibCheck": true
}
"extends": "../tsconfig.json"
}
Loading