-
Notifications
You must be signed in to change notification settings - Fork 301
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
17afe2e
commit 1557b10
Showing
57 changed files
with
1,185 additions
and
1,124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.