Skip to content

Commit bbe74ee

Browse files
Upgrade to @coral-xyz/anchor 0.28.0 (#50)
1 parent 559dc9c commit bbe74ee

File tree

40 files changed

+761
-682
lines changed

40 files changed

+761
-682
lines changed
Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
{
2-
"dependencies": {
3-
"@project-serum/anchor": "^0.24.2"
4-
},
5-
"devDependencies": {
6-
"@types/bn.js": "^5.1.0",
7-
"@types/chai": "^4.3.0",
8-
"@types/mocha": "^9.0.0",
9-
"chai": "^4.3.4",
10-
"mocha": "^9.0.3",
11-
"ts-mocha": "^10.0.0",
12-
"typescript": "^4.3.5"
13-
}
2+
"dependencies": {
3+
"@coral-xyz/anchor": "^0.28.0"
4+
},
5+
"devDependencies": {
6+
"@types/bn.js": "^5.1.0",
7+
"@types/chai": "^4.3.0",
8+
"@types/mocha": "^9.0.0",
9+
"chai": "^4.3.4",
10+
"mocha": "^9.0.3",
11+
"ts-mocha": "^10.0.0",
12+
"typescript": "^4.3.5"
13+
}
1414
}

basics/account-data/anchor/tests/test.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,20 @@
1-
import * as anchor from "@project-serum/anchor";
1+
import * as anchor from "@coral-xyz/anchor";
22
import { AnchorProgramExample } from "../target/types/anchor_program_example";
33

44
describe("Account Data!", () => {
5-
65
const provider = anchor.AnchorProvider.env();
76
anchor.setProvider(provider);
87
const payer = provider.wallet as anchor.Wallet;
9-
const program = anchor.workspace.AnchorProgramExample as anchor.Program<AnchorProgramExample>;
8+
const program = anchor.workspace
9+
.AnchorProgramExample as anchor.Program<AnchorProgramExample>;
1010

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

1313
it("Create the address info account", async () => {
1414
console.log(`Payer Address : ${payer.publicKey}`);
1515
console.log(`Address Info Acct : ${addressInfoAccount.publicKey}`);
16-
await program.methods.createAddressInfo(
17-
"Joe C",
18-
136,
19-
"Mile High Dr.",
20-
"Solana Beach",
21-
)
16+
await program.methods
17+
.createAddressInfo("Joe C", 136, "Mile High Dr.", "Solana Beach")
2218
.accounts({
2319
addressInfo: addressInfoAccount.publicKey,
2420
payer: payer.publicKey,
Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
{
2-
"dependencies": {
3-
"@project-serum/anchor": "^0.24.2"
4-
},
5-
"devDependencies": {
6-
"@types/bn.js": "^5.1.0",
7-
"@types/chai": "^4.3.0",
8-
"@types/mocha": "^9.0.0",
9-
"chai": "^4.3.4",
10-
"mocha": "^9.0.3",
11-
"ts-mocha": "^10.0.0",
12-
"typescript": "^4.3.5"
13-
}
2+
"dependencies": {
3+
"@coral-xyz/anchor": "^0.28.0"
4+
},
5+
"devDependencies": {
6+
"@types/bn.js": "^5.1.0",
7+
"@types/chai": "^4.3.0",
8+
"@types/mocha": "^9.0.0",
9+
"chai": "^4.3.4",
10+
"mocha": "^9.0.3",
11+
"ts-mocha": "^10.0.0",
12+
"typescript": "^4.3.5"
13+
}
1414
}
Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import * as anchor from "@project-serum/anchor";
1+
import * as anchor from "@coral-xyz/anchor";
22
import { AnchorProgramExample } from "../target/types/anchor_program_example";
33

44
describe("Anchor example", () => {
5-
65
const provider = anchor.AnchorProvider.env();
76
anchor.setProvider(provider);
8-
const program = anchor.workspace.AnchorProgramExample as anchor.Program<AnchorProgramExample>;
7+
const program = anchor.workspace
8+
.AnchorProgramExample as anchor.Program<AnchorProgramExample>;
99
const payer = provider.wallet as anchor.Wallet;
1010

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

1717
it("Create an account owned by our program", async () => {
18-
1918
let ix = anchor.web3.SystemProgram.createAccount({
20-
fromPubkey: provider.wallet.publicKey,
21-
newAccountPubkey: accountToChange.publicKey,
22-
lamports: await provider.connection.getMinimumBalanceForRentExemption(0),
23-
space: 0,
24-
programId: program.programId, // Our program
19+
fromPubkey: provider.wallet.publicKey,
20+
newAccountPubkey: accountToChange.publicKey,
21+
lamports: await provider.connection.getMinimumBalanceForRentExemption(0),
22+
space: 0,
23+
programId: program.programId, // Our program
2524
});
2625

2726
await anchor.web3.sendAndConfirmTransaction(
28-
provider.connection,
29-
new anchor.web3.Transaction().add(ix),
30-
[payer.payer, accountToChange]
27+
provider.connection,
28+
new anchor.web3.Transaction().add(ix),
29+
[payer.payer, accountToChange]
3130
);
3231
});
3332

3433
it("Check accounts", async () => {
35-
36-
await program.methods.checkAccounts()
34+
await program.methods
35+
.checkAccounts()
3736
.accounts({
3837
payer: provider.wallet.publicKey,
3938
accountToCreate: accountToCreate.publicKey,
@@ -42,6 +41,5 @@ describe("Anchor example", () => {
4241
})
4342
.signers([payer.payer])
4443
.rpc();
45-
4644
});
4745
});

basics/close-account/anchor/migrations/deploy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// single deploy script that's invoked from the CLI, injecting a provider
33
// configured from the workspace's Anchor.toml.
44

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

77
module.exports = async function (provider) {
88
// Configure client to use the provider.
Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
{
2-
"scripts": {
3-
"lint:fix": "prettier */*.js \"*/**/*{.js,.ts}\" -w",
4-
"lint": "prettier */*.js \"*/**/*{.js,.ts}\" --check"
5-
},
6-
"dependencies": {
7-
"@project-serum/anchor": "^0.25.0"
8-
},
9-
"devDependencies": {
10-
"chai": "^4.3.4",
11-
"mocha": "^9.0.3",
12-
"ts-mocha": "^10.0.0",
13-
"@types/bn.js": "^5.1.0",
14-
"@types/chai": "^4.3.0",
15-
"@types/mocha": "^9.0.0",
16-
"typescript": "^4.3.5",
17-
"prettier": "^2.6.2"
18-
}
2+
"scripts": {
3+
"lint:fix": "prettier */*.js \"*/**/*{.js,.ts}\" -w",
4+
"lint": "prettier */*.js \"*/**/*{.js,.ts}\" --check"
5+
},
6+
"dependencies": {
7+
"@coral-xyz/anchor": "^0.28.0"
8+
},
9+
"devDependencies": {
10+
"chai": "^4.3.4",
11+
"mocha": "^9.0.3",
12+
"ts-mocha": "^10.0.0",
13+
"@types/bn.js": "^5.1.0",
14+
"@types/chai": "^4.3.0",
15+
"@types/mocha": "^9.0.0",
16+
"typescript": "^4.3.5",
17+
"prettier": "^2.6.2"
18+
}
1919
}
Lines changed: 84 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,99 @@
1-
import * as anchor from "@project-serum/anchor";
2-
import { Program } from "@project-serum/anchor";
3-
import {Keypair, LAMPORTS_PER_SOL} from "@solana/web3.js";
1+
import * as anchor from "@coral-xyz/anchor";
2+
import { Program } from "@coral-xyz/anchor";
3+
import { Keypair, LAMPORTS_PER_SOL } from "@solana/web3.js";
44
import { CloseAccountProgram } from "../target/types/close_account_program";
5-
import {BlockheightBasedTransactionConfirmationStrategy, PublicKey} from "@solana/web3.js";
5+
import {
6+
BlockheightBasedTransactionConfirmationStrategy,
7+
PublicKey,
8+
} from "@solana/web3.js";
69
import assert from "assert";
710

811
describe("close-an-account", () => {
9-
// Configure the client to use the local cluster.
10-
anchor.setProvider(anchor.AnchorProvider.env());
12+
// Configure the client to use the local cluster.
13+
anchor.setProvider(anchor.AnchorProvider.env());
1114

12-
const program = anchor.workspace.CloseAccountProgram as Program<CloseAccountProgram>;
13-
const connection = program.provider.connection;
14-
const payer = Keypair.generate();
15+
const program = anchor.workspace
16+
.CloseAccountProgram as Program<CloseAccountProgram>;
17+
const connection = program.provider.connection;
18+
const payer = Keypair.generate();
1519

16-
async function airdrop(receiver: PublicKey, amount: number) {
17-
const sig = await program.provider.connection.requestAirdrop(receiver, amount);
18-
const blockStats = await program.provider.connection.getLatestBlockhash();
19-
const strategy: BlockheightBasedTransactionConfirmationStrategy = {
20-
signature: sig,
21-
blockhash: blockStats.blockhash,
22-
lastValidBlockHeight: blockStats.lastValidBlockHeight
23-
}
24-
await program.provider.connection.confirmTransaction(strategy, "confirmed");
25-
}
20+
async function airdrop(receiver: PublicKey, amount: number) {
21+
const sig = await program.provider.connection.requestAirdrop(
22+
receiver,
23+
amount
24+
);
25+
const blockStats = await program.provider.connection.getLatestBlockhash();
26+
const strategy: BlockheightBasedTransactionConfirmationStrategy = {
27+
signature: sig,
28+
blockhash: blockStats.blockhash,
29+
lastValidBlockHeight: blockStats.lastValidBlockHeight,
30+
};
31+
await program.provider.connection.confirmTransaction(strategy, "confirmed");
32+
}
2633

27-
function getUserAccount(user: PublicKey): [PublicKey, number] {
28-
return PublicKey.findProgramAddressSync(
29-
[
30-
Buffer.from("USER"),
31-
user.toBuffer()
32-
], program.programId)
33-
}
34+
function getUserAccount(user: PublicKey): [PublicKey, number] {
35+
return PublicKey.findProgramAddressSync(
36+
[Buffer.from("USER"), user.toBuffer()],
37+
program.programId
38+
);
39+
}
3440

35-
it("Airdrop", async () => {
36-
const balanceBefore = await connection.getBalance(payer.publicKey);
37-
await airdrop(payer.publicKey, LAMPORTS_PER_SOL);
38-
const balanceAfter = await connection.getBalance(payer.publicKey);
39-
assert.equal(balanceAfter, balanceBefore + LAMPORTS_PER_SOL);
40-
});
41+
it("Airdrop", async () => {
42+
const balanceBefore = await connection.getBalance(payer.publicKey);
43+
await airdrop(payer.publicKey, LAMPORTS_PER_SOL);
44+
const balanceAfter = await connection.getBalance(payer.publicKey);
45+
assert.equal(balanceAfter, balanceBefore + LAMPORTS_PER_SOL);
46+
});
4147

48+
it("Create Account", async () => {
49+
const [userAccountAddress] = getUserAccount(payer.publicKey);
50+
const userAccountBefore = await program.account.user.fetchNullable(
51+
userAccountAddress,
52+
"confirmed"
53+
);
54+
assert.equal(userAccountBefore, null);
4255

43-
it("Create Account", async () => {
44-
const [userAccountAddress] = getUserAccount(payer.publicKey);
45-
const userAccountBefore = await program.account.user.fetchNullable(userAccountAddress, "confirmed");
46-
assert.equal(userAccountBefore, null);
56+
await program.methods
57+
.createUser({
58+
name: "John Doe",
59+
})
60+
.accounts({
61+
payer: payer.publicKey,
62+
userAccount: userAccountAddress,
63+
})
64+
.signers([payer])
65+
.rpc({ commitment: "confirmed", skipPreflight: true });
4766

48-
await program.methods
49-
.createUser({
50-
name: "John Doe"
51-
})
52-
.accounts({
53-
payer: payer.publicKey,
54-
userAccount: userAccountAddress
55-
})
56-
.signers([payer])
57-
.rpc({commitment: "confirmed", skipPreflight: true});
67+
const userAccountAfter = await program.account.user.fetchNullable(
68+
userAccountAddress,
69+
"confirmed"
70+
);
71+
assert.notEqual(userAccountAfter, null);
72+
assert.equal(userAccountAfter.name, "John Doe");
73+
assert.equal(userAccountAfter.user.toBase58(), payer.publicKey.toBase58());
74+
});
5875

59-
const userAccountAfter = await program.account.user.fetchNullable(userAccountAddress, "confirmed");
60-
assert.notEqual(userAccountAfter, null);
61-
assert.equal(userAccountAfter.name, "John Doe");
62-
assert.equal(userAccountAfter.user.toBase58(), payer.publicKey.toBase58());
63-
})
76+
it("Close Account", async () => {
77+
const [userAccountAddress] = getUserAccount(payer.publicKey);
78+
const userAccountBefore = await program.account.user.fetchNullable(
79+
userAccountAddress,
80+
"confirmed"
81+
);
82+
assert.notEqual(userAccountBefore, null);
6483

65-
it("Close Account", async () => {
66-
const [userAccountAddress] = getUserAccount(payer.publicKey);
67-
const userAccountBefore = await program.account.user.fetchNullable(userAccountAddress, "confirmed");
68-
assert.notEqual(userAccountBefore, null);
84+
await program.methods
85+
.closeUser()
86+
.accounts({
87+
user: payer.publicKey,
88+
userAccount: userAccountAddress,
89+
})
90+
.signers([payer])
91+
.rpc({ commitment: "confirmed" });
6992

70-
await program.methods
71-
.closeUser()
72-
.accounts({
73-
user: payer.publicKey,
74-
userAccount: userAccountAddress
75-
})
76-
.signers([payer])
77-
.rpc({commitment: "confirmed"});
78-
79-
const userAccountAfter = await program.account.user.fetchNullable(userAccountAddress, "processed");
80-
assert.equal(userAccountAfter, null);
81-
})
93+
const userAccountAfter = await program.account.user.fetchNullable(
94+
userAccountAddress,
95+
"processed"
96+
);
97+
assert.equal(userAccountAfter, null);
98+
});
8299
});

basics/counter/anchor/migrations/deploy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// single deploy script that's invoked from the CLI, injecting a provider
33
// configured from the workspace's Anchor.toml.
44

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

77
module.exports = async function (provider) {
88
// Configure client to use the provider.

0 commit comments

Comments
 (0)