From f46adedbcb525df7bfc6a05b27b7d7176adf29ca Mon Sep 17 00:00:00 2001 From: Trevor Porter Date: Thu, 7 Apr 2022 16:46:31 +0100 Subject: [PATCH] New Inbox.sol tests --- .../contracts/test/TestValidatorManager.sol | 14 ++++++ solidity/core/test/inbox.test.ts | 48 ++++++++----------- solidity/core/test/lib/AbacusDeployment.ts | 13 ++--- 3 files changed, 41 insertions(+), 34 deletions(-) create mode 100644 solidity/core/contracts/test/TestValidatorManager.sol diff --git a/solidity/core/contracts/test/TestValidatorManager.sol b/solidity/core/contracts/test/TestValidatorManager.sol new file mode 100644 index 000000000..2864c6556 --- /dev/null +++ b/solidity/core/contracts/test/TestValidatorManager.sol @@ -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); + } +} diff --git a/solidity/core/test/inbox.test.ts b/solidity/core/test/inbox.test.ts index 5ca35de97..462208eb3 100644 --- a/solidity/core/test/inbox.test.ts +++ b/solidity/core/test/inbox.test.ts @@ -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 () => { diff --git a/solidity/core/test/lib/AbacusDeployment.ts b/solidity/core/test/lib/AbacusDeployment.ts index 0d0bceeed..65ba6f072 100644 --- a/solidity/core/test/lib/AbacusDeployment.ts +++ b/solidity/core/test/lib/AbacusDeployment.ts @@ -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! } }