Skip to content

Commit

Permalink
enhance spec
Browse files Browse the repository at this point in the history
  • Loading branch information
g11tech committed Apr 26, 2023
1 parent bde9ded commit 5e9d779
Showing 1 changed file with 38 additions and 14 deletions.
52 changes: 38 additions & 14 deletions packages/client/test/miner/pendingBlock.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Block, BlockHeader } from '@ethereumjs/block'
import { Common, Chain as CommonChain, Hardfork } from '@ethereumjs/common'
import { BlobEIP4844Transaction, Transaction } from '@ethereumjs/tx'
import { BlobEIP4844Transaction, FeeMarketEIP1559Transaction, Transaction } from '@ethereumjs/tx'
import {
Account,
Address,
Expand Down Expand Up @@ -275,42 +275,66 @@ tape('[PendingBlock]', async (t) => {
hardfork: Hardfork.Cancun,
})
const { txPool } = setup()

const blobs = getBlobs('hello world')
const commitments = blobsToCommitments(blobs)
const versionedHashes = commitmentsToVersionedHashes(commitments)
const proofs = blobsToProofs(blobs, commitments)

const txA01 = BlobEIP4844Transaction.fromTxData(
// Create 3 txs with 2 blobs each so that only 2 of them can be included in a build
for (let x = 0; x <= 2; x++) {
const txA01 = BlobEIP4844Transaction.fromTxData(
{
versionedHashes,
blobs: [...blobs, ...blobs],
kzgCommitments: [...commitments, ...commitments],
kzgProofs: [...proofs, ...proofs],
maxFeePerDataGas: 100000000n,
gasLimit: 0xffffffn,
maxFeePerGas: 1000000000n,
maxPriorityFeePerGas: 100000000n,
to: randomBytes(20),
nonce: BigInt(x),
},
{ common }
).sign(A.privateKey)
await txPool.add(txA01)
}

// Add one other normal tx for nonce 3 which should also be not included in the build
const txNorm = FeeMarketEIP1559Transaction.fromTxData(
{
versionedHashes,
blobs,
kzgCommitments: commitments,
kzgProofs: proofs,
maxFeePerDataGas: 100000000n,
gasLimit: 0xffffffn,
maxFeePerGas: 1000000000n,
maxPriorityFeePerGas: 100000000n,
to: randomBytes(20),
nonce: BigInt(3),
},
{ common }
).sign(A.privateKey)
await txPool.add(txA01)
await txPool.add(txNorm)
st.equal(txPool.txsInPool, 4, '4 txs should still be in the pool')

const pendingBlock = new PendingBlock({ config, txPool })
const vm = await VM.create({ common })
await setBalance(vm, A.address, BigInt(5000000000000000))
await setBalance(vm, A.address, BigInt(500000000000000000))
const parentBlock = await vm.blockchain.getCanonicalHeadBlock!()
// stub the vm's common set hf to do nothing but stay in cancun
vm._common.setHardforkByBlockNumber = (_a: bigint, _b?: bigint, _c?: bigint) => {
return vm._common.hardfork()
}
const payloadId = await pendingBlock.start(vm, parentBlock)
await pendingBlock.build(payloadId)
const [block, _receipts, _value, blobsBundles] = (await pendingBlock.build(payloadId)) ?? []

st.ok(block !== undefined && blobsBundles !== undefined)
st.equal(block!.transactions.length, 2, 'Only two blob txs should be included')
st.equal(blobsBundles!.blobs.length, 4, 'maximum 4 blobs should be included')
st.equal(blobsBundles!.commitments.length, 4, 'maximum 4 commitments should be included')
st.equal(blobsBundles!.proofs.length, 4, 'maximum 4 proofs should be included')

const blobsBundles = pendingBlock.blobsBundles.get(bytesToPrefixedHexString(payloadId))!
st.ok(blobsBundles !== undefined)
const pendingBlob = blobsBundles.blobs[0]
const pendingBlob = blobsBundles!.blobs[0]
st.ok(pendingBlob !== undefined && equalsBytes(pendingBlob, blobs[0]))
const blobProof = blobsBundles.proofs[0]
const blobProof = blobsBundles!.proofs[0]
st.ok(blobProof !== undefined && equalsBytes(blobProof, proofs[0]))
st.end()
})
Expand Down

0 comments on commit 5e9d779

Please sign in to comment.