New Inbox.sol tests

pull/334/head
Trevor Porter 3 years ago
parent ebfbdaa708
commit f46adedbcb
  1. 14
      solidity/core/contracts/test/TestValidatorManager.sol
  2. 48
      solidity/core/test/inbox.test.ts
  3. 13
      solidity/core/test/lib/AbacusDeployment.ts

@ -0,0 +1,14 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity >=0.6.11;
import {Inbox} from "../Inbox.sol";
contract TestValidatorManager {
function checkpoint(
Inbox _inbox,
bytes32 _root,
uint256 _index
) external {
_inbox.checkpoint(_root, _index);
}
}

@ -2,7 +2,6 @@ import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers';
import { ethers } from 'hardhat'; import { ethers } from 'hardhat';
import { expect } from 'chai'; import { expect } from 'chai';
import { types, utils } from '@abacus-network/utils'; import { types, utils } from '@abacus-network/utils';
import { Validator } from './lib/core';
import { import {
BadRecipient1__factory, BadRecipient1__factory,
BadRecipient3__factory, BadRecipient3__factory,
@ -11,9 +10,9 @@ import {
BadRecipientHandle__factory, BadRecipientHandle__factory,
TestInbox, TestInbox,
TestInbox__factory, TestInbox__factory,
ValidatorManager,
ValidatorManager__factory,
TestRecipient__factory, TestRecipient__factory,
TestValidatorManager,
TestValidatorManager__factory,
} from '../types'; } from '../types';
const merkleTestCases = require('../../../vectors/merkle.json'); const merkleTestCases = require('../../../vectors/merkle.json');
@ -22,7 +21,7 @@ const proveAndProcessTestCases = require('../../../vectors/proveAndProcess.json'
const localDomain = 2000; const localDomain = 2000;
const remoteDomain = 1000; const remoteDomain = 1000;
describe('Inbox', async () => { describe.only('Inbox', async () => {
const badRecipientFactories = [ const badRecipientFactories = [
BadRecipient1__factory, BadRecipient1__factory,
BadRecipient3__factory, BadRecipient3__factory,
@ -31,20 +30,17 @@ describe('Inbox', async () => {
]; ];
let inbox: TestInbox, let inbox: TestInbox,
validatorManager: ValidatorManager,
signer: SignerWithAddress, signer: SignerWithAddress,
fakeSigner: SignerWithAddress,
abacusMessageSender: SignerWithAddress, abacusMessageSender: SignerWithAddress,
validator: Validator, validatorManager: TestValidatorManager;
fakeValidator: Validator;
before(async () => { before(async () => {
[signer, fakeSigner, abacusMessageSender] = await ethers.getSigners(); [signer, abacusMessageSender] = await ethers.getSigners();
validator = await Validator.fromSigner(signer, remoteDomain); // Inbox.initialize will ensure the validator manager is a contract.
fakeValidator = await Validator.fromSigner(fakeSigner, remoteDomain); // TestValidatorManager doesn't have any special logic, it just submits
const validatorManagerFactory = new ValidatorManager__factory(signer); // checkpoints without any signature verification.
validatorManager = await validatorManagerFactory.deploy(); const testValidatorManagerFactory = new TestValidatorManager__factory(signer);
await validatorManager.enrollValidator(remoteDomain, validator.address); validatorManager = await testValidatorManagerFactory.deploy();
}); });
beforeEach(async () => { beforeEach(async () => {
@ -69,40 +65,36 @@ describe('Inbox', async () => {
).to.be.revertedWith('Initializable: contract is already initialized'); ).to.be.revertedWith('Initializable: contract is already initialized');
}); });
it('Accepts signed checkpoint from validator', async () => { it('Accepts checkpoint from validator manager', async () => {
const root = ethers.utils.formatBytes32String('first new root'); const root = ethers.utils.formatBytes32String('first new root');
const index = 1; const index = 1;
const { signature } = await validator.signCheckpoint(root, index); await validatorManager.checkpoint(inbox.address, root, index);
await inbox.checkpoint(root, index, signature);
const [croot, cindex] = await inbox.latestCheckpoint(); const [croot, cindex] = await inbox.latestCheckpoint();
expect(croot).to.equal(root); expect(croot).to.equal(root);
expect(cindex).to.equal(index); expect(cindex).to.equal(index);
}); });
it('Rejects signed checkpoint from non-validator', async () => { it('Rejects checkpoint from non-validator manager', async () => {
const root = ethers.utils.formatBytes32String('first new root'); const root = ethers.utils.formatBytes32String('first new root');
const index = 1; const index = 1;
const { signature } = await fakeValidator.signCheckpoint(root, index); await expect(inbox.checkpoint(root, index)).to.be.revertedWith(
await expect(inbox.checkpoint(root, index, signature)).to.be.revertedWith( '!validatorManager',
'!validator sig',
); );
}); });
it('Rejects old signed checkpoint from validator', async () => { it('Rejects old checkpoint from validator manager', async () => {
let root = ethers.utils.formatBytes32String('first new root'); let root = ethers.utils.formatBytes32String('first new root');
let index = 10; let index = 10;
let { signature } = await validator.signCheckpoint(root, index); await validatorManager.checkpoint(inbox.address, root, index);
await inbox.checkpoint(root, index, signature);
const [croot, cindex] = await inbox.latestCheckpoint(); const [croot, cindex] = await inbox.latestCheckpoint();
expect(croot).to.equal(root); expect(croot).to.equal(root);
expect(cindex).to.equal(index); expect(cindex).to.equal(index);
root = ethers.utils.formatBytes32String('second new root'); root = ethers.utils.formatBytes32String('second new root');
index = 9; index = 9;
({ signature } = await validator.signCheckpoint(root, index)); await expect(
await expect(inbox.checkpoint(root, index, signature)).to.be.revertedWith( validatorManager.checkpoint(inbox.address, root, index),
'old checkpoint', ).to.be.revertedWith('old checkpoint');
);
}); });
it('Proves a valid message', async () => { it('Proves a valid message', async () => {

@ -164,19 +164,20 @@ export class AbacusDeployment {
) { ) {
return; return;
} }
// TODO come back to this!
// Update the Outbox and Inboxs to the latest roots. // Update the Outbox and Inboxs to the latest roots.
// This is technically not necessary given that we are not proving against // This is technically not necessary given that we are not proving against
// a root in the TestInbox. // a root in the TestInbox.
const validator = this.validator(local); // const validator = this.validator(local);
const { signature } = await validator.signCheckpoint( // const { signature } = await validator.signCheckpoint(
root, // root,
index.toNumber(), // index.toNumber(),
); // );
for (const remote of this.domains) { for (const remote of this.domains) {
if (remote !== local) { if (remote !== local) {
const inbox = this.inbox(remote, local); const inbox = this.inbox(remote, local);
await inbox.checkpoint(root, index, signature); await inbox.checkpoint(root, index); // TODO come back to this!
} }
} }

Loading…
Cancel
Save