From 6394d4669a88a78acf2b7779fc4f4d44e25052b7 Mon Sep 17 00:00:00 2001 From: benesjan Date: Thu, 1 Feb 2024 15:14:51 +0000 Subject: [PATCH] test: testing toFields length --- .../structs/contract_deployment_data.test.ts | 10 +++++++++- .../src/structs/function_data.test.ts | 17 ++++++++++++++--- .../public_circuit_public_inputs.test.ts | 7 +++++++ 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/yarn-project/circuits.js/src/structs/contract_deployment_data.test.ts b/yarn-project/circuits.js/src/structs/contract_deployment_data.test.ts index 40fa0173a03e..387f29ff70b6 100644 --- a/yarn-project/circuits.js/src/structs/contract_deployment_data.test.ts +++ b/yarn-project/circuits.js/src/structs/contract_deployment_data.test.ts @@ -1,6 +1,8 @@ +import { CONTRACT_DEPLOYMENT_DATA_LENGTH } from '../constants.gen.js'; import { makeContractDeploymentData } from '../tests/factories.js'; import { ContractDeploymentData } from './contract_deployment_data.js'; + describe('ContractDeploymentData', () => { it(`serializes to buffer and deserializes it back`, () => { const expected = makeContractDeploymentData(1); @@ -14,4 +16,10 @@ describe('ContractDeploymentData', () => { const target = ContractDeploymentData.empty(); expect(target.isEmpty()).toBe(true); }); -}); + + it('number of fields matches constant', () => { + const target = makeContractDeploymentData(327); + const fields = target.toFields(); + expect(fields.length).toBe(CONTRACT_DEPLOYMENT_DATA_LENGTH); + }); +}); \ No newline at end of file diff --git a/yarn-project/circuits.js/src/structs/function_data.test.ts b/yarn-project/circuits.js/src/structs/function_data.test.ts index 269198d6ef7d..4a953ccdb0c4 100644 --- a/yarn-project/circuits.js/src/structs/function_data.test.ts +++ b/yarn-project/circuits.js/src/structs/function_data.test.ts @@ -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); + }); }); diff --git a/yarn-project/circuits.js/src/structs/public_circuit_public_inputs.test.ts b/yarn-project/circuits.js/src/structs/public_circuit_public_inputs.test.ts index 7fb1145ea634..0471473221a3 100644 --- a/yarn-project/circuits.js/src/structs/public_circuit_public_inputs.test.ts +++ b/yarn-project/circuits.js/src/structs/public_circuit_public_inputs.test.ts @@ -1,3 +1,4 @@ +import { PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH } from '../constants.gen.js'; import { makePublicCircuitPublicInputs } from '../tests/factories.js'; import { PublicCircuitPublicInputs } from './public_circuit_public_inputs.js'; @@ -15,4 +16,10 @@ describe('PublicCircuitPublicInputs', () => { const target = PublicCircuitPublicInputs.empty(); expect(target.isEmpty()).toBe(true); }); + + it("number of fields matches constant", () => { + const target = makePublicCircuitPublicInputs(327); + const fields = target.toFields(); + expect(fields.length).toBe(PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH); + }); });