Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// HACK(albrow): This dummy `catch` should not be necessary, but if you
// remove it, there is an uncaught exception and the Node process will
// forcibly exit. It's possible this is a false positive in
// make-promises-safe.
p.catch(e => {
_.noop(e);
});
if (nodeType === undefined) {
nodeType = await web3Wrapper.getNodeTypeAsync();
}
switch (nodeType) {
case NodeType.Ganache:
const rejectionMessageRegex = new RegExp(`^VM Exception while processing transaction: revert ${reason}$`);
return expect(p).to.be.rejectedWith(rejectionMessageRegex);
case NodeType.Geth:
logUtils.warn(
'WARNING: Geth does not support revert reasons for sendTransaction. This test will pass if the transaction fails for any reason.',
);
return expectTransactionFailedWithoutReasonAsync(p);
default:
throw new Error(`Unknown node type: ${nodeType}`);
}
}
public async startAsync(): Promise {
const nodeType = await this._getNodeTypeAsync();
switch (nodeType) {
case NodeType.Ganache:
const snapshotId = await this._web3Wrapper.takeSnapshotAsync();
this._snapshotIdsStack.push(snapshotId);
break;
case NodeType.Geth:
let blockNumber = await this._web3Wrapper.getBlockNumberAsync();
if (blockNumber < MINIMUM_BLOCKS) {
// If the minimum block number is not met, force Geth to
// mine some blocks by sending some dummy transactions.
await this._mineMinimumBlocksAsync();
blockNumber = await this._web3Wrapper.getBlockNumberAsync();
}
this._snapshotIdsStack.push(blockNumber);
// HACK(albrow) It's possible that we applied a time offset but
// the transaction we mined to put that time offset into the
// blockchain was reverted. As a workaround, we mine a new dummy
// block so that the latest block timestamp accounts for any
// possible time offsets.
await this._mineDummyBlockAsync();
break;
default:
async function _getGanacheOrGethErrorAsync(ganacheError: string, gethError: string): Promise {
if (nodeType === undefined) {
nodeType = await web3Wrapper.getNodeTypeAsync();
}
switch (nodeType) {
case NodeType.Ganache:
return ganacheError;
case NodeType.Geth:
return gethError;
default:
throw new Error(`Unknown node type: ${nodeType}`);
}
}