Browse Source

examples/escrow: refector tests to typescript

Chris Heaney 4 years ago
parent
commit
c935f75347
4 changed files with 31 additions and 19 deletions
  1. 2 1
      .travis.yml
  2. 8 7
      examples/escrow/package.json
  3. 11 11
      examples/escrow/tests/escrow.ts
  4. 10 0
      examples/escrow/tsconfig.json

+ 2 - 1
.travis.yml

@@ -73,7 +73,8 @@ jobs:
     - <<: *examples
       name: Runs the examples 3
       script:
-        - pushd examples/escrow && yarn && anchor test && popd
+        - pushd ts && yarn && yarn build && npm link && popd
+        - pushd examples/escrow && npm link @project-serum/anchor && yarn && anchor test && popd
         - pushd examples/pyth && yarn && anchor test && popd
         - pushd examples/tutorial/basic-0 && anchor test && popd
         - pushd examples/tutorial/basic-1 && anchor test && popd

+ 8 - 7
examples/escrow/package.json

@@ -1,11 +1,12 @@
 {
   "dependencies": {
-    "@project-serum/anchor": "^0.9.0",
-    "@project-serum/serum": "0.13.38",
-    "@solana/web3.js": "^1.18.0",
-    "@solana/spl-token": "^0.1.6"
-  },
-  "devDependencies": {
-    "ts-mocha": "^8.0.0"
+    "@project-serum/anchor": "../../ts",
+    "@project-serum/serum": "latest",
+    "@solana/web3.js": "latest",
+    "@solana/spl-token": "latest",
+    "@types/mocha": "^8.2.3",
+    "@types/node": "^14.14.37",
+    "chai": "^4.3.4",
+    "bn.js": "^5.2.0"
   }
 }

+ 11 - 11
examples/escrow/tests/escrow.js → examples/escrow/tests/escrow.ts

@@ -1,20 +1,20 @@
-const anchor = require("@project-serum/anchor");
-const { TOKEN_PROGRAM_ID, Token } = require("@solana/spl-token");
-const assert = require("assert");
+import * as anchor from "@project-serum/anchor";
+import { TOKEN_PROGRAM_ID, Token } from "@solana/spl-token";
+import {assert} from "chai";
 
 describe("escrow", () => {
   const provider = anchor.Provider.env();
   anchor.setProvider(provider);
 
-  const program = anchor.workspace.Escrow;
+  const program = anchor.workspace.Escrow as anchor.Program;
 
-  let mintA = null;
-  let mintB = null;
-  let initializerTokenAccountA = null;
-  let initializerTokenAccountB = null;
-  let takerTokenAccountA = null;
-  let takerTokenAccountB = null;
-  let pda = null;
+  let mintA : Token = null;
+  let mintB : Token = null;
+  let initializerTokenAccountA : anchor.web3.PublicKey = null;
+  let initializerTokenAccountB : anchor.web3.PublicKey = null;
+  let takerTokenAccountA : anchor.web3.PublicKey = null;
+  let takerTokenAccountB : anchor.web3.PublicKey = null;
+  let pda : anchor.web3.PublicKey = null;
 
   const takerAmount = 1000;
   const initializerAmount = 500;

+ 10 - 0
examples/escrow/tsconfig.json

@@ -0,0 +1,10 @@
+{
+  "compilerOptions": {
+    "types": ["mocha", "chai"],
+    "typeRoots": ["./node_modules/@types"],
+    "lib": ["es2015"],
+    "module": "commonjs",
+    "target": "es6",
+    "esModuleInterop": true
+  }
+}