-
Notifications
You must be signed in to change notification settings - Fork 23
/
08.custom-network.ava.ts
40 lines (34 loc) · 1.19 KB
/
08.custom-network.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
import process from 'process';
import {Worker, getNetworkFromEnv} from 'near-workspaces';
import anyTest, {TestFn} from 'ava';
// To run this test, you need to set the NEAR_RPC_API_KEY environment variable tied the Pagoda testnet network.
// And the NEAR_WORKSPACES_NETWORK environment variable to 'custom'.
//
// Sample: NEAR_WORKSPACES_NETWORK=custom NEAR_RPC_API_KEY="xxx" yarn test...
if (getNetworkFromEnv() === 'custom' && process.env.NEAR_RPC_API_KEY !== '') {
const test = anyTest as TestFn<{
worker: Worker;
}>;
test.before(async t => {
const worker = await Worker.init({
network: 'custom',
rpcAddr: 'https://near-testnet.api.pagoda.co/rpc/v1/',
apiKey: process.env.NEAR_RPC_API_KEY!,
});
t.context.worker = worker;
});
test.after.always(async t => {
await t.context.worker.tearDown().catch(error => {
console.log('Failed to tear down the worker:', error);
});
});
test('Ping network', async t => {
try {
await t.context.worker.provider.block({finality: 'final'});
} catch (error: unknown) {
t.fail(`Failed to ping the network: ${error as string}`);
return;
}
t.pass('Network pinged successfully!');
});
}