Skip to content

Commit

Permalink
Merge branch '1.x' into ci/add-buildsize-checker
Browse files Browse the repository at this point in the history
  • Loading branch information
nivida committed Dec 10, 2019
2 parents 8df5e45 + 8804708 commit f0f9ffc
Show file tree
Hide file tree
Showing 12 changed files with 999 additions and 681 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ dist/
packages/web3/dist/
lerna-debug.log
!./dist/web3.min.js
.nyc_output/
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ Released with 1.0.0-beta.37 code base.
- ``BN`` and ``BigNumber`` objects are now supported by the ``abi.encodeParameter(s)`` method (#3238)
- ``getPendingTransactions`` added to web3-eth package (#3239)
- Revert instruction handling added which can get activated with the ``handleRevert`` module property (#3248)
- The ``receipt`` does now exist as property on the error object for transaction related errors (#3259)

### Changed

Expand Down
1,468 changes: 830 additions & 638 deletions package-lock.json

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
},
"bundlesize": [
{
"path": "./packages/web3/dist/web3.min.js",
"maxSize": "1.5 mB",
"compression": "none"
"path": "./packages/web3/dist/web3.min.js",
"maxSize": "1.5 mB",
"compression": "none"
}
],
"scripts": {
Expand All @@ -29,7 +29,7 @@
"docs": "cd docs; make html;",
"lint": "jshint *.js packages",
"test": "mocha --grep E2E --invert; jshint *.js packages",
"test:unit": "istanbul cover _mocha -- -R spec --grep E2E --invert",
"test:unit": "nyc --no-clean --silent _mocha -- -R spec --grep E2E --invert",
"dtslint": "lerna run dtslint",
"depcheck": "lerna exec dependency-check -- --missing --verbose .",
"bundlesize": "bundlesize",
Expand Down Expand Up @@ -120,8 +120,6 @@
"gulp-replace": "^1.0.0",
"gulp-streamify": "^1.0.2",
"gulp-uglify": "^3.0.2",
"istanbul": "^1.1.0-alpha.1",
"istanbul-combine-updated": "^0.3.0",
"jshint": "^2.10.2",
"karma": "^4.4.1",
"karma-browserify": "^6.1.0",
Expand All @@ -131,7 +129,9 @@
"karma-spec-reporter": "0.0.32",
"lerna": "^3.18.3",
"mocha": "^6.2.1",
"nyc": "^14.1.1",
"puppeteer": "^1.20.0",
"regenerator-runtime": "^0.13.3",
"sandboxed-module": "^2.0.3",
"typescript": "next",
"underscore": "^1.9.1",
Expand Down
19 changes: 19 additions & 0 deletions packages/web3-core-helpers/src/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,26 @@ module.exports = {
var error = new Error('Transaction has been reverted by the EVM:\n' + JSON.stringify(receipt, null, 2));
error.reason = reason;
error.signature = signature;
error.receipt = receipt;

return error;
},
TransactionError: function(message, receipt) {
var error = new Error(message);
error.receipt = receipt;

return error;
},
NoContractAddressFoundError: function(receipt) {
return this.TransactionError('The transaction receipt didn\'t contain a contract address.', receipt);
},
ContractCodeNotStoredError: function(receipt) {
return this.TransactionError('The contract code couldn\'t be stored, please check your gas limit.', receipt);
},
TransactionRevertedWithoutReasonError: function(receipt) {
return this.TransactionError('Transaction has been reverted by the EVM:\n' + JSON.stringify(receipt, null, 2), receipt);
},
TransactionOutOfGasError: function(receipt) {
return this.TransactionError('Transaction ran out of gas. Please provide more gas:\n' + JSON.stringify(receipt, null, 2), receipt);
}
};
9 changes: 9 additions & 0 deletions packages/web3-core-helpers/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ export class errors {
static ConnectionTimeout(ms: string): Error;
static RevertInstructionError(reason: string, signature: string): RevertInstructionError
static TransactionRevertInstructionError(reason: string, signature: string, receipt: object): TransactionRevertInstructionError
static TransactionError(message: string, receipt: object): TransactionError
static NoContractAddressFoundError(receipt: object): TransactionError
static ContractCodeNotStoredError(receipt: object): TransactionError
static TransactionRevertedWithoutReasonError(receipt: object): TransactionError
static TransactionOutOfGasError(receipt: object): TransactionError
}

export class WebsocketProviderBase {
Expand Down Expand Up @@ -194,3 +199,7 @@ export interface TransactionRevertInstructionError extends Error {
reason: string;
signature: string;
}

export interface TransactionError extends Error {
receipt: object;
}
12 changes: 6 additions & 6 deletions packages/web3-core-method/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ Method.prototype._confirmTransaction = function (defer, result, payload) {
}

utils._fireError(
new Error('The transaction receipt didn\'t contain a contract address.'),
errors.NoContractAddressFoundError(receipt),
defer.eventEmitter,
defer.reject,
null,
Expand Down Expand Up @@ -375,7 +375,7 @@ Method.prototype._confirmTransaction = function (defer, result, payload) {

} else {
utils._fireError(
new Error('The contract code couldn\'t be stored, please check your gas limit.'),
errors.ContractCodeNotStoredError(receipt),
defer.eventEmitter,
defer.reject,
null,
Expand Down Expand Up @@ -437,7 +437,7 @@ Method.prototype._confirmTransaction = function (defer, result, payload) {
} catch (error) {
// Throw an normal revert error if no revert reason is given or the detection of it is disabled
utils._fireError(
new Error('Transaction has been reverted by the EVM:\n' + receiptJSON),
errors.TransactionRevertedWithoutReasonError(receipt),
defer.eventEmitter,
defer.reject,
null,
Expand All @@ -447,7 +447,7 @@ Method.prototype._confirmTransaction = function (defer, result, payload) {
} else {
// Throw OOG if status is not existing and provided gas and used gas are equal
utils._fireError(
new Error('Transaction ran out of gas. Please provide more gas:\n' + receiptJSON),
errors.TransactionOutOfGasError(receipt),
defer.eventEmitter,
defer.reject,
null,
Expand All @@ -474,7 +474,7 @@ Method.prototype._confirmTransaction = function (defer, result, payload) {
sub.unsubscribe();
promiseResolved = true;
utils._fireError(
new Error('Transaction was not mined within ' + method.transactionPollingTimeout + ' seconds, please make sure your transaction was properly sent. Be aware that it might still be mined!'),
errors.TransactionError('Transaction was not mined within ' + method.transactionPollingTimeout + ' seconds, please make sure your transaction was properly sent. Be aware that it might still be mined!'),
defer.eventEmitter,
defer.reject
);
Expand All @@ -484,7 +484,7 @@ Method.prototype._confirmTransaction = function (defer, result, payload) {
sub.unsubscribe();
promiseResolved = true;
utils._fireError(
new Error('Transaction was not mined within ' + method.transactionBlockTimeout + ' blocks, please make sure your transaction was properly sent. Be aware that it might still be mined!'),
errors.TransactionError('Transaction was not mined within ' + method.transactionBlockTimeout + ' blocks, please make sure your transaction was properly sent. Be aware that it might still be mined!'),
defer.eventEmitter,
defer.reject
);
Expand Down
14 changes: 2 additions & 12 deletions scripts/coveralls.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
#!/usr/bin/env bash

# ----------------------------------------------------------------------------------
# Combines coverage.json files generated by e2e and units & pushes them to coveralls
# Merges previous reports from e2e and units & pushes them to coveralls
# ----------------------------------------------------------------------------------

npx istanbul-combine-updated \
-d coverage \
-p summary \
-r lcov \
-r html \
./.cov_ganache.json \
./.cov_geth_insta.json \
./.cov_geth_auto.json \
./coverage/coverage.raw.json

cat coverage/lcov.info | ./node_modules/.bin/coveralls
nyc report --reporter=text-lcov | ./node_modules/.bin/coveralls
7 changes: 1 addition & 6 deletions scripts/e2e.ganache.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,8 @@ client=$!
npx wait-port 8545

# Test
GANACHE=true istanbul cover _mocha -- \
GANACHE=true nyc --no-clean --silent _mocha -- \
--reporter spec \
--grep 'E2E' \
--timeout 5000 \
--exit

# Copy cov for this run to a temp file we can combine later and send to coveralls
if [ "$CI" = true ]; then
cp coverage/coverage.raw.json .cov_ganache.json
fi
7 changes: 1 addition & 6 deletions scripts/e2e.geth.automine.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,8 @@ echo " "
geth-dev-assistant --period 2 --accounts 1 --tag 'stable'

# Test
istanbul cover _mocha -- \
nyc --no-clean --silent _mocha -- \
--reporter spec \
--grep 'E2E' \
--timeout 15000 \
--exit

# Copy cov for this run to a temp file we can combine later and send to coveralls
if [ "$CI" = true ]; then
cp coverage/coverage.raw.json .cov_geth_auto.json
fi
8 changes: 1 addition & 7 deletions scripts/e2e.geth.instamine.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,8 @@ echo " "
geth-dev-assistant --accounts 1 --tag 'stable'

# Test
GETH_INSTAMINE=true istanbul cover _mocha -- \
GETH_INSTAMINE=true nyc --no-clean --silent _mocha -- \
--reporter spec \
--grep 'E2E' \
--timeout 15000 \
--exit

# Copy cov for this run to a temp file we can combine later and send to coveralls
if [ "$CI" = true ]; then
cp coverage/coverage.raw.json .cov_geth_insta.json
fi

122 changes: 122 additions & 0 deletions test/eth.sendTransaction.revert.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
var assert = require('chai').assert;
var FakeHttpProvider = require('./helpers/FakeHttpProvider');
var Web3 = require('../packages/web3');

describe('sendTransaction revert:', function () {
var provider;
var web3;

beforeEach(function () {
provider = new FakeHttpProvider();
web3 = new Web3(provider);
web3.eth.handleRevert = true;
});

it('Errors without revert reason string', function (done) {
provider.injectResult('0x1234567');
provider.injectValidation(function (payload) {
assert.equal(payload.jsonrpc, '2.0');
assert.equal(payload.method, 'eth_sendTransaction');
assert.deepEqual(
payload.params,
[{
from: "0xdbdbdb2cbd23b783741e8d7fcf51e459b497e4a6",
to: "0xdbdbdb2cbd23b783741e8d7fcf51e459b497e4a6",
value: "0x11f71f76bb1",
gasPrice: "0x4b7dddc97a"
}]
);
});

provider.injectResult(null);
provider.injectValidation(function (payload) {
assert.equal(payload.method, 'eth_getTransactionReceipt');
});


// inject receipt
provider.injectResult({
"blockHash": "0x6fd9e2a26ab",
"blockNumber": "0x15df",
"transactionHash": "0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b",
"transactionIndex": "0x1",
"contractAddress": "0x407d73d8a49eeb85d32cf465507dd71d507100c1",
"cumulativeGasUsed": "0x7f110",
"gasUsed": "0x7f110",
"status": "0x0"
});

var options = {
from: '0xdbdbdB2cBD23b783741e8d7fcF51e459b497e4a6',
to: '0xdbdbdB2cBD23b783741e8d7fcF51e459b497e4a6',
value: '1234567654321',
gasPrice: '324234234234'
};

web3.eth.sendTransaction(options).catch(function (error) {
assert.equal(error.receipt.status, false);
assert.equal(error.reason, undefined);
assert.equal(error.signature, undefined);

done();
});
});

it('Errors with revert reason string', function (done) {
provider.injectResult('0x1234567');
provider.injectValidation(function (payload) {
assert.equal(payload.jsonrpc, '2.0');
assert.equal(payload.method, 'eth_sendTransaction');
assert.deepEqual(
payload.params,
[{
from: "0xdbdbdb2cbd23b783741e8d7fcf51e459b497e4a6",
to: "0xdbdbdb2cbd23b783741e8d7fcf51e459b497e4a6",
value: "0x11f71f76bb1",
gasPrice: "0x4b7dddc97a"
}]
);
});

provider.injectResult(null);
provider.injectValidation(function (payload) {
assert.equal(payload.method, 'eth_getTransactionReceipt');
});


// inject receipt
provider.injectResult({
"blockHash": "0x6fd9e2a26ab",
"blockNumber": "0x15df",
"transactionHash": "0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b",
"transactionIndex": "0x1",
"contractAddress": "0x407d73d8a49eeb85d32cf465507dd71d507100c1",
"cumulativeGasUsed": "0x7f110",
"gasUsed": "0x7f110",
"status": "0x0"
});
provider.injectValidation(function (payload) {
assert.equal(payload.method, 'eth_getTransactionReceipt');
});

provider.injectResult('0x08c379a00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001a4e6f7420656e6f7567682045746865722070726f76696465642e000000000000');
provider.injectValidation(function (payload) {
assert.equal(payload.method, 'eth_call');
});

var options = {
from: '0xdbdbdB2cBD23b783741e8d7fcF51e459b497e4a6',
to: '0xdbdbdB2cBD23b783741e8d7fcF51e459b497e4a6',
value: '1234567654321',
gasPrice: '324234234234'
};

web3.eth.sendTransaction(options).catch(function (error) {
assert.equal(error.receipt.status, false);
assert.equal(error.reason, 'Not enough Ether provided.');
assert.equal(error.signature, 'Error(String)');

done();
});
});
});

0 comments on commit f0f9ffc

Please sign in to comment.