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

ts: improve types for Provider and AccountClient #2666

Closed
wants to merge 5 commits into from
Closed
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ The minor version will be incremented upon a breaking change and the patch versi
- ts: Remove `base64-js` dependency ([#2635](https://github.com/coral-xyz/anchor/pull/2635)).
- syn: `IdlTypeDefinitionTy` enum has a new variant `Alias` ([#2637](https://github.com/coral-xyz/anchor/pull/2637)).
- cli, client, lang, spl: Solana `1.14` is no longer supported, minimum required Solana version is `1.16.0` ([#2645](https://github.com/coral-xyz/anchor/pull/2645)).
- ts: Change Provider.publicKey type into `PublicKey | null` instead of `PublicKey | undefined`, `AccountClient.createInstruction(signer: Signer, size?: number)` into `AccountClient.createInstruction(signerPubkey: PublicKey, size?: number)` ([#2665](https://github.com/coral-xyz/anchor/issues/2665)).
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why put the summary of changes in the issue and link the issue instead of the PR?


## [0.28.0] - 2023-06-09

Expand Down
4 changes: 2 additions & 2 deletions tests/bench/tests/compute-units.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ describe("Compute units", () => {
const mintKp = new anchor.web3.Keypair();
mintPk = mintKp.publicKey;
const createMintIx = await tokenProgram.account.mint.createInstruction(
mintKp
mintPk
);
const initMintIx = await tokenProgram.methods
.initializeMint2(0, owner, null)
Expand All @@ -133,7 +133,7 @@ describe("Compute units", () => {
const tokenKp = new anchor.web3.Keypair();
tokenPk = tokenKp.publicKey;
const createTokenIx = await tokenProgram.account.account.createInstruction(
tokenKp
tokenPk
);
const initTokenIx = await tokenProgram.methods
.initializeAccount3(owner)
Expand Down
2 changes: 1 addition & 1 deletion tests/cashiers-check/tests/cashiers-check.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ describe("cashiers-check", () => {
},
signers: [check, vault],
instructions: [
await program.account.check.createInstruction(check, 300),
await program.account.check.createInstruction(check.publicKey, 300),
...(await serumCmn.createTokenAccountInstrs(
program.provider,
vault.publicKey,
Expand Down
7 changes: 5 additions & 2 deletions tests/cfo/tests/utils/stake.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,11 @@ async function setupStakePool(mint, god) {
},
signers: [registrar, rewardQ],
instructions: [
await registry.account.registrar.createInstruction(registrar),
await registry.account.rewardQueue.createInstruction(rewardQ, 8250),
await registry.account.registrar.createInstruction(registrar.publicKey),
await registry.account.rewardQueue.createInstruction(
rewardQ.publicKey,
8250
),
],
}
);
Expand Down
2 changes: 1 addition & 1 deletion tests/chat/tests/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe("chat", () => {
rent: anchor.web3.SYSVAR_RENT_PUBKEY,
},
instructions: [
await program.account.chatRoom.createInstruction(chatRoom),
await program.account.chatRoom.createInstruction(chatRoom.publicKey),
],
signers: [chatRoom],
});
Expand Down
4 changes: 2 additions & 2 deletions tests/composite/tests/composite.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ describe("composite", () => {
},
signers: [dummyA, dummyB],
instructions: [
await program.account.dummyA.createInstruction(dummyA),
await program.account.dummyB.createInstruction(dummyB),
await program.account.dummyA.createInstruction(dummyA.publicKey),
await program.account.dummyB.createInstruction(dummyB.publicKey),
],
});

Expand Down
2 changes: 1 addition & 1 deletion tests/custom-coder/tests/spl-associated-token-coder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe("spl-associated-token-coder", () => {
})
.preInstructions(
await Promise.all([
tokenProgram.account.mint.createInstruction(mintKeypair),
tokenProgram.account.mint.createInstruction(mintKeypair.publicKey),
tokenProgram.methods
.initializeMint(mintDecimals, provider.wallet.publicKey, null)
.accounts({
Expand Down
10 changes: 7 additions & 3 deletions tests/custom-coder/tests/spl-token-coder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe("spl-token", () => {
})
.signers([mintKeypair])
.preInstructions([
await program.account.mint.createInstruction(mintKeypair),
await program.account.mint.createInstruction(mintKeypair.publicKey),
])
.rpc();
const mintAccount = await program.account.mint.fetch(mintKeypair.publicKey);
Expand All @@ -53,7 +53,9 @@ describe("spl-token", () => {
})
.signers([aliceTokenKeypair])
.preInstructions([
await program.account.account.createInstruction(aliceTokenKeypair),
await program.account.account.createInstruction(
aliceTokenKeypair.publicKey
),
])
.rpc();
const token = await program.account.account.fetch(
Expand Down Expand Up @@ -98,7 +100,9 @@ describe("spl-token", () => {
})
.signers([bobTokenKeypair])
.preInstructions([
await program.account.account.createInstruction(bobTokenKeypair),
await program.account.account.createInstruction(
bobTokenKeypair.publicKey
),
])
.rpc();
});
Expand Down
4 changes: 3 additions & 1 deletion tests/errors/tests/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,9 @@ describe("errors", () => {
},
// this initializes the account.owner variable with Pubkey::default
instructions: [
await program.account.hasOneAccount.createInstruction(account),
await program.account.hasOneAccount.createInstruction(
account.publicKey
),
],
signers: [account],
});
Expand Down
14 changes: 10 additions & 4 deletions tests/idl/tests/client-interactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ describe("Client interactions", () => {
.int(i8, i16, i32, i64, i128)
.accounts({ account: kp.publicKey })
.signers([kp])
.preInstructions([await program.account.intAccount.createInstruction(kp)])
.preInstructions([
await program.account.intAccount.createInstruction(kp.publicKey),
])
.rpc();

const account = await program.account.intAccount.fetch(kp.publicKey);
Expand All @@ -46,7 +48,9 @@ describe("Client interactions", () => {
.accounts({ account: kp.publicKey })
.signers([kp])
.preInstructions([
await program.account.unsignedIntAccount.createInstruction(kp),
await program.account.unsignedIntAccount.createInstruction(
kp.publicKey
),
])
.rpc();

Expand All @@ -70,7 +74,7 @@ describe("Client interactions", () => {
.accounts({ account: kp.publicKey })
.signers([kp])
.preInstructions([
await program.account.enumAccount.createInstruction(kp),
await program.account.enumAccount.createInstruction(kp.publicKey),
])
.rpc();
return await program.account.enumAccount.fetch(kp.publicKey);
Expand Down Expand Up @@ -135,7 +139,9 @@ describe("Client interactions", () => {
.typeAlias(typeAliasU8, typeAliasU8Array, typeAliasStruct)
.accounts({ account: kp.publicKey })
.signers([kp])
.preInstructions([await program.account.intAccount.createInstruction(kp)])
.preInstructions([
await program.account.intAccount.createInstruction(kp.publicKey),
])
.rpc();

const account = await program.account.typeAliasAccount.fetch(kp.publicKey);
Expand Down
2 changes: 1 addition & 1 deletion tests/idl/tests/idl-build-features.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe("idl-build features", () => {
.fullPath(outerMyStructArg, someModuleMyStructArg)
.accounts({ account: kp.publicKey })
.preInstructions([
await program.account.fullPathAccount.createInstruction(kp),
await program.account.fullPathAccount.createInstruction(kp.publicKey),
])
.signers([kp])
.rpc();
Expand Down
7 changes: 5 additions & 2 deletions tests/lockup/migrations/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,11 @@ async function registrarInit(
},
signers: [registrar, rewardQ],
instructions: [
await registry.account.registrar.createInstruction(registrar),
await registry.account.rewardQueue.createInstruction(rewardQ, 8250),
await registry.account.registrar.createInstruction(registrar.publicKey),
await registry.account.rewardQueue.createInstruction(
rewardQ.publicKey,
8250
),
],
}
);
Expand Down
23 changes: 15 additions & 8 deletions tests/lockup/tests/lockup.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ describe("Lockup and Registry", () => {
},
signers: [vesting, vault],
instructions: [
await lockup.account.vesting.createInstruction(vesting),
await lockup.account.vesting.createInstruction(vesting.publicKey),
...(await serumCmn.createTokenAccountInstrs(
provider,
vault.publicKey,
Expand Down Expand Up @@ -323,8 +323,13 @@ describe("Lockup and Registry", () => {
},
signers: [registrar, rewardQ],
instructions: [
await registry.account.registrar.createInstruction(registrar),
await registry.account.rewardQueue.createInstruction(rewardQ, 8250),
await registry.account.registrar.createInstruction(
registrar.publicKey
),
await registry.account.rewardQueue.createInstruction(
rewardQ.publicKey,
8250
),
],
}
);
Expand Down Expand Up @@ -381,7 +386,9 @@ describe("Lockup and Registry", () => {
tokenProgram: TOKEN_PROGRAM_ID,
rent: anchor.web3.SYSVAR_RENT_PUBKEY,
},
instructions: [await registry.account.member.createInstruction(member)],
instructions: [
await registry.account.member.createInstruction(member.publicKey),
],
});

const signers = [member, provider.wallet.payer];
Expand Down Expand Up @@ -515,7 +522,7 @@ describe("Lockup and Registry", () => {
mint,
unlockedVendorSigner
)),
await registry.account.rewardVendor.createInstruction(unlockedVendor),
await registry.account.rewardVendor.createInstruction(unlockedVendor.publicKey),
],
}
);
Expand Down Expand Up @@ -634,7 +641,7 @@ describe("Lockup and Registry", () => {
mint,
lockedVendorSigner
)),
await registry.account.rewardVendor.createInstruction(lockedVendor),
await registry.account.rewardVendor.createInstruction(lockedVendor.publicKey),
],
}
);
Expand Down Expand Up @@ -721,7 +728,7 @@ describe("Lockup and Registry", () => {
remainingAccounts,
signers: [vendoredVesting, vendoredVestingVault],
instructions: [
await lockup.account.vesting.createInstruction(vendoredVesting),
await lockup.account.vesting.createInstruction(vendoredVesting.publicKey),
...(await serumCmn.createTokenAccountInstrs(
provider,
vendoredVestingVault.publicKey,
Expand Down Expand Up @@ -834,7 +841,7 @@ describe("Lockup and Registry", () => {
signers: [pendingWithdrawal],
instructions: [
await registry.account.pendingWithdrawal.createInstruction(
pendingWithdrawal
pendingWithdrawal.publicKey
),
],
});
Expand Down
24 changes: 17 additions & 7 deletions tests/misc/tests/misc/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ const miscTest = (
.initialize(udata, idata)
.accounts({ data: data.publicKey })
.signers([data])
.preInstructions([await program.account.data.createInstruction(data)])
.preInstructions([
await program.account.data.createInstruction(data.publicKey),
])
.rpc();
const dataAccount = await program.account.data.fetch(data.publicKey);
assert(dataAccount.udata.eq(udata));
Expand Down Expand Up @@ -155,7 +157,9 @@ const miscTest = (
await program.methods
.initialize(new anchor.BN(10), new anchor.BN(10))
.accounts({ data: data.publicKey })
.preInstructions([await program.account.data.createInstruction(data)])
.preInstructions([
await program.account.data.createInstruction(data.publicKey),
])
.signers([data])
.rpc();

Expand Down Expand Up @@ -205,7 +209,9 @@ const miscTest = (
await program.methods
.initialize(new anchor.BN(10), new anchor.BN(10))
.accounts({ data: data.publicKey })
.preInstructions([await program.account.data.createInstruction(data)])
.preInstructions([
await program.account.data.createInstruction(data.publicKey),
])
.signers([data])
.rpc();

Expand Down Expand Up @@ -1342,7 +1348,9 @@ const miscTest = (
},
signers: [data],
instructions: [
await program.account.dataConstArraySize.createInstruction(data),
await program.account.dataConstArraySize.createInstruction(
data.publicKey
),
],
});
const dataAccount = await program.account.dataConstArraySize.fetch(
Expand All @@ -1360,7 +1368,9 @@ const miscTest = (
},
signers: [data],
instructions: [
await program.account.dataConstArraySize.createInstruction(data),
await program.account.dataConstArraySize.createInstruction(
data.publicKey
),
],
});
const dataAccount = await program.account.dataConstArraySize.fetch(
Expand Down Expand Up @@ -2420,7 +2430,7 @@ const miscTest = (
signers: [data],
instructions: [
await program.account.dataMultidimensionalArray.createInstruction(
data
data.publicKey
),
],
});
Expand All @@ -2440,7 +2450,7 @@ const miscTest = (
signers: [data],
instructions: [
await program.account.dataMultidimensionalArrayConstSizes.createInstruction(
data
data.publicKey
),
],
});
Expand Down
4 changes: 2 additions & 2 deletions tests/multisig/tests/multisig.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe("multisig", () => {
},
instructions: [
await program.account.multisig.createInstruction(
multisig,
multisig.publicKey,
multisigSize
),
],
Expand Down Expand Up @@ -74,7 +74,7 @@ describe("multisig", () => {
},
instructions: [
await program.account.transaction.createInstruction(
transaction,
transaction.publicKey,
txSize
),
],
Expand Down
2 changes: 1 addition & 1 deletion tests/optional/tests/optional.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ describe("Optional", () => {
): Promise<[web3.Keypair, web3.TransactionInstruction]> => {
const keypair = requiredKeypair ?? new web3.Keypair();
const createIx = await program.account.dataAccount.createInstruction(
keypair
keypair.publicKey
);
return [keypair, createIx];
};
Expand Down
6 changes: 4 additions & 2 deletions tests/spl/token-proxy/tests/token-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,9 @@ async function getMintInfo(provider, mintAddr) {
async function createMint(tokenProgram) {
const mint = anchor.web3.Keypair.generate();
const authority = tokenProgram.provider.wallet.publicKey;
const createMintIx = await tokenProgram.account.mint.createInstruction(mint);
const createMintIx = await tokenProgram.account.mint.createInstruction(
mint.publicKey
);
const initMintIx = await tokenProgram.methods
.initializeMint2(0, authority, null)
.accounts({ mint: mint.publicKey })
Expand All @@ -284,7 +286,7 @@ async function createTokenAccount(tokenProgram, mint, owner) {
const vault = anchor.web3.Keypair.generate();
const tx = new anchor.web3.Transaction();
const createTokenAccountIx =
await tokenProgram.account.account.createInstruction(vault);
await tokenProgram.account.account.createInstruction(vault.publicKey);
const initTokenAccountIx = await tokenProgram.methods
.initializeAccount3(owner)
.accounts({ account: vault.publicKey, mint })
Expand Down
6 changes: 4 additions & 2 deletions tests/tictactoe/tests/tictactoe.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe("tictactoe", () => {
},
signers: [dashboard],
instructions: [
await program.account.dashboard.createInstruction(dashboard),
await program.account.dashboard.createInstruction(dashboard.publicKey),
],
});

Expand All @@ -32,7 +32,9 @@ describe("tictactoe", () => {
rent: anchor.web3.SYSVAR_RENT_PUBKEY,
},
signers: [game],
instructions: [await program.account.game.createInstruction(game)],
instructions: [
await program.account.game.createInstruction(game.publicKey),
],
});

console.log("transaction: ", tx);
Expand Down
Loading
Loading