Skip to content

Commit

Permalink
finished private globals test
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed Feb 8, 2024
1 parent 50da038 commit 42c8a66
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions yarn-project/simulator/src/client/private_execution.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1133,20 +1133,37 @@ describe('Private Execution test suite', () => {
describe('Private global variables', () => {
let chainId: Fr;
let version: Fr;
let args: any[];
let artifact: FunctionArtifact;

beforeAll(() => {
chainId = Fr.random();
version = Fr.random();
});
args = [chainId, version];

it.only('emits a field as an unencrypted log', async () => {
const args = [chainId, version];
const artifact = getFunctionArtifact(TestContractArtifact, 'assert_private_global_vars');
artifact = getFunctionArtifact(TestContractArtifact, 'assert_private_global_vars');
oracle.getFunctionArtifact.mockImplementation(() => Promise.resolve(artifact));
});

const result = await runSimulator({ artifact, msgSender: owner, args });
it('Private global vars are correctly set', () => {
// Chain id and version set in tx context is the same as the ones we pass via args so this should not throw
expect(() => runSimulator({ artifact, msgSender: owner, args, txContext: { chainId, version } })).not.toThrow();
});

it('Throws when chainId is incorrectly set', async () => {
// We set the chainId in the tx context to a different value than the one we pass via args so the simulator should throw
const unexpectedChainId = Fr.random();
await expect(
runSimulator({ artifact, msgSender: owner, args, txContext: { chainId: unexpectedChainId, version } }),
).rejects.toThrowError('Invalid chain id');
});

console.log(result);
it('Throws when version is incorrectly set', async () => {
// We set the version in the tx context to a different value than the one we pass via args so the simulator should throw
const unexpectedVersion = Fr.random();
await expect(
runSimulator({ artifact, msgSender: owner, args, txContext: { chainId, version: unexpectedVersion } }),
).rejects.toThrowError('Invalid version');
});
});
});

0 comments on commit 42c8a66

Please sign in to comment.