-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Expand file tree
/
Copy pathhttpPublicDecrypt.ts
More file actions
57 lines (50 loc) · 2.12 KB
/
httpPublicDecrypt.ts
File metadata and controls
57 lines (50 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import { assert, expect } from 'chai';
import { ethers } from 'hardhat';
import { createInstances } from '../instance';
import { getSigners, initSigners } from '../signers';
describe('HTTPPublicDecrypt', function () {
before(async function () {
await initSigners(2);
this.signers = await getSigners();
this.instances = await createInstances(this.signers);
const contractFactory = await ethers.getContractFactory('HTTPPublicDecrypt');
this.contract = await contractFactory.connect(this.signers.alice).deploy();
await this.contract.waitForDeployment();
this.contractAddress = await this.contract.getAddress();
this.instances = await createInstances(this.signers);
});
it('test HTTPPublicDecrypt ebool', async function () {
const handleBool = await this.contract.xBool();
const res = await this.instances.alice.publicDecrypt([handleBool]);
const expectedRes = {
[handleBool]: true,
};
assert.deepEqual(res.clearValues, expectedRes);
});
it('test HTTPPublicDecrypt mixed', async function () {
const handleBool = await this.contract.xBool();
const handle32 = await this.contract.xUint32();
const handleAddress = await this.contract.xAddress();
const res = await this.instances.alice.publicDecrypt([handleBool, handle32, handleAddress]);
const expectedRes = {
[handleBool]: true,
[handle32]: 242n,
[handleAddress]: '0xfC4382C084fCA3f4fB07c3BCDA906C01797595a8',
};
assert.deepEqual(res.clearValues, expectedRes);
});
describe('negative-acl', function () {
it('should reject when handle is not publicly decryptable', async function () {
const factory = await ethers.getContractFactory('UserDecrypt');
const contract = await factory.connect(this.signers.alice).deploy();
await contract.waitForDeployment();
const handle = await contract.xUint8();
try {
await this.instances.alice.publicDecrypt([handle]);
expect.fail('Expected an error - handle is not publicly decryptable');
} catch (error) {
expect(error.message).to.include('not allowed for public decryption');
}
});
});
});