-
Notifications
You must be signed in to change notification settings - Fork 306
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add return type parsing for noir private kernel circuit (#2762)
Please provide a paragraph or two giving a summary of the change, including relevant motivation and context. # Checklist: Remove the checklist to signal you've completed it. Enable auto-merge if the PR is ready to merge. - [ ] If the pull request requires a cryptography review (e.g. cryptographic algorithm implementations) I have added the 'crypto' tag. - [ ] I have reviewed my diff in github, line by line and removed unexpected formatting changes, testing logs, or commented-out code. - [ ] Every change is related to the PR description. - [ ] I have [linked](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue) this pull request to relevant issues (if any exist).
- Loading branch information
1 parent
d5a14eb
commit c6c8e4b
Showing
2 changed files
with
403 additions
and
16 deletions.
There are no files selected for viewing
104 changes: 104 additions & 0 deletions
104
yarn-project/noir-private-kernel/src/type_conversion.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 |
---|---|---|
@@ -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, | ||
); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.