Skip to content

Commit

Permalink
tests: asstestation collector
Browse files Browse the repository at this point in the history
  • Loading branch information
ChiTimesChi committed Jul 14, 2022
1 parent b8eec3b commit 3f20a9c
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 0 deletions.
98 changes: 98 additions & 0 deletions packages/contracts/test/AttestationCollector.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
// SPDX-License-Identifier: MIT

pragma solidity 0.8.13;

import { SynapseTest } from "./utils/SynapseTest.sol";

import { AttestationCollectorHarness } from "./harnesses/AttestationCollectorHarness.sol";

contract AttestationCollectorTest is SynapseTest {
AttestationCollectorHarness internal collector;

event AttestationSubmitted(address indexed updater, bytes attestation, bytes signature);

event UpdaterAdded(uint32 indexed domain, address updater);

event UpdaterRemoved(uint32 indexed domain, address updater);

uint32 internal nonce = 420;
bytes32 internal root = "root";

function setUp() public override {
super.setUp();
collector = new AttestationCollectorHarness();
collector.initialize();
}

function test_cannotInitializeTwice() public {
vm.expectRevert("Initializable: contract is already initialized");
collector.initialize();
}

function test_addUpdater() public {
vm.expectEmit(true, true, true, true);
emit UpdaterAdded(localDomain, updater);
collector.addUpdater(localDomain, updater);
}

function test_addUpdater_notOwner() public {
vm.expectRevert("Ownable: caller is not the owner");
vm.prank(address(1337));
collector.addUpdater(localDomain, fakeUpdater);
}

function test_removeUpdater() public {
test_addUpdater();
emit UpdaterRemoved(localDomain, updater);
collector.removeUpdater(localDomain, updater);
}

function test_removeUpdater_notOwner() public {
test_addUpdater();
vm.expectRevert("Ownable: caller is not the owner");
vm.prank(address(1337));
collector.addUpdater(localDomain, fakeUpdater);
}

function test_submitAttestation() public {
test_addUpdater();
(bytes memory attestation, bytes memory signature) = signHomeUpdate(updaterPK, nonce, root);
vm.expectEmit(true, true, true, true);
emit AttestationSubmitted(updater, attestation, signature);
collector.submitAttestation(updater, attestation, signature);
}

function test_submitAttestation_invalidSignature() public {
test_addUpdater();
(bytes memory attestation, bytes memory signature) = signHomeUpdate(
fakeUpdaterPK,
nonce,
root
);
vm.expectRevert("Invalid signature");
collector.submitAttestation(updater, attestation, signature);
}

function test_submitAttestation_notUpdater() public {
test_addUpdater();
(bytes memory attestation, bytes memory signature) = signHomeUpdate(
fakeUpdaterPK,
nonce,
root
);
vm.expectRevert("Signer is not an updater");
collector.submitAttestation(fakeUpdater, attestation, signature);
}

function test_submitAttestation_wrongDomain() public {
test_addUpdater();
(bytes memory attestation, bytes memory signature) = signRemoteUpdate(
updaterPK,
nonce,
root
);
// Signer is not set as updater for the `remoteDomain`
vm.expectRevert("Signer is not an updater");
collector.submitAttestation(updater, attestation, signature);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// SPDX-License-Identifier: MIT

pragma solidity 0.8.13;

import { AttestationCollector } from "../../contracts/AttestationCollector.sol";

contract AttestationCollectorHarness is AttestationCollector {}

0 comments on commit 3f20a9c

Please sign in to comment.