diff --git a/.travis.yml b/.travis.yml index defd2c6..b9754a7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,14 +1,13 @@ language: node_js -node_js: "node" +node_js: + - 12 before_script: - - npm install -g truffle@5.0.1 ganache-cli@6.1.8 + - npm install -g truffle@5.1.41 ganache-cli@6.10.1 - npm install script: - - ganache-cli > /dev/null & + - ganache-cli -p 8545 > /dev/null & - sleep 5 - - rm -rf build - - truffle migrate - - truffle test + - npm run test diff --git a/contracts/RLPReader.sol b/contracts/RLPReader.sol index 89e51b5..784c92b 100644 --- a/contracts/RLPReader.sol +++ b/contracts/RLPReader.sol @@ -135,7 +135,7 @@ library RLPReader { return result; } - // any non-zero byte is considered true + // any non-zero byte except "0x80" is considered true function toBoolean(RLPItem memory item) internal pure returns (bool) { require(item.len == 1); uint result; @@ -144,7 +144,15 @@ library RLPReader { result := byte(0, mload(memPtr)) } - return result == 0 ? false : true; + // SEE Github Issue #5. + // Summary: Most commonly used RLP libraries (i.e Geth) will encode + // "0" as "0x80" instead of as "0". We handle this edge case explicitly + // here. + if (result == 0 || result == STRING_SHORT_START) { + return false; + } else { + return true; + } } function toAddress(RLPItem memory item) internal pure returns (address) { diff --git a/package-lock.json b/package-lock.json index f86c635..a351f9b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,18 +1,20 @@ { "name": "solidity-rlp", - "version": "1.1.0", + "version": "2.0.1", "lockfileVersion": 1, "requires": true, "dependencies": { "assertion-error": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/assertion-error/-/assertion-error-1.1.0.tgz", - "integrity": "sha512-jgsaNduz+ndvGyFt3uSuWqvy4lCnIJiovtouQN5JZHOKCS2QuhEdbcQHFhVksz2N2U9hXJo8odG7ETyWlEeuDw==" + "integrity": "sha512-jgsaNduz+ndvGyFt3uSuWqvy4lCnIJiovtouQN5JZHOKCS2QuhEdbcQHFhVksz2N2U9hXJo8odG7ETyWlEeuDw==", + "dev": true }, "chai": { "version": "4.1.2", "resolved": "https://registry.npmjs.org/chai/-/chai-4.1.2.tgz", "integrity": "sha1-D2RYS6ZC8PKs4oBiefTwbKI61zw=", + "dev": true, "requires": { "assertion-error": "^1.0.1", "check-error": "^1.0.1", @@ -25,12 +27,14 @@ "check-error": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/check-error/-/check-error-1.0.2.tgz", - "integrity": "sha1-V00xLt2Iu13YkS6Sht1sCu1KrII=" + "integrity": "sha1-V00xLt2Iu13YkS6Sht1sCu1KrII=", + "dev": true }, "deep-eql": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/deep-eql/-/deep-eql-3.0.1.tgz", "integrity": "sha512-+QeIQyN5ZuO+3Uk5DYh6/1eKO0m0YmJFGNmFHGACpf1ClL1nmlV/p4gNgbl2pJGxgXb4faqo6UE+M5ACEMyVcw==", + "dev": true, "requires": { "type-detect": "^4.0.0" } @@ -38,22 +42,26 @@ "get-func-name": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/get-func-name/-/get-func-name-2.0.0.tgz", - "integrity": "sha1-6td0q+5y4gQJQzoGY2YCPdaIekE=" + "integrity": "sha1-6td0q+5y4gQJQzoGY2YCPdaIekE=", + "dev": true }, "pathval": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/pathval/-/pathval-1.1.0.tgz", - "integrity": "sha1-uULm1L3mUwBe9rcTYd74cn0GReA=" + "integrity": "sha1-uULm1L3mUwBe9rcTYd74cn0GReA=", + "dev": true }, "rlp": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/rlp/-/rlp-2.0.0.tgz", - "integrity": "sha1-nbOE/0uJqPYVY9kjldhiWxjzr7A=" + "integrity": "sha1-nbOE/0uJqPYVY9kjldhiWxjzr7A=", + "dev": true }, "type-detect": { "version": "4.0.8", "resolved": "https://registry.npmjs.org/type-detect/-/type-detect-4.0.8.tgz", - "integrity": "sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==" + "integrity": "sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==", + "dev": true } } } diff --git a/test/basic-tests.js b/test/basic-tests.js index 767ecca..2ef9653 100644 --- a/test/basic-tests.js +++ b/test/basic-tests.js @@ -164,7 +164,10 @@ contract("RLPReader", async (accounts) => { // toBoolean result = await helper.toBoolean.call(toHex(rlp.encode(1))); - assert(result == true, "Incorrect toBoolean conversion"); + assert(result == true, "Incorrect toBoolean true conversion"); + + result = await helper.toBoolean.call(toHex(rlp.encode(0))); + assert(result == false, "Incorrect toBoolean false conversion"); // Mix of data types str = [accounts[0], 1, 65537]; @@ -282,7 +285,7 @@ contract("RLPReader", async (accounts) => { totalDifficulty: '10690776258913596267754', }; const rlpHeader = toRLPHeader(block); - const result = await helper.toBlockHeader.call(rlpHeader, {}); + const result = await helper.toBlockHeader.call(rlpHeader); assert(result.parentHash == block.parentHash, "parentHash not equal"); assert(result.sha3Uncles == block.sha3Uncles, "sha3Uncles not equal"); assert(result.stateRoot == block.stateRoot, "stateRoot not equal"); diff --git a/truffle-config.js b/truffle-config.js index a6330d6..4425674 100644 --- a/truffle-config.js +++ b/truffle-config.js @@ -1,4 +1,11 @@ module.exports = { // See // to customize your Truffle configuration! + networks: { + development: { + host: 'localhost', + port: 8545, + network_id: '*' + } + } }; diff --git a/truffle.js b/truffle.js deleted file mode 100644 index 4425674..0000000 --- a/truffle.js +++ /dev/null @@ -1,11 +0,0 @@ -module.exports = { - // See - // to customize your Truffle configuration! - networks: { - development: { - host: 'localhost', - port: 8545, - network_id: '*' - } - } -};