Skip to content

Commit

Permalink
test(prover): add test for derive batch id
Browse files Browse the repository at this point in the history
  • Loading branch information
mariocao committed Oct 31, 2024
1 parent bb1cfd0 commit 12b4cf0
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 11 deletions.
36 changes: 35 additions & 1 deletion test/Secp256k1Prover.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -424,8 +424,42 @@ describe('Secp256k1Prover', () => {
await runGasAnalysis(67, 100);
});

it('20 validators', async () => {
it.skip('20 validators', async () => {
await runGasAnalysis(20, 100);
});
});

describe('batch id', () => {
it('should generate the correct batch id for test vectors', async () => {
const testBatch: SedaDataTypes.BatchStruct = {
batchHeight: 4,
blockHeight: 134,
resultsRoot:
'0x49918c4e986fff80aeb3532466132920d2ffd8db2a9615e8d02dd0f02e19503a',
validatorsRoot:
'0xaa13705083effb122a0d9ff3cbb97c2db68caf9dce10572d18979237a1a8d359',
provingMetadata:
'0x0000000000000000000000000000000000000000000000000000000000000000',
};
const expectedBatchId = deriveBatchId(testBatch);
expect(expectedBatchId).to.equal(
'0x9b8a1c156da9096bc89288e9d64df3c897435e962ae7402f0c25c97f3de76e94'
);

// Deploy the SedaDataTypes library first
const DataTypesFactory = await ethers.getContractFactory('SedaDataTypes');
const dataTypes = await DataTypesFactory.deploy();

// Deploy the contract
const ProverFactory = await ethers.getContractFactory('Secp256k1Prover', {
libraries: {
SedaDataTypes: await dataTypes.getAddress(),
},
});
const prover = await ProverFactory.deploy(testBatch);
expect(prover)
.to.emit(prover, 'BatchPosted')
.withArgs(testBatch.batchHeight, expectedBatchId);
});
});
});
17 changes: 7 additions & 10 deletions test/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,13 @@ export function generateNewBatchWithId(

export function deriveBatchId(batch: SedaDataTypes.BatchStruct): string {
return ethers.keccak256(
ethers.AbiCoder.defaultAbiCoder().encode(
['uint256', 'uint256', 'bytes32', 'bytes32', 'bytes32'],
[
batch.batchHeight,
batch.blockHeight,
batch.validatorsRoot,
batch.resultsRoot,
batch.provingMetadata,
]
)
ethers.concat([
padBigIntToBytes(BigInt(batch.batchHeight), 8),
padBigIntToBytes(BigInt(batch.blockHeight), 8),
batch.validatorsRoot,
batch.resultsRoot,
batch.provingMetadata,
])
);
}

Expand Down

0 comments on commit 12b4cf0

Please sign in to comment.