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

lang: Sends lamports to payer on init #648

Merged
merged 4 commits into from
Aug 31, 2021
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
122 changes: 122 additions & 0 deletions examples/misc/tests/misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,28 @@ describe("misc", () => {
assert.ok(account.data === 3);
});

it("Can init a random account prefunded", async () => {
const data = anchor.web3.Keypair.generate();
await program.rpc.testInit({
accounts: {
data: data.publicKey,
payer: program.provider.wallet.publicKey,
systemProgram: anchor.web3.SystemProgram.programId,
},
signers: [data],
instructions: [
anchor.web3.SystemProgram.transfer({
fromPubkey: program.provider.wallet.publicKey,
toPubkey: data.publicKey,
lamports: 4039280,
}),
],
});

const account = await program.account.dataI8.fetch(data.publicKey);
assert.ok(account.data === 3);
});

it("Can init a random zero copy account", async () => {
const data = anchor.web3.Keypair.generate();
await program.rpc.testInitZeroCopy({
Expand Down Expand Up @@ -428,6 +450,38 @@ describe("misc", () => {
);
});

it("Can create a random mint account prefunded", async () => {
mint = anchor.web3.Keypair.generate();
await program.rpc.testInitMint({
accounts: {
mint: mint.publicKey,
payer: program.provider.wallet.publicKey,
systemProgram: anchor.web3.SystemProgram.programId,
tokenProgram: TOKEN_PROGRAM_ID,
rent: anchor.web3.SYSVAR_RENT_PUBKEY,
},
signers: [mint],
instructions: [
anchor.web3.SystemProgram.transfer({
fromPubkey: program.provider.wallet.publicKey,
toPubkey: mint.publicKey,
lamports: 4039280,
}),
],
});
const client = new Token(
program.provider.connection,
mint.publicKey,
TOKEN_PROGRAM_ID,
program.provider.wallet.payer
);
const mintAccount = await client.getMintInfo();
assert.ok(mintAccount.decimals === 6);
assert.ok(
mintAccount.mintAuthority.equals(program.provider.wallet.publicKey)
);
});

it("Can create a random token account", async () => {
const token = anchor.web3.Keypair.generate();
await program.rpc.testInitToken({
Expand All @@ -454,4 +508,72 @@ describe("misc", () => {
assert.ok(account.owner.equals(program.provider.wallet.publicKey));
assert.ok(account.mint.equals(mint.publicKey));
});

it("Can create a random token with prefunding", async () => {
const token = anchor.web3.Keypair.generate();
await program.rpc.testInitToken({
accounts: {
token: token.publicKey,
mint: mint.publicKey,
payer: program.provider.wallet.publicKey,
systemProgram: anchor.web3.SystemProgram.programId,
tokenProgram: TOKEN_PROGRAM_ID,
rent: anchor.web3.SYSVAR_RENT_PUBKEY,
},
signers: [token],
instructions: [
anchor.web3.SystemProgram.transfer({
fromPubkey: program.provider.wallet.publicKey,
toPubkey: token.publicKey,
lamports: 4039280,
}),
],
});
const client = new Token(
program.provider.connection,
mint.publicKey,
TOKEN_PROGRAM_ID,
program.provider.wallet.payer
);
const account = await client.getAccountInfo(token.publicKey);
assert.ok(account.state === 1);
assert.ok(account.amount.toNumber() === 0);
assert.ok(account.isInitialized);
assert.ok(account.owner.equals(program.provider.wallet.publicKey));
assert.ok(account.mint.equals(mint.publicKey));
});

it("Can create a random token with prefunding under the rent exemption", async () => {
const token = anchor.web3.Keypair.generate();
await program.rpc.testInitToken({
accounts: {
token: token.publicKey,
mint: mint.publicKey,
payer: program.provider.wallet.publicKey,
systemProgram: anchor.web3.SystemProgram.programId,
tokenProgram: TOKEN_PROGRAM_ID,
rent: anchor.web3.SYSVAR_RENT_PUBKEY,
},
signers: [token],
instructions: [
anchor.web3.SystemProgram.transfer({
fromPubkey: program.provider.wallet.publicKey,
toPubkey: token.publicKey,
lamports: 1,
}),
],
});
const client = new Token(
program.provider.connection,
mint.publicKey,
TOKEN_PROGRAM_ID,
program.provider.wallet.payer
);
const account = await client.getAccountInfo(token.publicKey);
assert.ok(account.state === 1);
assert.ok(account.amount.toNumber() === 0);
assert.ok(account.isInitialized);
assert.ok(account.owner.equals(program.provider.wallet.publicKey));
assert.ok(account.mint.equals(mint.publicKey));
});
});
Loading