Skip to content

Commit

Permalink
block: remove unnecessary fields and adjust types (#2281)
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrocheleau committed Sep 15, 2022
1 parent 6744d6b commit 3f7594a
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 53 deletions.
4 changes: 2 additions & 2 deletions packages/block/test/block.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import * as testDataPreLondon2 from './testdata/testdata_pre-london-2.json'
import * as testDataPreLondon from './testdata/testdata_pre-london.json'
import * as testnetMerge from './testdata/testnetMerge.json'

import type { BlockBuffer, JsonRpcBlock } from '../src'
import type { BlockBuffer } from '../src'
import type { NestedUint8Array } from '@ethereumjs/util'

tape('[Block]: block functions', function (t) {
Expand Down Expand Up @@ -176,7 +176,7 @@ tape('[Block]: block functions', function (t) {
const common = new Common({ chain: Chain.Goerli, hardfork: Hardfork.Chainstart })

try {
blockFromRpc(testDataFromRpcGoerli as unknown as JsonRpcBlock, [], { common })
blockFromRpc(testDataFromRpcGoerli, [], { common })
st.pass('does not throw')
} catch (error: any) {
st.fail('error thrown')
Expand Down
19 changes: 7 additions & 12 deletions packages/block/test/from-rpc.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,20 @@ import * as blockDataWithUncles from './testdata/testdata-from-rpc-with-uncles.j
import * as uncleBlockData from './testdata/testdata-from-rpc-with-uncles_uncle-block-data.json'
import * as blockData from './testdata/testdata-from-rpc.json'

import type { JsonRpcBlock } from '../src/types'
import type { Transaction } from '@ethereumjs/tx'

tape('[fromRPC]: block #2924874', function (t) {
const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Istanbul })

t.test('should create a block with transactions with valid signatures', function (st) {
const block = blockFromRpc(blockData as unknown as JsonRpcBlock, [], { common })
const block = blockFromRpc(blockData, [], { common })
const allValid = block.transactions.every((tx) => tx.verifySignature())
st.equal(allValid, true, 'all transaction signatures are valid')
st.end()
})

t.test('should create a block header with the correct hash', function (st) {
const block = blockHeaderFromRpc(blockData as unknown as JsonRpcBlock, { common })
const block = blockHeaderFromRpc(blockData, { common })
const hash = Buffer.from(blockData.hash.slice(2), 'hex')
st.ok(block.hash().equals(hash))
st.end()
Expand All @@ -46,7 +45,7 @@ tape('[fromRPC]:', function (t) {
const blockDataTransactionValueAsInteger = blockData
blockDataTransactionValueAsInteger.transactions[0].value = valueAsIntegerString
const blockFromTransactionValueAsInteger = blockFromRpc(
blockDataTransactionValueAsInteger as unknown as JsonRpcBlock,
blockDataTransactionValueAsInteger,
undefined,
{ common }
)
Expand All @@ -67,7 +66,7 @@ tape('[fromRPC]:', function (t) {
const blockDataTransactionGasPriceAsInteger = blockData
blockDataTransactionGasPriceAsInteger.transactions[0].gasPrice = gasPriceAsIntegerString
const blockFromTransactionGasPriceAsInteger = blockFromRpc(
blockDataTransactionGasPriceAsInteger as unknown as JsonRpcBlock,
blockDataTransactionGasPriceAsInteger,
undefined,
{ common }
)
Expand All @@ -84,13 +83,9 @@ tape('[fromRPC]:', function (t) {
'should create a block given json data that includes a difficulty parameter of type integer string',
function (st) {
const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.London })
const blockDifficultyAsInteger = blockFromRpc(
blockDataDifficultyAsInteger as unknown as JsonRpcBlock,
undefined,
{
common,
}
)
const blockDifficultyAsInteger = blockFromRpc(blockDataDifficultyAsInteger, undefined, {
common,
})
st.equal(
blockDifficultyAsInteger.header.difficulty.toString(),
blockDataDifficultyAsInteger.difficulty
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"author": "0x4bb96091ee9d802ed039c4d1a5f6216f90f81b01",
"difficulty": "82459156443011",
"extraData": "0x657468706f6f6c202d20555331",
"gasLimit": "0x3d37da",
Expand All @@ -12,10 +11,6 @@
"number": "0x2ca14a",
"parentHash": "0x24f155bdf17217767531f464636fe4b84b87a38c53127541f952b3052adbac95",
"receiptsRoot": "0x0eb6a50257911130ea2fa2e500e71e55e2dfc38eb97f64ca9cfca6faeabd693e",
"sealFields": [
"0xcb3723ab82e84594d0ec9ed5a45fd976d5aba09903826e5ed5e06ae893011eaa",
"0xa76a9a500301e044"
],
"sha3Uncles": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
"size": "0x3d7",
"stateRoot": "0xdf97474b1b492cb6491cff267ca53c33aa42b611ba15239b4027a77275afeffc",
Expand All @@ -25,77 +20,73 @@
{
"blockHash": "0xc596cb892b649b4917da8c6b78611346d55daf7bcf4375da86a2d98810888e84",
"blockNumber": "0x2ca14a",
"creates": null,
"from": "0x41959417325160f8952bc933ae8317b4e5140dda",
"gas": "0x5e1b",
"gasPrice": "0x98bca5a00",
"hash": "0x542e06b2b8beb71305bf1bfd4d2088da9848d8795971d93d5f7893ecceef095b",
"input": "0x",
"nonce": "0x0",
"publicKey": "0x0ddc5f895f174466d0278ed91297d18346632fbcd98d902b4f36c1e3ac0fc2b14e3024c25280415a37ef1dccdb8118ea2232305485c0a87e17417637a972c7bd",
"r": "0x7150d00a9dcd8a8287ad220010c52ff2608906b746de23c993999768091ff210",
"raw": "0xf86c8085098bca5a00825e1b940c7c0b72004a7a66ffa780637427fed0c4faac478844004c09e76a00008025a07150d00a9dcd8a8287ad220010c52ff2608906b746de23c993999768091ff210a05585fabcd1dc415e1668d4cbc2d419cf0381bf9707480ad2f86d0800732f6d7e",
"s": "0x5585fabcd1dc415e1668d4cbc2d419cf0381bf9707480ad2f86d0800732f6d7e",
"to": "0x0c7c0b72004a7a66ffa780637427fed0c4faac47",
"transactionIndex": "0x0",
"v": 0,
"type": "0x0",
"v": "0x1b",
"value": "0x44004c09e76a0000"
},
{
"blockHash": "0xc596cb892b649b4917da8c6b78611346d55daf7bcf4375da86a2d98810888e84",
"blockNumber": "0x2ca14a",
"creates": null,
"from": "0x56ce1399be2831f8a3f918a0408c05bbad658ef3",
"gas": "0x5208",
"gasPrice": "0x4e3b29200",
"hash": "0xe9e15dd4f1070ec30ca4bfbe70738e78b0bb7d126a512e7dc9b22df5b64af791",
"input": "0x",
"nonce": "0x9d",
"publicKey": "0x82a51957d31375120093359ab7beefe9d7d68579d6e40b99d85bff1283a687f8a88c0f3c0a1160f68df814a3bfe7f649a4c16f9b6dbdaf289e6dec93bf083287",
"r": "0x5d92c10b5789801d4ce0fc558eedc6e6cccbaf0105a7c1f909feabcedfe56cd9",
"raw": "0xf86d819d8504e3b2920082520894f4702bb51b8270729db362b0d4f82a56bdd66c6588120a871cc0020000801ba05d92c10b5789801d4ce0fc558eedc6e6cccbaf0105a7c1f909feabcedfe56cd9a072cc370fa5fd3b43c2ba4e9e70fea1b5e950b4261ab4274982d8ae15a3403a33",
"s": "0x72cc370fa5fd3b43c2ba4e9e70fea1b5e950b4261ab4274982d8ae15a3403a33",
"to": "0xf4702bb51b8270729db362b0d4f82a56bdd66c65",
"transactionIndex": "0x1",
"v": 0,
"type": "0x0",
"v": "0x1b",
"value": "0x120a871cc0020000"
},
{
"blockHash": "0xc596cb892b649b4917da8c6b78611346d55daf7bcf4375da86a2d98810888e84",
"blockNumber": "0x2ca14a",
"creates": null,
"from": "0x1e9939daaad6924ad004c2560e90804164900341",
"gas": "0x9858",
"gasPrice": "0x4a817c800",
"hash": "0x3078eeb8227d104338666de260aac59c141a08f519856fd8b7253398d9347f51",
"input": "0x",
"nonce": "0x22f5d",
"publicKey": "0x9fd89da696721cb906af81fe5d8bc3d0a4a7368be52db98d9e3a2d7c5f7aef545e8e578c2a158236d6221512c5df892b23bbe1087966f134799d6e36d3097973",
"r": "0x7ee15b226f6c767ccace78a4b5b4cbf0be6ec20a899e058d3c95977bacd0cbd5",
"raw": "0xf86f83022f5d8504a817c80082985894b8201140a49b0d5b65a23b4b2fa8a6efff87c576880de4ea09ac8f1e888025a07ee15b226f6c767ccace78a4b5b4cbf0be6ec20a899e058d3c95977bacd0cbd5a027e75bcd3bfd199e8c3e3f0c90b0d39f01b773b3da64060e06c0d568ae5c7523",
"s": "0x27e75bcd3bfd199e8c3e3f0c90b0d39f01b773b3da64060e06c0d568ae5c7523",
"to": "0xb8201140a49b0d5b65a23b4b2fa8a6efff87c576",
"transactionIndex": "0x2",
"v": 0,
"type": "0x0",
"v": "0x1b",
"value": "0xde4ea09ac8f1e88"
},
{
"blockHash": "0xc596cb892b649b4917da8c6b78611346d55daf7bcf4375da86a2d98810888e84",
"blockNumber": "0x2ca14a",
"creates": null,
"from": "0xea674fdde714fd979de3edf0f56aa9716b898ec8",
"gas": "0x15f90",
"gasPrice": "0x4a817c800",
"hash": "0x9de43b061e5286ab1ad7494f50fac1ec9b541998800f9388ae6e7119f312c5cd",
"input": "0x",
"nonce": "0xfc02d",
"publicKey": "0x5d8af02c52b1fb40e45d6e04ae2351d443d1f7327e9b6dbb5ae1d918414899c625690c4c236889e23d9705f9db88876542b959d947a3497a30d0d922ee30015f",
"r": "0x059934eeace580cc2bdc292415976692c751f0bcb025930bd40fcc31e91208f3",
"raw": "0xf870830fc02d8504a817c80083015f9094c4f381af25c41786110242623373cc9c7647f3f1880e139507cd50c0188026a0059934eeace580cc2bdc292415976692c751f0bcb025930bd40fcc31e91208f3a077ff34a10a3de0d906a0363b4bdbc0e9a06cb4378476d96dfd446225d8d9949c",
"s": "0x77ff34a10a3de0d906a0363b4bdbc0e9a06cb4378476d96dfd446225d8d9949c",
"to": "0xc4f381af25c41786110242623373cc9c7647f3f1",
"transactionIndex": "0x3",
"v": 1,
"type": "0x0",
"v": "0x1c",
"value": "0xe139507cd50c018"
}
],
Expand Down
2 changes: 2 additions & 0 deletions packages/block/test/testdata/testdata-from-rpc-goerli.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"s": "0x740710eed9696c663510b7fb71a553112551121595a54ec6d2ec0afcec72a973",
"to": "0x7ef66b77759e12caf3ddb3e4aff524e577c59d8d",
"transactionIndex": "0x0",
"type": "0x0",
"v": "0x1c",
"value": "0x0"
},
Expand All @@ -46,6 +47,7 @@
"s": "0x51b156e05f21f499fa1ae47ebf536b15a237208f1d4a62e33956b6b03cf47742",
"to": "0x7ef66b77759e12caf3ddb3e4aff524e577c59d8d",
"transactionIndex": "0x1",
"type": "0x0",
"v": "0x1b",
"value": "0x0"
}
Expand Down
31 changes: 9 additions & 22 deletions packages/block/test/testdata/testdata-from-rpc.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"author": "0x4bb96091ee9d802ed039c4d1a5f6216f90f81b01",
"difficulty": "0x4aff04ba6f83",
"extraData": "0x657468706f6f6c202d20555331",
"gasLimit": "0x3d37da",
Expand All @@ -12,10 +11,6 @@
"number": "0x2ca14a",
"parentHash": "0x24f155bdf17217767531f464636fe4b84b87a38c53127541f952b3052adbac95",
"receiptsRoot": "0x0eb6a50257911130ea2fa2e500e71e55e2dfc38eb97f64ca9cfca6faeabd693e",
"sealFields": [
"0xcb3723ab82e84594d0ec9ed5a45fd976d5aba09903826e5ed5e06ae893011eaa",
"0xa76a9a500301e044"
],
"sha3Uncles": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
"size": "0x3d7",
"stateRoot": "0xdf97474b1b492cb6491cff267ca53c33aa42b611ba15239b4027a77275afeffc",
Expand All @@ -25,77 +20,69 @@
{
"blockHash": "0xc596cb892b649b4917da8c6b78611346d55daf7bcf4375da86a2d98810888e84",
"blockNumber": "0x2ca14a",
"creates": null,
"from": "0x41959417325160f8952bc933ae8317b4e5140dda",
"gas": "0x5e1b",
"gasPrice": "0x98bca5a00",
"hash": "0x542e06b2b8beb71305bf1bfd4d2088da9848d8795971d93d5f7893ecceef095b",
"input": "0x",
"nonce": "0x0",
"publicKey": "0x0ddc5f895f174466d0278ed91297d18346632fbcd98d902b4f36c1e3ac0fc2b14e3024c25280415a37ef1dccdb8118ea2232305485c0a87e17417637a972c7bd",
"r": "0x7150d00a9dcd8a8287ad220010c52ff2608906b746de23c993999768091ff210",
"raw": "0xf86c8085098bca5a00825e1b940c7c0b72004a7a66ffa780637427fed0c4faac478844004c09e76a00008025a07150d00a9dcd8a8287ad220010c52ff2608906b746de23c993999768091ff210a05585fabcd1dc415e1668d4cbc2d419cf0381bf9707480ad2f86d0800732f6d7e",
"s": "0x5585fabcd1dc415e1668d4cbc2d419cf0381bf9707480ad2f86d0800732f6d7e",
"to": "0x0c7c0b72004a7a66ffa780637427fed0c4faac47",
"transactionIndex": "0x0",
"v": 0,
"type": "0x0",
"v": "0x25",
"value": "0x44004c09e76a0000"
},
{
"blockHash": "0xc596cb892b649b4917da8c6b78611346d55daf7bcf4375da86a2d98810888e84",
"blockNumber": "0x2ca14a",
"creates": null,
"from": "0x56ce1399be2831f8a3f918a0408c05bbad658ef3",
"gas": "0x5208",
"gasPrice": "0x4e3b29200",
"hash": "0xe9e15dd4f1070ec30ca4bfbe70738e78b0bb7d126a512e7dc9b22df5b64af791",
"input": "0x",
"nonce": "0x9d",
"publicKey": "0x82a51957d31375120093359ab7beefe9d7d68579d6e40b99d85bff1283a687f8a88c0f3c0a1160f68df814a3bfe7f649a4c16f9b6dbdaf289e6dec93bf083287",
"r": "0x5d92c10b5789801d4ce0fc558eedc6e6cccbaf0105a7c1f909feabcedfe56cd9",
"raw": "0xf86d819d8504e3b2920082520894f4702bb51b8270729db362b0d4f82a56bdd66c6588120a871cc0020000801ba05d92c10b5789801d4ce0fc558eedc6e6cccbaf0105a7c1f909feabcedfe56cd9a072cc370fa5fd3b43c2ba4e9e70fea1b5e950b4261ab4274982d8ae15a3403a33",
"s": "0x72cc370fa5fd3b43c2ba4e9e70fea1b5e950b4261ab4274982d8ae15a3403a33",
"to": "0xf4702bb51b8270729db362b0d4f82a56bdd66c65",
"transactionIndex": "0x1",
"v": 0,
"type": "0x0",
"v": "0x1b",
"value": "0x120a871cc0020000"
},
{
"blockHash": "0xc596cb892b649b4917da8c6b78611346d55daf7bcf4375da86a2d98810888e84",
"blockNumber": "0x2ca14a",
"creates": null,
"from": "0x1e9939daaad6924ad004c2560e90804164900341",
"gas": "0x9858",
"gasPrice": "0x4a817c800",
"hash": "0x3078eeb8227d104338666de260aac59c141a08f519856fd8b7253398d9347f51",
"input": "0x",
"nonce": "0x22f5d",
"publicKey": "0x9fd89da696721cb906af81fe5d8bc3d0a4a7368be52db98d9e3a2d7c5f7aef545e8e578c2a158236d6221512c5df892b23bbe1087966f134799d6e36d3097973",
"r": "0x7ee15b226f6c767ccace78a4b5b4cbf0be6ec20a899e058d3c95977bacd0cbd5",
"raw": "0xf86f83022f5d8504a817c80082985894b8201140a49b0d5b65a23b4b2fa8a6efff87c576880de4ea09ac8f1e888025a07ee15b226f6c767ccace78a4b5b4cbf0be6ec20a899e058d3c95977bacd0cbd5a027e75bcd3bfd199e8c3e3f0c90b0d39f01b773b3da64060e06c0d568ae5c7523",
"s": "0x27e75bcd3bfd199e8c3e3f0c90b0d39f01b773b3da64060e06c0d568ae5c7523",
"to": "0xb8201140a49b0d5b65a23b4b2fa8a6efff87c576",
"transactionIndex": "0x2",
"v": 0,
"type": "0x0",
"v": "0x25",
"value": "0xde4ea09ac8f1e88"
},
{
"blockHash": "0xc596cb892b649b4917da8c6b78611346d55daf7bcf4375da86a2d98810888e84",
"blockNumber": "0x2ca14a",
"creates": null,
"from": "0xea674fdde714fd979de3edf0f56aa9716b898ec8",
"gas": "0x15f90",
"gasPrice": "0x4a817c800",
"hash": "0x9de43b061e5286ab1ad7494f50fac1ec9b541998800f9388ae6e7119f312c5cd",
"input": "0x",
"nonce": "0xfc02d",
"publicKey": "0x5d8af02c52b1fb40e45d6e04ae2351d443d1f7327e9b6dbb5ae1d918414899c625690c4c236889e23d9705f9db88876542b959d947a3497a30d0d922ee30015f",
"r": "0x059934eeace580cc2bdc292415976692c751f0bcb025930bd40fcc31e91208f3",
"raw": "0xf870830fc02d8504a817c80083015f9094c4f381af25c41786110242623373cc9c7647f3f1880e139507cd50c0188026a0059934eeace580cc2bdc292415976692c751f0bcb025930bd40fcc31e91208f3a077ff34a10a3de0d906a0363b4bdbc0e9a06cb4378476d96dfd446225d8d9949c",
"r": "0x59934eeace580cc2bdc292415976692c751f0bcb025930bd40fcc31e91208f3",
"s": "0x77ff34a10a3de0d906a0363b4bdbc0e9a06cb4378476d96dfd446225d8d9949c",
"to": "0xc4f381af25c41786110242623373cc9c7647f3f1",
"transactionIndex": "0x3",
"v": 1,
"type": "0x0",
"v": "0x26",
"value": "0xe139507cd50c018"
}
],
Expand Down

0 comments on commit 3f7594a

Please sign in to comment.