Skip to content

Commit 777a93f

Browse files
committed
simplify sandbox-ts
1 parent 6dea455 commit 777a93f

File tree

3 files changed

+21
-34
lines changed

3 files changed

+21
-34
lines changed

contract-ts/ava.config.cjs

-15
This file was deleted.

contract-ts/package.json

+9-10
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
11
{
2-
"name": "contract",
2+
"name": "coin_flip",
33
"version": "1.0.0",
44
"license": "(MIT AND Apache-2.0)",
55
"type": "module",
66
"scripts": {
7-
"build": "near-sdk-js build src/contract.ts build/contract.wasm",
8-
"test": "$npm_execpath run build && ava -- ./build/contract.wasm"
7+
"build": "near-sdk-js build src/contract.ts build/coin_flip.wasm",
8+
"test": "$npm_execpath run build && ava -- ./build/coin_flip.wasm"
99
},
1010
"dependencies": {
11-
"near-cli": "^4.0.10",
1211
"near-sdk-js": "1.0.0"
1312
},
1413
"devDependencies": {
15-
"@ava/typescript": "^4.1.0",
16-
"ava": "^6.1.2",
14+
"ava": "^6.1.3",
1715
"near-workspaces": "^3.5.0",
18-
"ts-morph": "^22.0.0",
19-
"ts-node": "^10.9.2",
20-
"tsimp": "^2.0.11",
21-
"typescript": "^5.4.2"
16+
"typescript": "^5.4.5"
17+
},
18+
"ava": {
19+
"timeout": "20000",
20+
"files": ["sandbox-test/*.ava.js"]
2221
}
2322
}

contract-ts/sandbox-ts/main.ava.ts contract-ts/sandbox-test/main.ava.js

+12-9
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
import { Worker, NearAccount } from 'near-workspaces';
2-
import anyTest, { TestFn } from 'ava';
1+
import anyTest from 'ava';
2+
import { Worker } from 'near-workspaces';
33
import { setDefaultResultOrder } from 'dns'; setDefaultResultOrder('ipv4first'); // temp fix for node >v17
44

5-
// Global context
6-
const test = anyTest as TestFn<{ worker: Worker, accounts: Record<string, NearAccount> }>;
7-
5+
/**
6+
* @typedef {import('near-workspaces').NearAccount} NearAccount
7+
* @type {import('ava').TestFn<{worker: Worker, accounts: Record<string, NearAccount>}>}
8+
*/
9+
const test = anyTest;
810
test.beforeEach(async (t) => {
911
// Create sandbox, accounts, deploy contracts, etc.
1012
const worker = t.context.worker = await Worker.init();
@@ -29,26 +31,27 @@ test.afterEach.always(async (t) => {
2931

3032
test('by default the user has no points', async (t) => {
3133
const { root, contract } = t.context.accounts;
32-
const points: number = await contract.view('points_of', { player: root.accountId });
34+
const points = await contract.view('points_of', { player: root.accountId });
3335
t.is(points, 0);
3436
});
3537

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

39-
let counter: {[key:string]:number} = { 'heads': 0, 'tails': 0 }
41+
let counter = { 'heads': 0, 'tails': 0 }
4042
let expected_points = 0;
4143

4244
for(let i=0; i<10; i++){
4345
const res = await root.call(contract, 'flip_coin', { 'player_guess': 'heads' })
44-
counter[res as string] += 1;
46+
counter[res] += 1;
4547
expected_points += res == 'heads' ? 1 : -1;
4648
expected_points = Math.max(expected_points, 0);
4749
}
4850

4951
// A binomial(10, 1/2) has a P(x>2) ~ 0.98%
5052
t.true(counter['heads'] >= 2);
53+
t.true(counter['tails'] >= 2);
5154

52-
const points: number = await contract.view('points_of', { 'player': root.accountId });
55+
const points = await contract.view('points_of', { 'player': root.accountId });
5356
t.is(points, expected_points);
5457
});

0 commit comments

Comments
 (0)