Skip to content

Commit

Permalink
Add conditional network1 tests
Browse files Browse the repository at this point in the history
  • Loading branch information
david-zk committed Oct 25, 2023
1 parent a9a84cb commit 0233e43
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 28 deletions.
3 changes: 3 additions & 0 deletions codegen/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export type Operator = {

export type CodegenContext = {
libFheAddress: string;
optimisticRequiresEnabled: boolean;
};

export enum OperatorArguments {
Expand Down Expand Up @@ -242,10 +243,12 @@ export function networkCodegenContext(network: Network): CodegenContext {
case Network.Evmos:
return {
libFheAddress: '0x000000000000000000000000000000000000005d',
optimisticRequiresEnabled: true,
};
case Network.Network1:
return {
libFheAddress: '0x010000000000000000000000000000000000005D',
optimisticRequiresEnabled: false,
};
}
}
1 change: 1 addition & 0 deletions codegen/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ function generateAllFiles() {
'test/generated.ts',
`
export const FHE_LIB_ADDRESS = '${context.libFheAddress}';
export const OPTIMISTIC_REQUIRES_ENABLED = '${context.optimisticRequiresEnabled}';
`,
);
}
Expand Down
1 change: 1 addition & 0 deletions test/generated.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export const FHE_LIB_ADDRESS = '0x000000000000000000000000000000000000005d';
export const OPTIMISTIC_REQUIRES_ENABLED = 'true';
60 changes: 32 additions & 28 deletions test/tfheOperations/manual.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ import { expect } from 'chai';
import { ethers } from 'hardhat';

import type { TFHEManualTestSuite } from '../../types/contracts/tests/TFHEManualTestSuite';
import { OPTIMISTIC_REQUIRES_ENABLED } from '../generated';
import { createInstances } from '../instance';
import { getSigners, initSigners } from '../signers';
import { testRequires } from '../utils';

async function deployTfheManualTestFixture(): Promise<TFHEManualTestSuite> {
const signers = await getSigners();
Expand Down Expand Up @@ -67,32 +69,34 @@ describe('TFHE manual operations', function () {
expect(res).to.equal(0);
});

it('optimistic require with true succeeds', async function () {
await this.contract.test_opt_req(true);
});

it('optimistic require with false fails', async function () {
try {
await this.contract.test_opt_req(false);
fail('This should fail');
} catch (e: any) {
expect(e.message).to.contain('execution reverted');
}
});

it('stateful optimistic require with true succeeds', async function () {
const res = await this.contract.test_opt_req_stateful(true);
const receipt = await res.wait();
expect(receipt.status).to.equal(1);
});

it('stateful optimistic require with false fails', async function () {
const res = await this.contract.test_opt_req_stateful(false);
try {
const _ = await res.wait();
fail('This should fail');
} catch (e: any) {
expect(e.toString()).to.contain('transaction execution reverted');
}
});
if (OPTIMISTIC_REQUIRES_ENABLED) {
it('optimistic require with true succeeds', async function () {
await this.contract.test_opt_req(true);
});

it('optimistic require with false fails', async function () {
try {
await this.contract.test_opt_req(false);
fail('This should fail');
} catch (e: any) {
expect(e.message).to.contain('execution reverted');
}
});

it('stateful optimistic require with true succeeds', async function () {
const res = await this.contract.test_opt_req_stateful(true);
const receipt = await res.wait();
expect(receipt.status).to.equal(1);
});

it('stateful optimistic require with false fails', async function () {
const res = await this.contract.test_opt_req_stateful(false);
try {
const _ = await res.wait();
fail('This should fail');
} catch (e: any) {
expect(e.toString()).to.contain('transaction execution reverted');
}
});
}
});

0 comments on commit 0233e43

Please sign in to comment.