-
Notifications
You must be signed in to change notification settings - Fork 0
/
tenderly.ts
50 lines (38 loc) · 1.03 KB
/
tenderly.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
48
49
50
import { exec as execProcess } from 'child_process';
import { promisify } from 'util';
const exec = promisify(execProcess);
let devNetRpcUrl;
export const createDevNet = async (
project: string,
template: string,
accountId: string,
accessKey: string,
) => {
// return from cache if already created
if (devNetRpcUrl) {
return devNetRpcUrl;
}
const command = `tenderly devnet spawn-rpc --project ${project} --template ${template} --account ${accountId} --access_key ${accessKey}`;
const { stderr } = await exec(command);
if (!stderr) {
throw new Error('Failed to create devnet');
}
if (!isDevNetSpawnOutputValid(stderr)) {
throw new Error('Failed to create devnet');
}
devNetRpcUrl = stderr.trim().toString();
return devNetRpcUrl;
};
const isDevNetSpawnOutputValid = (output: string) => {
let err;
if (!output) {
err = new Error('Failed to create devnet (no output)');
}
if (!output.includes('https://')) {
err = new Error('Failed to create devnet (invalid output)');
}
if (err) {
throw err;
}
return true;
};