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: make Provider an interface and update provider functions #1707

Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
0a286ee
initial Provider interface
paul-schaaf Mar 29, 2022
835a29e
functions that dont require the wallet to sign are not part of the pr…
paul-schaaf Mar 29, 2022
8003e72
unbundle interface fn args
paul-schaaf Mar 31, 2022
00f6b29
empty commit
paul-schaaf Mar 31, 2022
6aa31c5
remove unnecessary undefined checks
paul-schaaf Mar 31, 2022
17ef9a8
ts: fix build errorsg
paul-schaaf Mar 31, 2022
ae60b35
ts: make signers arg optional
paul-schaaf Mar 31, 2022
067148a
ts: shortcircuit ctx.options.commitment
paul-schaaf Mar 31, 2022
df53506
ts: fix simulate
paul-schaaf Mar 31, 2022
b93c233
update send to sendAndConfirm in AnchorProvider
paul-schaaf Mar 31, 2022
61d1ed6
tests: update more tests to use new Provider interface
paul-schaaf Mar 31, 2022
30d0104
ts: make Provider interface default export
paul-schaaf Mar 31, 2022
7d037cc
lint:fix
paul-schaaf Mar 31, 2022
9386e34
tests: use the AnchorProvider Provider interface implementor
paul-schaaf Mar 31, 2022
45e364a
tests: hack Provider.send to use sendAndConfirm for tests that use se…
paul-schaaf Mar 31, 2022
2d4a92a
examples: use AnchorProvider
paul-schaaf Mar 31, 2022
078c652
update auction-house submodule
paul-schaaf Mar 31, 2022
740b6e0
Merge branch 'master' into 411-ts-use-provider-interface-instead-of-c…
paul-schaaf Mar 31, 2022
ad1f27a
tests: fix final failing tests
paul-schaaf Mar 31, 2022
50251bd
update changelog
paul-schaaf Mar 31, 2022
ae759d5
Merge branch 'master' into 411-ts-use-provider-interface-instead-of-c…
paul-schaaf Mar 31, 2022
9c78a0d
Merge branch 'master' into 411-ts-use-provider-interface-instead-of-c…
paul-schaaf Apr 11, 2022
5dbd551
ts: address review comments
paul-schaaf Apr 11, 2022
f2e3b3e
Merge branch 'master' into 411-ts-use-provider-interface-instead-of-c…
paul-schaaf Apr 11, 2022
1736dca
ts: remove blockhash logic from simulateTransaction
paul-schaaf Apr 11, 2022
b8da5d8
merge master
paul-schaaf Apr 11, 2022
1c5d2ff
update submodules
paul-schaaf Apr 11, 2022
21d70bf
Merge branch 'master' into 411-ts-use-provider-interface-instead-of-c…
paul-schaaf Apr 11, 2022
64a70b9
changelog
paul-schaaf Apr 11, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -27,6 +27,7 @@ The minor version will be incremented upon a breaking change and the patch versi
* avm: `amv install` switches to the newly installed version after installation finishes ([#1670](https://github.com/project-serum/anchor/pull/1670)).
* spl: Re-export the `spl_token` crate ([#1665](https://github.com/project-serum/anchor/pull/1665)).
* lang, cli, spl: Update solana toolchain to v1.9.13 ([#1653](https://github.com/project-serum/anchor/pull/1653)).
* ts: Make `Provider` an interface and adjust its signatures and add `AnchorProvider` implementor class. ([#1707](https://github.com/project-serum/anchor/pull/1707)).
paul-schaaf marked this conversation as resolved.
Show resolved Hide resolved

## [0.23.0] - 2022-03-20

Expand Down
2 changes: 1 addition & 1 deletion examples/tutorial/basic-0/client.js
Expand Up @@ -5,7 +5,7 @@
const anchor = require("@project-serum/anchor");

// Configure the local cluster.
anchor.setProvider(anchor.Provider.local());
anchor.setProvider(anchor.AnchorProvider.local());

async function main() {
// #region main
Expand Down
2 changes: 1 addition & 1 deletion examples/tutorial/basic-0/tests/basic-0.js
Expand Up @@ -2,7 +2,7 @@ const anchor = require("@project-serum/anchor");

describe("basic-0", () => {
// Configure the client to use the local cluster.
anchor.setProvider(anchor.Provider.local());
anchor.setProvider(anchor.AnchorProvider.local());

it("Uses the workspace to invoke the initialize instruction", async () => {
// #region code
Expand Down
2 changes: 1 addition & 1 deletion examples/tutorial/basic-1/tests/basic-1.js
Expand Up @@ -4,7 +4,7 @@ const { SystemProgram } = anchor.web3;

describe("basic-1", () => {
// Use a local provider.
const provider = anchor.Provider.local();
const provider = anchor.AnchorProvider.local();

// Configure the client to use the local cluster.
anchor.setProvider(provider);
Expand Down
2 changes: 1 addition & 1 deletion examples/tutorial/basic-2/tests/basic-2.js
Expand Up @@ -3,7 +3,7 @@ const anchor = require("@project-serum/anchor");
const { SystemProgram } = anchor.web3;

describe("basic-2", () => {
const provider = anchor.Provider.local();
const provider = anchor.AnchorProvider.local();

// Configure the client to use the local cluster.
anchor.setProvider(provider);
Expand Down
2 changes: 1 addition & 1 deletion examples/tutorial/basic-3/tests/basic-3.js
Expand Up @@ -3,7 +3,7 @@ const anchor = require("@project-serum/anchor");
const { SystemProgram } = anchor.web3;

describe("basic-3", () => {
const provider = anchor.Provider.local();
const provider = anchor.AnchorProvider.local();

// Configure the client to use the local cluster.
anchor.setProvider(provider);
Expand Down
2 changes: 1 addition & 1 deletion examples/tutorial/basic-4/tests/basic-4.js
Expand Up @@ -2,7 +2,7 @@ const assert = require("assert");
const anchor = require("@project-serum/anchor");

describe("basic-4", () => {
const provider = anchor.Provider.local();
const provider = anchor.AnchorProvider.local();

// Configure the client to use the local cluster.
anchor.setProvider(provider);
Expand Down
2 changes: 1 addition & 1 deletion tests/auction-house
2 changes: 1 addition & 1 deletion tests/bpf-upgradeable-state/tests/bpf-upgradable-state.ts
Expand Up @@ -6,7 +6,7 @@ import { assert } from "chai";
import { BpfUpgradeableState } from "../target/types/bpf_upgradeable_state";

describe("bpf_upgradeable_state", () => {
const provider = anchor.Provider.env();
const provider = anchor.AnchorProvider.env();
// Configure the client to use the local cluster.
anchor.setProvider(provider);

Expand Down
6 changes: 5 additions & 1 deletion tests/cashiers-check/tests/cashiers-check.js
Expand Up @@ -5,7 +5,11 @@ const { TOKEN_PROGRAM_ID } = require("@solana/spl-token");

describe("cashiers-check", () => {
// Configure the client to use the local cluster.
anchor.setProvider(anchor.Provider.env());
const provider = anchor.AnchorProvider.env();
// hack so we don't have to update serum-common library
// to the new AnchorProvider class and Provider interface
provider.send = provider.sendAndConfirm;
anchor.setProvider(provider);

const program = anchor.workspace.CashiersCheck;

Expand Down
2 changes: 1 addition & 1 deletion tests/cfo/deps/stake
Submodule stake updated 1 files
+1 −1 tests/lockup.js
2 changes: 1 addition & 1 deletion tests/cfo/deps/swap
2 changes: 1 addition & 1 deletion tests/cfo/scripts/fees.js
Expand Up @@ -6,7 +6,7 @@ const anchor = require("@project-serum/anchor");
const { Market, OpenOrders } = require("@project-serum/serum");
const Account = anchor.web3.Account;
const Program = anchor.Program;
const provider = anchor.Provider.local();
const provider = anchor.AnchorProvider.local();
const secret = JSON.parse(fs.readFileSync("./scripts/market-maker.json"));
const MARKET_MAKER = new Account(secret);
const PublicKey = anchor.web3.PublicKey;
Expand Down
5 changes: 4 additions & 1 deletion tests/cfo/scripts/list-market.js
Expand Up @@ -5,7 +5,10 @@
const utils = require("../tests/utils");
const fs = require("fs");
const anchor = require("@project-serum/anchor");
const provider = anchor.Provider.local();
const provider = anchor.AnchorProvider.local();
// hack so we don't have to update serum-common library
// to the new AnchorProvider class and Provider interface
provider.send = provider.sendAndConfirm;

async function main() {
ORDERBOOK_ENV = await utils.initMarket({
Expand Down
2 changes: 1 addition & 1 deletion tests/cfo/scripts/trade-bot.js
Expand Up @@ -9,7 +9,7 @@ const { runTradeBot } = require("../tests/utils");

async function main() {
const market = new PublicKey(process.argv[2]);
const provider = anchor.Provider.local();
const provider = anchor.AnchorProvider.local();
runTradeBot(market, provider);
}

Expand Down
6 changes: 5 additions & 1 deletion tests/cfo/tests/cfo.js
Expand Up @@ -23,9 +23,13 @@ const SYSVAR_INSTRUCTIONS_PUBKEY = new PublicKey(
const FEES = "6160355581";

describe("cfo", () => {
anchor.setProvider(anchor.Provider.env());
const provider = anchor.AnchorProvider.env();
anchor.setProvider(provider);

const program = anchor.workspace.Cfo;
// hack so we don't have to update serum-common library
// to the new AnchorProvider class and Provider interface
program.provider.send = provider.sendAndConfirm;
const sweepAuthority = program.provider.wallet.publicKey;
let officer, srmVault, usdcVault, bVault, stake, treasury;
let officerBump, srmBump, usdcBump, bBump, stakeBump, treasuryBump;
Expand Down
18 changes: 12 additions & 6 deletions tests/cfo/tests/utils/index.js
Expand Up @@ -125,7 +125,7 @@ async function fundAccount({ provider, mints }) {
};

// Transfer lamports to market maker.
await provider.send(
await provider.sendAndConfirm(
(() => {
const tx = new Transaction();
tx.add(
Expand Down Expand Up @@ -155,7 +155,7 @@ async function fundAccount({ provider, mints }) {
MARKET_MAKER.publicKey
);

await provider.send(
await provider.sendAndConfirm(
(() => {
const tx = new Transaction();
tx.add(
Expand Down Expand Up @@ -220,7 +220,10 @@ async function setupMarket({
feeDiscountPubkey: null,
selfTradeBehavior: "abortTransaction",
});
await provider.send(transaction, signers.concat(marketMaker.account));
await provider.sendAndConfirm(
transaction,
signers.concat(marketMaker.account)
);
}

for (let k = 0; k < bids.length; k += 1) {
Expand All @@ -239,7 +242,10 @@ async function setupMarket({
feeDiscountPubkey: null,
selfTradeBehavior: "abortTransaction",
});
await provider.send(transaction, signers.concat(marketMaker.account));
await provider.sendAndConfirm(
transaction,
signers.concat(marketMaker.account)
);
}

return [MARKET_A_USDC, vaultOwner];
Expand Down Expand Up @@ -527,7 +533,7 @@ async function runTradeBot(market, provider, iterations = undefined) {
feeDiscountPubkey: null,
selfTradeBehavior: "abortTransaction",
});
let txSig = await provider.send(tx_ask, sigs_ask.concat(maker));
let txSig = await provider.sendAndConfirm(tx_ask, sigs_ask.concat(maker));
console.log("Ask", txSig);

// Take.
Expand All @@ -545,7 +551,7 @@ async function runTradeBot(market, provider, iterations = undefined) {
feeDiscountPubkey: null,
selfTradeBehavior: "abortTransaction",
});
txSig = await provider.send(tx_bid, sigs_bid.concat(taker));
txSig = await provider.sendAndConfirm(tx_bid, sigs_bid.concat(taker));
console.log("Bid", txSig);

await sleep(1000);
Expand Down
5 changes: 4 additions & 1 deletion tests/cfo/tests/utils/stake.js
Expand Up @@ -5,7 +5,10 @@ const utils = require("../../deps/stake/tests/utils");

const lockup = anchor.workspace.Lockup;
const registry = anchor.workspace.Registry;
const provider = anchor.Provider.env();
const provider = anchor.AnchorProvider.env();
// hack so we don't have to update serum-common library
// to the new AnchorProvider class and Provider interface
provider.send = provider.sendAndConfirm;

let lockupAddress = null;
let mint = null;
Expand Down
2 changes: 1 addition & 1 deletion tests/chat/tests/chat.js
Expand Up @@ -4,7 +4,7 @@ const { PublicKey } = anchor.web3;

describe("chat", () => {
// Configure the client to use the local cluster.
anchor.setProvider(anchor.Provider.env());
anchor.setProvider(anchor.AnchorProvider.env());

// Program client handle.
const program = anchor.workspace.Chat;
Expand Down
2 changes: 1 addition & 1 deletion tests/composite/tests/composite.js
Expand Up @@ -2,7 +2,7 @@ const { assert } = require("chai");
const anchor = require("@project-serum/anchor");

describe("composite", () => {
const provider = anchor.Provider.local();
const provider = anchor.AnchorProvider.local();

// Configure the client to use the local cluster.
anchor.setProvider(provider);
Expand Down
2 changes: 1 addition & 1 deletion tests/cpi-returns/tests/cpi-return.ts
Expand Up @@ -8,7 +8,7 @@ import { Caller } from "../target/types/caller";
const { SystemProgram } = anchor.web3;

describe("CPI return", () => {
const provider = anchor.Provider.env();
const provider = anchor.AnchorProvider.env();
anchor.setProvider(provider);

const callerProgram = anchor.workspace.Caller as Program<Caller>;
Expand Down
2 changes: 1 addition & 1 deletion tests/custom-coder/tests/custom-coder.ts
Expand Up @@ -6,7 +6,7 @@ import { Keypair, SYSVAR_RENT_PUBKEY } from "@solana/web3.js";

describe("custom-coder", () => {
// Configure the client to use the local cluster.
anchor.setProvider(anchor.Provider.env());
anchor.setProvider(anchor.AnchorProvider.env());

// Client.
const program = Spl.token();
Expand Down
2 changes: 1 addition & 1 deletion tests/declare-id/tests/declare-id.ts
Expand Up @@ -5,7 +5,7 @@ import { DeclareId } from "../target/types/declare_id";
import { assert } from "chai";

describe("declare_id", () => {
anchor.setProvider(anchor.Provider.local());
anchor.setProvider(anchor.AnchorProvider.local());
const program = anchor.workspace.DeclareId as Program<DeclareId>;

it("throws error!", async () => {
Expand Down
4 changes: 2 additions & 2 deletions tests/errors/tests/errors.ts
Expand Up @@ -64,7 +64,7 @@ const withLogTest = async (callback, expectedLogs) => {

describe("errors", () => {
// Configure the client to use the local cluster.
const localProvider = anchor.Provider.local();
const localProvider = anchor.AnchorProvider.local();
localProvider.opts.skipPreflight = true;
// processed failed tx do not result in AnchorErrors in the client
// because we cannot get logs for them (only through overkill `onLogs`)
Expand Down Expand Up @@ -279,7 +279,7 @@ describe("errors", () => {
data: program.coder.instruction.encode("signer_error", {}),
})
);
await program.provider.send(tx);
await program.provider.sendAndConfirm(tx);
assert.ok(false);
} catch (err) {
anchor.getProvider().connection.removeOnLogsListener(listener);
Expand Down
2 changes: 1 addition & 1 deletion tests/escrow/tests/escrow.ts
Expand Up @@ -8,7 +8,7 @@ import { Escrow } from "../target/types/escrow";
type EscrowAccount = IdlAccounts<Escrow>["escrowAccount"];

describe("escrow", () => {
const provider = anchor.Provider.env();
const provider = anchor.AnchorProvider.env();
anchor.setProvider(provider);

const program = anchor.workspace.Escrow as Program<Escrow>;
Expand Down
2 changes: 1 addition & 1 deletion tests/events/tests/events.js
Expand Up @@ -3,7 +3,7 @@ const { assert } = require("chai");

describe("events", () => {
// Configure the client to use the local cluster.
anchor.setProvider(anchor.Provider.env());
anchor.setProvider(anchor.AnchorProvider.env());
const program = anchor.workspace.Events;

it("Is initialized!", async () => {
Expand Down
2 changes: 1 addition & 1 deletion tests/floats/tests/floats.ts
Expand Up @@ -6,7 +6,7 @@ import { assert } from "chai";

describe("floats", () => {
// Configure the client to use the local cluster.
anchor.setProvider(anchor.Provider.env());
anchor.setProvider(anchor.AnchorProvider.env());

const program = anchor.workspace.Floats as Program<Floats>;

Expand Down
6 changes: 3 additions & 3 deletions tests/ido-pool/tests/ido-pool.js
Expand Up @@ -14,7 +14,7 @@ const {
const { token } = require("@project-serum/anchor/dist/cjs/utils");

describe("ido-pool", () => {
const provider = anchor.Provider.local();
const provider = anchor.AnchorProvider.local();

// Configure the client to use the local cluster.
anchor.setProvider(provider);
Expand Down Expand Up @@ -182,7 +182,7 @@ describe("ido-pool", () => {
let createUserUsdcTrns = new anchor.web3.Transaction().add(
createUserUsdcInstr
);
await provider.send(createUserUsdcTrns);
await provider.sendAndConfirm(createUserUsdcTrns);
await usdcMintAccount.mintTo(
userUsdc,
provider.wallet.publicKey,
Expand Down Expand Up @@ -283,7 +283,7 @@ describe("ido-pool", () => {
let createSecondUserUsdcTrns = new anchor.web3.Transaction();
createSecondUserUsdcTrns.add(transferSolInstr);
createSecondUserUsdcTrns.add(createSecondUserUsdcInstr);
await provider.send(createSecondUserUsdcTrns);
await provider.sendAndConfirm(createSecondUserUsdcTrns);
await usdcMintAccount.mintTo(
secondUserUsdc,
provider.wallet.publicKey,
Expand Down
2 changes: 1 addition & 1 deletion tests/interface/tests/interface.js
Expand Up @@ -4,7 +4,7 @@ const nativeAssert = require("assert");

describe("interface", () => {
// Configure the client to use the local cluster.
anchor.setProvider(anchor.Provider.env());
anchor.setProvider(anchor.AnchorProvider.env());

const counter = anchor.workspace.Counter;
const counterAuth = anchor.workspace.CounterAuth;
Expand Down
5 changes: 4 additions & 1 deletion tests/lockup/tests/lockup.js
Expand Up @@ -9,7 +9,10 @@ anchor.utils.features.set("anchor-deprecated-state");

describe("Lockup and Registry", () => {
// Read the provider from the configured environmnet.
const provider = anchor.Provider.env();
const provider = anchor.AnchorProvider.env();
// hack so we don't have to update serum-common library
// to the new AnchorProvider class and Provider interface
provider.send = provider.sendAndConfirm;

// Configure the client to use the provider.
anchor.setProvider(provider);
Expand Down
2 changes: 1 addition & 1 deletion tests/misc/miscNonRentExempt.ts
Expand Up @@ -11,7 +11,7 @@ const { assert } = require("chai");

describe("miscNonRentExempt", () => {
// Configure the client to use the local cluster.
anchor.setProvider(anchor.Provider.env());
anchor.setProvider(anchor.AnchorProvider.env());
const program = anchor.workspace.Misc as Program<Misc>;

it("init_if_needed checks rent_exemption if init is not needed", async () => {
Expand Down
4 changes: 2 additions & 2 deletions tests/misc/tests/misc.ts
Expand Up @@ -20,7 +20,7 @@ const miscIdl = require("../target/idl/misc.json");

describe("misc", () => {
// Configure the client to use the local cluster.
anchor.setProvider(anchor.Provider.env());
anchor.setProvider(anchor.AnchorProvider.env());
const program = anchor.workspace.Misc as Program<Misc>;
const misc2Program = anchor.workspace.Misc2 as Program<Misc2>;

Expand Down Expand Up @@ -760,7 +760,7 @@ describe("misc", () => {
const anotherProgram = new anchor.Program(
miscIdl,
program.programId,
new anchor.Provider(
new anchor.AnchorProvider(
program.provider.connection,
new anchor.Wallet(anchor.web3.Keypair.generate()),
{ commitment: program.provider.connection.commitment }
Expand Down
2 changes: 1 addition & 1 deletion tests/multiple-suites/tests/another-suite/another-suite.ts
Expand Up @@ -6,7 +6,7 @@ import { MultipleSuites } from "../../target/types/multiple_suites";

describe("multiple-suites", () => {
// Configure the client to use the local cluster.
anchor.setProvider(anchor.Provider.env());
anchor.setProvider(anchor.AnchorProvider.env());

const program = anchor.workspace.MultipleSuites as Program<MultipleSuites>;

Expand Down
Expand Up @@ -6,7 +6,7 @@ import { MultipleSuites } from "../../../target/types/multiple_suites";

describe("multiple-suites", () => {
// Configure the client to use the local cluster.
anchor.setProvider(anchor.Provider.env());
anchor.setProvider(anchor.AnchorProvider.env());

const program = anchor.workspace.MultipleSuites as Program<MultipleSuites>;

Expand Down