-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathstacktical.validation.ts
More file actions
77 lines (71 loc) · 2.45 KB
/
stacktical.validation.ts
File metadata and controls
77 lines (71 loc) · 2.45 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import { extendConfig } from 'hardhat/config';
import { HardhatConfig, HardhatUserConfig } from 'hardhat/types';
import './type-extensions';
const Joi = require('joi');
require('dotenv').config({ path: '../.env' });
const schema = Joi.object({
IPFS_URI: Joi.string().required(),
}).unknown();
const { error, value } = schema.validate(process.env);
if (error) {
throw new Error(`global .env file validation error: ${error.message}`);
} else {
process.env = value;
}
extendConfig(
(config: HardhatConfig, userConfig: Readonly<HardhatUserConfig>) => {
Object.keys(userConfig.networks).forEach((network) => {
const stackticalConfig = userConfig.networks[network]['stacktical'];
// Check if potentially env parameters fields (private data such as credentials) is parsed correctly before executing
if (stackticalConfig) {
const schema = Joi.object({
ipfs: Joi.string().required(),
chainlink: Joi.object({
ethWsUrl: Joi.string().required(),
nodesConfiguration: Joi.array().items(
Joi.object({
name: Joi.string().required(),
restApiUrl: Joi.string().required(),
restApiPort: Joi.string().required(),
email: Joi.string().required(),
password: Joi.string().required(),
})
),
}).unknown(),
}).unknown();
const { error } = schema.validate(stackticalConfig);
if (error) {
throw new Error(
`Config validation error for network ${network}: ${error.message}`
);
}
if (!stackticalConfig.deployTokens) {
const undefTokenAddress = stackticalConfig.tokens.find(
(token) => token.address === undefined
);
if (undefTokenAddress) {
throw new Error(
undefTokenAddress.name +
' token has no address in ' +
network +
' network config'
);
}
}
if (
new Set(
stackticalConfig.messengers.map(
(messenger) => messenger.useCaseName
)
).size !== stackticalConfig.messengers.length
) {
throw new Error(
'Messenger use case name repeated for network ' + network
);
}
config.networks[network]['stacktical'] =
userConfig.networks[network]['stacktical'];
}
});
}
);