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 to @coral-xyz/anchor 0.28.0 #50

Merged
merged 1 commit into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions basics/account-data/anchor/package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"dependencies": {
"@project-serum/anchor": "^0.24.2"
},
"devDependencies": {
"@types/bn.js": "^5.1.0",
"@types/chai": "^4.3.0",
"@types/mocha": "^9.0.0",
"chai": "^4.3.4",
"mocha": "^9.0.3",
"ts-mocha": "^10.0.0",
"typescript": "^4.3.5"
}
"dependencies": {
"@coral-xyz/anchor": "^0.28.0"
},
"devDependencies": {
"@types/bn.js": "^5.1.0",
"@types/chai": "^4.3.0",
"@types/mocha": "^9.0.0",
"chai": "^4.3.4",
"mocha": "^9.0.3",
"ts-mocha": "^10.0.0",
"typescript": "^4.3.5"
}
}
14 changes: 5 additions & 9 deletions basics/account-data/anchor/tests/test.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
import * as anchor from "@project-serum/anchor";
import * as anchor from "@coral-xyz/anchor";
import { AnchorProgramExample } from "../target/types/anchor_program_example";

describe("Account Data!", () => {

const provider = anchor.AnchorProvider.env();
anchor.setProvider(provider);
const payer = provider.wallet as anchor.Wallet;
const program = anchor.workspace.AnchorProgramExample as anchor.Program<AnchorProgramExample>;
const program = anchor.workspace
.AnchorProgramExample as anchor.Program<AnchorProgramExample>;

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

it("Create the address info account", async () => {
console.log(`Payer Address : ${payer.publicKey}`);
console.log(`Address Info Acct : ${addressInfoAccount.publicKey}`);
await program.methods.createAddressInfo(
"Joe C",
136,
"Mile High Dr.",
"Solana Beach",
)
await program.methods
.createAddressInfo("Joe C", 136, "Mile High Dr.", "Solana Beach")
.accounts({
addressInfo: addressInfoAccount.publicKey,
payer: payer.publicKey,
Expand Down
24 changes: 12 additions & 12 deletions basics/checking-accounts/anchor/package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"dependencies": {
"@project-serum/anchor": "^0.24.2"
},
"devDependencies": {
"@types/bn.js": "^5.1.0",
"@types/chai": "^4.3.0",
"@types/mocha": "^9.0.0",
"chai": "^4.3.4",
"mocha": "^9.0.3",
"ts-mocha": "^10.0.0",
"typescript": "^4.3.5"
}
"dependencies": {
"@coral-xyz/anchor": "^0.28.0"
},
"devDependencies": {
"@types/bn.js": "^5.1.0",
"@types/chai": "^4.3.0",
"@types/mocha": "^9.0.0",
"chai": "^4.3.4",
"mocha": "^9.0.3",
"ts-mocha": "^10.0.0",
"typescript": "^4.3.5"
}
}
28 changes: 13 additions & 15 deletions basics/checking-accounts/anchor/tests/test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import * as anchor from "@project-serum/anchor";
import * as anchor from "@coral-xyz/anchor";
import { AnchorProgramExample } from "../target/types/anchor_program_example";

describe("Anchor example", () => {

const provider = anchor.AnchorProvider.env();
anchor.setProvider(provider);
const program = anchor.workspace.AnchorProgramExample as anchor.Program<AnchorProgramExample>;
const program = anchor.workspace
.AnchorProgramExample as anchor.Program<AnchorProgramExample>;
const payer = provider.wallet as anchor.Wallet;

// We'll create this ahead of time.
Expand All @@ -15,25 +15,24 @@ describe("Anchor example", () => {
const accountToCreate = anchor.web3.Keypair.generate();

it("Create an account owned by our program", async () => {

let ix = anchor.web3.SystemProgram.createAccount({
fromPubkey: provider.wallet.publicKey,
newAccountPubkey: accountToChange.publicKey,
lamports: await provider.connection.getMinimumBalanceForRentExemption(0),
space: 0,
programId: program.programId, // Our program
fromPubkey: provider.wallet.publicKey,
newAccountPubkey: accountToChange.publicKey,
lamports: await provider.connection.getMinimumBalanceForRentExemption(0),
space: 0,
programId: program.programId, // Our program
});

await anchor.web3.sendAndConfirmTransaction(
provider.connection,
new anchor.web3.Transaction().add(ix),
[payer.payer, accountToChange]
provider.connection,
new anchor.web3.Transaction().add(ix),
[payer.payer, accountToChange]
);
});

it("Check accounts", async () => {

await program.methods.checkAccounts()
await program.methods
.checkAccounts()
.accounts({
payer: provider.wallet.publicKey,
accountToCreate: accountToCreate.publicKey,
Expand All @@ -42,6 +41,5 @@ describe("Anchor example", () => {
})
.signers([payer.payer])
.rpc();

});
});
2 changes: 1 addition & 1 deletion basics/close-account/anchor/migrations/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// single deploy script that's invoked from the CLI, injecting a provider
// configured from the workspace's Anchor.toml.

const anchor = require("@project-serum/anchor");
const anchor = require("@coral-xyz/anchor");

module.exports = async function (provider) {
// Configure client to use the provider.
Expand Down
34 changes: 17 additions & 17 deletions basics/close-account/anchor/package.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
{
"scripts": {
"lint:fix": "prettier */*.js \"*/**/*{.js,.ts}\" -w",
"lint": "prettier */*.js \"*/**/*{.js,.ts}\" --check"
},
"dependencies": {
"@project-serum/anchor": "^0.25.0"
},
"devDependencies": {
"chai": "^4.3.4",
"mocha": "^9.0.3",
"ts-mocha": "^10.0.0",
"@types/bn.js": "^5.1.0",
"@types/chai": "^4.3.0",
"@types/mocha": "^9.0.0",
"typescript": "^4.3.5",
"prettier": "^2.6.2"
}
"scripts": {
"lint:fix": "prettier */*.js \"*/**/*{.js,.ts}\" -w",
"lint": "prettier */*.js \"*/**/*{.js,.ts}\" --check"
},
"dependencies": {
"@coral-xyz/anchor": "^0.28.0"
},
"devDependencies": {
"chai": "^4.3.4",
"mocha": "^9.0.3",
"ts-mocha": "^10.0.0",
"@types/bn.js": "^5.1.0",
"@types/chai": "^4.3.0",
"@types/mocha": "^9.0.0",
"typescript": "^4.3.5",
"prettier": "^2.6.2"
}
}
151 changes: 84 additions & 67 deletions basics/close-account/anchor/tests/close-account.ts
Original file line number Diff line number Diff line change
@@ -1,82 +1,99 @@
import * as anchor from "@project-serum/anchor";
import { Program } from "@project-serum/anchor";
import {Keypair, LAMPORTS_PER_SOL} from "@solana/web3.js";
import * as anchor from "@coral-xyz/anchor";
import { Program } from "@coral-xyz/anchor";
import { Keypair, LAMPORTS_PER_SOL } from "@solana/web3.js";
import { CloseAccountProgram } from "../target/types/close_account_program";
import {BlockheightBasedTransactionConfirmationStrategy, PublicKey} from "@solana/web3.js";
import {
BlockheightBasedTransactionConfirmationStrategy,
PublicKey,
} from "@solana/web3.js";
import assert from "assert";

describe("close-an-account", () => {
// Configure the client to use the local cluster.
anchor.setProvider(anchor.AnchorProvider.env());
// Configure the client to use the local cluster.
anchor.setProvider(anchor.AnchorProvider.env());

const program = anchor.workspace.CloseAccountProgram as Program<CloseAccountProgram>;
const connection = program.provider.connection;
const payer = Keypair.generate();
const program = anchor.workspace
.CloseAccountProgram as Program<CloseAccountProgram>;
const connection = program.provider.connection;
const payer = Keypair.generate();

async function airdrop(receiver: PublicKey, amount: number) {
const sig = await program.provider.connection.requestAirdrop(receiver, amount);
const blockStats = await program.provider.connection.getLatestBlockhash();
const strategy: BlockheightBasedTransactionConfirmationStrategy = {
signature: sig,
blockhash: blockStats.blockhash,
lastValidBlockHeight: blockStats.lastValidBlockHeight
}
await program.provider.connection.confirmTransaction(strategy, "confirmed");
}
async function airdrop(receiver: PublicKey, amount: number) {
const sig = await program.provider.connection.requestAirdrop(
receiver,
amount
);
const blockStats = await program.provider.connection.getLatestBlockhash();
const strategy: BlockheightBasedTransactionConfirmationStrategy = {
signature: sig,
blockhash: blockStats.blockhash,
lastValidBlockHeight: blockStats.lastValidBlockHeight,
};
await program.provider.connection.confirmTransaction(strategy, "confirmed");
}

function getUserAccount(user: PublicKey): [PublicKey, number] {
return PublicKey.findProgramAddressSync(
[
Buffer.from("USER"),
user.toBuffer()
], program.programId)
}
function getUserAccount(user: PublicKey): [PublicKey, number] {
return PublicKey.findProgramAddressSync(
[Buffer.from("USER"), user.toBuffer()],
program.programId
);
}

it("Airdrop", async () => {
const balanceBefore = await connection.getBalance(payer.publicKey);
await airdrop(payer.publicKey, LAMPORTS_PER_SOL);
const balanceAfter = await connection.getBalance(payer.publicKey);
assert.equal(balanceAfter, balanceBefore + LAMPORTS_PER_SOL);
});
it("Airdrop", async () => {
const balanceBefore = await connection.getBalance(payer.publicKey);
await airdrop(payer.publicKey, LAMPORTS_PER_SOL);
const balanceAfter = await connection.getBalance(payer.publicKey);
assert.equal(balanceAfter, balanceBefore + LAMPORTS_PER_SOL);
});

it("Create Account", async () => {
const [userAccountAddress] = getUserAccount(payer.publicKey);
const userAccountBefore = await program.account.user.fetchNullable(
userAccountAddress,
"confirmed"
);
assert.equal(userAccountBefore, null);

it("Create Account", async () => {
const [userAccountAddress] = getUserAccount(payer.publicKey);
const userAccountBefore = await program.account.user.fetchNullable(userAccountAddress, "confirmed");
assert.equal(userAccountBefore, null);
await program.methods
.createUser({
name: "John Doe",
})
.accounts({
payer: payer.publicKey,
userAccount: userAccountAddress,
})
.signers([payer])
.rpc({ commitment: "confirmed", skipPreflight: true });

await program.methods
.createUser({
name: "John Doe"
})
.accounts({
payer: payer.publicKey,
userAccount: userAccountAddress
})
.signers([payer])
.rpc({commitment: "confirmed", skipPreflight: true});
const userAccountAfter = await program.account.user.fetchNullable(
userAccountAddress,
"confirmed"
);
assert.notEqual(userAccountAfter, null);
assert.equal(userAccountAfter.name, "John Doe");
assert.equal(userAccountAfter.user.toBase58(), payer.publicKey.toBase58());
});

const userAccountAfter = await program.account.user.fetchNullable(userAccountAddress, "confirmed");
assert.notEqual(userAccountAfter, null);
assert.equal(userAccountAfter.name, "John Doe");
assert.equal(userAccountAfter.user.toBase58(), payer.publicKey.toBase58());
})
it("Close Account", async () => {
const [userAccountAddress] = getUserAccount(payer.publicKey);
const userAccountBefore = await program.account.user.fetchNullable(
userAccountAddress,
"confirmed"
);
assert.notEqual(userAccountBefore, null);

it("Close Account", async () => {
const [userAccountAddress] = getUserAccount(payer.publicKey);
const userAccountBefore = await program.account.user.fetchNullable(userAccountAddress, "confirmed");
assert.notEqual(userAccountBefore, null);
await program.methods
.closeUser()
.accounts({
user: payer.publicKey,
userAccount: userAccountAddress,
})
.signers([payer])
.rpc({ commitment: "confirmed" });

await program.methods
.closeUser()
.accounts({
user: payer.publicKey,
userAccount: userAccountAddress
})
.signers([payer])
.rpc({commitment: "confirmed"});

const userAccountAfter = await program.account.user.fetchNullable(userAccountAddress, "processed");
assert.equal(userAccountAfter, null);
})
const userAccountAfter = await program.account.user.fetchNullable(
userAccountAddress,
"processed"
);
assert.equal(userAccountAfter, null);
});
});
2 changes: 1 addition & 1 deletion basics/counter/anchor/migrations/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// single deploy script that's invoked from the CLI, injecting a provider
// configured from the workspace's Anchor.toml.

const anchor = require("@project-serum/anchor");
const anchor = require("@coral-xyz/anchor");

module.exports = async function (provider) {
// Configure client to use the provider.
Expand Down
Loading