Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 104 additions & 0 deletions yarn-project/noir-private-kernel/src/type_conversion.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import {
AztecAddress,
ContractDeploymentData,
EthAddress,
Fr,
FunctionData,
FunctionSelector,
HistoricBlockData,
Point,
TxContext,
} from '@aztec/circuits.js';

import {
mapAztecAddressFromNoir,
mapAztecAddressToNoir,
mapContractDeploymentDataFromNoir,
mapContractDeploymentDataToNoir,
mapEthAddressFromNoir,
mapEthAddressToNoir,
mapFieldFromNoir,
mapFieldToNoir,
mapFunctionDataFromNoir,
mapFunctionDataToNoir,
mapFunctionSelectorFromNoir,
mapFunctionSelectorToNoir,
mapHistoricalBlockDataFromNoir,
mapHistoricalBlockDataToNoir,
mapPointFromNoir,
mapPointToNoir,
mapTxContextFromNoir,
mapTxContextToNoir,
} from './type_conversion.js';

describe('Noir<>Circuits.js type conversion test suite', () => {
describe('Round trip', () => {
it('should map fields', () => {
const field = new Fr(27n);
expect(mapFieldFromNoir(mapFieldToNoir(field))).toEqual(field);
});

const point = new Point(new Fr(27n), new Fr(28n));

it('should map points', () => {
expect(mapPointFromNoir(mapPointToNoir(point))).toEqual(point);
});

it('should map aztec addresses', () => {
const aztecAddress = AztecAddress.random();
expect(mapAztecAddressFromNoir(mapAztecAddressToNoir(aztecAddress))).toEqual(aztecAddress);
});

it('should map eth addresses', () => {
const ethAddress = EthAddress.random();
expect(mapEthAddressFromNoir(mapEthAddressToNoir(ethAddress))).toEqual(ethAddress);
});

const contractDeploymentData = new ContractDeploymentData(
point,
new Fr(29n),
new Fr(30n),
new Fr(31n),
AztecAddress.random(),
);

it('should map contract deployment data', () => {
expect(mapContractDeploymentDataFromNoir(mapContractDeploymentDataToNoir(contractDeploymentData))).toEqual(
contractDeploymentData,
);
});

it('should map tx context', () => {
const txContext = new TxContext(false, true, false, contractDeploymentData, new Fr(32n), new Fr(33n));
expect(mapTxContextFromNoir(mapTxContextToNoir(txContext))).toEqual(txContext);
});

const functionSelector = new FunctionSelector(34);

it('should map function selectors', () => {
expect(mapFunctionSelectorFromNoir(mapFunctionSelectorToNoir(functionSelector))).toEqual(functionSelector);
});

const functionData = new FunctionData(functionSelector, false, true, false);

it('should map function data', () => {
expect(mapFunctionDataFromNoir(mapFunctionDataToNoir(functionData))).toEqual(functionData);
});

it('should map historical block data', () => {
const historicalBlockData = new HistoricBlockData(
new Fr(35n),
new Fr(36n),
new Fr(37n),
new Fr(38n),
new Fr(39n),
new Fr(40n),
new Fr(41n),
new Fr(42n),
);
expect(mapHistoricalBlockDataFromNoir(mapHistoricalBlockDataToNoir(historicalBlockData))).toEqual(
historicalBlockData,
);
});
});
});
Loading