Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow 'null' receipt.status values #3090

Merged
merged 4 commits into from
Oct 8, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,6 @@ Released with 1.0.0-beta.37 code base.

### Fixed

- Fix error incorrectly thrown when receipt.status is `null` (#2183)
- regeneratorRuntime error fixed (#3058)
- Fix accessing event.name where event is undefined (#3014)
2 changes: 1 addition & 1 deletion packages/web3-core-helpers/src/formatters.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ var outputTransactionReceiptFormatter = function (receipt){
receipt.contractAddress = utils.toChecksumAddress(receipt.contractAddress);
}

if(typeof receipt.status !== 'undefined') {
if(typeof receipt.status !== 'undefined' && receipt.status !== null) {
receipt.status = Boolean(parseInt(receipt.status));
}

Expand Down
122 changes: 122 additions & 0 deletions test/formatters.outputTransactionReceiptFormatter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
var assert = require('assert');
var formatters = require('../packages/web3-core-helpers/src/formatters.js');

describe('outputTransactionReceiptFormatter', function() {

it('call outputTransactionReceiptFormatter with a valid receipt', function() {
var receipt = {
status: '0x0',
cumulativeGasUsed: '0x100',
gasUsed: '0x100',
blockNumber: '0x100',
transactionIndex: '0xa',
to: '0x03c9a938ff7f54090d0d99e2c6f80380510ea078',
from: '0x03c9a938ff7f54090d0d99e2c6f80380510ea078',
contractAddress: '0x03c9a938ff7f54090d0d99e2c6f80380510ea078'
};

assert.deepEqual(formatters.outputTransactionReceiptFormatter(receipt), {
status: false,
cumulativeGasUsed: 256,
gasUsed: 256,
blockNumber: 256,
transactionIndex: 10,
to: '0x03c9a938ff7f54090d0d99e2c6f80380510ea078',
from: '0x03c9a938ff7f54090d0d99e2c6f80380510ea078',
contractAddress: '0x03C9A938fF7f54090d0d99e2c6f80380510Ea078'
});
});

it('call outputTransactionReceiptFormatter with a valid receipt and logs', function() {
var receipt = {
status: '0x0',
cumulativeGasUsed: '0x100',
gasUsed: '0x100',
blockNumber: '0x100',
transactionIndex: '0xa',
to: '0x03c9a938ff7f54090d0d99e2c6f80380510ea078',
from: '0x03c9a938ff7f54090d0d99e2c6f80380510ea078',
contractAddress: '0x03c9a938ff7f54090d0d99e2c6f80380510ea078',
logs: [{}]
};

assert.deepEqual(formatters.outputTransactionReceiptFormatter(receipt), {
status: false,
cumulativeGasUsed: 256,
gasUsed: 256,
blockNumber: 256,
transactionIndex: 10,
to: '0x03c9a938ff7f54090d0d99e2c6f80380510ea078',
from: '0x03c9a938ff7f54090d0d99e2c6f80380510ea078',
contractAddress: '0x03C9A938fF7f54090d0d99e2c6f80380510Ea078',
logs: [
{
blockNumber: undefined,
id: null,
logIndex: undefined,
transactionIndex: undefined
}
]
});
});

it('call outputTransactionReceiptFormatter when status is "0x1"', function() {
var receipt = {
status: '0x1',
cumulativeGasUsed: '0x100',
gasUsed: '0x100',
blockNumber: '0x100',
transactionIndex: '0xa',
to: '0x03c9a938ff7f54090d0d99e2c6f80380510ea078',
from: '0x03c9a938ff7f54090d0d99e2c6f80380510ea078',
contractAddress: '0x03c9a938ff7f54090d0d99e2c6f80380510ea078'
};

assert.equal(formatters.outputTransactionReceiptFormatter(receipt).status, true)
});

it('call outputTransactionReceiptFormatter when status is "0x01"', function() {
var receipt = {
status: '0x01',
cumulativeGasUsed: '0x100',
gasUsed: '0x100',
blockNumber: '0x100',
transactionIndex: '0xa',
to: '0x03c9a938ff7f54090d0d99e2c6f80380510ea078',
from: '0x03c9a938ff7f54090d0d99e2c6f80380510ea078',
contractAddress: '0x03c9a938ff7f54090d0d99e2c6f80380510ea078'
};

assert.equal(formatters.outputTransactionReceiptFormatter(receipt).status, true)
});

it('call outputTransactionReceiptFormatter when status is "undefined"', function() {
var receipt = {
status: undefined,
cumulativeGasUsed: '0x100',
gasUsed: '0x100',
blockNumber: '0x100',
transactionIndex: '0xa',
to: '0x03c9a938ff7f54090d0d99e2c6f80380510ea078',
from: '0x03c9a938ff7f54090d0d99e2c6f80380510ea078',
contractAddress: '0x03c9a938ff7f54090d0d99e2c6f80380510ea078'
};

assert.equal(formatters.outputTransactionReceiptFormatter(receipt).status, undefined)
});

it('call outputTransactionReceiptFormatter when status is "null"', function() {
var receipt = {
status: null,
cumulativeGasUsed: '0x100',
gasUsed: '0x100',
blockNumber: '0x100',
transactionIndex: '0xa',
to: '0x03c9a938ff7f54090d0d99e2c6f80380510ea078',
from: '0x03c9a938ff7f54090d0d99e2c6f80380510ea078',
contractAddress: '0x03c9a938ff7f54090d0d99e2c6f80380510ea078'
};

assert.equal(formatters.outputTransactionReceiptFormatter(receipt).status, null)
});
});