Skip to content

Commit

Permalink
test: updates for custom errors
Browse files Browse the repository at this point in the history
  • Loading branch information
PacificYield committed Dec 16, 2024
1 parent 1f08296 commit 53e6926
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions contracts/test/kmsVerifier/kmsVerifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ describe('KMSVerifier', function () {
expect(y).to.equal(true); // in this case, one signature still suffices to pass the decrypt (threshold is still 1)

const kmsSignerDup = new ethers.Wallet(privKeySigner).connect(ethers.provider);
await expect(kmsVerifier.connect(deployer).addSigner(kmsSignerDup.address)).to.revertedWith(
'KMSVerifier: Address is already a signer',
await expect(kmsVerifier.connect(deployer).addSigner(kmsSignerDup.address)).to.revertedWithCustomError(
kmsVerifier,
'KMSAlreadySigner',
); // cannot add duplicated signer
expect((await kmsVerifier.getSigners()).length).to.equal(2);

Expand All @@ -59,9 +60,9 @@ describe('KMSVerifier', function () {

const tx5 = await contract.requestUint4({ gasLimit: 5_000_000 });
await tx5.wait();
await expect(awaitAllDecryptionResults()).to.revertedWith(
'KmsVerifier: at least threshold number of signatures required',
); // should revert because now we are below the threshold! (we receive only 1 signature but threshold is 2)
await expect(awaitAllDecryptionResults())
.to.revertedWithCustomError(kmsVerifier, 'KMSSignatureThresholdNotReached')
.withArgs(1n); // should revert because now we are below the threshold! (we receive only 1 signature but threshold is 2)
const y2 = await contract.yUint4();
expect(y2).to.equal(0);

Expand Down Expand Up @@ -90,7 +91,9 @@ describe('KMSVerifier', function () {
contract2.requestMixedBytes256Trustless(encryptedAmount2.handles[0], encryptedAmount2.inputProof, {
gasLimit: 5_000_000,
}),
).to.revertedWith('KmsVerifier: at least threshold number of signatures required'); // this should fail because in this case the InputVerifier received only one KMS signature (instead of at least 2);
)
.to.revertedWithCustomError(kmsVerifier, 'KMSSignatureThresholdNotReached')
.withArgs(1n); // this should fail because in this case the InputVerifier received only one KMS signature (instead of at least 2);

if (process.env.IS_COPROCESSOR === 'true') {
// different format of inputProof for native
Expand All @@ -100,7 +103,9 @@ describe('KMSVerifier', function () {
contract2.requestMixedBytes256Trustless(encryptedAmount2.handles[0], cheat, {
gasLimit: 5_000_000,
}),
).to.revertedWith('Not enough unique KMS input signatures'); // this should fail because in this case the InputVerifier received only one KMS signature (instead of at least 2)
)
.to.revertedWithCustomError(kmsVerifier, 'KMSSignatureThresholdNotReached')
.withArgs(1n); // this should fail because in this case the InputVerifier received only one KMS signature (instead of at least 2)
}
process.env.NUM_KMS_SIGNERS = '4';
const encryptedAmount = await inputAlice.encrypt();
Expand All @@ -124,7 +129,7 @@ describe('KMSVerifier', function () {
process.env.PRIVATE_KEY_KMS_SIGNER_1 = process.env.PRIVATE_KEY_KMS_SIGNER_0;
const tx7 = await contract.requestUint16({ gasLimit: 5_000_000 });
await tx7.wait();
await expect(awaitAllDecryptionResults()).to.revertedWith('KMS signature verification failed'); // cannot use duplicated signatures if threshold is 2
await expect(awaitAllDecryptionResults()).to.revertedWithCustomError(kmsVerifier, 'KMSInvalidSigner'); // cannot use duplicated signatures if threshold is 2
const y5 = await contract.yUint16();
expect(y5).to.equal(0);

Expand Down

0 comments on commit 53e6926

Please sign in to comment.