diff --git a/lib/configService.ts b/lib/configService.ts index 4f497ef26..6f97be251 100644 --- a/lib/configService.ts +++ b/lib/configService.ts @@ -6,11 +6,27 @@ export class ConfigService { public static data: any; public static get(setting: string): any { - return ConfigService.data[setting]; + const parts = setting.split("."); + let result; + if (parts.length) { + result = ConfigService.data; + parts.forEach((part: any): void => { + result = result[part]; + }); + } + return result; } public static set(setting: string, value: any): void { - ConfigService.data[setting] = value; + const parts = setting.split("."); + const count = parts.length - 1; + let section = ConfigService.data; + if (count > 0) { + for (let i = 0; i < count; ++i) { + section = section[parts[i]]; + } + } + section[parts[count]] = value; } constructor() { diff --git a/test/utils.ts b/test/utils.ts index e03fe3e37..a0d2e6c3b 100644 --- a/test/utils.ts +++ b/test/utils.ts @@ -11,6 +11,20 @@ import * as helpers from "./helpers"; describe("Misc", () => { + it("can set/get txDepthRequiredForConfirmation", async () => { + + let setting = ConfigService.get("logLevel"); + assert.equal(setting, 9); + + setting = ConfigService.get("txDepthRequiredForConfirmation.live"); + assert.equal(setting, 20); + + setting = ConfigService.set("txDepthRequiredForConfirmation.live", 10); + + setting = ConfigService.get("txDepthRequiredForConfirmation.live"); + assert.equal(setting, 10); + }); + it("can check correct wrapper", async () => { const contractNameShouldBe = "GenesisProtocol"; const contractNameDontWant = "AbsoluteVote";