Skip to content

Commit

Permalink
test: integration test of body publishing (#4795)
Browse files Browse the repository at this point in the history
When working on updating the tx effects encoding I stumbled upon a need
to add a test case which checks whether the txs hash emitted when
publishing a body matches the one computed in TS. This PR adds it.
  • Loading branch information
benesjan authored Feb 27, 2024
1 parent 0c99de7 commit e414846
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -281,14 +281,12 @@ describe('e2e_public_cross_chain_messaging', () => {
// for later use
let msgKey!: Fr;
{
const abiItem = getAbiItem({
abi: InboxAbi,
name: 'MessageAdded',
});

const events = await crossChainTestHarness.publicClient.getLogs<typeof abiItem>({
const events = await crossChainTestHarness.publicClient.getLogs({
address: getAddress(inbox.address.toString()),
event: abiItem,
event: getAbiItem({
abi: InboxAbi,
name: 'MessageAdded',
}),
fromBlock: 0n,
});

Expand Down
28 changes: 27 additions & 1 deletion yarn-project/end-to-end/src/integration_l1_publisher.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import {
import { createEthereumChain } from '@aztec/ethereum';
import { makeTuple, range } from '@aztec/foundation/array';
import { openTmpStore } from '@aztec/kv-store/utils';
import { InboxAbi, OutboxAbi, RollupAbi } from '@aztec/l1-artifacts';
import { AvailabilityOracleAbi, InboxAbi, OutboxAbi, RollupAbi } from '@aztec/l1-artifacts';
import {
EmptyRollupProver,
L1Publisher,
Expand Down Expand Up @@ -77,6 +77,7 @@ describe('L1Publisher integration', () => {
let publicClient: PublicClient<HttpTransport, Chain>;
let deployerAccount: PrivateKeyAccount;

let availabilityOracleAddress: Address;
let rollupAddress: Address;
let inboxAddress: Address;
let outboxAddress: Address;
Expand Down Expand Up @@ -111,6 +112,7 @@ describe('L1Publisher integration', () => {
} = await setupL1Contracts(config.rpcUrl, deployerAccount, logger);
publicClient = publicClient_;

availabilityOracleAddress = getAddress(l1ContractAddresses.availabilityOracleAddress.toString());
rollupAddress = getAddress(l1ContractAddresses.rollupAddress.toString());
inboxAddress = getAddress(l1ContractAddresses.inboxAddress.toString());
outboxAddress = getAddress(l1ContractAddresses.outboxAddress.toString());
Expand Down Expand Up @@ -322,6 +324,30 @@ describe('L1Publisher integration', () => {
fs.writeFileSync(path, output, 'utf8');
};

it('Block body is correctly published to AvailabilityOracle', async () => {
const body = L2Block.random(4).body;
// `sendPublishTx` function is private so I am hacking around TS here. I think it's ok for test purposes.
const txHash = await (publisher as any).sendPublishTx(body.toBuffer());

// We verify that the body was successfully published by fetching TxsPublished events from the AvailabilityOracle
// and checking if the txsHash in the event is as expected
const events = await publicClient.getLogs({
address: availabilityOracleAddress,
event: getAbiItem({
abi: AvailabilityOracleAbi,
name: 'TxsPublished',
}),
fromBlock: 0n,
});

// We get the event just for the relevant transaction
const txEvents = events.filter(event => event.transactionHash === txHash);

// We check that exactly 1 TxsPublished event was emitted and txsHash is as expected
expect(txEvents.length).toBe(1);
expect(txEvents[0].args.txsHash).toEqual(`0x${body.getCalldataHash().toString('hex')}`);
});

it(`Build ${numberOfConsecutiveBlocks} blocks of 4 bloated txs building on each other`, async () => {
const archiveInRollup_ = await rollup.read.archive();
expect(hexStringToBuffer(archiveInRollup_.toString())).toEqual(Buffer.alloc(32, 0));
Expand Down

0 comments on commit e414846

Please sign in to comment.