Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.

Commit f688f6d

Browse files
Change the file name to command-utils.js
1 parent dae3025 commit f688f6d

File tree

1 file changed

+93
-0
lines changed

1 file changed

+93
-0
lines changed
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
const assert = require("chai").assert;
2+
const fs = require("fs-extra");
3+
const path = require("path");
4+
const tmp = require("tmp");
5+
const TruffleConfig = require("@truffle/config");
6+
const { deriveConfigEnvironment } = require("../../lib/command-utils");
7+
8+
let config;
9+
10+
function createSandbox(source) {
11+
if (!fs.existsSync(source)) {
12+
throw new Error(`Sandbox failed: source: ${source} does not exist`);
13+
}
14+
15+
const tempDir = tmp.dirSync({ unsafeCleanup: true });
16+
fs.copySync(source, tempDir.name);
17+
const config = TruffleConfig.load(
18+
path.join(tempDir.name, "truffle-config.js"),
19+
{}
20+
);
21+
return config;
22+
}
23+
24+
describe("command-utils", function () {
25+
before(function () {
26+
config = createSandbox(
27+
path.join(__dirname, "..", "sources", "command-utils")
28+
);
29+
});
30+
31+
describe("deriveConfigEnvironment", function () {
32+
it("returns a config with specified network object having a provider property", function () {
33+
const expectedNetworkConfig = config.networks.crazyTimeNetwork;
34+
const cfg = deriveConfigEnvironment(
35+
config,
36+
"crazyTimeNetwork",
37+
undefined
38+
);
39+
assert.equal(
40+
cfg.networks.crazyTimeNetwork.confirmations,
41+
expectedNetworkConfig.confirmations
42+
);
43+
assert.equal(
44+
cfg.networks.crazyTimeNetwork.customUserProperty,
45+
expectedNetworkConfig.customUserProperty
46+
);
47+
});
48+
49+
it("returns a config with a url host network object having the url property ", function () {
50+
const cfg = deriveConfigEnvironment(
51+
config,
52+
"anyTimeNetwork",
53+
"http://localhost:5555"
54+
);
55+
assert.equal(cfg.networks["anyTimeNetwork"].url, "http://localhost:5555");
56+
});
57+
58+
it("returns a config with a network object having user specified properties", function () {
59+
const expectedNetworkConfig = config.networks.funTimeNetwork;
60+
const cfg = deriveConfigEnvironment(config, "funTimeNetwork", undefined);
61+
assert.equal(
62+
cfg.networks.funTimeNetwork.host,
63+
expectedNetworkConfig.host
64+
);
65+
assert.equal(
66+
cfg.networks.funTimeNetwork.port,
67+
expectedNetworkConfig.port
68+
);
69+
assert.equal(
70+
cfg.networks.funTimeNetwork.confirmations,
71+
expectedNetworkConfig.confirmations
72+
);
73+
assert.equal(
74+
cfg.networks.funTimeNetwork.customUserProperty,
75+
expectedNetworkConfig.customUserProperty
76+
);
77+
});
78+
79+
it("returns a config with a dashboard network object having user specified properties", function () {
80+
const expectedNetworkConfig = config.networks.dashboard;
81+
const cfg = deriveConfigEnvironment(config, "dashboard", undefined);
82+
assert.equal(cfg.networks.dashboard.url, expectedNetworkConfig.url);
83+
assert.equal(
84+
cfg.networks.dashboard.confirmations,
85+
expectedNetworkConfig.confirmations
86+
);
87+
assert.equal(
88+
cfg.networks.dashboard.customUserProperty,
89+
expectedNetworkConfig.customUserProperty
90+
);
91+
});
92+
});
93+
});

0 commit comments

Comments
 (0)