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

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