Skip to content

Commit

Permalink
Soloseng/L2-Accounts-test (#11268)
Browse files Browse the repository at this point in the history
* running all tests in L2

* using registry from utils

* using WhenL2 utils contract
  • Loading branch information
soloseng authored Nov 14, 2024
1 parent 44c70c9 commit 3145e52
Showing 1 changed file with 47 additions and 19 deletions.
66 changes: 47 additions & 19 deletions packages/protocol/test-sol/unit/common/Accounts.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ pragma experimental ABIEncoderV2;

import "celo-foundry/Test.sol";
import "@celo-contracts/common/FixidityLib.sol";
import "@celo-contracts/common/Registry.sol";
import "@celo-contracts/common/Accounts.sol";
import "@celo-contracts/governance/test/MockValidators.sol";

import { TestConstants } from "@test-sol/constants.sol";
import { Utils } from "@test-sol/utils.sol";
import "@test-sol/utils/WhenL2.sol";

contract AccountsTest is Test, TestConstants {
contract AccountsTest is Utils {
using FixidityLib for FixidityLib.Fraction;

Registry registry;
Accounts accounts;
MockValidators validators;

Expand Down Expand Up @@ -80,13 +80,11 @@ contract AccountsTest is Test, TestConstants {
event PaymentDelegationSet(address indexed beneficiary, uint256 fraction);

function setUp() public {
deployCodeTo("Registry.sol", abi.encode(false), REGISTRY_ADDRESS);
super.setUp();

accounts = new Accounts(true);
validators = new MockValidators();

registry = Registry(REGISTRY_ADDRESS);

registry.setAddressFor("Validators", address(validators));
registry.setAddressFor("Accounts", address(accounts));

Expand All @@ -97,10 +95,6 @@ contract AccountsTest is Test, TestConstants {
(caller2, caller2PK) = actorWithPK("caller2");
}

function _whenL2() public {
deployCodeTo("Registry.sol", abi.encode(false), PROXY_ADMIN_ADDRESS);
}

function getParsedSignatureOfAddress(
address _address,
uint256 privateKey
Expand Down Expand Up @@ -201,6 +195,8 @@ contract AccountsTest is Test, TestConstants {
}
}

contract AccountsTest_L2 is AccountsTest, WhenL2 {}

contract AccountsTest_createAccount is AccountsTest {
function setUp() public {
super.setUp();
Expand All @@ -219,6 +215,8 @@ contract AccountsTest_createAccount is AccountsTest {
}
}

contract AccountsTest_createAccount_L2 is AccountsTest_L2, AccountsTest_createAccount {}

contract AccountsTest_setAccountDataEncryptionKey is AccountsTest {
function setUp() public {
super.setUp();
Expand Down Expand Up @@ -254,6 +252,11 @@ contract AccountsTest_setAccountDataEncryptionKey is AccountsTest {
}
}

contract AccountsTest_setAccountDataEncryptionKey_L2 is
AccountsTest_L2,
AccountsTest_setAccountDataEncryptionKey
{}

contract AccountsTest_setAccount is AccountsTest {
function setUp() public {
super.setUp();
Expand Down Expand Up @@ -340,6 +343,8 @@ contract AccountsTest_setAccount is AccountsTest {
}
}

contract AccountsTest_setAccount_L2 is AccountsTest_L2, AccountsTest_setAccount {}

contract AccountsTest_setWalletAddress is AccountsTest {
function setUp() public {
super.setUp();
Expand Down Expand Up @@ -390,6 +395,8 @@ contract AccountsTest_setWalletAddress is AccountsTest {
}
}

contract AccountsTest_setWalletAddress_L2 is AccountsTest_L2, AccountsTest_setWalletAddress {}

contract AccountsTest_setMetadataURL is AccountsTest {
function setUp() public {
super.setUp();
Expand All @@ -414,6 +421,8 @@ contract AccountsTest_setMetadataURL is AccountsTest {
}
}

contract AccountsTest_setMetadataURL_L2 is AccountsTest_L2, AccountsTest_setMetadataURL {}

contract AccountsTest_batchGetMetadataURL is AccountsTest {
function setUp() public {
super.setUp();
Expand Down Expand Up @@ -464,6 +473,8 @@ contract AccountsTest_batchGetMetadataURL is AccountsTest {
}
}

contract AccountsTest_batchGetMetadataURL_L2 is AccountsTest_L2, AccountsTest_batchGetMetadataURL {}

contract AccountsTest_addStorageRoot is AccountsTest {
function setUp() public {
super.setUp();
Expand Down Expand Up @@ -510,6 +521,8 @@ contract AccountsTest_addStorageRoot is AccountsTest {
}
}

contract AccountsTest_addStorageRoot_L2 is AccountsTest_L2, AccountsTest_addStorageRoot {}

contract AccountsTest_removeStorageRoot is AccountsTest {
function setUp() public {
super.setUp();
Expand Down Expand Up @@ -586,6 +599,8 @@ contract AccountsTest_removeStorageRoot is AccountsTest {
}
}

contract AccountsTest_removeStorageRoot_L2 is AccountsTest_L2, AccountsTest_removeStorageRoot {}

contract AccountsTest_setPaymentDelegation is AccountsTest {
address beneficiary = actor("beneficiary");
uint256 fraction = FixidityLib.newFixedFraction(2, 10).unwrap();
Expand All @@ -608,15 +623,6 @@ contract AccountsTest_setPaymentDelegation is AccountsTest {
assertEq(realFraction, fraction);
}

function test_ShouldSetAnAddressAndAFraction_WhenL2() public {
_whenL2();
accounts.createAccount();
accounts.setPaymentDelegation(beneficiary, fraction);
(address realBeneficiary, uint256 realFraction) = accounts.getPaymentDelegation(address(this));
assertEq(realBeneficiary, beneficiary);
assertEq(realFraction, fraction);
}

function test_ShouldNotAllowFractionGreaterThan1() public {
accounts.createAccount();
vm.expectRevert("Fraction must not be greater than 1");
Expand All @@ -637,6 +643,11 @@ contract AccountsTest_setPaymentDelegation is AccountsTest {
}
}

contract AccountsTest_setPaymentDelegation_L2 is
AccountsTest_L2,
AccountsTest_setPaymentDelegation
{}

contract AccountsTest_deletePaymentDelegation is AccountsTest {
address beneficiary = actor("beneficiary");
uint256 fraction = FixidityLib.newFixedFraction(2, 10).unwrap();
Expand Down Expand Up @@ -667,6 +678,11 @@ contract AccountsTest_deletePaymentDelegation is AccountsTest {
}
}

contract AccountsTest_deletePaymentDelegation_L2 is
AccountsTest_L2,
AccountsTest_deletePaymentDelegation
{}

contract AccountsTest_setName is AccountsTest {
function setUp() public {
super.setUp();
Expand All @@ -691,6 +707,8 @@ contract AccountsTest_setName is AccountsTest {
}
}

contract AccountsTest_setName_L2 is AccountsTest_L2, AccountsTest_setName {}

contract AccountsTest_GenericAuthorization is AccountsTest {
address account2 = actor("account2");
address signer;
Expand Down Expand Up @@ -875,6 +893,11 @@ contract AccountsTest_GenericAuthorization is AccountsTest {
}
}

contract AccountsTest_GenericAuthorization_L2 is
AccountsTest_L2,
AccountsTest_GenericAuthorization
{}

contract AccountsTest_BackwardCompatibility is AccountsTest {
address account = address(this);
address otherAccount = actor("otherAccount");
Expand Down Expand Up @@ -1542,3 +1565,8 @@ contract AccountsTest_BackwardCompatibility is AccountsTest {
helper_ShouldRemoveSigner(Role.Validator, false, true);
}
}

contract AccountsTest_BackwardCompatibility_L2 is
AccountsTest_L2,
AccountsTest_BackwardCompatibility
{}

0 comments on commit 3145e52

Please sign in to comment.