Skip to content

Commit

Permalink
chore: Nicer snapshots (#5133)
Browse files Browse the repository at this point in the history
Adds a function to register custom snapshot serializer for well-known
Aztec basic types (AztecAddress, Fields, etc) as well as Buffers. This
needs to be called explicitly on each test file. Alternatively, we could
[load it as part of the jest
config](https://jestjs.io/docs/configuration#snapshotserializers-arraystring),
but I preferred to be explicit in the dependency and avoid pointing
directly to a file in a different package.
  • Loading branch information
spalladino authored Mar 11, 2024
1 parent b2d7d14 commit 9a737eb
Show file tree
Hide file tree
Showing 39 changed files with 1,461 additions and 55,061 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,131 +6,8 @@ exports[`ContractAddress Public key hash matches Noir 1`] = `"0x1923a6246e305720

exports[`ContractAddress computeContractAddressFromInstance 1`] = `"0x2fd71a4f0742364f194dd16d0ae32d2f47845ddc7f5d328f37d4148b565c4123"`;

exports[`ContractAddress computeInitializationHash 1`] = `
Fr {
"asBigInt": 11287307308183188516369033835241775664908452274022428157981236923904607656063n,
"asBuffer": {
"data": [
24,
244,
99,
184,
236,
16,
42,
8,
156,
101,
39,
106,
125,
199,
236,
87,
43,
9,
28,
163,
148,
181,
224,
108,
3,
191,
211,
120,
203,
68,
24,
127,
],
"type": "Buffer",
},
}
`;
exports[`ContractAddress computeInitializationHash 1`] = `Fr<0x18f463b8ec102a089c65276a7dc7ec572b091ca394b5e06c03bfd378cb44187f>`;

exports[`ContractAddress computePartialAddress 1`] = `
Fr {
"asBigInt": 11370807533904788559065519582196668367978392224620203970943957018221100220632n,
"asBuffer": {
"data": [
25,
35,
166,
36,
110,
48,
87,
32,
182,
170,
247,
81,
253,
224,
52,
38,
19,
233,
60,
130,
228,
85,
195,
131,
30,
40,
55,
92,
22,
221,
64,
216,
],
"type": "Buffer",
},
}
`;
exports[`ContractAddress computePartialAddress 1`] = `Fr<0x1923a6246e305720b6aaf751fde0342613e93c82e455c3831e28375c16dd40d8>`;

exports[`ContractAddress computeSaltedInitializationHash 1`] = `
Fr {
"asBigInt": 11725758444245911667025964940014811412794639055001970719147766917493953867026n,
"asBuffer": {
"data": [
25,
236,
139,
73,
109,
192,
136,
17,
189,
50,
237,
56,
134,
9,
56,
184,
97,
39,
147,
221,
79,
57,
195,
179,
116,
155,
140,
213,
210,
243,
45,
18,
],
"type": "Buffer",
},
}
`;
exports[`ContractAddress computeSaltedInitializationHash 1`] = `Fr<0x19ec8b496dc08811bd32ed38860938b8612793dd4f39c3b3749b8cd5d2f32d12>`;
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ABIParameterVisibility, FunctionAbi, FunctionType } from '@aztec/foundation/abi';
import { Fr, Point } from '@aztec/foundation/fields';
import { setupCustomSnapshotSerializers } from '@aztec/foundation/testing';

import { EthAddress } from '../index.js';
import {
Expand All @@ -12,6 +13,7 @@ import {
} from './contract_address.js';

describe('ContractAddress', () => {
setupCustomSnapshotSerializers(expect);
it('computePartialAddress', () => {
const mockInstance = {
contractClassId: new Fr(1),
Expand Down
2 changes: 2 additions & 0 deletions yarn-project/circuits.js/src/contract/contract_class.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { Fr } from '@aztec/foundation/fields';
import { toFriendlyJSON } from '@aztec/foundation/serialize';
import { setupCustomSnapshotSerializers } from '@aztec/foundation/testing';

import { getSampleContractArtifact } from '../tests/fixtures.js';
import { getContractClassFromArtifact } from './contract_class.js';

describe('ContractClass', () => {
setupCustomSnapshotSerializers(expect);
it('creates a contract class from a contract compilation artifact', () => {
const contractClass = getContractClassFromArtifact({
...getSampleContractArtifact(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { Fr } from '@aztec/foundation/fields';
import { setupCustomSnapshotSerializers } from '@aztec/foundation/testing';
import { PrivateFunction } from '@aztec/types/contracts';

import { fr, makeSelector } from '../tests/factories.js';
import { computePrivateFunctionsRoot, computePrivateFunctionsTree } from './private_function.js';

describe('PrivateFunction', () => {
setupCustomSnapshotSerializers(expect);
const privateFunctions: PrivateFunction[] = [
{ selector: makeSelector(1), vkHash: fr(2), isInternal: false },
{ selector: makeSelector(3), vkHash: fr(4), isInternal: false },
Expand Down
Loading

0 comments on commit 9a737eb

Please sign in to comment.