Skip to content

Commit

Permalink
verson 0.1.4 -- tighter schema enforcement
Browse files Browse the repository at this point in the history
  • Loading branch information
SilentCicero committed Dec 11, 2016
1 parent 7c73eac commit 828b303
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 11 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# 0.1.5 -- fixed block formatting

1. Spec down enforcement (not value up)
2. Tighter spec enforement
3. More tests on Block data structure
4. Schema update

# 0.1.4 -- removed negative number

1. Remove possibility of negative numbers on chain
Expand Down
8 changes: 5 additions & 3 deletions dist/ethjs-format.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/ethjs-format.js.map

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions dist/ethjs-format.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ethjs-format",
"version": "0.1.4",
"version": "0.1.5",
"description": "A payload formatter for the Ethereum RPC layer.",
"main": "lib/index.js",
"files": [
Expand Down Expand Up @@ -120,7 +120,7 @@
},
"dependencies": {
"bn.js": "4.11.6",
"ethjs-schema": "0.1.3",
"ethjs-schema": "0.1.4",
"strip-hex-prefix": "1.0.0",
"is-hex-prefixed": "1.0.0",
"number-to-bn": "1.4.0",
Expand Down
6 changes: 4 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,10 @@ function formatObject(formatter, value, encode) {
}

// assume formatObject is an object, go through keys and format each
Object.keys(value).forEach((valueKey) => {
output[valueKey] = format(formatObject[valueKey], value[valueKey], encode);
Object.keys(formatObject).forEach((valueKey) => {
if (valueKey !== '__required' && typeof value[valueKey] !== 'undefined') {
output[valueKey] = format(formatObject[valueKey], value[valueKey], encode);
}
});

return output;
Expand Down
17 changes: 17 additions & 0 deletions src/tests/test.index.js
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,24 @@ describe('test ethjs-format object', () => {
assert.equal(encodedObject_5.gas, '0x09184e72a000');
assert.equal(encodedObject_5.gasPrice, '0x14CCFF1D'.toLowerCase());
});
});

describe('test decode of getBlockByNumber', () => {
const payload = JSON.parse('{"author":"0x61c808d82a3ac53231750dadc13c777b59310bd9","difficulty":"0x4cc38f1df101","extraData":"0xe4b883e5bda9e7a59ee4bb99e9b1bc","gasLimit":"0x3d1e65","gasUsed":"0xb238","hash":"0x5d336fc52ebd4c32dec4fd1a82058521f8d43f76e0c47a6540577253fcc5eba4","logsBloom":"0x00000000000000020000000000020000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000202000000000000000000000000000001000000000040000000000400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000001000000000000000000000000000000000","miner":"0x61c808d82a3ac53231750dadc13c777b59310bd9","mixHash":"0xf3bd964ff1ba978efad5538e855b6d76a5e60fd55d556893abf5dcecd5cd339b","nonce":"0x128d840a2e9b7ba2","number":"0x2a91ec","parentHash":"0x31ba04f14e28e0ae36ccb69d440adcf67bead1648e43341186fc86324f76db3a","receiptsRoot":"0xa09bf3f2b0f9d7fb8dc03c6d40d24903c336ce1d06803acc75337a4518e1ba23","sealFields":["0xf3bd964ff1ba978efad5538e855b6d76a5e60fd55d556893abf5dcecd5cd339b","0x128d840a2e9b7ba2"],"sha3Uncles":"0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347","size":"0x2c3","stateRoot":"0xeac15b6137f875f45dade12633005003898c73c6f8b52c024a70a5746c7c093b","timestamp":"0x584d8cfd","totalDifficulty":"0x582c5ac155a130807","transactions":["0xc2c139851af8c356039c717be5741604bc01231968c09db284a6d809a74c67de"],"transactionsRoot":"0x4ef878dcdafa2569903739be44e10ed89548114ad0c8078b6b7619ca4dca12c7","uncles":[]}');

const formattedData = format.formatOutputs('eth_getBlockByHash', payload);

assert.equal(typeof formattedData.receiptsRoot, 'string');
assert.equal(formattedData.miner, '0x61c808d82a3ac53231750dadc13c777b59310bd9');
assert.equal(formattedData.author, '0x61c808d82a3ac53231750dadc13c777b59310bd9');
assert.equal(formattedData.extraData, '0xe4b883e5bda9e7a59ee4bb99e9b1bc');
assert.equal(typeof formattedData.number, 'object');
assert.equal(typeof formattedData.nonce, 'string');
assert.equal(typeof formattedData.gasLimit, 'object');
assert.equal(typeof formattedData.size, 'object');
assert.equal(typeof formattedData.timestamp, 'object');
assert.equal(Array.isArray(formattedData.uncles), true);
assert.equal(formattedData.transactionsRoot, '0x4ef878dcdafa2569903739be44e10ed89548114ad0c8078b6b7619ca4dca12c7');
});

describe('test format', () => {
Expand Down

0 comments on commit 828b303

Please sign in to comment.