Skip to content

Commit

Permalink
interop test header hash
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed Feb 21, 2024
1 parent d8ad2a9 commit 520f2e6
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
use crate::{
abis::{
append_only_tree_snapshot::{AppendOnlyTreeSnapshot, APPEND_ONLY_TREE_SNAPSHOT_LENGTH},
global_variables::{GlobalVariables, GLOBAL_VARIABLES_LENGTH}
},
constants::{GENERATOR_INDEX__BLOCK_HASH, HEADER_LENGTH, NUM_FIELDS_PER_SHA256, STATE_REFERENCE_LENGTH, CONTENT_COMMITMENT_LENGTH},
append_only_tree_snapshot::{AppendOnlyTreeSnapshot, APPEND_ONLY_TREE_SNAPSHOT_LENGTH},
global_variables::{GlobalVariables, GLOBAL_VARIABLES_LENGTH}
},
constants::{
GENERATOR_INDEX__BLOCK_HASH, HEADER_LENGTH, NUM_FIELDS_PER_SHA256, STATE_REFERENCE_LENGTH,
CONTENT_COMMITMENT_LENGTH
},
hash::pedersen_hash, state_reference::StateReference, traits::{Deserialize, Empty, Hash, Serialize},
utils::{arr_copy_slice},
content_commitment::ContentCommitment
utils::{arr_copy_slice}, content_commitment::ContentCommitment
};

// docs:start:header
Expand Down Expand Up @@ -94,3 +96,12 @@ fn hash_smoke() {
let header: Header = dep::std::unsafe::zeroed();
let _hashed = header.hash();
}

#[test]
fn empty_hash_is_zero() {
let header: Header = dep::std::unsafe::zeroed();
let hash = header.hash();

// Value from new_contract_data.test.ts "computes empty hash" test
assert_eq(hash, 0x2df930cc7b9fc763e82ade72f7c4618834692b2a3d0936aff8d7bbfb27f59d6e);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,48 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Header computes empty hash 1`] = `
Fr {
"asBigInt": 20794359902049712309840803989537372971066838126069955186305683313093334375790n,
"asBuffer": {
"data": [
45,
249,
48,
204,
123,
159,
199,
99,
232,
42,
222,
114,
247,
196,
97,
136,
52,
105,
43,
42,
61,
9,
54,
175,
248,
215,
187,
251,
39,
245,
157,
110,
],
"type": "Buffer",
},
}
`;

exports[`Header computes hash 1`] = `
Fr {
"asBigInt": 17965313985247589544372198735324565090920557482351371957268170919526618141863n,
Expand Down
9 changes: 9 additions & 0 deletions yarn-project/circuits.js/src/structs/header.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,13 @@ describe('Header', () => {
const fields = header.toFields();
expect(fields.length).toBe(HEADER_LENGTH);
});

it('computes empty hash', () => {
const header = Header.empty();
const hash = header.hash();
expect(hash).toMatchSnapshot();

// Value used in empty_hash test in header.nr
// console.log("hash", hash.toString());
});
});

0 comments on commit 520f2e6

Please sign in to comment.