Skip to content

Commit

Permalink
test: unit tests ACL
Browse files Browse the repository at this point in the history
  • Loading branch information
PacificYield committed Dec 19, 2024
1 parent 223a2a8 commit 82fca56
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions contracts/test/acl/acl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { expect } from 'chai';
import { ethers } from 'hardhat';

import { initGateway } from '../asyncDecrypt';
import { createInstances } from '../instance';
import { getSigners, initSigners } from '../signers';

describe('ACL', function () {
before(async function () {
await initSigners(2);
this.signers = await getSigners();
this.instances = await createInstances(this.signers);
const aclFactory = await ethers.getContractFactory('ACL');
await initGateway();
const acl = await aclFactory.deploy();
await acl.waitForDeployment();
this.acl = acl;
this.tfheAddress = await acl.getTFHEExecutorAddress();

const amountToDistribute = BigInt(100 * 1e18);
await ethers.provider.send('hardhat_impersonateAccount', [this.tfheAddress]);
await ethers.provider.send('hardhat_setBalance', [this.tfheAddress, '0x' + amountToDistribute.toString(16)]);
this.tfheExecutor = await ethers.getSigner(this.tfheAddress);
});

it('allowTransient() is not persistent', async function () {
const randomHandle = 3290232n;
const randomAccount = this.signers.bob.address;
await this.acl.connect(this.tfheExecutor).allowTransient(randomHandle, randomAccount);

/// @dev The isAllowed returns false since it is transient.
expect(await this.acl.isAllowed(randomHandle, randomAccount)).to.be.eq(false);

/// @dev The isAllowed returns false since it is transient.
expect(await this.acl.allowedTransient(randomHandle, randomAccount)).to.be.eq(false);
});

it('allowTransient() reverts if sender is not allowed', async function () {
const randomHandle = 3290232n;
const randomAccount = this.signers.alice.address;
const sender = this.signers.alice;

await expect(this.acl.connect(sender).allowTransient(randomHandle, randomAccount))
.to.be.revertedWithCustomError(this.acl, 'SenderNotAllowed')
.withArgs(sender);
});

it('allow() reverts if sender is not allowed', async function () {
const randomHandle = 3290232n;
const randomAccount = this.signers.alice.address;
const sender = this.signers.alice;

await expect(this.acl.connect(sender).allow(randomHandle, randomAccount))
.to.be.revertedWithCustomError(this.acl, 'SenderNotAllowed')
.withArgs(sender);
});
});

0 comments on commit 82fca56

Please sign in to comment.