Skip to content

Commit

Permalink
Allow 'null' receipt.status values (#3090)
Browse files Browse the repository at this point in the history
* Add outputTransactionReceiptFormatter tests

* Allow null receipt.status
  • Loading branch information
cgewecke authored and nivida committed Oct 8, 2019
1 parent 6d4ea0d commit 4b91f10
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ Released with 1.0.0-beta.37 code base.

### Fixed

- Fix error incorrectly thrown when receipt.status is `null` (#2183)
- Fix incorrectly populating chainId param with `net_version` when signing txs (#2378)
- 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)
});
});

0 comments on commit 4b91f10

Please sign in to comment.