-
Notifications
You must be signed in to change notification settings - Fork 23
/
07.resue-worker.ava.ts
47 lines (40 loc) · 1.51 KB
/
07.resue-worker.ava.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/**
* This test file demonstrates the reuse of the Worker across several tests.
* The maine differance is the usage of before() and after() AVA functions
* instead of beforeEach() and after each.
* Keep in mind that tests are executed in parallel.
* It means that they should not depend on each other.
*/
import {Worker, NEAR, NearAccount} from 'near-workspaces';
import anyTest, {TestFn} from 'ava';
const test = anyTest as TestFn<{
worker: Worker;
accounts: Record<string, NearAccount>;
}>;
test.before(async t => {
const worker = await Worker.init();
const root = worker.rootAccount;
const contract = await root.devDeploy(
'__tests__/build/debug/status_message.wasm',
{initialBalance: NEAR.parse('3 N').toJSON()},
);
const ali = await root.createSubAccount('ali', {initialBalance: NEAR.parse('3 N').toJSON()});
t.context.worker = worker;
t.context.accounts = {root, contract, ali};
});
test.after.always(async t => {
await t.context.worker.tearDown().catch(error => {
console.log('Failed to tear down the worker:', error);
});
});
test('Root gets null status', async t => {
const {root, contract} = t.context.accounts;
const result: null = await contract.view('get_status', {account_id: root.accountId});
t.is(result, null);
});
test('Ali sets then gets status', async t => {
const {ali, contract} = t.context.accounts;
await ali.call(contract, 'set_status', {message: 'hello'});
const result: string = await contract.view('get_status', {account_id: ali});
t.is(result, 'hello');
});