Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed May 7, 2024
1 parent 41d19a9 commit c2f5200
Showing 1 changed file with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { PUBLIC_DATA_TREE_HEIGHT, PublicDataTreeLeafPreimage } from '@aztec/circuits.js';
import { fr } from '@aztec/circuits.js/testing';
import { toBufferBE } from '@aztec/foundation/bigint-buffer';
import { randomInt } from '@aztec/foundation/crypto';

import { SiblingPath } from '../sibling_path/sibling_path.js';
import { PublicDataWitness } from './public_data_witness.js';

describe('contract_artifact', () => {
it('serializes and deserializes an instance', () => {
const witness = makePublicDataWitness(randomInt(1000000));

const deserialized = PublicDataWitness.fromBuffer(witness.toBuffer());
expect(deserialized).toEqual(witness);
});
});

/**
* Factory function to create a PublicDataWitness based on given seed.
* @param seed - A seed used to derive all parameters.
* @returns A new instance of PublicDataWitness.
*/
function makePublicDataWitness(seed: number): PublicDataWitness {
const leafPreimage = new PublicDataTreeLeafPreimage(fr(seed + 1), fr(seed + 2), fr(seed + 3), BigInt(seed + 4));
const siblingPath = new SiblingPath(
PUBLIC_DATA_TREE_HEIGHT,
Array.from({ length: PUBLIC_DATA_TREE_HEIGHT }, (_, i) => toBufferBE(BigInt(seed + i + 6), 32)),
);

return new PublicDataWitness(BigInt(seed + 5), leafPreimage, siblingPath);
}

0 comments on commit c2f5200

Please sign in to comment.