forked from visoftsolutions/noir_rs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: testing
toFields()
length (AztecProtocol#4364)
Testing results of `toFields()` length against the noir constants.
- Loading branch information
Showing
11 changed files
with
126 additions
and
42 deletions.
There are no files selected for viewing
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
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
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,24 @@ | ||
import { CALL_CONTEXT_LENGTH } from '../constants.gen.js'; | ||
import { makeCallContext } from '../tests/factories.js'; | ||
import { CallContext } from './call_context.js'; | ||
|
||
describe('CallContext', () => { | ||
let callContext: CallContext; | ||
|
||
beforeAll(() => { | ||
const randomInt = Math.floor(Math.random() * 1000); | ||
callContext = makeCallContext(randomInt); | ||
}); | ||
|
||
it(`serializes to buffer and deserializes it back`, () => { | ||
const buffer = callContext.toBuffer(); | ||
const res = CallContext.fromBuffer(buffer); | ||
expect(res).toEqual(callContext); | ||
expect(res.isEmpty()).toBe(false); | ||
}); | ||
|
||
it('number of fields matches constant', () => { | ||
const fields = callContext.toFields(); | ||
expect(fields.length).toBe(CALL_CONTEXT_LENGTH); | ||
}); | ||
}); |
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
26 changes: 17 additions & 9 deletions
26
yarn-project/circuits.js/src/structs/contract_storage_read.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 |
---|---|---|
@@ -1,21 +1,29 @@ | ||
import { CONTRACT_STORAGE_READ_LENGTH } from '../constants.gen.js'; | ||
import { makeContractStorageRead } from '../tests/factories.js'; | ||
import { ContractStorageRead } from './contract_storage_read.js'; | ||
|
||
describe('ContractStorageRead', () => { | ||
it('serializes to buffer and deserializes it back', () => { | ||
let read: ContractStorageRead; | ||
|
||
beforeAll(() => { | ||
const randomInt = Math.floor(Math.random() * 1000); | ||
const expected = makeContractStorageRead(randomInt); | ||
const buffer = expected.toBuffer(); | ||
read = makeContractStorageRead(randomInt); | ||
}); | ||
|
||
it('serializes to buffer and deserializes it back', () => { | ||
const buffer = read.toBuffer(); | ||
const res = ContractStorageRead.fromBuffer(buffer); | ||
expect(res).toEqual(expected); | ||
expect(res).toEqual(read); | ||
}); | ||
|
||
it('serializes to field array and deserializes it back', () => { | ||
const randomInt = Math.floor(Math.random() * 1000); | ||
const expected = makeContractStorageRead(randomInt); | ||
|
||
const fieldArray = expected.toFields(); | ||
const fieldArray = read.toFields(); | ||
const res = ContractStorageRead.fromFields(fieldArray); | ||
expect(res).toEqual(expected); | ||
expect(res).toEqual(read); | ||
}); | ||
|
||
it('number of fields matches constant', () => { | ||
const fields = read.toFields(); | ||
expect(fields.length).toBe(CONTRACT_STORAGE_READ_LENGTH); | ||
}); | ||
}); |
26 changes: 17 additions & 9 deletions
26
yarn-project/circuits.js/src/structs/contract_storage_update_request.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 |
---|---|---|
@@ -1,21 +1,29 @@ | ||
import { CONTRACT_STORAGE_UPDATE_REQUEST_LENGTH } from '../constants.gen.js'; | ||
import { makeContractStorageUpdateRequest } from '../tests/factories.js'; | ||
import { ContractStorageUpdateRequest } from './contract_storage_update_request.js'; | ||
|
||
describe('ContractStorageUpdateRequest', () => { | ||
it('serializes to buffer and deserializes it back', () => { | ||
let request: ContractStorageUpdateRequest; | ||
|
||
beforeAll(() => { | ||
const randomInt = Math.floor(Math.random() * 1000); | ||
const expected = makeContractStorageUpdateRequest(randomInt); | ||
const buffer = expected.toBuffer(); | ||
request = makeContractStorageUpdateRequest(randomInt); | ||
}); | ||
|
||
it('serializes to buffer and deserializes it back', () => { | ||
const buffer = request.toBuffer(); | ||
const res = ContractStorageUpdateRequest.fromBuffer(buffer); | ||
expect(res).toEqual(expected); | ||
expect(res).toEqual(request); | ||
}); | ||
|
||
it('serializes to field array and deserializes it back', () => { | ||
const randomInt = Math.floor(Math.random() * 1000); | ||
const expected = makeContractStorageUpdateRequest(randomInt); | ||
|
||
const fieldArray = expected.toFields(); | ||
const fieldArray = request.toFields(); | ||
const res = ContractStorageUpdateRequest.fromFields(fieldArray); | ||
expect(res).toEqual(expected); | ||
expect(res).toEqual(request); | ||
}); | ||
|
||
it('number of fields matches constant', () => { | ||
const fields = request.toFields(); | ||
expect(fields.length).toBe(CONTRACT_STORAGE_UPDATE_REQUEST_LENGTH); | ||
}); | ||
}); |
17 changes: 14 additions & 3 deletions
17
yarn-project/circuits.js/src/structs/function_data.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 |
---|---|---|
@@ -1,13 +1,24 @@ | ||
import { FunctionSelector } from '@aztec/foundation/abi'; | ||
|
||
import { FUNCTION_DATA_LENGTH } from '../constants.gen.js'; | ||
import { FunctionData } from './function_data.js'; | ||
|
||
describe('FunctionData', () => { | ||
let functionData: FunctionData; | ||
|
||
beforeAll(() => { | ||
functionData = new FunctionData(new FunctionSelector(123), false, true, true); | ||
}); | ||
|
||
it(`serializes to buffer and deserializes it back`, () => { | ||
const expected = new FunctionData(new FunctionSelector(123), false, true, true); | ||
const buffer = expected.toBuffer(); | ||
const buffer = functionData.toBuffer(); | ||
const res = FunctionData.fromBuffer(buffer); | ||
expect(res).toEqual(expected); | ||
expect(res).toEqual(functionData); | ||
expect(res.isEmpty()).toBe(false); | ||
}); | ||
|
||
it('number of fields matches constant', () => { | ||
const fields = functionData.toFields(); | ||
expect(fields.length).toBe(FUNCTION_DATA_LENGTH); | ||
}); | ||
}); |
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
23 changes: 17 additions & 6 deletions
23
yarn-project/circuits.js/src/structs/private_circuit_public_inputs.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 |
---|---|---|
@@ -1,23 +1,34 @@ | ||
import { PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH } from '../constants.gen.js'; | ||
import { makePrivateCircuitPublicInputs } from '../tests/factories.js'; | ||
import { PrivateCircuitPublicInputs } from './private_circuit_public_inputs.js'; | ||
|
||
describe('PrivateCircuitPublicInputs', () => { | ||
let inputs: PrivateCircuitPublicInputs; | ||
|
||
beforeAll(() => { | ||
const randomInt = Math.floor(Math.random() * 1000); | ||
inputs = makePrivateCircuitPublicInputs(randomInt); | ||
}); | ||
|
||
it('serializes to buffer and back', () => { | ||
const target = makePrivateCircuitPublicInputs(100); | ||
const buffer = target.toBuffer(); | ||
const buffer = inputs.toBuffer(); | ||
const result = PrivateCircuitPublicInputs.fromBuffer(buffer); | ||
expect(result).toEqual(target); | ||
expect(result).toEqual(inputs); | ||
}); | ||
|
||
it('serializes to fields and back', () => { | ||
const target = makePrivateCircuitPublicInputs(100); | ||
const fields = target.toFields(); | ||
const fields = inputs.toFields(); | ||
const result = PrivateCircuitPublicInputs.fromFields(fields); | ||
expect(result).toEqual(target); | ||
expect(result).toEqual(inputs); | ||
}); | ||
|
||
it(`initializes an empty PrivateCircuitPublicInputs`, () => { | ||
const target = PrivateCircuitPublicInputs.empty(); | ||
expect(target.isEmpty()).toBe(true); | ||
}); | ||
|
||
it('number of fields matches constant', () => { | ||
const fields = inputs.toFields(); | ||
expect(fields.length).toBe(PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH); | ||
}); | ||
}); |
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
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