Skip to content
This repository was archived by the owner on Mar 23, 2021. It is now read-only.

Commit c92be2f

Browse files
author
Tobin C. Harding
committed
Make the e2e tests pass
1 parent e0efc99 commit c92be2f

File tree

5 files changed

+45
-32
lines changed

5 files changed

+45
-32
lines changed

api_tests/lib/cnd_runner.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as fs from "fs";
2+
import * as path from "path";
23
import { promisify } from "util";
34
import { CndInstance } from "../lib_sdk/cnd_instance";
45
import { CND_CONFIGS } from "./config";
@@ -43,8 +44,10 @@ export class CndRunner {
4344
ledgerConfig
4445
);
4546

46-
if (await existsAsync(cndconfig.dbPath)) {
47-
await unlinkAsync(cndconfig.dbPath); // delete the old database for the new test
47+
const db = path.join(cndconfig.data, "cnd.sqlite");
48+
49+
if (await existsAsync(db)) {
50+
await unlinkAsync(db); // delete the old database for the new test
4851
}
4952

5053
await process.start();

api_tests/lib/config.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import tempfile from "tempfile";
1+
import * as tmp from "tmp";
22
import { BitcoinNodeConfig } from "./bitcoin";
33
import { EthereumNodeConfig } from "./ethereum";
44
import { LedgerConfig } from "./ledger_runner";
55

66
export interface CndConfigFile {
77
http_api: HttpApi;
8-
database?: { sqlite: string };
8+
data?: { dir: string };
99
network: { listen: string[] };
1010
}
1111

@@ -15,7 +15,7 @@ export interface HttpApi {
1515

1616
export class E2ETestActorConfig {
1717
public readonly seed: Uint8Array;
18-
public readonly dbPath: string;
18+
public readonly data: string;
1919

2020
constructor(
2121
public readonly httpApiPort: number,
@@ -26,7 +26,11 @@ export class E2ETestActorConfig {
2626
this.httpApiPort = httpApiPort;
2727
this.comitPort = comitPort;
2828
this.seed = new Uint8Array(Buffer.from(seed, "hex"));
29-
this.dbPath = tempfile(`.${this.name}.sqlite`);
29+
30+
const tmpobj = tmp.dirSync();
31+
tmpobj.removeCallback(); // Manual cleanup
32+
33+
this.data = tmpobj.name;
3034
}
3135

3236
public generateCndConfigFile(ledgerConfig: LedgerConfig): CndConfigFile {
@@ -37,8 +41,8 @@ export class E2ETestActorConfig {
3741
port: this.httpApiPort,
3842
},
3943
},
40-
database: {
41-
sqlite: this.dbPath,
44+
data: {
45+
dir: this.data,
4246
},
4347
network: {
4448
listen: [`/ip4/0.0.0.0/tcp/${this.comitPort}`],

api_tests/lib_sdk/cnd_instance.ts

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { JsonMap, stringify } from "@iarna/toml";
22
import { ChildProcess, spawn } from "child_process";
33
import * as fs from "fs";
4-
import { PEMObject } from "pem-ts";
54
import tempWrite from "temp-write";
65
import { promisify } from "util";
76
import { CndConfigFile, E2ETestActorConfig } from "../lib/config";
@@ -39,27 +38,20 @@ export class CndInstance {
3938
"config.toml"
4039
);
4140

42-
const pemObject = new PEMObject("SEED", this.actorConfig.seed);
43-
const seedFile = await tempWrite(pemObject.encoded, "seed.pem");
44-
45-
this.process = spawn(
46-
bin,
47-
["--config", configFile, "--seed-file", seedFile],
48-
{
49-
cwd: this.projectRoot,
50-
stdio: [
51-
"ignore", // stdin
52-
await openAsync(
53-
this.logDir + "/cnd-" + this.actorConfig.name + ".log",
54-
"w"
55-
), // stdout
56-
await openAsync(
57-
this.logDir + "/cnd-" + this.actorConfig.name + ".log",
58-
"w"
59-
), // stderr
60-
],
61-
}
62-
);
41+
this.process = spawn(bin, ["--config", configFile], {
42+
cwd: this.projectRoot,
43+
stdio: [
44+
"ignore", // stdin
45+
await openAsync(
46+
this.logDir + "/cnd-" + this.actorConfig.name + ".log",
47+
"w"
48+
), // stdout
49+
await openAsync(
50+
this.logDir + "/cnd-" + this.actorConfig.name + ".log",
51+
"w"
52+
), // stderr
53+
],
54+
});
6355

6456
this.process.on("exit", (code: number, signal: number) => {
6557
console.log(

api_tests/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@
5555
"rimraf": "^3.0.0",
5656
"satoshi-bitcoin": "^1.0.4",
5757
"temp-write": "^4.0.0",
58-
"tempfile": "^3.0.0",
5958
"testcontainers": "^2.1.0",
59+
"tmp": "^0.1.0",
6060
"ts-node": "^8.5.4",
6161
"tslint": "^5.20.1",
6262
"tslint-config-prettier": "^1.18.0",

api_tests/yarn.lock

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2557,6 +2557,13 @@ rfdc@^1.1.4:
25572557
resolved "https://registry.yarnpkg.com/rfdc/-/rfdc-1.1.4.tgz#ba72cc1367a0ccd9cf81a870b3b58bd3ad07f8c2"
25582558
integrity sha512-5C9HXdzK8EAqN7JDif30jqsBzavB7wLpaubisuQIGHWf2gUXSpzy6ArX/+Da8RjFpagWsCn+pIgxTMAmKw9Zug==
25592559

2560+
rimraf@^2.6.3:
2561+
version "2.7.1"
2562+
resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-2.7.1.tgz#35797f13a7fdadc566142c29d4f07ccad483e3ec"
2563+
integrity sha512-uWjbaKIK3T1OSVptzX7Nl6PvQ3qAGtKEtVRjRuazjfL3Bx5eI409VZSqgND+4UNnmzLVdPj9FqFJNPqBZFve4w==
2564+
dependencies:
2565+
glob "^7.1.3"
2566+
25602567
rimraf@^3.0.0:
25612568
version "3.0.0"
25622569
resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-3.0.0.tgz#614176d4b3010b75e5c390eb0ee96f6dc0cebb9b"
@@ -2914,7 +2921,7 @@ temp-write@^4.0.0:
29142921
temp-dir "^1.0.0"
29152922
uuid "^3.3.2"
29162923

2917-
tempfile@*, tempfile@^3.0.0:
2924+
tempfile@*:
29182925
version "3.0.0"
29192926
resolved "https://registry.yarnpkg.com/tempfile/-/tempfile-3.0.0.tgz#5376a3492de7c54150d0cc0612c3f00e2cdaf76c"
29202927
integrity sha512-uNFCg478XovRi85iD42egu+eSFUmmka750Jy7L5tfHI5hQKKtbPnxaSaXAbBqCDYrw3wx4tXjKwci4/QmsZJxw==
@@ -2974,6 +2981,13 @@ tiny-secp256k1@^1.1.0, tiny-secp256k1@^1.1.1:
29742981
elliptic "^6.4.0"
29752982
nan "^2.13.2"
29762983

2984+
tmp@^0.1.0:
2985+
version "0.1.0"
2986+
resolved "https://registry.yarnpkg.com/tmp/-/tmp-0.1.0.tgz#ee434a4e22543082e294ba6201dcc6eafefa2877"
2987+
integrity sha512-J7Z2K08jbGcdA1kkQpJSqLF6T0tdQqpR2pnSUXsIchbPdTI9v3e85cLW0d6WDhwuAleOV71j2xWs8qMPfK7nKw==
2988+
dependencies:
2989+
rimraf "^2.6.3"
2990+
29772991
to-buffer@^1.1.1:
29782992
version "1.1.1"
29792993
resolved "https://registry.yarnpkg.com/to-buffer/-/to-buffer-1.1.1.tgz#493bd48f62d7c43fcded313a03dcadb2e1213a80"

0 commit comments

Comments
 (0)