Skip to content

Commit

Permalink
client -> execution refactor: added test fixture for blockchain creat…
Browse files Browse the repository at this point in the history
…ion, reactivated VM execution test
  • Loading branch information
holgerd77 committed Jan 25, 2021
1 parent d8136d1 commit a3c32cc
Show file tree
Hide file tree
Showing 2 changed files with 166 additions and 36 deletions.
59 changes: 23 additions & 36 deletions packages/client/test/sync/execution/vmexecution.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import tape from 'tape-catch'
import td from 'testdouble'
//import { BN } from 'ethereumjs-util'
import VM from '@ethereumjs/vm'
import Blockchain from '@ethereumjs/blockchain'
import { Config } from '../../../lib/config'
import { Chain } from '../../../lib/blockchain'
import { VMExecution } from '../../../lib/sync/execution/vmexecution'
import blocksData from './../../testdata/blocks_mainnet.json'

tape('[FullSynchronizer]', async (t) => {
tape('[VMExecution]', async (t) => {
t.test('should initialize with VM provided by config', async (t) => {
const vm = new VM()
const config = new Config({ vm, loglevel: 'error', transports: [] })
Expand All @@ -20,50 +19,38 @@ tape('[FullSynchronizer]', async (t) => {
t.end()
})

t.test('should run blocks', async (t) => {
function initWithBlockchain(blockchain: Blockchain) {
const vm = new VM()
vm.runBlockchain = td.func<any>()
//vm.runBlockchain = td.func<any>()
const config = new Config({ vm, loglevel: 'error', transports: [] })
const blockchain = new Blockchain() as any
const chain = new Chain({ config, blockchain })
const exec = new VMExecution({
config,
chain,
})
exec.syncing = true
return exec
}

t.test('should run blocks', async (t) => {
let blockchain = new Blockchain({
validateBlocks: true,
validateConsensus: false,
})
let exec = initWithBlockchain(blockchain)
const oldHead = await exec.vm.blockchain.getHead()
await exec.runBlocks()
t.deepEqual(
(await exec.vm.blockchain.getHead()).hash(),
oldHead.hash(),
'should not modify blockchain on emtpy run'
)
let newHead = await exec.vm.blockchain.getHead()
t.deepEqual(newHead.hash(), oldHead.hash(), 'should not modify blockchain on emtpy run')

//TODO: replace with testdata blockchain tests, mocking not feasible on
// block execution getting more complex
/*blockchain.getHead = td.func<any>()
const getHeadResponse: any = []
for (let i = 2; i <= 100; i++) {
getHeadResponse.push({
hash: () => {
return Buffer.from(`hash${i}`)
},
header: { number: new BN(i) },
transactions: [i],
})
}
td.when(blockchain.getHead()).thenResolve(
{
hash: () => {
return Buffer.from('hash0')
},
header: { number: new BN(1) },
transactions: [],
},
...getHeadResponse
)
t.equal(await exec.runBlocks(), 49)*/
blockchain = await Blockchain.fromBlocksData(blocksData, {
validateBlocks: true,
validateConsensus: false,
})
exec = initWithBlockchain(blockchain)
await exec.runBlocks()
newHead = await exec.vm.blockchain.getHead()
t.deepEqual(newHead.header.number.toNumber(), 5, 'should run all blocks from testfile')

t.end()
})
Expand Down
143 changes: 143 additions & 0 deletions packages/client/test/testdata/blocks_mainnet.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
[
{
"header": {
"parentHash": "0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3",
"uncleHash": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
"coinbase": "0x05a56e2d52c817161883f50c441c3228cfe54d9f",
"stateRoot": "0xd67e4d450343046425ae4271474353857ab860dbc0a1dde64b41b5cd3a532bf3",
"transactionsTrie": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
"receiptTrie": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
"bloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"difficulty": "0x3ff800000",
"number": "0x1",
"gasLimit": "0x1388",
"gasUsed": "0x0",
"timestamp": "0x55ba4224",
"extraData": "0x476574682f76312e302e302f6c696e75782f676f312e342e32",
"mixHash": "0x969b900de27b6ac6a67742365dd65f55a0526c41fd18e1b16f1a1215c2e66f59",
"nonce": "0x539bd4979fef1ec4"
},
"transactions": [],
"uncleHeaders": []
},
{
"header": {
"parentHash": "0x88e96d4537bea4d9c05d12549907b32561d3bf31f45aae734cdc119f13406cb6",
"uncleHash": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
"coinbase": "0xdd2f1e6e498202e86d8f5442af596580a4f03c2c",
"stateRoot": "0x4943d941637411107494da9ec8bc04359d731bfd08b72b4d0edcbd4cd2ecb341",
"transactionsTrie": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
"receiptTrie": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
"bloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"difficulty": "0x3ff001000",
"number": "0x2",
"gasLimit": "0x1388",
"gasUsed": "0x0",
"timestamp": "0x55ba4241",
"extraData": "0x476574682f76312e302e302d30636463373634372f6c696e75782f676f312e34",
"mixHash": "0x2f0790c5aa31ab94195e1f6443d645af5b75c46c04fbf9911711198a0ce8fdda",
"nonce": "0xb853fa261a86aa9e"
},
"transactions": [],
"uncleHeaders": []
},
{
"header": {
"parentHash": "0xb495a1d7e6663152ae92708da4843337b958146015a2802f4193a410044698c9",
"uncleHash": "0x6b17b938c6e4ef18b26ad81b9ca3515f27fd9c4e82aac56a1fd8eab288785e41",
"coinbase": "0x5088d623ba0fcf0131e0897a91734a4d83596aa0",
"stateRoot": "0x76ab0b899e8387436ff2658e2988f83cbf1af1590b9fe9feca3714f8d1824940",
"transactionsTrie": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
"receiptTrie": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
"bloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"difficulty": "0x3fe802ffe",
"number": "0x3",
"gasLimit": "0x1388",
"gasUsed": "0x0",
"timestamp": "0x55ba4260",
"extraData": "0x476574682f76312e302e302d66633739643332642f6c696e75782f676f312e34",
"mixHash": "0x65e12eec23fe6555e6bcdb47aa25269ae106e5f16b54e1e92dcee25e1c8ad037",
"nonce": "0x2e9344e0cbde83ce"
},
"transactions": [],
"uncleHeaders": [
{
"parentHash": "0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3",
"uncleHash": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
"coinbase": "0xc8ebccc5f5689fa8659d83713341e5ad19349448",
"stateRoot": "0x1e6e030581fd1873b4784280859cd3b3c04aa85520f08c304cf5ee63d3935add",
"transactionsTrie": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
"receiptTrie": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
"bloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"difficulty": "0x3ff800000",
"number": "0x1",
"gasLimit": "0x1388",
"gasUsed": "0x0",
"timestamp": "0x55ba4242",
"extraData": "0x59617465732052616e64616c6c202d2045746865724e696e6a61",
"mixHash": "0xf8c94dfe61cf26dcdf8cffeda337cf6a903d65c449d7691a022837f6e2d99459",
"nonce": "0x68b769c5451a7aea"
}
]
},
{
"header": {
"parentHash": "0x3d6122660cc824376f11ee842f83addc3525e2dd6756b9bcf0affa6aa88cf741",
"uncleHash": "0x83a8da8965660cb6bdf0c37f1b111778e49753c4213bf7c3e280fccfde89f2b5",
"coinbase": "0xc8ebccc5f5689fa8659d83713341e5ad19349448",
"stateRoot": "0xe6d9f6e95a05ee69719c718c6157d0759049ef3dffdba2d48f015d7c8b9933d8",
"transactionsTrie": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
"receiptTrie": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
"bloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"difficulty": "0x3fe005ff9",
"number": "0x4",
"gasLimit": "0x1388",
"gasUsed": "0x0",
"timestamp": "0x55ba427d",
"extraData": "0x59617465732052616e64616c6c202d2045746865724e696e6a61",
"mixHash": "0x06ba40902198357cbeac24a86b2ef11e9fdff48d28a421a0055e26476e3ac59f",
"nonce": "0xc2535b5efca9bee0"
},
"transactions": [],
"uncleHeaders": [
{
"parentHash": "0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3",
"uncleHash": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
"coinbase": "0x5088d623ba0fcf0131e0897a91734a4d83596aa0",
"stateRoot": "0x9a6597b26adc0e5915cfcca537ba493a647cad1c3c923d406cdec6ca49a0a06d",
"transactionsTrie": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
"receiptTrie": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
"bloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"difficulty": "0x3ff800000",
"number": "0x1",
"gasLimit": "0x1388",
"gasUsed": "0x0",
"timestamp": "0x55ba4237",
"extraData": "0x476574682f76312e302e302d66633739643332642f6c696e75782f676f312e34",
"mixHash": "0xd045b852770160da169ec793ec0c6e6ff562e473b2bf3f8192dc59842e36f754",
"nonce": "0xdb821a775bf9dace"
}
]
},
{
"header": {
"parentHash": "0x23adf5a3be0f5235b36941bcb29b62504278ec5b9cdfa277b992ba4a7a3cd3a2",
"uncleHash": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
"coinbase": "0x05a56e2d52c817161883f50c441c3228cfe54d9f",
"stateRoot": "0x4470f3dc1cc8097394a4ae85302eac3368462b3c1cfa523ffca942c1dd478220",
"transactionsTrie": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
"receiptTrie": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
"bloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"difficulty": "0x3fe802004",
"number": "0x5",
"gasLimit": "0x1388",
"gasUsed": "0x0",
"timestamp": "0x55ba4283",
"extraData": "0x476574682f76312e302e302f6c696e75782f676f312e342e32",
"mixHash": "0x17b85b5ec310c4868249fa2f378c83b4f330e2d897e5373a8195946c71d1d19e",
"nonce": "0xfba9d0cff9dc5cf3"
},
"transactions": [],
"uncleHeaders": []
}
]

0 comments on commit a3c32cc

Please sign in to comment.