1
- import { Worker , NearAccount } from 'near-workspaces ' ;
2
- import anyTest , { TestFn } from 'ava ' ;
1
+ import anyTest from 'ava ' ;
2
+ import { Worker } from 'near-workspaces ' ;
3
3
import { setDefaultResultOrder } from 'dns' ; setDefaultResultOrder ( 'ipv4first' ) ; // temp fix for node >v17
4
4
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 ;
8
10
test . beforeEach ( async ( t ) => {
9
11
// Create sandbox, accounts, deploy contracts, etc.
10
12
const worker = t . context . worker = await Worker . init ( ) ;
@@ -29,26 +31,27 @@ test.afterEach.always(async (t) => {
29
31
30
32
test ( 'by default the user has no points' , async ( t ) => {
31
33
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 } ) ;
33
35
t . is ( points , 0 ) ;
34
36
} ) ;
35
37
36
38
test ( 'the points are correctly computed' , async ( t ) => {
37
39
const { root, contract } = t . context . accounts ;
38
40
39
- let counter : { [ key : string ] : number } = { 'heads' : 0 , 'tails' : 0 }
41
+ let counter = { 'heads' : 0 , 'tails' : 0 }
40
42
let expected_points = 0 ;
41
43
42
44
for ( let i = 0 ; i < 10 ; i ++ ) {
43
45
const res = await root . call ( contract , 'flip_coin' , { 'player_guess' : 'heads' } )
44
- counter [ res as string ] += 1 ;
46
+ counter [ res ] += 1 ;
45
47
expected_points += res == 'heads' ? 1 : - 1 ;
46
48
expected_points = Math . max ( expected_points , 0 ) ;
47
49
}
48
50
49
51
// A binomial(10, 1/2) has a P(x>2) ~ 0.98%
50
52
t . true ( counter [ 'heads' ] >= 2 ) ;
53
+ t . true ( counter [ 'tails' ] >= 2 ) ;
51
54
52
- const points : number = await contract . view ( 'points_of' , { 'player' : root . accountId } ) ;
55
+ const points = await contract . view ( 'points_of' , { 'player' : root . accountId } ) ;
53
56
t . is ( points , expected_points ) ;
54
57
} ) ;
0 commit comments