Skip to content

Commit

Permalink
✅(test) Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pgonday committed Oct 2, 2024
1 parent 17d7741 commit 5bbe9a5
Show file tree
Hide file tree
Showing 23 changed files with 204 additions and 57 deletions.
6 changes: 3 additions & 3 deletions contracts/DVA/DVATransferManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@ import "../roles/AgentRole.sol";
import "../token/IToken.sol";
import "./IDVATransferManager.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol";
import "../utils/OwnableOnceNext2StepUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import "@openzeppelin/contracts/utils/introspection/IERC165.sol";
import "../roles/IERC173.sol";

contract DVATransferManager is IDVATransferManager, Initializable, Ownable2StepUpgradeable, UUPSUpgradeable, IERC165 {
contract DVATransferManager is IDVATransferManager, Initializable, OwnableOnceNext2StepUpgradeable, UUPSUpgradeable, IERC165 {

// Mapping for token approval criteria
mapping(address => ApprovalCriteria) private _approvalCriteria;
Expand All @@ -89,7 +89,7 @@ contract DVATransferManager is IDVATransferManager, Initializable, Ownable2StepU
uint256 private _txNonce;

function initialize() external initializer {
__Ownable2Step_init();
__Ownable_init();
_txNonce = 0;
}

Expand Down
6 changes: 3 additions & 3 deletions contracts/compliance/modular/ModularCompliance.sol
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@

pragma solidity 0.8.27;

import "@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol";
import "../../utils/OwnableOnceNext2StepUpgradeable.sol";
import "../../token/IToken.sol";
import "./IModularCompliance.sol";
import "./MCStorage.sol";
Expand Down Expand Up @@ -92,7 +92,7 @@ error OnlyOwnerOrTokenCanCall();
error TokenNotBound();


contract ModularCompliance is IModularCompliance, Ownable2StepUpgradeable, MCStorage, IERC165 {
contract ModularCompliance is IModularCompliance, OwnableOnceNext2StepUpgradeable, MCStorage, IERC165 {

/// modifiers

Expand All @@ -105,7 +105,7 @@ contract ModularCompliance is IModularCompliance, Ownable2StepUpgradeable, MCSto
}

function init() external initializer {
__Ownable2Step_init();
__Ownable_init();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
pragma solidity 0.8.27;

import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol";
import "../../../utils/OwnableOnceNext2StepUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import "./IModule.sol";
import "../../../errors/InvalidArgumentErrors.sol";
Expand All @@ -72,7 +72,7 @@ import "@openzeppelin/contracts/utils/introspection/IERC165.sol";
import "../../../roles/IERC173.sol";


abstract contract AbstractModuleUpgradeable is IModule, Initializable, Ownable2StepUpgradeable, UUPSUpgradeable, IERC165 {
abstract contract AbstractModuleUpgradeable is IModule, Initializable, OwnableOnceNext2StepUpgradeable, UUPSUpgradeable, IERC165 {
struct AbstractModuleStorage {
/// compliance contract binding status
mapping(address => bool) complianceBound;
Expand Down Expand Up @@ -143,7 +143,7 @@ abstract contract AbstractModuleUpgradeable is IModule, Initializable, Ownable2S

// solhint-disable-next-line func-name-mixedcase
function __AbstractModule_init() internal onlyInitializing {
__Ownable2Step_init();
__Ownable_init();
__AbstractModule_init_unchained();
}

Expand Down
6 changes: 3 additions & 3 deletions contracts/registry/implementation/ClaimTopicsRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@

pragma solidity 0.8.27;

import "@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol";
import "../../utils/OwnableOnceNext2StepUpgradeable.sol";
import "../storage/CTRStorage.sol";
import "../interface/IClaimTopicsRegistry.sol";
import "@openzeppelin/contracts/utils/introspection/IERC165.sol";
Expand All @@ -78,10 +78,10 @@ error MaxTopicsReached(uint256 _max);
error ClaimTopicAlreadyExists();


contract ClaimTopicsRegistry is IClaimTopicsRegistry, Ownable2StepUpgradeable, CTRStorage, IERC165 {
contract ClaimTopicsRegistry is IClaimTopicsRegistry, OwnableOnceNext2StepUpgradeable, CTRStorage, IERC165 {

function init() external initializer {
__Ownable2Step_init();
__Ownable_init();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion contracts/registry/implementation/IdentityRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ contract IdentityRegistry is IIdentityRegistry, AgentRoleUpgradeable, IRStorage,
emit TrustedIssuersRegistrySet(_trustedIssuersRegistry);
emit IdentityStorageSet(_identityStorage);
emit EligibilityChecksEnabled();
__Ownable2Step_init();
__Ownable_init();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ error MaxIRByIRSReached(uint256 _max);
contract IdentityRegistryStorage is IIdentityRegistryStorage, AgentRoleUpgradeable, IRSStorage, IERC165 {

function init() external initializer {
__Ownable2Step_init();
__Ownable_init();
}

/**
Expand Down
6 changes: 3 additions & 3 deletions contracts/registry/implementation/TrustedIssuersRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
pragma solidity 0.8.27;

import "@onchain-id/solidity/contracts/interface/IClaimIssuer.sol";
import "@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol";
import "../../utils/OwnableOnceNext2StepUpgradeable.sol";
import "../interface/ITrustedIssuersRegistry.sol";
import "../storage/TIRStorage.sol";
import "../../errors/InvalidArgumentErrors.sol";
Expand Down Expand Up @@ -97,12 +97,12 @@ error TrustedIssuerAlreadyExists();
error TrustedIssuerDoesNotExist();


contract TrustedIssuersRegistry is ITrustedIssuersRegistry, Ownable2StepUpgradeable, TIRStorage, IERC165 {
contract TrustedIssuersRegistry is ITrustedIssuersRegistry, OwnableOnceNext2StepUpgradeable, TIRStorage, IERC165 {

/// Functions

function init() external initializer {
__Ownable2Step_init();
__Ownable_init();
}

/**
Expand Down
5 changes: 2 additions & 3 deletions contracts/roles/AgentRoleUpgradeable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@

pragma solidity 0.8.27;

import "@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol";

import "../utils/OwnableOnceNext2StepUpgradeable.sol";
import "./Roles.sol";
import "../errors/InvalidArgumentErrors.sol";
import "../errors/RoleErrors.sol";
Expand All @@ -80,7 +79,7 @@ event AgentAdded(address indexed _agent);
event AgentRemoved(address indexed _agent);


contract AgentRoleUpgradeable is Ownable2StepUpgradeable {
contract AgentRoleUpgradeable is OwnableOnceNext2StepUpgradeable {
using Roles for Roles.Role;

Roles.Role private _agents;
Expand Down
5 changes: 2 additions & 3 deletions contracts/roles/permissioning/agent/AgentRolesUpgradeable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@

pragma solidity 0.8.27;

import "@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol";

import "../../../utils/OwnableOnceNext2StepUpgradeable.sol";
import "../../Roles.sol";
import "../../../errors/RoleErrors.sol";

Expand All @@ -81,7 +80,7 @@ event RoleAdded(address indexed _agent, string _role);
event RoleRemoved(address indexed _agent, string _role);


contract AgentRolesUpgradeable is Ownable2StepUpgradeable {
contract AgentRolesUpgradeable is OwnableOnceNext2StepUpgradeable {
using Roles for Roles.Role;

/// variables
Expand Down
5 changes: 2 additions & 3 deletions contracts/roles/permissioning/owner/OwnerRolesUpgradeable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@

pragma solidity 0.8.27;

import "@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol";

import "../../../utils/OwnableOnceNext2StepUpgradeable.sol";
import "../../Roles.sol";
import "../../../errors/RoleErrors.sol";

Expand All @@ -81,7 +80,7 @@ event RoleAdded(address indexed _owner, string _role);
event RoleRemoved(address indexed _owner, string _role);


contract OwnerRolesUpgradeable is Ownable2StepUpgradeable {
contract OwnerRolesUpgradeable is OwnableOnceNext2StepUpgradeable {
using Roles for Roles.Role;

/// variables
Expand Down
2 changes: 1 addition & 1 deletion contracts/token/Token.sol
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ contract Token is IToken, AgentRoleUpgradeable, TokenStorage, IERC165 {
&& keccak256(abi.encode(_symbol)) != keccak256(abi.encode(""))
, EmptyString());
require(0 <= _decimals && _decimals <= 18, DecimalsOutOfRange(_decimals));
__Ownable2Step_init();
__Ownable_init();
_tokenName = _name;
_tokenSymbol = _symbol;
_tokenDecimals = _decimals;
Expand Down
94 changes: 94 additions & 0 deletions contracts/utils/OwnableOnceNext2StepUpgradeable.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
// SPDX-License-Identifier: GPL-3.0
//
// :+#####%%%%%%%%%%%%%%+
// .-*@@@%+.:+%@@@@@%%#***%@@%=
// :=*%@@@#=. :#@@% *@@@%=
// .-+*%@%*-.:+%@@@@@@+. -*+: .=#. :%@@@%-
// :=*@@@@%%@@@@@@@@@%@@@- .=#@@@%@%= =@@@@#.
// -=+#%@@%#*=:. :%@@@@%. -*@@#*@@@@@@@#=:- *@@@@+
// =@@%=:. :=: *@@@@@%#- =%*%@@@@#+-. =+ :%@@@%-
// -@@%. .+@@@ =+=-. @@#- +@@@%- =@@@@%:
// :@@@. .+@@#%: : .=*=-::.-%@@@+*@@= +@@@@#.
// %@@: +@%%* =%@@@@@@@@@@@#. .*@%- +@@@@*.
// #@@= .+@@@@%:=*@@@@@- :%@%: .*@@@@+
// *@@* +@@@#-@@%-:%@@* +@@#. :%@@@@-
// -@@% .:-=++*##%%%@@@@@@@@@@@@*. :@+.@@@%: .#@@+ =@@@@#:
// .@@@*-+*#%%%@@@@@@@@@@@@@@@@%%#**@@%@@@. *@=*@@# :#@%= .#@@@@#-
// -%@@@@@@@@@@@@@@@*+==-:-@@@= *@# .#@*-=*@@@@%= -%@@@* =@@@@@%-
// -+%@@@#. %@%%= -@@:+@: -@@* *@@*-:: -%@@%=. .*@@@@@#
// *@@@* +@* *@@##@@- #@*@@+ -@@= . :+@@@#: .-+@@@%+-
// +@@@%*@@:..=@@@@* .@@@* .#@#. .=+- .=%@@@*. :+#@@@@*=:
// =@@@@%@@@@@@@@@@@@@@@@@@@@@@%- :+#*. :*@@@%=. .=#@@@@%+:
// .%@@= ..... .=#@@+. .#@@@*: -*%@@@@%+.
// +@@#+===---:::... .=%@@*- +@@@+. -*@@@@@%+.
// -@@@@@@@@@@@@@@@@@@@@@@%@@@@= -@@@+ -#@@@@@#=.
// ..:::---===+++***###%%%@@@#- .#@@+ -*@@@@@#=.
// @@@@@@+. +@@*. .+@@@@@%=.
// -@@@@@= =@@%: -#@@@@%+.
// +@@@@@. =@@@= .+@@@@@*:
// #@@@@#:%@@#. :*@@@@#-
// @@@@@%@@@= :#@@@@+.
// :@@@@@@@#.:#@@@%-
// +@@@@@@-.*@@@*:
// #@@@@#.=@@@+.
// @@@@+-%@%=
// :@@@#%@%=
// +@@@@%-
// :#%%=
//

/**
* NOTICE
*
* The T-REX software is licensed under a proprietary license or the GPL v.3.
* If you choose to receive it under the GPL v.3 license, the following applies:
* T-REX is a suite of smart contracts implementing the ERC-3643 standard and
* developed by Tokeny to manage and transfer financial assets on EVM blockchains
*
* Copyright (C) 2023, Tokeny sàrl.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

pragma solidity 0.8.27;

import "@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol";

contract OwnableOnceNext2StepUpgradeable is Ownable2StepUpgradeable {

struct Ownable2StepsStorage {
bool firstCall;
}

bytes32 private constant _STORAGE_SLOT = keccak256("ownableOnceNext2StepUpgradeable.storage.firstCall");

function transferOwnership(address newOwner) public override onlyOwner {
Ownable2StepsStorage storage s = _getStorage();
if (s.firstCall) {
s.firstCall = false;
super._transferOwnership(newOwner);
}
else {
super.transferOwnership(newOwner);
}
}

function _getStorage() internal pure returns (Ownable2StepsStorage storage s) {
bytes32 position = _STORAGE_SLOT;
assembly {
s.slot := position
}
}

}
13 changes: 10 additions & 3 deletions test/compliances/module-conditional-transfer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,16 @@ describe('ConditionalTransferModule', () => {
const context = await loadFixture(deployComplianceWithConditionalTransferModule);

// when
await context.suite.conditionalTransferModule.connect(context.accounts.deployer).transferOwnership(context.accounts.bobWallet.address);
await context.suite.conditionalTransferModule.connect(context.accounts.bobWallet).acceptOwnership();

const tx1 = await context.suite.conditionalTransferModule
.connect(context.accounts.deployer)
.transferOwnership(context.accounts.bobWallet.address);
expect(tx1)
.to.emit(context.suite.conditionalTransferModule, 'OwnershipTransferStarted')
.withArgs(context.accounts.deployer.address, context.accounts.bobWallet.address);
const tx2 = await context.suite.conditionalTransferModule.connect(context.accounts.bobWallet).acceptOwnership();
expect(tx2)
.to.emit(context.suite.conditionalTransferModule, 'OwnershipTransferred')
.withArgs(context.accounts.deployer.address, context.accounts.bobWallet.address);
// then
const owner = await context.suite.conditionalTransferModule.owner();
expect(owner).to.eq(context.accounts.bobWallet.address);
Expand Down
11 changes: 8 additions & 3 deletions test/compliances/module-country-allow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,14 @@ describe('CountryAllowModule', () => {
const context = await loadFixture(deployComplianceWithCountryAllowModule);

// when
await context.suite.countryAllowModule.connect(context.accounts.deployer).transferOwnership(context.accounts.bobWallet.address);
await context.suite.countryAllowModule.connect(context.accounts.bobWallet).acceptOwnership();

const tx1 = await context.suite.countryAllowModule.connect(context.accounts.deployer).transferOwnership(context.accounts.bobWallet.address);
expect(tx1)
.to.emit(context.suite.countryAllowModule, 'OwnershipTransferStarted')
.withArgs(context.accounts.deployer.address, context.accounts.bobWallet.address);
const tx2 = await context.suite.countryAllowModule.connect(context.accounts.bobWallet).acceptOwnership();
expect(tx2)
.to.emit(context.suite.countryAllowModule, 'OwnershipTransferred')
.withArgs(context.accounts.deployer.address, context.accounts.bobWallet.address);
// then
const owner = await context.suite.countryAllowModule.owner();
expect(owner).to.eq(context.accounts.bobWallet.address);
Expand Down
13 changes: 10 additions & 3 deletions test/compliances/module-country-restrict.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,16 @@ describe('CountryRestrictModule', () => {
const context = await loadFixture(deployComplianceWithCountryRestrictModule);

// when
await context.suite.countryRestrictModule.connect(context.accounts.deployer).transferOwnership(context.accounts.bobWallet.address);
await context.suite.countryRestrictModule.connect(context.accounts.bobWallet).acceptOwnership();

const tx1 = await context.suite.countryRestrictModule
.connect(context.accounts.deployer)
.transferOwnership(context.accounts.bobWallet.address);
expect(tx1)
.to.emit(context.suite.countryRestrictModule, 'OwnershipTransferStarted')
.withArgs(context.accounts.deployer.address, context.accounts.bobWallet.address);
const tx2 = await context.suite.countryRestrictModule.connect(context.accounts.bobWallet).acceptOwnership();
expect(tx2)
.to.emit(context.suite.countryRestrictModule, 'OwnershipTransferred')
.withArgs(context.accounts.deployer.address, context.accounts.bobWallet.address);
// then
const owner = await context.suite.countryRestrictModule.owner();
expect(owner).to.eq(context.accounts.bobWallet.address);
Expand Down
11 changes: 8 additions & 3 deletions test/compliances/module-exchange-monthly-limits.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,14 @@ describe('Compliance Module: ExchangeMonthlyLimits', () => {
const context = await loadFixture(deployExchangeMonthlyLimitsFixture);

// when
await context.contracts.complianceModule.connect(context.accounts.deployer).transferOwnership(context.accounts.bobWallet.address);
await context.contracts.complianceModule.connect(context.accounts.bobWallet).acceptOwnership();

const tx1 = await context.contracts.complianceModule.connect(context.accounts.deployer).transferOwnership(context.accounts.bobWallet.address);
expect(tx1)
.to.emit(context.contracts.complianceModule, 'OwnershipTransferStarted')
.withArgs(context.accounts.deployer.address, context.accounts.bobWallet.address);
const tx2 = await context.contracts.complianceModule.connect(context.accounts.bobWallet).acceptOwnership();
expect(tx2)
.to.emit(context.contracts.complianceModule, 'OwnershipTransferred')
.withArgs(context.accounts.deployer.address, context.accounts.bobWallet.address);
// then
const owner = await context.contracts.complianceModule.owner();
expect(owner).to.eq(context.accounts.bobWallet.address);
Expand Down
11 changes: 8 additions & 3 deletions test/compliances/module-max-balance.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,14 @@ describe('Compliance Module: MaxBalance', () => {
const context = await loadFixture(deployMaxBalanceFullSuite);

// when
await context.suite.complianceModule.connect(context.accounts.deployer).transferOwnership(context.accounts.bobWallet.address);
await context.suite.complianceModule.connect(context.accounts.bobWallet).acceptOwnership();

const tx1 = await context.suite.complianceModule.connect(context.accounts.deployer).transferOwnership(context.accounts.bobWallet.address);
expect(tx1)
.to.emit(context.suite.complianceModule, 'OwnershipTransferStarted')
.withArgs(context.accounts.deployer.address, context.accounts.bobWallet.address);
const tx2 = await context.suite.complianceModule.connect(context.accounts.bobWallet).acceptOwnership();
expect(tx2)
.to.emit(context.suite.complianceModule, 'OwnershipTransferred')
.withArgs(context.accounts.deployer.address, context.accounts.bobWallet.address);
// then
const owner = await context.suite.complianceModule.owner();
expect(owner).to.eq(context.accounts.bobWallet.address);
Expand Down
Loading

0 comments on commit 5bbe9a5

Please sign in to comment.