-
Notifications
You must be signed in to change notification settings - Fork 333
/
Copy pathartifact_hash.test.ts
49 lines (41 loc) · 1.66 KB
/
artifact_hash.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { type ContractArtifact } from '@aztec/foundation/abi';
import { loadContractArtifact } from '@aztec/types/abi';
import type { NoirCompiledContract } from '@aztec/types/noir';
import { readFileSync } from 'fs';
import { getPathToFixture, getTestContractArtifact } from '../tests/fixtures.js';
import { computeArtifactHash } from './artifact_hash.js';
describe('ArtifactHash', () => {
it('calculates the artifact hash', () => {
const emptyArtifact: ContractArtifact = {
fileMap: [],
functions: [],
name: 'Test',
outputs: {
globals: {},
structs: {},
},
storageLayout: {},
notes: {},
};
expect(computeArtifactHash(emptyArtifact).toString()).toMatchInlineSnapshot(
`"0x0dea64e7fa0688017f77bcb7075485485afb4a5f1f8508483398869439f82fdf"`,
);
});
it('calculates the test contract artifact hash multiple times to ensure deterministic hashing', () => {
const testArtifact = getTestContractArtifact();
for (let i = 0; i < 1000; i++) {
expect(computeArtifactHash(testArtifact).toString()).toMatchInlineSnapshot(
`"0x21070d88558fdc3906322f267cf6f0f632caf3949295520fe1f71f156fbb0d0b"`,
);
}
});
it('calculates the test contract artifact hash', () => {
const path = getPathToFixture('Test.test.json');
const content = JSON.parse(readFileSync(path).toString()) as NoirCompiledContract;
content.outputs.structs.functions.reverse();
const testArtifact = loadContractArtifact(content);
expect(computeArtifactHash(testArtifact).toString()).toMatchInlineSnapshot(
`"0x21070d88558fdc3906322f267cf6f0f632caf3949295520fe1f71f156fbb0d0b"`,
);
});
});