Explorar o código

ci: ci should error if tests have typescript errors (#1801)

Paul %!s(int64=3) %!d(string=hai) anos
pai
achega
42663eda25

+ 16 - 13
.github/workflows/no-cashing-tests.yaml

@@ -165,6 +165,7 @@ jobs:
       - run: cd tests/bpf-upgradeable-state && anchor build --skip-lint
       - run: cd tests/bpf-upgradeable-state && solana program deploy --program-id program_with_different_programdata.json target/deploy/bpf_upgradeable_state.so
       - run: cd tests/bpf-upgradeable-state && cp bpf_upgradeable_state-keypair.json target/deploy/bpf_upgradeable_state-keypair.json && anchor test --skip-local-validator --skip-build --skip-lint
+      - run: cd tests/bpf-upgradeable-state && npx tsc --noEmit
       - uses: ./.github/actions/git-diff/
 
   # this test exists to make sure that anchor
@@ -220,7 +221,7 @@ jobs:
           path: ~/.cargo/bin/
       - run: chmod +x ~/.cargo/bin/anchor
 
-      - run: cd "$(mktemp -d)" && anchor init hello-anchor && cd hello-anchor && yarn link @project-serum/anchor && anchor test && yarn lint:fix
+      - run: cd "$(mktemp -d)" && anchor init hello-anchor && cd hello-anchor && yarn link @project-serum/anchor && yarn && anchor test && yarn lint:fix
       - uses: ./.github/actions/git-diff/
 
   test-programs:
@@ -236,7 +237,7 @@ jobs:
             path: tests/sysvars
           - cmd: cd tests/composite && anchor test --skip-lint
             path: tests/composite
-          - cmd: cd tests/errors && anchor test --skip-lint
+          - cmd: cd tests/errors && anchor test --skip-lint && npx tsc --noEmit
             path: tests/errors
           - cmd: cd tests/spl/token-proxy && anchor test --skip-lint
             path: spl/token-proxy
@@ -248,21 +249,21 @@ jobs:
             path: tests/lockup
           - cmd: cd tests/swap/deps/serum-dex/dex && cargo build-bpf -- --locked && cd ../../../ && anchor test --skip-lint
             path: tests/swap
-          - cmd: cd tests/escrow && anchor test --skip-lint
+          - cmd: cd tests/escrow && anchor test --skip-lint && npx tsc --noEmit
             path: tests/escrow
-          - cmd: cd tests/pyth && anchor test --skip-lint
+          - cmd: cd tests/pyth && anchor test --skip-lint && npx tsc --noEmit
             path: tests/pyth
           - cmd: cd tests/system-accounts && anchor test --skip-lint
             path: tests/system-accounts
-          - cmd: cd tests/misc && anchor test --skip-lint
+          - cmd: cd tests/misc && anchor test --skip-lint && npx tsc --noEmit
             path: tests/misc
           - cmd: cd tests/events && anchor test --skip-lint
             path: tests/events
           - cmd: cd tests/cashiers-check && anchor test --skip-lint
             path: tests/cashiers-check
-          - cmd: cd tests/declare-id && anchor test --skip-lint
+          - cmd: cd tests/declare-id && anchor test --skip-lint && npx tsc --noEmit
             path: tests/declare-id
-          - cmd: cd tests/typescript && anchor test --skip-lint
+          - cmd: cd tests/typescript && anchor test --skip-lint && npx tsc --noEmit
             path: tests/typescript
           - cmd: cd tests/zero-copy && anchor test --skip-lint && cd programs/zero-copy && cargo test-bpf
             path: tests/zero-copy
@@ -274,18 +275,20 @@ jobs:
             path: tests/cfo
           - cmd: cd tests/auction-house && yarn --frozen-lockfile && anchor test --skip-lint && git checkout Cargo.lock
             path: tests/auction-house
-          - cmd: cd tests/floats && yarn --frozen-lockfile && anchor test --skip-lint
+          - cmd: cd tests/floats && yarn --frozen-lockfile && anchor test --skip-lint && npx tsc --noEmit
             path: tests/floats
-          - cmd: cd tests/safety-checks && ./test.sh
+          - cmd: cd tests/safety-checks && anchor run test
             path: tests/safety-checks
-          - cmd: cd tests/custom-coder && anchor test --skip-lint
+          - cmd: cd tests/custom-coder && anchor test --skip-lint && npx tsc --noEmit
             path: tests/custom-coder
-          - cmd: cd tests/validator-clone && yarn --frozen-lockfile && anchor test --skip-lint
+          - cmd: cd tests/validator-clone && anchor test --skip-lint && npx tsc --noEmit
             path: tests/validator-clone
-          - cmd: cd tests/cpi-returns && anchor test --skip-lint
+          - cmd: cd tests/cpi-returns && anchor test --skip-lint && npx tsc --noEmit
             path: tests/cpi-returns
-          - cmd: cd tests/multiple-suites && anchor test --skip-lint
+          - cmd: cd tests/multiple-suites && anchor test --skip-lint && npx tsc --noEmit
             path: tests/multiple-suites
+          - cmd: cd tests/pda-derivation && anchor test --skip-lint && npx tsc --noEmit
+            path: tests/pda-derivation
     steps:
       - uses: actions/checkout@v2
       - uses: ./.github/actions/setup/

+ 15 - 12
.github/workflows/tests.yaml

@@ -245,6 +245,7 @@ jobs:
       - run: cd tests/bpf-upgradeable-state && anchor build --skip-lint
       - run: cd tests/bpf-upgradeable-state && solana program deploy --program-id program_with_different_programdata.json target/deploy/bpf_upgradeable_state.so
       - run: cd tests/bpf-upgradeable-state && cp bpf_upgradeable_state-keypair.json target/deploy/bpf_upgradeable_state-keypair.json && anchor test --skip-local-validator --skip-build --skip-lint
+      - run: cd tests/bpf-upgradeable-state && npx tsc --noEmit
       - uses: ./.github/actions/git-diff/
 
   # this test exists to make sure that anchor
@@ -343,7 +344,7 @@ jobs:
             path: tests/sysvars
           - cmd: cd tests/composite && anchor test --skip-lint
             path: tests/composite
-          - cmd: cd tests/errors && anchor test --skip-lint
+          - cmd: cd tests/errors && anchor test --skip-lint && npx tsc --noEmit
             path: tests/errors
           - cmd: cd tests/spl/token-proxy && anchor test --skip-lint
             path: spl/token-proxy
@@ -355,21 +356,21 @@ jobs:
             path: tests/lockup
           - cmd: cd tests/swap/deps/serum-dex/dex && cargo build-bpf -- --locked && cd ../../../ && anchor test --skip-lint
             path: tests/swap
-          - cmd: cd tests/escrow && anchor test --skip-lint
+          - cmd: cd tests/escrow && anchor test --skip-lint && npx tsc --noEmit
             path: tests/escrow
-          - cmd: cd tests/pyth && anchor test --skip-lint
+          - cmd: cd tests/pyth && anchor test --skip-lint && npx tsc --noEmit
             path: tests/pyth
           - cmd: cd tests/system-accounts && anchor test --skip-lint
             path: tests/system-accounts
-          - cmd: cd tests/misc && anchor test --skip-lint
+          - cmd: cd tests/misc && anchor test --skip-lint && npx tsc --noEmit
             path: tests/misc
           - cmd: cd tests/events && anchor test --skip-lint
             path: tests/events
           - cmd: cd tests/cashiers-check && anchor test --skip-lint
             path: tests/cashiers-check
-          - cmd: cd tests/declare-id && anchor test --skip-lint
+          - cmd: cd tests/declare-id && anchor test --skip-lint && npx tsc --noEmit
             path: tests/declare-id
-          - cmd: cd tests/typescript && anchor test --skip-lint
+          - cmd: cd tests/typescript && anchor test --skip-lint && npx tsc --noEmit
             path: tests/typescript
           - cmd: cd tests/zero-copy && anchor test --skip-lint && cd programs/zero-copy && cargo test-bpf
             path: tests/zero-copy
@@ -381,18 +382,20 @@ jobs:
             path: tests/cfo
           - cmd: cd tests/auction-house && yarn --frozen-lockfile && anchor test --skip-lint && git checkout Cargo.lock
             path: tests/auction-house
-          - cmd: cd tests/floats && yarn --frozen-lockfile && anchor test --skip-lint
+          - cmd: cd tests/floats && yarn --frozen-lockfile && anchor test --skip-lint && npx tsc --noEmit
             path: tests/floats
-          - cmd: cd tests/safety-checks && ./test.sh
+          - cmd: cd tests/safety-checks && anchor run test
             path: tests/safety-checks
-          - cmd: cd tests/custom-coder && anchor test --skip-lint
+          - cmd: cd tests/custom-coder && anchor test --skip-lint && npx tsc --noEmit
             path: tests/custom-coder
-          - cmd: cd tests/validator-clone && yarn --frozen-lockfile && anchor test --skip-lint
+          - cmd: cd tests/validator-clone && anchor test --skip-lint && npx tsc --noEmit
             path: tests/validator-clone
-          - cmd: cd tests/cpi-returns && anchor test --skip-lint
+          - cmd: cd tests/cpi-returns && anchor test --skip-lint && npx tsc --noEmit
             path: tests/cpi-returns
-          - cmd: cd tests/multiple-suites && anchor test --skip-lint
+          - cmd: cd tests/multiple-suites && anchor test --skip-lint && npx tsc --noEmit
             path: tests/multiple-suites
+          - cmd: cd tests/pda-derivation && anchor test --skip-lint && npx tsc --noEmit
+            path: tests/pda-derivation
     steps:
       - uses: actions/checkout@v2
       - uses: ./.github/actions/setup/

+ 7 - 7
tests/bpf-upgradeable-state/tests/bpf-upgradable-state.ts

@@ -21,7 +21,7 @@ describe("bpf_upgradeable_state", () => {
     const settings = anchor.web3.Keypair.generate();
     const tx = await program.rpc.setAdminSettings(new anchor.BN(500), {
       accounts: {
-        authority: program.provider.wallet.publicKey,
+        authority: provider.wallet.publicKey,
         systemProgram: anchor.web3.SystemProgram.programId,
         programData: programDataAddress,
         program: program.programId,
@@ -43,7 +43,7 @@ describe("bpf_upgradeable_state", () => {
       new anchor.BN(500),
       {
         accounts: {
-          authority: program.provider.wallet.publicKey,
+          authority: provider.wallet.publicKey,
           systemProgram: anchor.web3.SystemProgram.programId,
           programData: programDataAddress,
           program: program.programId,
@@ -98,7 +98,7 @@ describe("bpf_upgradeable_state", () => {
     try {
       await program.rpc.setAdminSettings(new anchor.BN(500), {
         accounts: {
-          authority: program.provider.wallet.publicKey,
+          authority: provider.wallet.publicKey,
           systemProgram: anchor.web3.SystemProgram.programId,
           programData: program.programId,
           settings: settings.publicKey,
@@ -123,9 +123,9 @@ describe("bpf_upgradeable_state", () => {
     try {
       await program.rpc.setAdminSettings(new anchor.BN(500), {
         accounts: {
-          authority: program.provider.wallet.publicKey,
+          authority: provider.wallet.publicKey,
           systemProgram: anchor.web3.SystemProgram.programId,
-          programData: program.provider.wallet.publicKey,
+          programData: provider.wallet.publicKey,
           settings: settings.publicKey,
           program: program.programId,
         },
@@ -156,7 +156,7 @@ describe("bpf_upgradeable_state", () => {
     try {
       await program.rpc.setAdminSettings(new anchor.BN(500), {
         accounts: {
-          authority: program.provider.wallet.publicKey,
+          authority: provider.wallet.publicKey,
           systemProgram: anchor.web3.SystemProgram.programId,
           programData: secondProgramProgramDataAddress,
           settings: settings.publicKey,
@@ -185,7 +185,7 @@ describe("bpf_upgradeable_state", () => {
     try {
       await program.rpc.setAdminSettingsUseProgramState(new anchor.BN(500), {
         accounts: {
-          authority: program.provider.wallet.publicKey,
+          authority: provider.wallet.publicKey,
           systemProgram: anchor.web3.SystemProgram.programId,
           programData: secondProgramProgramDataAddress,
           settings: settings.publicKey,

+ 2 - 1
tests/bpf-upgradeable-state/tsconfig.json

@@ -5,6 +5,7 @@
     "lib": ["es2015"],
     "module": "commonjs",
     "target": "es6",
-    "esModuleInterop": true
+    "esModuleInterop": true,
+    "skipLibCheck": true
   }
 }

+ 7 - 1
tests/cpi-returns/tests/cpi-return.ts

@@ -4,6 +4,7 @@ import * as borsh from "borsh";
 import { Program } from "@project-serum/anchor";
 import { Callee } from "../target/types/callee";
 import { Caller } from "../target/types/caller";
+import { ConfirmOptions } from "@solana/web3.js";
 
 const { SystemProgram } = anchor.web3;
 
@@ -27,7 +28,7 @@ describe("CPI return", () => {
 
   const cpiReturn = anchor.web3.Keypair.generate();
 
-  const confirmOptions = { commitment: "confirmed" };
+  const confirmOptions: ConfirmOptions = { commitment: "confirmed" };
 
   it("can initialize", async () => {
     await calleeProgram.methods
@@ -146,11 +147,13 @@ describe("CPI return", () => {
   });
 
   it("sets a return value in idl", async () => {
+    // @ts-expect-error
     const returnu64Instruction = calleeProgram._idl.instructions.find(
       (f) => f.name == "returnU64"
     );
     assert.equal(returnu64Instruction.returns, "u64");
 
+    // @ts-expect-error
     const returnStructInstruction = calleeProgram._idl.instructions.find(
       (f) => f.name == "returnStruct"
     );
@@ -160,6 +163,7 @@ describe("CPI return", () => {
   });
 
   it("can return a u64 via view", async () => {
+    // @ts-expect-error
     assert(new anchor.BN(99).eq(await callerProgram.views.returnU64()));
     // Via methods API
     assert(
@@ -168,6 +172,7 @@ describe("CPI return", () => {
   });
 
   it("can return a struct via view", async () => {
+    // @ts-expect-error
     const struct = await callerProgram.views.returnStruct();
     assert(struct.a.eq(new anchor.BN(1)));
     assert(struct.b.eq(new anchor.BN(2)));
@@ -178,6 +183,7 @@ describe("CPI return", () => {
   });
 
   it("can return a vec via view", async () => {
+    // @ts-expect-error
     const vec = await callerProgram.views.returnVec();
     assert(vec[0].eq(new anchor.BN(1)));
     assert(vec[1].eq(new anchor.BN(2)));

+ 2 - 1
tests/cpi-returns/tsconfig.json

@@ -5,6 +5,7 @@
     "lib": ["es2015"],
     "module": "commonjs",
     "target": "es6",
-    "esModuleInterop": true
+    "esModuleInterop": true,
+    "skipLibCheck": true
   }
 }

+ 19 - 25
tests/custom-coder/tests/custom-coder.ts

@@ -6,7 +6,8 @@ import { Keypair, SYSVAR_RENT_PUBKEY } from "@solana/web3.js";
 
 describe("custom-coder", () => {
   // Configure the client to use the local cluster.
-  anchor.setProvider(anchor.AnchorProvider.env());
+  const provider = anchor.AnchorProvider.env();
+  anchor.setProvider(provider);
 
   // Client.
   const program = Spl.token();
@@ -18,25 +19,18 @@ describe("custom-coder", () => {
   const rent = SYSVAR_RENT_PUBKEY;
 
   it("Creates a mint", async () => {
-    await program.rpc.initializeMint(
-      6,
-      program.provider.wallet.publicKey,
-      null,
-      {
-        accounts: {
-          mint: mintKeypair.publicKey,
-          rent,
-        },
-        signers: [mintKeypair],
-        preInstructions: [
-          await program.account.mint.createInstruction(mintKeypair),
-        ],
-      }
-    );
+    await program.rpc.initializeMint(6, provider.wallet.publicKey, null, {
+      accounts: {
+        mint: mintKeypair.publicKey,
+        rent,
+      },
+      signers: [mintKeypair],
+      preInstructions: [
+        await program.account.mint.createInstruction(mintKeypair),
+      ],
+    });
     const mintAccount = await program.account.mint.fetch(mintKeypair.publicKey);
-    assert.isTrue(
-      mintAccount.mintAuthority.equals(program.provider.wallet.publicKey)
-    );
+    assert.isTrue(mintAccount.mintAuthority.equals(provider.wallet.publicKey));
     assert.isNull(mintAccount.freezeAuthority);
     assert.strictEqual(mintAccount.decimals, 6);
     assert.isTrue(mintAccount.isInitialized);
@@ -48,7 +42,7 @@ describe("custom-coder", () => {
       accounts: {
         account: aliceTokenKeypair.publicKey,
         mint: mintKeypair.publicKey,
-        authority: program.provider.wallet.publicKey,
+        authority: provider.wallet.publicKey,
         rent,
       },
       signers: [aliceTokenKeypair],
@@ -59,7 +53,7 @@ describe("custom-coder", () => {
     const token = await program.account.token.fetch(
       aliceTokenKeypair.publicKey
     );
-    assert.isTrue(token.authority.equals(program.provider.wallet.publicKey));
+    assert.isTrue(token.authority.equals(provider.wallet.publicKey));
     assert.isTrue(token.mint.equals(mintKeypair.publicKey));
     assert.strictEqual(token.amount.toNumber(), 0);
     assert.isNull(token.delegate);
@@ -74,7 +68,7 @@ describe("custom-coder", () => {
       accounts: {
         mint: mintKeypair.publicKey,
         to: aliceTokenKeypair.publicKey,
-        authority: program.provider.wallet.publicKey,
+        authority: provider.wallet.publicKey,
       },
     });
 
@@ -91,7 +85,7 @@ describe("custom-coder", () => {
       accounts: {
         account: bobTokenKeypair.publicKey,
         mint: mintKeypair.publicKey,
-        authority: program.provider.wallet.publicKey,
+        authority: provider.wallet.publicKey,
         rent,
       },
       signers: [bobTokenKeypair],
@@ -106,7 +100,7 @@ describe("custom-coder", () => {
       accounts: {
         source: aliceTokenKeypair.publicKey,
         destination: bobTokenKeypair.publicKey,
-        authority: program.provider.wallet.publicKey,
+        authority: provider.wallet.publicKey,
       },
     });
     const aliceToken = await program.account.token.fetch(
@@ -124,7 +118,7 @@ describe("custom-coder", () => {
       accounts: {
         source: aliceTokenKeypair.publicKey,
         mint: mintKeypair.publicKey,
-        authority: program.provider.wallet.publicKey,
+        authority: provider.wallet.publicKey,
       },
     });
     const aliceToken = await program.account.token.fetch(

+ 2 - 1
tests/custom-coder/tsconfig.json

@@ -5,6 +5,7 @@
     "lib": ["es2015"],
     "module": "commonjs",
     "target": "es6",
-    "esModuleInterop": true
+    "esModuleInterop": true,
+    "skipLibCheck": true
   }
 }

+ 1 - 1
tests/declare-id/tests/declare-id.ts

@@ -10,7 +10,7 @@ describe("declare_id", () => {
 
   it("throws error!", async () => {
     try {
-      await program.rpc.initialize();
+      await program.methods.initialize().rpc();
       assert.ok(false);
     } catch (_err) {
       assert.isTrue(_err instanceof AnchorError);

+ 2 - 1
tests/declare-id/tsconfig.json

@@ -5,6 +5,7 @@
         "lib": ["es2015"],
         "module": "commonjs",
         "target": "es6",
-        "esModuleInterop": true
+        "esModuleInterop": true,
+        "skipLibCheck": true
     }
 }

+ 24 - 42
tests/errors/tests/errors.ts

@@ -1,28 +1,10 @@
 import * as anchor from "@project-serum/anchor";
-import {
-  Program,
-  BN,
-  IdlAccounts,
-  AnchorError,
-  ProgramError,
-} from "@project-serum/anchor";
-import {
-  PublicKey,
-  Keypair,
-  SystemProgram,
-  Transaction,
-  TransactionInstruction,
-} from "@solana/web3.js";
+import { Program, AnchorError } from "@project-serum/anchor";
+import { Keypair, Transaction, TransactionInstruction } from "@solana/web3.js";
 import { TOKEN_PROGRAM_ID, Token } from "@solana/spl-token";
 import { assert, expect } from "chai";
 import { Errors } from "../target/types/errors";
 
-// sleep to allow logs to come in
-const sleep = (ms) =>
-  new Promise((resolve) => {
-    setTimeout(() => resolve(0), ms);
-  });
-
 const withLogTest = async (callback, expectedLogs) => {
   let logTestOk = false;
   const listener = anchor.getProvider().connection.onLogs(
@@ -64,19 +46,19 @@ const withLogTest = async (callback, expectedLogs) => {
 
 describe("errors", () => {
   // Configure the client to use the local cluster.
-  const localProvider = anchor.AnchorProvider.local();
-  localProvider.opts.skipPreflight = true;
+  const provider = anchor.AnchorProvider.local();
+  provider.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`)
-  localProvider.opts.commitment = "confirmed";
-  anchor.setProvider(localProvider);
+  provider.opts.commitment = "confirmed";
+  anchor.setProvider(provider);
 
   const program = anchor.workspace.Errors as Program<Errors>;
 
   it("Emits a Hello error", async () => {
     await withLogTest(async () => {
       try {
-        const tx = await program.rpc.hello();
+        const tx = await program.methods.hello().rpc();
         assert.ok(false);
       } catch (_err) {
         assert.isTrue(_err instanceof AnchorError);
@@ -104,7 +86,7 @@ describe("errors", () => {
 
   it("Emits a Hello error via require!", async () => {
     try {
-      const tx = await program.rpc.testRequire();
+      const tx = await program.methods.testRequire().rpc();
       assert.ok(false);
     } catch (_err) {
       assert.isTrue(_err instanceof AnchorError);
@@ -119,7 +101,7 @@ describe("errors", () => {
 
   it("Emits a Hello error via err!", async () => {
     try {
-      const tx = await program.rpc.testErr();
+      const tx = await program.methods.testErr().rpc();
       assert.ok(false);
     } catch (_err) {
       assert.isTrue(_err instanceof AnchorError);
@@ -134,7 +116,7 @@ describe("errors", () => {
   it("Logs a ProgramError", async () => {
     await withLogTest(async () => {
       try {
-        const tx = await program.rpc.testProgramError();
+        const tx = await program.methods.testProgramError().rpc();
         assert.ok(false);
       } catch (err) {
         expect(err.programErrorStack.map((pk) => pk.toString())).to.deep.equal([
@@ -150,7 +132,7 @@ describe("errors", () => {
   it("Logs a ProgramError with source", async () => {
     await withLogTest(async () => {
       try {
-        const tx = await program.rpc.testProgramErrorWithSource();
+        const tx = await program.methods.testProgramErrorWithSource().rpc();
         assert.ok(false);
       } catch (err) {
         expect(err.programErrorStack.map((pk) => pk.toString())).to.deep.equal([
@@ -164,7 +146,7 @@ describe("errors", () => {
 
   it("Emits a HelloNoMsg error", async () => {
     try {
-      const tx = await program.rpc.helloNoMsg();
+      const tx = await program.methods.helloNoMsg().rpc();
       assert.ok(false);
     } catch (_err) {
       assert.isTrue(_err instanceof AnchorError);
@@ -176,7 +158,7 @@ describe("errors", () => {
 
   it("Emits a HelloNext error", async () => {
     try {
-      const tx = await program.rpc.helloNext();
+      const tx = await program.methods.helloNext().rpc();
       assert.ok(false);
     } catch (_err) {
       assert.isTrue(_err instanceof AnchorError);
@@ -333,9 +315,9 @@ describe("errors", () => {
   it("Emits an AccountOwnedByWrongProgram error", async () => {
     let client = await Token.createMint(
       program.provider.connection,
-      program.provider.wallet.payer,
-      program.provider.wallet.publicKey,
-      program.provider.wallet.publicKey,
+      (provider.wallet as anchor.Wallet).payer,
+      provider.wallet.publicKey,
+      provider.wallet.publicKey,
       9,
       TOKEN_PROGRAM_ID
     );
@@ -369,7 +351,7 @@ describe("errors", () => {
   it("Emits a ValueMismatch error via require_eq", async () => {
     await withLogTest(async () => {
       try {
-        const tx = await program.rpc.requireEq();
+        const tx = await program.methods.requireEq().rpc();
         assert.fail(
           "Unexpected success in creating a transaction that should have failed with `ValueMismatch` error"
         );
@@ -389,7 +371,7 @@ describe("errors", () => {
   it("Emits a RequireEqViolated error via require_eq", async () => {
     await withLogTest(async () => {
       try {
-        const tx = await program.rpc.requireEqDefaultError();
+        const tx = await program.methods.requireEqDefaultError().rpc();
         assert.fail(
           "Unexpected success in creating a transaction that should have failed with `ValueMismatch` error"
         );
@@ -408,7 +390,7 @@ describe("errors", () => {
   it("Emits a ValueMatch error via require_neq", async () => {
     await withLogTest(async () => {
       try {
-        const tx = await program.rpc.requireNeq();
+        const tx = await program.methods.requireNeq().rpc();
         assert.fail(
           "Unexpected success in creating a transaction that should have failed with `ValueMatch` error"
         );
@@ -427,7 +409,7 @@ describe("errors", () => {
   it("Emits a RequireNeqViolated error via require_neq", async () => {
     await withLogTest(async () => {
       try {
-        const tx = await program.rpc.requireNeqDefaultError();
+        const tx = await program.methods.requireNeqDefaultError().rpc();
         assert.fail(
           "Unexpected success in creating a transaction that should have failed with `RequireNeqViolated` error"
         );
@@ -550,7 +532,7 @@ describe("errors", () => {
   it("Emits a ValueLessOrEqual error via require_gt", async () => {
     await withLogTest(async () => {
       try {
-        const tx = await program.rpc.requireGt();
+        const tx = await program.methods.requireGt().rpc();
         assert.fail(
           "Unexpected success in creating a transaction that should have failed with `ValueLessOrEqual` error"
         );
@@ -569,7 +551,7 @@ describe("errors", () => {
   it("Emits a RequireGtViolated error via require_gt", async () => {
     await withLogTest(async () => {
       try {
-        const tx = await program.rpc.requireGtDefaultError();
+        const tx = await program.methods.requireGtDefaultError().rpc();
         assert.fail(
           "Unexpected success in creating a transaction that should have failed with `RequireGtViolated` error"
         );
@@ -588,7 +570,7 @@ describe("errors", () => {
   it("Emits a ValueLess error via require_gte", async () => {
     await withLogTest(async () => {
       try {
-        const tx = await program.rpc.requireGte();
+        const tx = await program.methods.requireGte().rpc();
         assert.fail(
           "Unexpected success in creating a transaction that should have failed with `ValueLess` error"
         );
@@ -607,7 +589,7 @@ describe("errors", () => {
   it("Emits a RequireGteViolated error via require_gte", async () => {
     await withLogTest(async () => {
       try {
-        const tx = await program.rpc.requireGteDefaultError();
+        const tx = await program.methods.requireGteDefaultError().rpc();
         assert.fail(
           "Unexpected success in creating a transaction that should have failed with `RequireGteViolated` error"
         );

+ 2 - 1
tests/errors/tsconfig.json

@@ -5,6 +5,7 @@
         "lib": ["es2015"],
         "module": "commonjs",
         "target": "es6",
-        "esModuleInterop": true
+        "esModuleInterop": true,
+        "skipLibCheck": true
     }
 }

+ 2 - 1
tests/escrow/tsconfig.json

@@ -5,6 +5,7 @@
     "lib": ["es2015"],
     "module": "commonjs",
     "target": "es6",
-    "esModuleInterop": true
+    "esModuleInterop": true,
+    "skipLibCheck": true
   }
 }

+ 4 - 3
tests/floats/tests/floats.ts

@@ -6,7 +6,8 @@ import { assert } from "chai";
 
 describe("floats", () => {
   // Configure the client to use the local cluster.
-  anchor.setProvider(anchor.AnchorProvider.env());
+  const provider = anchor.AnchorProvider.env();
+  anchor.setProvider(provider);
 
   const program = anchor.workspace.Floats as Program<Floats>;
 
@@ -17,7 +18,7 @@ describe("floats", () => {
       .create(1.0, 2.0)
       .accounts({
         account: accountKeypair.publicKey,
-        authority: getProvider().wallet.publicKey,
+        authority: provider.wallet.publicKey,
         systemProgram: SystemProgram.programId,
       })
       .signers([accountKeypair])
@@ -33,7 +34,7 @@ describe("floats", () => {
 
   it("Updates an account with float data", async () => {
     const accountKeypair = Keypair.generate();
-    const authorityPublicKey = getProvider().wallet.publicKey;
+    const authorityPublicKey = provider.wallet.publicKey;
 
     await program.methods
       .create(1.0, 2.0)

+ 2 - 1
tests/floats/tsconfig.json

@@ -5,6 +5,7 @@
     "lib": ["es2015"],
     "module": "commonjs",
     "target": "es6",
-    "esModuleInterop": true
+    "esModuleInterop": true,
+    "skipLibCheck": true
   }
 }

+ 9 - 7
tests/misc/miscNonRentExempt.ts

@@ -1,17 +1,19 @@
 import * as anchor from "@project-serum/anchor";
-import { Program, BN, IdlAccounts, AnchorError } from "@project-serum/anchor";
+import { Program, AnchorError } from "@project-serum/anchor";
 import {
   PublicKey,
   Keypair,
   SystemProgram,
   SYSVAR_RENT_PUBKEY,
 } from "@solana/web3.js";
+// @ts-expect-error
 import { Misc } from "../../target/types/misc";
 const { assert } = require("chai");
 
 describe("miscNonRentExempt", () => {
   // Configure the client to use the local cluster.
-  anchor.setProvider(anchor.AnchorProvider.env());
+  const provider = anchor.AnchorProvider.env();
+  anchor.setProvider(provider);
   const program = anchor.workspace.Misc as Program<Misc>;
 
   it("init_if_needed checks rent_exemption if init is not needed", async () => {
@@ -19,7 +21,7 @@ describe("miscNonRentExempt", () => {
     await program.rpc.initDecreaseLamports({
       accounts: {
         data: data.publicKey,
-        user: anchor.getProvider().wallet.publicKey,
+        user: provider.wallet.publicKey,
         systemProgram: SystemProgram.programId,
       },
       signers: [data],
@@ -29,7 +31,7 @@ describe("miscNonRentExempt", () => {
       await program.rpc.initIfNeededChecksRentExemption({
         accounts: {
           data: data.publicKey,
-          user: anchor.getProvider().wallet.publicKey,
+          user: provider.wallet.publicKey,
           systemProgram: SystemProgram.programId,
         },
         signers: [data],
@@ -58,7 +60,7 @@ describe("miscNonRentExempt", () => {
             await program.provider.connection.getMinimumBalanceForRentExemption(
               39
             ),
-          fromPubkey: anchor.getProvider().wallet.publicKey,
+          fromPubkey: provider.wallet.publicKey,
           newAccountPubkey: data.publicKey,
         }),
       ],
@@ -86,7 +88,7 @@ describe("miscNonRentExempt", () => {
             await program.provider.connection.getMinimumBalanceForRentExemption(
               39
             ),
-          fromPubkey: anchor.getProvider().wallet.publicKey,
+          fromPubkey: provider.wallet.publicKey,
           newAccountPubkey: data.publicKey,
         }),
       ],
@@ -109,7 +111,7 @@ describe("miscNonRentExempt", () => {
             await program.provider.connection.getMinimumBalanceForRentExemption(
               39
             ),
-          fromPubkey: anchor.getProvider().wallet.publicKey,
+          fromPubkey: provider.wallet.publicKey,
           newAccountPubkey: data.publicKey,
         }),
       ],

+ 0 - 1
tests/misc/programs/misc/src/context.rs

@@ -5,7 +5,6 @@ use anchor_lang::prelude::*;
 use anchor_spl::associated_token::AssociatedToken;
 use anchor_spl::token::{Mint, Token, TokenAccount};
 use misc2::misc2::MyState as Misc2State;
-use std::mem::size_of;
 
 #[derive(Accounts)]
 pub struct TestTokenSeedsInit<'info> {

+ 14 - 14
tests/misc/programs/misc/src/lib.rs

@@ -49,11 +49,11 @@ pub mod misc {
         Ok(())
     }
 
-    pub fn initialize_no_rent_exempt(ctx: Context<InitializeNoRentExempt>) -> Result<()> {
+    pub fn initialize_no_rent_exempt(_ctx: Context<InitializeNoRentExempt>) -> Result<()> {
         Ok(())
     }
 
-    pub fn initialize_skip_rent_exempt(ctx: Context<InitializeSkipRentExempt>) -> Result<()> {
+    pub fn initialize_skip_rent_exempt(_ctx: Context<InitializeSkipRentExempt>) -> Result<()> {
         Ok(())
     }
 
@@ -207,11 +207,11 @@ pub mod misc {
         Ok(())
     }
 
-    pub fn test_init_with_empty_seeds(ctx: Context<TestInitWithEmptySeeds>) -> Result<()> {
+    pub fn test_init_with_empty_seeds(_ctx: Context<TestInitWithEmptySeeds>) -> Result<()> {
         Ok(())
     }
 
-    pub fn test_empty_seeds_constraint(ctx: Context<TestEmptySeedsConstraint>) -> Result<()> {
+    pub fn test_empty_seeds_constraint(_ctx: Context<TestEmptySeedsConstraint>) -> Result<()> {
         Ok(())
     }
 
@@ -221,36 +221,36 @@ pub mod misc {
     }
 
     pub fn test_init_if_needed_checks_owner(
-        ctx: Context<TestInitIfNeededChecksOwner>,
+        _ctx: Context<TestInitIfNeededChecksOwner>,
     ) -> Result<()> {
         Ok(())
     }
 
     pub fn test_init_if_needed_checks_seeds(
-        ctx: Context<TestInitIfNeededChecksSeeds>,
-        seed_data: String,
+        _ctx: Context<TestInitIfNeededChecksSeeds>,
+        _seed_data: String,
     ) -> Result<()> {
         Ok(())
     }
 
     pub fn test_init_mint_if_needed(
-        ctx: Context<TestInitMintIfNeeded>,
-        decimals: u8,
+        _ctx: Context<TestInitMintIfNeeded>,
+        _decimals: u8,
     ) -> Result<()> {
         Ok(())
     }
 
-    pub fn test_init_token_if_needed(ctx: Context<TestInitTokenIfNeeded>) -> Result<()> {
+    pub fn test_init_token_if_needed(_ctx: Context<TestInitTokenIfNeeded>) -> Result<()> {
         Ok(())
     }
 
     pub fn test_init_associated_token_if_needed(
-        ctx: Context<TestInitAssociatedTokenIfNeeded>,
+        _ctx: Context<TestInitAssociatedTokenIfNeeded>,
     ) -> Result<()> {
         Ok(())
     }
 
-    pub fn init_with_space(ctx: Context<InitWithSpace>, data: u16) -> Result<()> {
+    pub fn init_with_space(_ctx: Context<InitWithSpace>, data: u16) -> Result<()> {
         Ok(())
     }
 
@@ -270,11 +270,11 @@ pub mod misc {
         Ok(())
     }
 
-    pub fn test_no_rent_exempt(ctx: Context<NoRentExempt>) -> Result<()> {
+    pub fn test_no_rent_exempt(_ctx: Context<NoRentExempt>) -> Result<()> {
         Ok(())
     }
 
-    pub fn test_enforce_rent_exempt(ctx: Context<EnforceRentExempt>) -> Result<()> {
+    pub fn test_enforce_rent_exempt(_ctx: Context<EnforceRentExempt>) -> Result<()> {
         Ok(())
     }
 

+ 4 - 3
tests/misc/tests/init-if-needed/init-if-needed.ts

@@ -5,7 +5,8 @@ import { SystemProgram, LAMPORTS_PER_SOL } from "@solana/web3.js";
 import { expect } from "chai";
 
 describe("init-if-needed", () => {
-  anchor.setProvider(anchor.AnchorProvider.env());
+  const provider = anchor.AnchorProvider.env();
+  anchor.setProvider(provider);
 
   const program = anchor.workspace.InitIfNeeded as Program<InitIfNeeded>;
 
@@ -37,11 +38,11 @@ describe("init-if-needed", () => {
             .close()
             .accounts({
               acc: account.publicKey,
-              receiver: program.provider.wallet.publicKey,
+              receiver: provider.wallet.publicKey,
             })
             .instruction(),
           SystemProgram.transfer({
-            fromPubkey: program.provider.wallet.publicKey,
+            fromPubkey: provider.wallet.publicKey,
             toPubkey: account.publicKey,
             lamports: 1 * LAMPORTS_PER_SOL,
           }),

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 135 - 132
tests/misc/tests/misc/misc.ts


+ 4 - 3
tests/misc/tsconfig.json

@@ -5,6 +5,7 @@
         "lib": ["es2015"],
         "module": "commonjs",
         "target": "es6",
-        "esModuleInterop": true
-    }
-}
+        "esModuleInterop": true,
+        "skipLibCheck": true
+    },
+}

+ 2 - 1
tests/multiple-suites/tsconfig.json

@@ -5,6 +5,7 @@
     "lib": ["es2015"],
     "module": "commonjs",
     "target": "es6",
-    "esModuleInterop": true
+    "esModuleInterop": true,
+    "skipLibCheck": true
   }
 }

+ 2 - 1
tests/package.json

@@ -50,6 +50,7 @@
     "mocha": "^9.1.3",
     "ts-mocha": "^8.0.0",
     "typescript": "^4.4.4",
-    "prettier": "^2.5.1"
+    "prettier": "^2.5.1",
+    "tsc": "^2.0.4"
   }
 }

+ 2 - 1
tests/pda-derivation/tsconfig.json

@@ -5,6 +5,7 @@
     "lib": ["es2015"],
     "module": "commonjs",
     "target": "es6",
-    "esModuleInterop": true
+    "esModuleInterop": true,
+    "skipLibCheck": true
   }
 }

+ 7 - 6
tests/pyth/tests/oracleUtils.ts

@@ -1,5 +1,5 @@
 import { Buffer } from "buffer";
-import { BN, Program, web3 } from "@project-serum/anchor";
+import { AnchorProvider, BN, Program, web3 } from "@project-serum/anchor";
 
 export const Magic = 0xa1b2c3d4;
 export const Version1 = 1;
@@ -17,12 +17,14 @@ interface ICreatePriceFeed {
   initPrice: number;
   confidence?: BN;
   expo?: number;
+  provider: AnchorProvider;
 }
 export const createPriceFeed = async ({
   oracleProgram,
   initPrice,
   confidence,
   expo = -4,
+  provider,
 }: ICreatePriceFeed) => {
   const conf = confidence || new BN((initPrice / 10) * 10 ** -expo);
   const collateralTokenFeed = new web3.Account();
@@ -35,13 +37,12 @@ export const createPriceFeed = async ({
       signers: [collateralTokenFeed],
       instructions: [
         web3.SystemProgram.createAccount({
-          fromPubkey: oracleProgram.provider.wallet.publicKey,
+          fromPubkey: provider.wallet.publicKey,
           newAccountPubkey: collateralTokenFeed.publicKey,
           space: 3312,
-          lamports:
-            await oracleProgram.provider.connection.getMinimumBalanceForRentExemption(
-              3312
-            ),
+          lamports: await provider.connection.getMinimumBalanceForRentExemption(
+            3312
+          ),
           programId: oracleProgram.programId,
         }),
       ],

+ 4 - 1
tests/pyth/tests/pyth.spec.ts

@@ -4,7 +4,8 @@ import { assert } from "chai";
 import { createPriceFeed, setFeedPrice, getFeedData } from "./oracleUtils";
 
 describe("pyth-oracle", () => {
-  anchor.setProvider(anchor.AnchorProvider.env());
+  const provider = anchor.AnchorProvider.env();
+  anchor.setProvider(provider);
   const program = anchor.workspace.Pyth as Program;
 
   it("initialize", async () => {
@@ -13,6 +14,7 @@ describe("pyth-oracle", () => {
       oracleProgram: program,
       initPrice: price,
       expo: -6,
+      provider,
     });
     const feedData = await getFeedData(program, priceFeedAddress);
     assert.strictEqual(feedData.price, price);
@@ -25,6 +27,7 @@ describe("pyth-oracle", () => {
       oracleProgram: program,
       initPrice: price,
       expo: expo,
+      provider,
     });
     const feedDataBefore = await getFeedData(program, priceFeedAddress);
     assert.strictEqual(feedDataBefore.price, price);

+ 1 - 1
tests/safety-checks/Anchor.toml

@@ -10,4 +10,4 @@ cluster = "localnet"
 wallet = "~/.config/solana/id.json"
 
 [scripts]
-test = "yarn run ts-mocha -p ./tsconfig.json -t 1000000 tests/**/*.ts"
+test = "./test.sh"

+ 0 - 12
tests/safety-checks/migrations/deploy.ts

@@ -1,12 +0,0 @@
-// Migrations are an early feature. Currently, they're nothing more than this
-// single deploy script that's invoked from the CLI, injecting a provider
-// configured from the workspace's Anchor.toml.
-
-const anchor = require("@project-serum/anchor");
-
-module.exports = async function (provider) {
-  // Configure client to use the provider.
-  anchor.setProvider(provider);
-
-  // Add your deploy script here.
-};

+ 1 - 1
tests/safety-checks/test.sh

@@ -24,4 +24,4 @@ if ! [[ $output =~ "Struct field \"unchecked\" is unsafe" ]]; then
 fi
 popd
 
-echo "Success. All builds failed."
+echo "Success. As expected, all builds failed."

+ 0 - 16
tests/safety-checks/tests/safety-checks.ts

@@ -1,16 +0,0 @@
-import * as anchor from "@project-serum/anchor";
-import { Program } from "@project-serum/anchor";
-import { SafetyChecks } from "../target/types/safety_checks";
-
-describe("safety-checks", () => {
-  // Configure the client to use the local cluster.
-  anchor.setProvider(anchor.AnchorProvider.env());
-
-  const program = anchor.workspace.SafetyChecks as Program<SafetyChecks>;
-
-  it("Is initialized!", async () => {
-    // Add your test here.
-    const tx = await program.rpc.initialize({});
-    console.log("Your transaction signature", tx);
-  });
-});

+ 2 - 2
tests/validator-clone/package.json

@@ -1,6 +1,6 @@
 {
   "name": "validator-clone",
-  "version": "0.22.0",
+  "version": "0.24.2",
   "license": "(MIT OR Apache-2.0)",
   "homepage": "https://github.com/project-serum/anchor#readme",
   "bugs": {
@@ -14,6 +14,6 @@
     "node": ">=11"
   },
   "scripts": {
-    "test": "anchor run test-with-build"
+    "test": "anchor test"
   }
 }

+ 2 - 1
tests/validator-clone/tsconfig.json

@@ -5,6 +5,7 @@
     "lib": ["es2015"],
     "module": "commonjs",
     "target": "es6",
-    "esModuleInterop": true
+    "esModuleInterop": true,
+    "skipLibCheck": true
   }
 }

+ 6 - 1
tests/yarn.lock

@@ -51,7 +51,7 @@
     toml "^3.0.0"
 
 "@project-serum/anchor@file:../ts":
-  version "0.24.0"
+  version "0.24.2"
   dependencies:
     "@project-serum/borsh" "^0.2.5"
     "@solana/web3.js" "^1.36.0"
@@ -1210,6 +1210,11 @@ ts-node@7.0.1:
     source-map-support "^0.5.6"
     yn "^2.0.0"
 
+tsc@^2.0.4:
+  version "2.0.4"
+  resolved "https://registry.yarnpkg.com/tsc/-/tsc-2.0.4.tgz#5f6499146abea5dca4420b451fa4f2f9345238f5"
+  integrity sha512-fzoSieZI5KKJVBYGvwbVZs/J5za84f2lSTLPYf6AGiIf43tZ3GNrI1QzTLcjtyDDP4aLxd46RTZq1nQxe7+k5Q==
+
 tsconfig-paths@^3.5.0:
   version "3.11.0"
   resolved "https://registry.yarnpkg.com/tsconfig-paths/-/tsconfig-paths-3.11.0.tgz#954c1fe973da6339c78e06b03ce2e48810b65f36"

Algúns arquivos non se mostraron porque demasiados arquivos cambiaron neste cambio