File tree 1 file changed +23
-8
lines changed
packages/hardhat-chai-matchers/src/internal
1 file changed +23
-8
lines changed Original file line number Diff line number Diff line change @@ -37,14 +37,7 @@ export function supportChangeEtherBalances(
37
37
chaiUtils
38
38
) ;
39
39
40
- if (
41
- Array . isArray ( balanceChanges ) &&
42
- accounts . length !== balanceChanges . length
43
- ) {
44
- throw new Error (
45
- `The number of accounts (${ accounts . length } ) is different than the number of expected balance changes (${ balanceChanges . length } )`
46
- ) ;
47
- }
40
+ validateInput ( this . _obj , accounts , balanceChanges ) ;
48
41
49
42
const checkBalanceChanges = ( [ actualChanges , accountAddresses ] : [
50
43
bigint [ ] ,
@@ -113,6 +106,28 @@ export function supportChangeEtherBalances(
113
106
) ;
114
107
}
115
108
109
+ function validateInput (
110
+ obj : any ,
111
+ accounts : Array < Addressable | string > ,
112
+ balanceChanges : EthersT . BigNumberish [ ] | ( ( changes : bigint [ ] ) => boolean )
113
+ ) {
114
+ try {
115
+ if (
116
+ Array . isArray ( balanceChanges ) &&
117
+ accounts . length !== balanceChanges . length
118
+ ) {
119
+ throw new Error (
120
+ `The number of accounts (${ accounts . length } ) is different than the number of expected balance changes (${ balanceChanges . length } )`
121
+ ) ;
122
+ }
123
+ } catch ( e ) {
124
+ // if the input validation fails, we discard the subject since it could
125
+ // potentially be a rejected promise
126
+ Promise . resolve ( obj ) . catch ( ( ) => { } ) ;
127
+ throw e ;
128
+ }
129
+ }
130
+
116
131
export async function getBalanceChanges (
117
132
transaction : TransactionResponse | Promise < TransactionResponse > ,
118
133
accounts : Array < Addressable | string > ,
You can’t perform that action at this time.
0 commit comments