Skip to content

Commit

Permalink
feat: handle failing callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
jatZama committed Dec 26, 2024
1 parent e2d876f commit 29800ab
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
1 change: 0 additions & 1 deletion contracts/examples/TestAsyncDecrypt.sol
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ contract TestAsyncDecrypt is DecryptionOracleCaller {
bytes[] memory signatures
) public checkSignatures(requestID, signatures) returns (bool) {
yBool = decryptedInput;
revert();
return yBool;
}

Expand Down
14 changes: 11 additions & 3 deletions contracts/test/asyncDecrypt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ const CiphertextType = {
11: 'bytes',
};

let toSkip: BigInt[] = [];

const currentTime = (): string => {
const now = new Date();
return now.toLocaleTimeString('en-US', { hour12: true, hour: 'numeric', minute: 'numeric', second: 'numeric' });
Expand Down Expand Up @@ -96,7 +98,7 @@ const fulfillAllPastRequestsIds = async (mocked: boolean) => {
const callbackSelector = event.args[3];
const typesList = handles.map((handle) => parseInt(handle.toString(16).slice(-4, -2), 16));
// if request is not already fulfilled
if (mocked) {
if (mocked && !toSkip.includes(requestID)) {
// in mocked mode, we trigger the decryption fulfillment manually
await awaitCoprocessor();

Expand Down Expand Up @@ -143,8 +145,14 @@ const fulfillAllPastRequestsIds = async (mocked: boolean) => {
to: contractCaller,
data: calldata,
};
const tx = await relayer.sendTransaction(txData);
await tx.wait();
try {
const tx = await relayer.sendTransaction(txData);
await tx.wait();
} catch (error) {
console.log('Gateway fulfillment tx failed with the following error:', error.message);
toSkip.push(requestID);
throw error;
}
}
}
};
Expand Down
4 changes: 4 additions & 0 deletions contracts/test/kmsVerifier/kmsVerifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ describe('KMSVerifier', function () {
const y2 = await contract.yUint4();
expect(y2).to.equal(0);

const tx5Bis = await contract.requestUint4();
await tx5Bis.wait();
process.env.NUM_KMS_SIGNERS = '2';
await awaitAllDecryptionResults();
const y3 = await contract.yUint4();
Expand Down Expand Up @@ -122,6 +124,8 @@ describe('KMSVerifier', function () {
process.env.NUM_KMS_SIGNERS = '1';
const tx8 = await kmsVerifier.connect(deployer).removeSigner(kmsSigner2.address);
await tx8.wait();
const tx7Bis = await contract.requestUint16();
await tx7Bis.wait();
await awaitAllDecryptionResults();
const y6 = await contract.yUint16();
expect(y6).to.equal(16); // after removing one of the 4 signers, one signature is enough for decryption
Expand Down

0 comments on commit 29800ab

Please sign in to comment.