-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b8eec3b
commit 3f20a9c
Showing
2 changed files
with
105 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
packages/contracts/test/harnesses/AttestationCollectorHarness.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 {} |