Skip to content

Commit a0e503d

Browse files
committed
chore(test-suite): restore missed user decrypt ebool test case
1 parent 9739463 commit a0e503d

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed

test-suite/e2e/test/userDecryption/userDecryption.ts

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,83 @@ describe('User decryption', function () {
1818
this.instances = await createInstances(this.signers);
1919
});
2020

21+
it('test user decrypt ebool', async function () {
22+
const handle = await this.contract.xBool();
23+
const { publicKey, privateKey } = this.instances.alice.generateKeypair();
24+
const decryptedValue = await userDecryptSingleHandle(
25+
handle,
26+
this.contractAddress,
27+
this.instances.alice,
28+
this.signers.alice,
29+
privateKey,
30+
publicKey,
31+
);
32+
expect(decryptedValue).to.equal(true);
33+
34+
// on the other hand, Bob should be unable to read Alice's handle
35+
try {
36+
const { publicKey: publicKeyBob, privateKey: privateKeyBob } = this.instances.bob.generateKeypair();
37+
await userDecryptSingleHandle(
38+
handle,
39+
this.contractAddress,
40+
this.instances.bob,
41+
this.signers.bob,
42+
privateKeyBob,
43+
publicKeyBob,
44+
);
45+
expect.fail('Expected an error to be thrown - Bob should not be able to user decrypt Alice balance');
46+
} catch (error) {
47+
expect(error.message).to.equal(
48+
`User address ${this.signers.bob.address} is not authorized to user decrypt handle ${handle}!`,
49+
);
50+
}
51+
52+
// and should be impossible to call userDecrypt if contractAddress is in list of userAddresses
53+
try {
54+
const handleContractPairs = [
55+
{
56+
handle: handle,
57+
contractAddress: this.signers.alice.address, // this should be impossible, as expected by this test
58+
},
59+
];
60+
const startTimeStamp = Math.floor(Date.now() / 1000);
61+
const durationDays = 10;
62+
const contractAddresses = [this.signers.alice.address]; // this should be impossible, as expected by this test
63+
64+
// Build the extraData field
65+
const extraData = await this.instances.alice.getExtraData();
66+
67+
// Use the new createEIP712 function
68+
const eip712 = this.instances.alice.createEIP712(publicKey, contractAddresses, startTimeStamp, durationDays, extraData);
69+
70+
// Update the signing to match the new primaryType
71+
const signature = await this.signers.alice.signTypedData(
72+
eip712.domain,
73+
{
74+
UserDecryptRequestVerification: eip712.types.UserDecryptRequestVerification,
75+
},
76+
eip712.message,
77+
);
78+
79+
await this.instances.alice.userDecrypt(
80+
handleContractPairs,
81+
privateKey,
82+
publicKey,
83+
signature.replace('0x', ''),
84+
contractAddresses,
85+
this.signers.alice.address,
86+
startTimeStamp,
87+
durationDays,
88+
);
89+
90+
expect.fail('Expected an error to be thrown - userAddress and contractAddress cannot be equal');
91+
} catch (error) {
92+
expect(error.message).to.equal(
93+
`User address ${this.signers.alice.address} should not be equal to contract address when requesting user decryption!`,
94+
);
95+
}
96+
});
97+
2198
it('test user decrypt euint8', async function () {
2299
const handle = await this.contract.xUint8();
23100
const { publicKey, privateKey } = this.instances.alice.generateKeypair();
@@ -134,6 +211,7 @@ describe('User decryption', function () {
134211
const extraData = await this.instances.alice.getExtraData();
135212

136213
const eip712 = this.instances.alice.createEIP712(publicKey, contractAddresses, startTimeStamp, durationDays, extraData);
214+
137215
const signature = await this.signers.alice.signTypedData(
138216
eip712.domain,
139217
{ UserDecryptRequestVerification: eip712.types.UserDecryptRequestVerification },

0 commit comments

Comments
 (0)