patch-package --- a/node_modules/truffle-contract/lib/contract/constructorMethods.js +++ b/node_modules/truffle-contract/lib/contract/constructorMethods.js @@ -170,13 +170,17 @@ module.exports = Contract => { constructor.web3.eth .getBlock("latest") .then(function(block) { + + // Fallback to 7 million gas + const blockLimit = block && block.gasLimit ? block.gasLimit : 7000000; + // Try to detect the network we have artifacts for. if (constructor.network_id) { // We have a network id and a configuration, let's go with it. if (constructor.networks[constructor.network_id] != null) { return accept({ id: constructor.network_id, - blockLimit: block.gasLimit + blockLimit, }); } } @@ -189,7 +193,7 @@ module.exports = Contract => { constructor.setNetwork(network_id); return accept({ id: constructor.network_id, - blockLimit: block.gasLimit + blockLimit, }); } @@ -217,7 +221,7 @@ module.exports = Contract => { constructor.setNetwork(uris[i]); return accept({ id: constructor.network_id, - blockLimit: block.gasLimit + blockLimit, }); } } @@ -226,7 +230,7 @@ module.exports = Contract => { constructor.setNetwork(network_id); return accept({ id: constructor.network_id, - blockLimit: block.gasLimit + blockLimit, }); }); }) --- a/node_modules/truffle-contract/lib/handlers.js +++ b/node_modules/truffle-contract/lib/handlers.js @@ -100,7 +100,12 @@ var handlers = { } catch (error) { return context.promiEvent.reject(error); } + if (!receipt.transactionHash) { + receipt.transactionHash = context.transactionHash; + receipt.status = 1; + } + // Emit receipt context.promiEvent.eventEmitter.emit("receipt", receipt); --- a/node_modules/truffle-contract/lib/override.js +++ b/node_modules/truffle-contract/lib/override.js @@ -48,21 +48,27 @@ var override = { // Reject after attempting to get reason string if we shouldn't be waiting. if (!timedOut || !shouldWait){ - // We might have been routed here in web3 >= beta.34 by their own status check + // We might have been routed here in web3 >= beta.34 by their own status check // error. We want to extract the receipt, emit a receipt event // and reject it ourselves. var receipt = override.extractReceipt(web3Error.message); if (receipt){ - await handlers.receipt(context, receipt); + try { + await handlers.receipt(context, receipt); + } catch (error) { + // FIXME: `this.removeListener is not a function` is returned sometimes + // console.error(err); + } return; } // This will run if there's a reason and no status field // e.g: revert with reason ganache-cli --vmErrorsOnRPCResponse=true - var reason = await Reason.get(context.params, constructor.web3); - if (reason) { - web3Error.reason = reason; - web3Error.message += ` -- Reason given: ${reason}.`; + var reason; + try { + await Reason.get(context.params, constructor.web3); + } catch (err) { + console.error(err); } return context.promiEvent.reject(web3Error); --- a/node_modules/truffle-contract/lib/reason.js +++ b/node_modules/truffle-contract/lib/reason.js @@ -44,7 +44,7 @@ const reason = { }; return new Promise(resolve => { - web3.currentProvider.send(packet, (err, response) => { + web3.currentProvider.sendAsync(packet, (err, response) => { const reasonString = reason._extract(response, web3); resolve(reasonString); });