-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtests-setup.ts
More file actions
32 lines (27 loc) · 898 Bytes
/
tests-setup.ts
File metadata and controls
32 lines (27 loc) · 898 Bytes
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
import 'dotenv/config'
import { isNoMnemonic } from './test/utils/sdk'
export default async function testsSetup(): Promise<void> {
// await assertRpcAvailable()
assertTestnetMnemonic()
}
/**
* Assert that mnemonic is set in the env file
*/
function assertTestnetMnemonic(): void {
if (isNoMnemonic()) {
throw new Error('Testnet mnemonic is not set in env file. It is required for tests to run.')
}
}
export async function assertRpcAvailable(): Promise<void> {
const rpcUrl = process.env.RPC_URL || 'http://localhost:8545'
// eslint-disable-next-line no-console
console.log('\nChecking blockchain connection...')
try {
const data = await fetch(rpcUrl)
if ((await data.text()).indexOf('jsonrpc') === -1) {
throw new Error('Response of RPC is not valid')
}
} catch (e) {
throw new Error(`Blockchain connection failed: ${(e as Error).message}`)
}
}