Skip to content

Commit

Permalink
update doc
Browse files Browse the repository at this point in the history
  • Loading branch information
rya-sge committed Jan 29, 2024
1 parent d6ed12b commit c932d12
Show file tree
Hide file tree
Showing 22 changed files with 59 additions and 49 deletions.
2 changes: 1 addition & 1 deletion FAQ.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,5 +100,5 @@ Normally, you can run the test suite and generate a code coverage report with `n

Please clone the repository and open the file inside your browser.

You will find a summary of all automatic tests in
You will find a list of automatic tests in
[test.pdf](https://github.com/CMTA/CMTAT/blob/master/doc/general/test/test.pdf).
6 changes: 3 additions & 3 deletions contracts/interfaces/engine/IAuthorizationEngine.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ pragma solidity ^0.8.0;

interface IAuthorizationEngine {
/**
* @dev Returns true if the operation is a success, and false otherwise.
* @dev Returns true if the operation is authorized, and false otherwise.
*/
function operateOnGrantRole(
bytes32 role, address account
) external returns (bool isValid);

/**
* @dev Returns true if the operation is a success, and false otherwise.
/**
* @dev Returns true if the operation is authorized, and false otherwise.
*/
function operateOnRevokeRole(
bytes32 role, address account
Expand Down
18 changes: 15 additions & 3 deletions doc/general/Engine.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,23 @@ Main advantages :

### Implementation

An **AuthorizationEngine** contract has to implement the interface `IAuthorizationEngine`. This interface defines mainly one function.
An **AuthorizationEngine** contract has to implement the interface `IAuthorizationEngine`. This interface defines mainly twos functions, one to grant a Role and the other one to revole a role.

```solidity
function operateOnAuthorization(bytes32 role, address account)
external returns (bool)
/**
* @dev Returns true if the operation is authorized, and false otherwise.
*/
function operateOnGrantRole(
bytes32 role, address account
) external returns (bool isValid);
/**
* @dev Returns true if the operation is authorized, and false otherwise.
*/
function operateOnRevokeRole(
bytes32 role, address account
) external returns (bool isValid);
```

### Schema
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified doc/schema/surya_graph/surya_graph_AuthorizationModule.sol.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified doc/schema/surya_graph/surya_graph_CMTAT_BASE.sol.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified doc/schema/surya_graph/surya_graph_IAuthorizationEngine.sol.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified doc/schema/surya_graph/surya_graph_MetaTxModule.sol.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
| **AuthorizationEngineMock** | Implementation | IAuthorizationEngine |||
|| <Constructor> | Public ❗️ | 🛑 |NO❗️ |
|| authorizeAdminChange | External ❗️ | 🛑 |NO❗️ |
|| operateOnAuthorization | External ❗️ | 🛑 |NO❗️ |
|| setRevokeAdminRoleAuthorized | External ❗️ | 🛑 |NO❗️ |
|| operateOnGrantRole | External ❗️ | 🛑 |NO❗️ |
|| operateOnRevokeRole | External ❗️ | |NO❗️ |


### Legend
Expand Down
1 change: 1 addition & 0 deletions doc/schema/surya_report/surya_report_CMTAT_BASE.sol.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
|| burnAndMint | Public ❗️ | 🛑 |NO❗️ |
|| _update | Internal 🔒 | 🛑 | |
|| _msgSender | Internal 🔒 | | |
|| _contextSuffixLength | Internal 🔒 | | |
|| _msgData | Internal 🔒 | | |


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
|| **Function Name** | **Visibility** | **Mutability** | **Modifiers** |
||||||
| **IAuthorizationEngine** | Interface | |||
|| operateOnAuthorization | External ❗️ | 🛑 |NO❗️ |
|| operateOnGrantRole | External ❗️ | 🛑 |NO❗️ |
|| operateOnRevokeRole | External ❗️ | 🛑 |NO❗️ |


### Legend
Expand Down
2 changes: 0 additions & 2 deletions doc/schema/surya_report/surya_report_MetaTxModule.sol.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
||||||
| **MetaTxModule** | Implementation | ERC2771ContextUpgradeable |||
|| <Constructor> | Public ❗️ | 🛑 | ERC2771ContextUpgradeable |
|| _msgSender | Internal 🔒 | | |
|| _msgData | Internal 🔒 | | |


### Legend
Expand Down
2 changes: 0 additions & 2 deletions test/common/AuthorizationModule/AuthorizationModuleCommon.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,5 @@ function AuthorizationModuleCommon (admin, address1, address2) {
(await this.cmtat.hasRole(PAUSER_ROLE, address1)).should.equal(true)
})
})


}
module.exports = AuthorizationModuleCommon
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const {
const { DEFAULT_ADMIN_ROLE } = require('../../utils.js')
const { should } = require('chai').should()

function AuthorizationModuleSetAuthorizationEngineCommon(admin, address1, authorizationEngine) {
function AuthorizationModuleSetAuthorizationEngineCommon (admin, address1, authorizationEngine) {
context('AuthorizationEngineSetTest', function () {
it('testCanBeSetByAdminIfNotAlreadySet', async function () {
// Act
Expand Down Expand Up @@ -48,7 +48,7 @@ function AuthorizationModuleSetAuthorizationEngineCommon(admin, address1, author
// Arrange
await this.authorizationEngineMock.authorizeAdminChange(address1)
// Act
await this.cmtat.setAuthorizationEngine(this.authorizationEngineMock.address, { from: admin})
await this.cmtat.setAuthorizationEngine(this.authorizationEngineMock.address, { from: admin })
// Assert
this.logs = await this.cmtat.grantRole(DEFAULT_ADMIN_ROLE, address1, {
from: admin
Expand All @@ -75,7 +75,7 @@ function AuthorizationModuleSetAuthorizationEngineCommon(admin, address1, author
// Arrange
await this.authorizationEngineMock.authorizeAdminChange(address1)
// Act
await this.cmtat.setAuthorizationEngine(this.authorizationEngineMock.address, { from: admin})
await this.cmtat.setAuthorizationEngine(this.authorizationEngineMock.address, { from: admin })
// Assert
this.logs = await this.cmtat.revokeRole(DEFAULT_ADMIN_ROLE, address1, {
from: admin
Expand All @@ -84,11 +84,11 @@ function AuthorizationModuleSetAuthorizationEngineCommon(admin, address1, author
(await this.cmtat.hasRole(DEFAULT_ADMIN_ROLE, address1)).should.equal(false)
})

// Mock
it('testCannotRevokeAdminIfNotAuthorizedByTheEngine', async function () {
// Mock
it('testCannotRevokeAdminIfNotAuthorizedByTheEngine', async function () {
// Arrange
await this.cmtat.setAuthorizationEngine(this.authorizationEngineMock.address, { from: admin })
await this.authorizationEngineMock.setRevokeAdminRoleAuthorized(false);
await this.authorizationEngineMock.setRevokeAdminRoleAuthorized(false)
// Act
await expectRevertCustomError(
this.cmtat.revokeRole(DEFAULT_ADMIN_ROLE, address1, {
Expand Down
19 changes: 9 additions & 10 deletions test/common/ERC20BurnModuleCommon.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,9 @@ function ERC20BurnModuleCommon (admin, address1, address2, address3) {
const AMOUNT_TO_MINT = BN(15)
await this.cmtat.grantRole(BURNER_ROLE, address2, { from: admin })
await this.cmtat.grantRole(MINTER_ROLE, address2, { from: admin })
//await this.cmtat.approve(address2, 50, { from: address1 })
// await this.cmtat.approve(address2, 50, { from: address1 })
// Act
this.logs = await this.cmtat.burnAndMint(address1, address3, AMOUNT_TO_BURN, AMOUNT_TO_MINT, "recovery", { from: address2 })
this.logs = await this.cmtat.burnAndMint(address1, address3, AMOUNT_TO_BURN, AMOUNT_TO_MINT, 'recovery', { from: address2 })
// Assert
expectEvent(this.logs, 'Transfer', {
from: address1,
Expand All @@ -197,12 +197,12 @@ function ERC20BurnModuleCommon (admin, address1, address2, address3) {
to: address3,
value: AMOUNT_TO_MINT
})

expectEvent(this.logs, 'Burn', {
owner: address1,
value: AMOUNT_TO_BURN,
reason: "recovery"
});
reason: 'recovery'
})

expectEvent(this.logs, 'Mint', {
account: address3,
Expand All @@ -218,10 +218,10 @@ function ERC20BurnModuleCommon (admin, address1, address2, address3) {
const AMOUNT_TO_BURN = BN(20)
const AMOUNT_TO_MINT = BN(15)
await this.cmtat.grantRole(BURNER_ROLE, address2, { from: admin })
//await this.cmtat.approve(address2, 50, { from: address1 })
// await this.cmtat.approve(address2, 50, { from: address1 })
// Act
await expectRevertCustomError(
this.cmtat.burnAndMint(address1, address3, AMOUNT_TO_BURN, AMOUNT_TO_MINT, "recovery", { from: address2 }),
this.cmtat.burnAndMint(address1, address3, AMOUNT_TO_BURN, AMOUNT_TO_MINT, 'recovery', { from: address2 }),
'AccessControlUnauthorizedAccount',
[address2, MINTER_ROLE])
})
Expand All @@ -231,16 +231,15 @@ function ERC20BurnModuleCommon (admin, address1, address2, address3) {
const AMOUNT_TO_BURN = BN(20)
const AMOUNT_TO_MINT = BN(15)
await this.cmtat.grantRole(MINTER_ROLE, address2, { from: admin })
//await this.cmtat.approve(address2, 50, { from: address1 })
// await this.cmtat.approve(address2, 50, { from: address1 })
// Assert
await expectRevertCustomError(
this.cmtat.burnAndMint(address1, address3, AMOUNT_TO_BURN, AMOUNT_TO_MINT, "recovery", { from: address2 }),
this.cmtat.burnAndMint(address1, address3, AMOUNT_TO_BURN, AMOUNT_TO_MINT, 'recovery', { from: address2 }),
'AccessControlUnauthorizedAccount',
[address2, BURNER_ROLE])
})
})


context('burnBatch', function () {
const REASON = 'BURN_TEST'
const TOKEN_HOLDER = [admin, address1, address2]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,13 @@ async function checkSnapshot (time, totalSupply, addresses, balances) {
).should.be.bignumber.equal(balances[i])
await this.cmtat.getSnapshotInfoBatch(time, addresses[i])
const { 0: ownerBalance, 1: totalSupplyGet } = await this.cmtat.getSnapshotInfoBatch(time, addresses[i])
//const [ownerBalance, totalSupplyGet]
// const [ownerBalance, totalSupplyGet]
ownerBalance.should.be.bignumber.equal(balances[i])
totalSupplyGet.should.be.bignumber.equal(totalSupply)
}
}

async function checkArraySnapshot (snapshots, snapshotsValue) {

for (let i = 0; i < snapshots.length; ++i) {
snapshots[i].should.be.bignumber.equal(snapshotsValue[i])
}
Expand Down
2 changes: 1 addition & 1 deletion test/common/EnforcementModuleCommon.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ function EnforcementModuleCommon (owner, address1, address2, address3) {
from: address2
});
// Assert
(await this.cmtat.frozen(address1)).should.equal(false);
(await this.cmtat.frozen(address1)).should.equal(false)
// emits an Unfreeze event
expectEvent(this.logs, 'Unfreeze', {
enforcer: address2,
Expand Down
4 changes: 2 additions & 2 deletions test/common/PauseModuleCommon.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ function PauseModuleCommon (admin, address1, address2, address3) {
this.logs = await this.cmtat.unpause({ from: address1 });

// Assert
(await this.cmtat.paused()).should.equal(false);
(await this.cmtat.paused()).should.equal(false)
// emits a Unpaused event
expectEvent(this.logs, 'Unpaused', { account: address1 })
// Transfer works
Expand All @@ -104,7 +104,7 @@ function PauseModuleCommon (admin, address1, address2, address3) {
// Act
await this.cmtat.pause({ from: admin });
// Act + Assert
(await this.cmtat.validateTransfer(address1, address2, AMOUNT_TO_TRANSFER) ).should.be.equal(false);
(await this.cmtat.validateTransfer(address1, address2, AMOUNT_TO_TRANSFER)).should.be.equal(false);
// Assert
(
await this.cmtat.detectTransferRestriction(
Expand Down
12 changes: 6 additions & 6 deletions test/common/ValidationModule/ValidationModuleCommon.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function ValidationModuleCommon (
(
await this.cmtat.detectTransferRestriction(address1, address2, 11)
).should.be.bignumber.equal('0');
(await this.cmtat.validateTransfer(address1, address2, 11)).should.be.equal(true)
(await this.cmtat.validateTransfer(address1, address2, 11)).should.be.equal(true)
})

it('testCanReturnMessageValidTransfer', async function () {
Expand All @@ -59,8 +59,8 @@ function ValidationModuleCommon (
)
).should.be.bignumber.equal('10');

(await this.cmtat.validateTransfer(address1, address2, RULE_MOCK_AMOUNT_MAX + 1))
.should.be.equal(false)
(await this.cmtat.validateTransfer(address1, address2, RULE_MOCK_AMOUNT_MAX + 1))
.should.be.equal(false)
})

it('testCanReturnMessageWithAmountTooHigh', async function () {
Expand All @@ -80,8 +80,8 @@ function ValidationModuleCommon (
// ADDRESS1 may transfer tokens to ADDRESS2
it('testCanTransferAllowedByRule', async function () {
const AMOUNT_TO_TRANSFER = 11;
// Act
(await this.cmtat.validateTransfer(address1, address2, AMOUNT_TO_TRANSFER) ).should.be.equal(true)
// Act
(await this.cmtat.validateTransfer(address1, address2, AMOUNT_TO_TRANSFER)).should.be.equal(true)
// Act
await this.cmtat.transfer(address2, AMOUNT_TO_TRANSFER, {
from: address1
Expand All @@ -102,7 +102,7 @@ function ValidationModuleCommon (
it('testCannotTransferIfNotAllowedByRule', async function () {
const AMOUNT_TO_TRANSFER = RULE_MOCK_AMOUNT_MAX + 1;
// Act
(await this.cmtat.validateTransfer(address1, address2, AMOUNT_TO_TRANSFER) ).should.be.equal(false)
(await this.cmtat.validateTransfer(address1, address2, AMOUNT_TO_TRANSFER)).should.be.equal(false)
// Act
await expectRevertCustomError(
this.cmtat.transfer(address2, AMOUNT_TO_TRANSFER, { from: address1 }),
Expand Down
2 changes: 1 addition & 1 deletion test/deployment/deployment.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,4 @@ contract('CMTAT - Deployment', function ([_], deployer, address1, address2) {
[]
)
})
})
})
7 changes: 3 additions & 4 deletions test/proxy/general/Beacon.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,13 @@ contract(

context('FactoryDeployment', function () {
it('testCanReturnTheRightImplementation', async function () {
// Act + Assert
// Act + Assert
(await this.FACTORY.implementation()).should.equal(this.CMTAT_PROXY_IMPL.address)
})

})

context('Deploy CMTAT with Factory', function () {
it('testCannotBeDeployedByAttacker', async function () {
it('testCannotBeDeployedByAttacker', async function () {
// Act
await expectRevertCustomError(
this.FACTORY.deployCMTAT(
Expand Down Expand Up @@ -67,7 +66,7 @@ contract(
(this.logs.logs[1].args[1]).should.be.bignumber.equal(BN(0))
// Assert
const CMTAT_ADDRESS = this.logs.logs[1].args[0];
//Check address with ID
// Check address with ID
(await this.FACTORY.getAddress(0)).should.equal(CMTAT_ADDRESS)
const CMTAT_TRUFFLE = await CMTAT.at(CMTAT_ADDRESS)
// Act + Assert
Expand Down
9 changes: 5 additions & 4 deletions test/proxy/general/Transparent.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const CMTAT = artifacts.require('CMTAT_PROXY')
const { DEFAULT_ADMIN_ROLE, PAUSER_ROLE, CMTAT_DEPLOYER_ROLE } = require('../../utils.js')
const { ZERO_ADDRESS } = require('../../utils.js')
const DECIMAL = 0
const { deployCMTATProxy, DEPLOYMENT_FLAG, deployCMTATProxyImplementation, } = require('../../deploymentUtils.js')
const { deployCMTATProxy, DEPLOYMENT_FLAG, deployCMTATProxyImplementation } = require('../../deploymentUtils.js')
const { upgrades } = require('hardhat')
const DEPLOYMENT_DECIMAL = 0
const { BN, expectEvent } = require('@openzeppelin/test-helpers')
Expand All @@ -22,7 +22,7 @@ contract(

context('FactoryDeployment', function () {
it('testCanReturnTheRightImplementation', async function () {
// Act + Assert
// Act + Assert
(await this.FACTORY.logic()).should.equal(this.CMTAT_PROXY_IMPL.address)
})
})
Expand All @@ -45,7 +45,8 @@ contract(
DEPLOYMENT_FLAG, { from: attacker }),
'AccessControlUnauthorizedAccount',
[attacker, CMTAT_DEPLOYER_ROLE]
)})
)
})
// Here the argument to indicate if it is deployed with a proxy, set at false by the attacker
it('testCanDeployCMTATWithFactory', async function () {
// Act
Expand All @@ -67,7 +68,7 @@ contract(
// Check Id
(this.logs.logs[1].args[1]).should.be.bignumber.equal(BN(0))
const CMTAT_ADDRESS = this.logs.logs[1].args[0];
//Check address with ID
// Check address with ID
(await this.FACTORY.getAddress(0)).should.equal(CMTAT_ADDRESS)
const CMTAT_TRUFFLE = await CMTAT.at(CMTAT_ADDRESS)
await CMTAT_TRUFFLE.mint(admin, 100, {
Expand Down

0 comments on commit c932d12

Please sign in to comment.