-
Notifications
You must be signed in to change notification settings - Fork 304
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
31 additions
and
0 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
yarn-project/circuit-types/src/interfaces/public_data_witness.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |