Skip to content

Commit 2d1c9fc

Browse files
authored
Merge pull request #752 from PolymathNetwork/chore/st-reason-strings
chore: ST unit tests:: explicit revert reason checks
2 parents 958340b + cd89c2c commit 2d1c9fc

File tree

6 files changed

+146
-180
lines changed

6 files changed

+146
-180
lines changed

test/f_ether_dividends.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -350,8 +350,7 @@ contract("EtherDividendCheckpoint", async (accounts) => {
350350

351351
it("Should not allow reclaiming withholding tax with incorrect index", async () => {
352352
await catchRevert(
353-
I_EtherDividendCheckpoint.withdrawWithholding(300, { from: token_owner, gasPrice: 0 }),
354-
"tx -> failed because dividend index is not valid"
353+
I_EtherDividendCheckpoint.withdrawWithholding(300, { from: token_owner, gasPrice: 0 })
355354
);
356355
});
357356

@@ -580,8 +579,7 @@ contract("EtherDividendCheckpoint", async (accounts) => {
580579
I_EtherDividendCheckpoint.createDividendWithCheckpointAndExclusions(maturity, expiry, 4, addresses, dividendName, {
581580
from: token_owner,
582581
value: new BN(web3.utils.toWei("10", "ether"))
583-
}),
584-
"tx -> failed because too many address excluded"
582+
})
585583
);
586584
});
587585

test/helpers/exceptions.js

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,19 @@
1-
const PREFIX = "VM Exception while processing transaction: ";
2-
const PREFIX2 = "Returned error: VM Exception while processing transaction: ";
3-
4-
async function tryCatch(promise, message) {
1+
async function tryCatch(promise, expectedError) {
52
try {
63
await promise;
7-
throw null;
84
} catch (error) {
9-
assert(error, "Expected an error but did not get one");
10-
try {
11-
assert(
12-
error.message.startsWith(PREFIX + message),
13-
"Expected an error starting with '" + PREFIX + message + "' but got '" + error.message + "' instead"
14-
);
15-
} catch (err) {
16-
assert(
17-
error.message.startsWith(PREFIX2 + message),
18-
"Expected an error starting with '" + PREFIX + message + "' but got '" + error.message + "' instead"
19-
);
5+
if (error.message.indexOf(expectedError) === -1) {
6+
throw Error(`Wrong failure type, expected '${expectedError}' and got '${error.message}'`);
207
}
8+
return;
219
}
10+
11+
throw Error('Expected failure not received');
2212
}
2313

2414
module.exports = {
25-
catchRevert: async function(promise) {
26-
await tryCatch(promise, "revert");
15+
catchRevert: async function(promise, message = 'revert') {
16+
await tryCatch(promise, message);
2717
},
2818
catchPermission: async function(promise) {
2919
await tryCatch(promise, "revert Permission check failed");

test/k_module_registry.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,7 @@ contract("ModuleRegistry", async (accounts) => {
155155
catchRevert(
156156
I_ModuleRegistryProxy.upgradeToAndCall("1.0.0", I_ModuleRegistry.address, bytesProxy, {
157157
from: account_polymath
158-
}),
159-
"tx-> revert because polymathRegistry address is 0x"
158+
})
160159
);
161160
});
162161

@@ -165,8 +164,7 @@ contract("ModuleRegistry", async (accounts) => {
165164
catchRevert(
166165
I_ModuleRegistryProxy.upgradeToAndCall("1.0.0", I_ModuleRegistry.address, bytesProxy, {
167166
from: account_polymath
168-
}),
169-
"tx-> revert because owner address is 0x"
167+
})
170168
);
171169
});
172170

@@ -175,8 +173,7 @@ contract("ModuleRegistry", async (accounts) => {
175173
catchRevert(
176174
I_ModuleRegistryProxy.upgradeToAndCall("1.0.0", I_ModuleRegistry.address, bytesProxy, {
177175
from: account_polymath
178-
}),
179-
"tx-> revert because all params are 0x"
176+
})
180177
);
181178
});
182179

0 commit comments

Comments
 (0)