Skip to content

Commit

Permalink
Merge branch 'release/core-contracts/12' into soloseng/L2-goldToken-test
Browse files Browse the repository at this point in the history
  • Loading branch information
soloseng authored Nov 19, 2024
2 parents 1b99774 + 9f0c393 commit a06b9eb
Showing 1 changed file with 44 additions and 22 deletions.
66 changes: 44 additions & 22 deletions packages/protocol/test-sol/unit/common/Registry.t.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.5.13;

import "celo-foundry/Test.sol";
import "@test-sol/utils/WhenL2.sol";

import "@celo-contracts/common/Registry.sol";

Expand All @@ -14,89 +14,111 @@ contract RegistryTest is Test {
// hash is harcoded to avoid test and implementation changing at the same time
bytes32 constant ID_HASH = 0x05445421d7b4d4c2e571c5a4ccf9317ec68601449f752c75ddbcc61a16061004;

Registry registry;
Registry _registry;
address owner;

function setUp() public {
owner = address(this);
vm.prank(owner);
registry = new Registry(true);
registry.initialize();
_registry = new Registry(true);
_registry.initialize();
}
}

contract RegistryTest_L2 is WhenL2, RegistryTest {
function setUp() public {
super.setUp();
registry = IRegistry(address(_registry));
}
}

contract RegistryTest_initialize is RegistryTest {
function test_SetsTheOwner() public {
assertEq(registry.owner(), owner);
assertEq(_registry.owner(), owner);
}

function test_Reverts_WhenCalledAgain() public {
vm.expectRevert("contract already initialized");
registry.initialize();
_registry.initialize();
}
}

contract RegistryTest_setAddressFor is RegistryTest {
function test_SetsAddress() public {
vm.prank(owner);
registry.setAddressFor(SOME_ID, SOME_ADDRESS);
assertEq(registry.registry(ID_HASH), SOME_ADDRESS);
_registry.setAddressFor(SOME_ID, SOME_ADDRESS);
assertEq(_registry.registry(ID_HASH), SOME_ADDRESS);
}

function test_Reverts_WhenCalledByNonOwner() public {
vm.expectRevert("Ownable: caller is not the owner");
vm.prank(msg.sender);
registry.setAddressFor(SOME_ID, SOME_ADDRESS);
_registry.setAddressFor(SOME_ID, SOME_ADDRESS);
}

function test_Emits_RegistryUpdated() public {
vm.expectEmit(true, true, false, true);
emit RegistryUpdated(SOME_ID, ID_HASH, SOME_ADDRESS);

registry.setAddressFor(SOME_ID, SOME_ADDRESS);
_registry.setAddressFor(SOME_ID, SOME_ADDRESS);
}
}

contract RegistryTest_setAddressFor_L2 is RegistryTest_L2, RegistryTest_setAddressFor {}

contract RegistryTest_getAddressFor is RegistryTest {
function test_GetsRightAddress() public {
registry.setAddressFor(SOME_ID, SOME_ADDRESS);
assertEq(registry.getAddressFor(ID_HASH), SOME_ADDRESS);
_registry.setAddressFor(SOME_ID, SOME_ADDRESS);
assertEq(_registry.getAddressFor(ID_HASH), SOME_ADDRESS);
}

function test_ReturnsZero_WhenNotFound() public {
assertEq(registry.getAddressFor(ID_HASH), address(0));
assertEq(_registry.getAddressFor(ID_HASH), address(0));
}
}

contract RegistryTest_getAddressFor_L2 is RegistryTest_L2, RegistryTest_getAddressFor {}

contract RegistryTest_getAddressForString is RegistryTest {
function test_GetsRightAddress() public {
registry.setAddressFor(SOME_ID, SOME_ADDRESS);
assertEq(registry.getAddressForString(SOME_ID), SOME_ADDRESS);
_registry.setAddressFor(SOME_ID, SOME_ADDRESS);
assertEq(_registry.getAddressForString(SOME_ID), SOME_ADDRESS);
}

function test_DoesNotRevers_WhenGettingAddress() public view {
registry.getAddressForString(SOME_ID);
_registry.getAddressForString(SOME_ID);
}
}

contract RegistryTest_getAddressForString_L2 is RegistryTest_L2, RegistryTest_getAddressForString {}

contract RegistryTest_getAddressForOrDie is RegistryTest {
function test_GetsRightAddress() public {
registry.setAddressFor(SOME_ID, SOME_ADDRESS);
assertEq(registry.getAddressForOrDie(ID_HASH), SOME_ADDRESS);
_registry.setAddressFor(SOME_ID, SOME_ADDRESS);
assertEq(_registry.getAddressForOrDie(ID_HASH), SOME_ADDRESS);
}

function test_Reverts_WhenAddressNotFound() public {
vm.expectRevert("identifier has no registry entry");
registry.getAddressForOrDie(ID_HASH);
_registry.getAddressForOrDie(ID_HASH);
}
}

contract RegistryTest_getAddressForOrDie_L2 is RegistryTest_L2, RegistryTest_getAddressForOrDie {}

contract RegistryTest_getAddressForStringOrDie is RegistryTest {
function test_GetAddressForStringOrDie_gets_address() public {
registry.setAddressFor(SOME_ID, SOME_ADDRESS);
assertEq(registry.getAddressForStringOrDie(SOME_ID), SOME_ADDRESS);
_registry.setAddressFor(SOME_ID, SOME_ADDRESS);
assertEq(_registry.getAddressForStringOrDie(SOME_ID), SOME_ADDRESS);
}

function test_Reverts_WhenAddressNotFound() public {
vm.expectRevert("identifier has no registry entry");
registry.getAddressForStringOrDie(SOME_ID);
_registry.getAddressForStringOrDie(SOME_ID);
}
}

contract RegistryTest_getAddressForStringOrDie_L2 is
RegistryTest_L2,
RegistryTest_getAddressForStringOrDie
{}

0 comments on commit a06b9eb

Please sign in to comment.