You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
159 lines
5.4 KiB
159 lines
5.4 KiB
3 years ago
|
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers';
|
||
3 years ago
|
import { expect } from 'chai';
|
||
3 years ago
|
import { ethers } from 'hardhat';
|
||
4 years ago
|
|
||
3 years ago
|
import {
|
||
3 years ago
|
AbacusConnectionManager,
|
||
|
AbacusConnectionManager__factory,
|
||
3 years ago
|
Outbox,
|
||
|
Outbox__factory,
|
||
3 years ago
|
TestInbox,
|
||
3 years ago
|
TestInbox__factory,
|
||
3 years ago
|
} from '../types';
|
||
4 years ago
|
|
||
4 years ago
|
const ONLY_OWNER_REVERT_MSG = 'Ownable: caller is not the owner';
|
||
4 years ago
|
const localDomain = 1000;
|
||
|
const remoteDomain = 2000;
|
||
4 years ago
|
|
||
3 years ago
|
describe('AbacusConnectionManager', async () => {
|
||
|
let connectionManager: AbacusConnectionManager,
|
||
3 years ago
|
enrolledInbox: TestInbox,
|
||
3 years ago
|
signer: SignerWithAddress,
|
||
|
nonOwner: SignerWithAddress;
|
||
4 years ago
|
|
||
|
before(async () => {
|
||
3 years ago
|
[signer, nonOwner] = await ethers.getSigners();
|
||
3 years ago
|
});
|
||
4 years ago
|
|
||
3 years ago
|
beforeEach(async () => {
|
||
3 years ago
|
const outboxFactory = new Outbox__factory(signer);
|
||
3 years ago
|
const outbox = await outboxFactory.deploy(localDomain);
|
||
3 years ago
|
|
||
3 years ago
|
const inboxFactory = new TestInbox__factory(signer);
|
||
3 years ago
|
enrolledInbox = await inboxFactory.deploy(localDomain);
|
||
2 years ago
|
// The ValidatorManager is unused in these tests *but* needs to be a
|
||
|
// contract.
|
||
|
await enrolledInbox.initialize(remoteDomain, outbox.address);
|
||
3 years ago
|
|
||
3 years ago
|
const connectionManagerFactory = new AbacusConnectionManager__factory(
|
||
|
signer,
|
||
|
);
|
||
3 years ago
|
connectionManager = await connectionManagerFactory.deploy();
|
||
3 years ago
|
await connectionManager.setOutbox(outbox.address);
|
||
3 years ago
|
await connectionManager.enrollInbox(remoteDomain, enrolledInbox.address);
|
||
4 years ago
|
});
|
||
|
|
||
|
it('Returns the local domain', async () => {
|
||
3 years ago
|
expect(await connectionManager!.localDomain()).to.equal(localDomain);
|
||
4 years ago
|
});
|
||
|
|
||
3 years ago
|
describe('#setOutbox', () => {
|
||
3 years ago
|
let newOutbox: Outbox;
|
||
3 years ago
|
|
||
|
beforeEach(async () => {
|
||
3 years ago
|
const outboxFactory = new Outbox__factory(signer);
|
||
3 years ago
|
newOutbox = await outboxFactory.deploy(localDomain);
|
||
|
});
|
||
|
|
||
|
it('Allows owner to set the outbox', async () => {
|
||
3 years ago
|
await connectionManager.setOutbox(newOutbox.address);
|
||
3 years ago
|
expect(await connectionManager.outbox()).to.equal(newOutbox.address);
|
||
|
});
|
||
|
|
||
3 years ago
|
it('Emits the OutboxSet event', async () => {
|
||
3 years ago
|
await expect(connectionManager.setOutbox(newOutbox.address))
|
||
3 years ago
|
.to.emit(connectionManager, 'OutboxSet')
|
||
3 years ago
|
.withArgs(newOutbox.address);
|
||
|
});
|
||
|
|
||
|
it('Reverts a call from non-owner', async () => {
|
||
3 years ago
|
await expect(
|
||
|
connectionManager.connect(nonOwner).setOutbox(newOutbox.address),
|
||
|
).to.be.revertedWith(ONLY_OWNER_REVERT_MSG);
|
||
3 years ago
|
});
|
||
4 years ago
|
});
|
||
|
|
||
3 years ago
|
it('isInbox returns true for enrolledInbox and false for non-enrolled Inbox', async () => {
|
||
|
const [nonEnrolledInbox] = await ethers.getSigners();
|
||
|
expect(await connectionManager.isInbox(enrolledInbox.address)).to.be.true;
|
||
|
expect(await connectionManager.isInbox(nonEnrolledInbox.address)).to.be
|
||
4 years ago
|
.false;
|
||
|
});
|
||
|
|
||
2 years ago
|
it('Owner can enroll a inbox', async () => {
|
||
4 years ago
|
const newRemoteDomain = 3000;
|
||
3 years ago
|
const inboxFactory = new TestInbox__factory(signer);
|
||
3 years ago
|
const newInbox = await inboxFactory.deploy(localDomain);
|
||
4 years ago
|
|
||
3 years ago
|
// Assert new inbox not considered inbox before enrolled
|
||
|
expect(await connectionManager.isInbox(newInbox.address)).to.be.false;
|
||
4 years ago
|
|
||
|
await expect(
|
||
3 years ago
|
connectionManager.enrollInbox(newRemoteDomain, newInbox.address),
|
||
3 years ago
|
).to.emit(connectionManager, 'InboxEnrolled');
|
||
4 years ago
|
|
||
3 years ago
|
expect(await connectionManager.getInboxes(newRemoteDomain)).to.eql([
|
||
3 years ago
|
newInbox.address,
|
||
3 years ago
|
]);
|
||
3 years ago
|
expect(await connectionManager.inboxToDomain(newInbox.address)).to.equal(
|
||
|
newRemoteDomain,
|
||
|
);
|
||
|
expect(await connectionManager.isInbox(newInbox.address)).to.be.true;
|
||
4 years ago
|
});
|
||
|
|
||
3 years ago
|
it('Owner can unenroll a inbox', async () => {
|
||
3 years ago
|
expect(await connectionManager.getInboxes(remoteDomain)).to.eql([
|
||
|
enrolledInbox.address,
|
||
|
]);
|
||
4 years ago
|
await expect(
|
||
3 years ago
|
connectionManager.unenrollInbox(enrolledInbox.address),
|
||
|
).to.emit(connectionManager, 'InboxUnenrolled');
|
||
4 years ago
|
|
||
|
expect(
|
||
3 years ago
|
await connectionManager.inboxToDomain(enrolledInbox.address),
|
||
4 years ago
|
).to.equal(0);
|
||
3 years ago
|
expect(await connectionManager.getInboxes(remoteDomain)).to.eql([]);
|
||
3 years ago
|
expect(await connectionManager.isInbox(enrolledInbox.address)).to.be.false;
|
||
4 years ago
|
});
|
||
3 years ago
|
|
||
2 years ago
|
it('Owner can enroll multiple inboxes per domain', async () => {
|
||
|
const newRemoteDomain = 3000;
|
||
3 years ago
|
const inboxFactory = new TestInbox__factory(signer);
|
||
2 years ago
|
const newInbox1 = await inboxFactory.deploy(localDomain);
|
||
|
const newInbox2 = await inboxFactory.deploy(localDomain);
|
||
|
|
||
|
// Assert new inbox not considered inbox before enrolled
|
||
|
expect(await connectionManager.isInbox(newInbox1.address)).to.be.false;
|
||
|
expect(await connectionManager.isInbox(newInbox2.address)).to.be.false;
|
||
|
|
||
3 years ago
|
await expect(
|
||
2 years ago
|
connectionManager.enrollInbox(newRemoteDomain, newInbox1.address),
|
||
|
).to.emit(connectionManager, 'InboxEnrolled');
|
||
|
await expect(
|
||
|
connectionManager.enrollInbox(newRemoteDomain, newInbox2.address),
|
||
|
).to.emit(connectionManager, 'InboxEnrolled');
|
||
|
|
||
|
expect(await connectionManager.inboxToDomain(newInbox1.address)).to.equal(
|
||
|
newRemoteDomain,
|
||
|
);
|
||
|
expect(await connectionManager.inboxToDomain(newInbox2.address)).to.equal(
|
||
|
newRemoteDomain,
|
||
|
);
|
||
|
|
||
|
expect(await connectionManager.isInbox(newInbox1.address)).to.be.true;
|
||
|
expect(await connectionManager.isInbox(newInbox2.address)).to.be.true;
|
||
|
|
||
|
expect(await connectionManager.getInboxes(newRemoteDomain)).to.eql([
|
||
|
newInbox1.address,
|
||
|
newInbox2.address,
|
||
|
]);
|
||
3 years ago
|
});
|
||
|
|
||
|
it('Owner cannot enroll an inbox twice', async () => {
|
||
2 years ago
|
const newRemoteDomain = 3000;
|
||
3 years ago
|
await expect(
|
||
2 years ago
|
connectionManager.enrollInbox(newRemoteDomain, enrolledInbox.address),
|
||
3 years ago
|
).to.be.revertedWith('already inbox');
|
||
3 years ago
|
});
|
||
4 years ago
|
});
|