|
| 1 | +import assert from "node:assert/strict"; |
| 2 | +import { describe, it } from "node:test"; |
| 3 | + |
| 4 | +import { HardhatError } from "@nomicfoundation/hardhat-errors"; |
| 5 | + |
| 6 | +import { ParameterType } from "../../src/config.js"; |
| 7 | +import { buildGlobalParameterDefinition } from "../../src/internal/global-parameters.js"; |
| 8 | +import { RESERVED_PARAMETER_NAMES } from "../../src/internal/parameters.js"; |
| 9 | + |
| 10 | +describe("Global Parameters", () => { |
| 11 | + describe.todo("buildGlobalParameterMap", () => { |
| 12 | + // TODO: Implement tests. |
| 13 | + }); |
| 14 | + |
| 15 | + describe("buildGlobalParameterDefinition", () => { |
| 16 | + it("should build a global parameter definition", () => { |
| 17 | + const options = { |
| 18 | + name: "foo", |
| 19 | + description: "Foo description", |
| 20 | + parameterType: ParameterType.BOOLEAN, |
| 21 | + defaultValue: true, |
| 22 | + }; |
| 23 | + const globalParameter = buildGlobalParameterDefinition(options); |
| 24 | + |
| 25 | + assert.deepEqual(globalParameter, options); |
| 26 | + }); |
| 27 | + |
| 28 | + it("should build a global parameter definition with a default type of STRING", () => { |
| 29 | + const options = { |
| 30 | + name: "foo", |
| 31 | + description: "Foo description", |
| 32 | + defaultValue: "bar", |
| 33 | + }; |
| 34 | + const globalParameter = buildGlobalParameterDefinition(options); |
| 35 | + |
| 36 | + assert.deepEqual(globalParameter, { |
| 37 | + ...options, |
| 38 | + parameterType: ParameterType.STRING, |
| 39 | + }); |
| 40 | + }); |
| 41 | + |
| 42 | + it("should throw if the parameter name is not valid", () => { |
| 43 | + assert.throws( |
| 44 | + () => |
| 45 | + buildGlobalParameterDefinition({ |
| 46 | + name: "foo bar", |
| 47 | + description: "Foo description", |
| 48 | + defaultValue: "bar", |
| 49 | + }), |
| 50 | + new HardhatError(HardhatError.ERRORS.ARGUMENTS.INVALID_NAME, { |
| 51 | + name: "foo bar", |
| 52 | + }), |
| 53 | + ); |
| 54 | + }); |
| 55 | + |
| 56 | + it("should throw if the parameter name is reserved", () => { |
| 57 | + RESERVED_PARAMETER_NAMES.forEach((name) => { |
| 58 | + assert.throws( |
| 59 | + () => |
| 60 | + buildGlobalParameterDefinition({ |
| 61 | + name, |
| 62 | + description: "Foo description", |
| 63 | + defaultValue: "bar", |
| 64 | + }), |
| 65 | + new HardhatError(HardhatError.ERRORS.ARGUMENTS.RESERVED_NAME, { |
| 66 | + name, |
| 67 | + }), |
| 68 | + ); |
| 69 | + }); |
| 70 | + }); |
| 71 | + |
| 72 | + it("should throw if the default value does not match the type", () => { |
| 73 | + assert.throws( |
| 74 | + () => |
| 75 | + buildGlobalParameterDefinition({ |
| 76 | + name: "foo", |
| 77 | + description: "Foo description", |
| 78 | + parameterType: ParameterType.BOOLEAN, |
| 79 | + /* eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- |
| 80 | + Intentionally testing an invalid type */ |
| 81 | + defaultValue: "bar" as any, |
| 82 | + }), |
| 83 | + new HardhatError(HardhatError.ERRORS.ARGUMENTS.INVALID_VALUE_FOR_TYPE, { |
| 84 | + value: "bar", |
| 85 | + name: "defaultValue", |
| 86 | + type: ParameterType.BOOLEAN, |
| 87 | + }), |
| 88 | + ); |
| 89 | + }); |
| 90 | + }); |
| 91 | + |
| 92 | + describe.todo("resolveGlobalArguments", () => { |
| 93 | + // TODO: Implement tests. |
| 94 | + }); |
| 95 | +}); |
0 commit comments