Skip to content

Commit

Permalink
Merge pull request #18 from garikbesson/fix-js-tests
Browse files Browse the repository at this point in the history
Fix JS tests
  • Loading branch information
gagdiez authored Mar 19, 2024
2 parents 121a724 + ab560f4 commit c2c20dc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 19 deletions.
8 changes: 4 additions & 4 deletions contract-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@
"test": "$npm_execpath build && ava -- ./build/contract.wasm"
},
"dependencies": {
"near-cli": "^4.0.8",
"near-cli": "^4.0.10",
"near-sdk-js": "1.0.0"
},
"devDependencies": {
"@ava/typescript": "^4.1.0",
"ava": "^6.1.2",
"near-workspaces": "^3.5.0",
"ts-morph": "^21.0.1",
"ts-morph": "^22.0.0",
"ts-node": "^10.9.2",
"tsimp": "^2.0.11",
"typescript": "^5.3.3"
"typescript": "^5.4.2"
}
}
}
25 changes: 10 additions & 15 deletions contract-ts/sandbox-ts/main.ava.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
import { setDefaultResultOrder } from 'dns'; setDefaultResultOrder('ipv4first'); // temp fix for node > v17

import { Worker, NearAccount } from 'near-workspaces';
import anyTest, { TestFn } from 'ava';
import * as path from 'path';
import { setDefaultResultOrder } from 'dns'; setDefaultResultOrder('ipv4first'); // temp fix for node >v17

// Global context
let worker: Worker;
let accounts: Record<string, NearAccount>;

const test = anyTest as TestFn<{}>;
const test = anyTest as TestFn<{ worker: Worker, accounts: Record<string, NearAccount> }>;

test.before(async (t) => {
// Init the worker and start a Sandbox server
worker = await Worker.init();
test.beforeEach(async (t) => {
// Create sandbox, accounts, deploy contracts, etc.
const worker = t.context.worker = await Worker.init();

// Deploy contract
const root = worker.rootAccount;
Expand All @@ -22,24 +17,24 @@ test.before(async (t) => {
await contract.deploy(process.argv[2]);

// Save state for test runs, it is unique for each test
accounts = { root, contract };
t.context.accounts = { root, contract };
});

test.after.always(async (t) => {
test.afterEach.always(async (t) => {
// Stop Sandbox server
await worker.tearDown().catch((error) => {
await t.context.worker.tearDown().catch((error) => {
console.log('Failed to stop the Sandbox:', error);
});
});

test('by default the user has no points', async (t) => {
const { root, contract } = accounts;
const { root, contract } = t.context.accounts;
const points: number = await contract.view('points_of', { player: root.accountId });
t.is(points, 0);
});

test('the points are correctly computed', async (t) => {
const { root, contract } = accounts;
const { root, contract } = t.context.accounts;

let counter: {[key:string]:number} = { 'heads': 0, 'tails': 0 }
let expected_points = 0;
Expand Down

0 comments on commit c2c20dc

Please sign in to comment.