Skip to content

Commit

Permalink
interop testing of hashing of empty private call stack item
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed Feb 5, 2024
1 parent 0ff3fa5 commit 2df9501
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 56 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`PrivateCallStackItem computes empty item hash 1`] = `
Fr {
"asBigInt": 2538825319674219123846958071590111740225106671201233263868844578355336664781n,
"asBuffer": {
"data": [
5,
156,
236,
152,
233,
157,
232,
67,
153,
229,
27,
168,
75,
195,
183,
254,
111,
10,
250,
64,
122,
141,
166,
174,
48,
176,
125,
64,
205,
67,
86,
205,
],
"type": "Buffer",
},
}
`;
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,43 @@ import { makePrivateCallStackItem } from '../tests/factories.js';
import { PrivateCallStackItem } from './private_call_stack_item.js';

describe('PrivateCallStackItem', () => {
let inputs: PrivateCallStackItem;
let item: PrivateCallStackItem;

beforeAll(() => {
const randomInt = Math.floor(Math.random() * 1000);
inputs = makePrivateCallStackItem(randomInt);
item = makePrivateCallStackItem(randomInt);
});

it('serializes to buffer and deserializes it back', () => {
const buffer = inputs.toBuffer();
const buffer = item.toBuffer();
const res = PrivateCallStackItem.fromBuffer(buffer);
expect(res).toEqual(inputs);
expect(res).toEqual(item);
});

it('serializes to field array and deserializes it back', () => {
const fieldArray = inputs.toFields();
const fieldArray = item.toFields();
const res = PrivateCallStackItem.fromFields(fieldArray);
expect(res).toEqual(inputs);
expect(res).toEqual(item);
});

it('number of fields matches constant', () => {
const fields = inputs.toFields();
const fields = item.toFields();
expect(fields.length).toBe(PRIVATE_CALL_STACK_ITEM_LENGTH);
});

it('computes hash', () => {
const seed = 9870243;
const PrivateCallStackItem = makePrivateCallStackItem(seed);
const hash = PrivateCallStackItem.hash();
const item = makePrivateCallStackItem(seed);
const hash = item.hash();
expect(hash).toMatchSnapshot();
});

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

// Value used in empty_hash test in private_call_stack_item.nr
// console.log("hash", hash.toString());
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,11 @@ fn serialization_smoke() {
}

#[test]
fn hash_smoke() {
let item: PrivateCallStackItem = dep::std::unsafe::zeroed();
let _hashed = item.hash();
fn empty_hash() {
let mut item: PrivateCallStackItem = dep::std::unsafe::zeroed();
item.function_data.is_private = true;
let hash = item.hash();

// Value from private_call_stack_item.test.ts "computes empty item hash" test
assert_eq(hash, 0x059cec98e99de84399e51ba84bc3b7fe6f0afa407a8da6ae30b07d40cd4356cd);
}

0 comments on commit 2df9501

Please sign in to comment.