File tree 2 files changed +36
-0
lines changed
test/internal/core/config
2 files changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -58,6 +58,12 @@ function getMessage(e: ValidationError): string {
58
58
) ;
59
59
}
60
60
61
+ function getEmptyErrorMessage ( path : string , value : any , expectedType : string ) {
62
+ return `Empty value ${ stringify (
63
+ value
64
+ ) } for ${ path } - Expected a non-empty value of type ${ expectedType } .`;
65
+ }
66
+
61
67
function getErrorMessage ( path : string , value : any , expectedType : string ) {
62
68
return `Invalid value ${ stringify (
63
69
value
@@ -148,6 +154,14 @@ function isDecimalString(v: unknown): v is string {
148
154
return v . match ( DEC_STRING_REGEX ) !== null ;
149
155
}
150
156
157
+ function isEmptyString ( v : unknown ) : v is string {
158
+ if ( typeof v !== "string" ) {
159
+ return false ;
160
+ }
161
+
162
+ return v . trim ( ) . length === 0 ;
163
+ }
164
+
151
165
export const hexString = new t . Type < string > (
152
166
"hex string" ,
153
167
isHexString ,
@@ -535,6 +549,14 @@ export function getValidationErrors(config: any): string[] {
535
549
"string"
536
550
)
537
551
) ;
552
+ } else if ( isEmptyString ( netConfig . url ) ) {
553
+ errors . push (
554
+ getEmptyErrorMessage (
555
+ `HardhatConfig.networks.${ networkName } .url` ,
556
+ netConfig . url ,
557
+ "string"
558
+ )
559
+ ) ;
538
560
}
539
561
}
540
562
Original file line number Diff line number Diff line change @@ -1171,6 +1171,20 @@ describe("Config validation", function () {
1171
1171
) ;
1172
1172
} ) ;
1173
1173
1174
+ it ( "Should fail if an empty url is set for custom networks" , function ( ) {
1175
+ // Empty string
1176
+ expectHardhatError (
1177
+ ( ) => validateConfig ( { networks : { custom : { url : "" } } } ) ,
1178
+ ERRORS . GENERAL . INVALID_CONFIG
1179
+ ) ;
1180
+
1181
+ // Empty string with at least 1 whitespace
1182
+ expectHardhatError (
1183
+ ( ) => validateConfig ( { networks : { custom : { url : " " } } } ) ,
1184
+ ERRORS . GENERAL . INVALID_CONFIG
1185
+ ) ;
1186
+ } ) ;
1187
+
1174
1188
it ( "Shouldn't fail if no url is set for localhost network" , function ( ) {
1175
1189
const errors = getValidationErrors ( { networks : { localhost : { } } } ) ;
1176
1190
assert . isEmpty ( errors ) ;
You can’t perform that action at this time.
0 commit comments