Skip to content

Commit 3cee990

Browse files
authored
feat(test-suite): add tests doing several requests in same block and tx (#36)
* feat(test-suite): add tests doing several requests in same block and tx * chore(test-suite): update docker image for test suite
1 parent 3374b48 commit 3cee990

File tree

3 files changed

+111
-2
lines changed

3 files changed

+111
-2
lines changed

test-suite/e2e/contracts/TestAsyncDecrypt.sol

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,14 @@ contract TestAsyncDecrypt is E2EFHEVMConfig {
1212
euint8 xUint8;
1313
euint16 xUint16;
1414
euint32 xUint32;
15+
euint32 xUint32_2;
16+
euint32 xUint32_3;
1517
euint64 xUint64;
1618
euint64 xUint64_2;
1719
euint64 xUint64_3;
1820
euint128 xUint128;
21+
euint128 xUint128_2;
22+
euint128 xUint128_3;
1923
eaddress xAddress;
2024
eaddress xAddress2;
2125
euint256 xUint256;
@@ -25,10 +29,14 @@ contract TestAsyncDecrypt is E2EFHEVMConfig {
2529
uint8 public yUint8;
2630
uint16 public yUint16;
2731
uint32 public yUint32;
32+
uint32 public yUint32_2;
33+
uint32 public yUint32_3;
2834
uint64 public yUint64;
2935
uint64 public yUint64_2;
3036
uint64 public yUint64_3;
3137
uint128 public yUint128;
38+
uint128 public yUint128_2;
39+
uint128 public yUint128_3;
3240
address public yAddress;
3341
address public yAddress2;
3442
uint256 public yUint256;
@@ -44,13 +52,16 @@ contract TestAsyncDecrypt is E2EFHEVMConfig {
4452
/// @dev Initialize encrypted variables with sample values
4553
xBool = FHE.asEbool(true);
4654
FHE.allowThis(xBool);
47-
4855
xUint8 = FHE.asEuint8(42);
4956
FHE.allowThis(xUint8);
5057
xUint16 = FHE.asEuint16(16);
5158
FHE.allowThis(xUint16);
5259
xUint32 = FHE.asEuint32(32);
5360
FHE.allowThis(xUint32);
61+
xUint32_2 = FHE.asEuint32(1000);
62+
FHE.allowThis(xUint32_2);
63+
xUint32_3 = FHE.asEuint32(2000);
64+
FHE.allowThis(xUint32_3);
5465
xUint64 = FHE.asEuint64(18446744073709551600);
5566
FHE.allowThis(xUint64);
5667
xUint64_2 = FHE.asEuint64(76575465786);
@@ -59,6 +70,10 @@ contract TestAsyncDecrypt is E2EFHEVMConfig {
5970
FHE.allowThis(xUint64_3);
6071
xUint128 = FHE.asEuint128(1267650600228229401496703205443);
6172
FHE.allowThis(xUint128);
73+
xUint128_2 = FHE.asEuint128(10000);
74+
FHE.allowThis(xUint128_2);
75+
xUint128_3 = FHE.asEuint128(20000);
76+
FHE.allowThis(xUint128_3);
6277
xUint256 = FHE.asEuint256(27606985387162255149739023449108101809804435888681546220650096895197251);
6378
FHE.allowThis(xUint256);
6479
xAddress = FHE.asEaddress(0x8ba1f109551bD432803012645Ac136ddd64DBA72);
@@ -200,6 +215,38 @@ contract TestAsyncDecrypt is E2EFHEVMConfig {
200215
}
201216
}
202217

218+
/// @notice Request decryption of a 32-bit unsigned integer
219+
function requestUint32_2() public {
220+
bytes32[] memory cts = new bytes32[](1);
221+
cts[0] = FHE.toBytes32(xUint32_2);
222+
FHE.requestDecryption(cts, this.callbackUint32_2.selector);
223+
}
224+
225+
function callbackUint32_2(
226+
uint256 requestID,
227+
uint32 decryptedInput,
228+
bytes[] memory signatures
229+
) public {
230+
FHE.checkSignatures(requestID, signatures);
231+
yUint32_2 = decryptedInput;
232+
}
233+
234+
/// @notice Request decryption of a 32-bit unsigned integer
235+
function requestUint32_3() public {
236+
bytes32[] memory cts = new bytes32[](1);
237+
cts[0] = FHE.toBytes32(xUint32_3);
238+
FHE.requestDecryption(cts, this.callbackUint32_3.selector);
239+
}
240+
241+
function callbackUint32_3(
242+
uint256 requestID,
243+
uint32 decryptedInput,
244+
bytes[] memory signatures
245+
) public {
246+
FHE.checkSignatures(requestID, signatures);
247+
yUint32_3 = decryptedInput;
248+
}
249+
203250
/// @notice Request decryption of a 64-bit unsigned integer
204251
function requestUint64() public {
205252
bytes32[] memory cts = new bytes32[](1);
@@ -261,6 +308,33 @@ contract TestAsyncDecrypt is E2EFHEVMConfig {
261308
return decryptedInput;
262309
}
263310

311+
function requestUint128_Many() public {
312+
bytes32[] memory cts = new bytes32[](1);
313+
cts[0] = FHE.toBytes32(xUint128_2);
314+
FHE.requestDecryption(cts, this.callbackUint128_2.selector);
315+
bytes32[] memory cts_2 = new bytes32[](1);
316+
cts_2[0] = FHE.toBytes32(xUint128_3);
317+
FHE.requestDecryption(cts_2, this.callbackUint128_3.selector);
318+
}
319+
320+
function callbackUint128_2(
321+
uint256 requestID,
322+
uint128 decryptedInput,
323+
bytes[] memory signatures
324+
) public {
325+
FHE.checkSignatures(requestID, signatures);
326+
yUint128_2 = decryptedInput;
327+
}
328+
329+
function callbackUint128_3(
330+
uint256 requestID,
331+
uint128 decryptedInput,
332+
bytes[] memory signatures
333+
) public {
334+
FHE.checkSignatures(requestID, signatures);
335+
yUint128_3 = decryptedInput;
336+
}
337+
264338
function requestUint256() public {
265339
bytes32[] memory cts = new bytes32[](1);
266340
cts[0] = FHE.toBytes32(xUint256);

test-suite/e2e/test/gatewayDecrypt/testAsyncDecrypt.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,31 @@ describe('TestAsyncDecrypt', function () {
132132
expect(y).to.equal(52); // 5+15+32
133133
});
134134

135+
it('test async decrypt uint32 - two requests in same block', async function () {
136+
const pendingNonce = await ethers.provider.getTransactionCount(this.signers.alice.address, "pending");
137+
138+
const [txA, txB] = await Promise.all([
139+
this.contract.requestUint32_2({
140+
nonce: pendingNonce,
141+
}),
142+
this.contract.requestUint32_3({
143+
nonce: pendingNonce+1,
144+
}),
145+
]);
146+
147+
const [receiptA, receiptB] = await Promise.all([txA.wait(), txB.wait()]);
148+
149+
console.log("txA block:", receiptA.blockNumber);
150+
console.log("txB block:", receiptB.blockNumber);
151+
152+
await awaitAllDecryptionResults();
153+
154+
const y2 = await this.contract.yUint32_2();
155+
expect(y2).to.equal(1000);
156+
const y3 = await this.contract.yUint32_3();
157+
expect(y3).to.equal(2000);
158+
});
159+
135160
it.skip('test async decrypt FAKE uint32', async function () {
136161
if (network.name !== 'hardhat') {
137162
// only in fhevm mode
@@ -167,6 +192,16 @@ describe('TestAsyncDecrypt', function () {
167192
expect(y).to.equal(1267650600228229401496703205443n);
168193
});
169194

195+
it('test async decrypt uint128 - two requests in same tx', async function () {
196+
const tx2 = await this.contract.connect(this.signers.carol).requestUint128_Many();
197+
await tx2.wait();
198+
await awaitAllDecryptionResults();
199+
const y2 = await this.contract.yUint128_2();
200+
expect(y2).to.equal(10000n);
201+
const y3 = await this.contract.yUint128_3();
202+
expect(y3).to.equal(20000n);
203+
});
204+
170205
it('test async decrypt uint128 non-trivial', async function () {
171206
const inputAlice = this.instances.alice.createEncryptedInput(this.contractAddress, this.signers.alice.address);
172207
inputAlice.add128(184467440737095500429401496n);

test-suite/fhevm/fhevm-cli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export DB_MIGRATION_VERSION=${DB_MIGRATION_VERSION:-"v0.7.0-rc8"}
2424
export HOST_VERSION=${HOST_VERSION:-"31c51c3"}
2525
export GATEWAY_VERSION=${GATEWAY_VERSION:-"5d13e72"}
2626
export RELAYER_VERSION=${RELAYER_VERSION:-"v0.1.0-rc8"}
27-
export TEST_SUITE_VERSION=${TEST_SUITE_VERSION:-"0d61373"}
27+
export TEST_SUITE_VERSION=${TEST_SUITE_VERSION:-"76b0e4f"}
2828

2929
function print_logo() {
3030
echo -e "${LIGHT_BLUE}"

0 commit comments

Comments
 (0)