Skip to content

Commit

Permalink
Update snapshot test
Browse files Browse the repository at this point in the history
  • Loading branch information
rya-sge committed Jul 30, 2024
1 parent fa23b90 commit 689dbc6
Show file tree
Hide file tree
Showing 16 changed files with 280 additions and 330 deletions.
6 changes: 1 addition & 5 deletions contracts/modules/CMTAT_BASE.sol
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ abstract contract CMTAT_BASE is
ValidationModule,
MetaTxModule,
ERC20BaseModule,
ERC20SnapshotModule,
DebtBaseModule,
CreditEventsModule
ERC20SnapshotModule
{
/**
* @notice
Expand Down Expand Up @@ -137,8 +135,6 @@ abstract contract CMTAT_BASE is


/* Other modules */
__DebtBaseModule_init_unchained();
__CreditEvents_init_unchained();
__Base_init_unchained(tokenId_, terms_, information_, flag_);

/* own function */
Expand Down
16 changes: 8 additions & 8 deletions test/common/AuthorizationModule/AuthorizationModuleCommon.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function AuthorizationModuleCommon () {
// Act
this.logs = await this.cmtat.connect(this.admin).grantRole(PAUSER_ROLE, this.address1);
// Assert
(await this.cmtat.hasRole(PAUSER_ROLE, this.address1)).should.equal(true)
expect(await this.cmtat.hasRole(PAUSER_ROLE, this.address1)).to.equal(true)
// emits a RoleGranted event
await expect(this.logs).to.emit(this.cmtat, 'RoleGranted').withArgs( PAUSER_ROLE, this.address1, this.admin);
})
Expand All @@ -22,11 +22,11 @@ function AuthorizationModuleCommon () {
// Arrange
await this.cmtat.connect(this.admin).grantRole(PAUSER_ROLE, this.address1);
// Arrange - Assert
(await this.cmtat.hasRole(PAUSER_ROLE, this.address1)).should.equal(true)
expect(await this.cmtat.hasRole(PAUSER_ROLE, this.address1)).to.equal(true)
// Act
this.logs = await this.cmtat.connect(this.admin).revokeRole(PAUSER_ROLE, this.address1);
// Assert
(await this.cmtat.hasRole(PAUSER_ROLE, this.address1)).should.equal(false)
expect(await this.cmtat.hasRole(PAUSER_ROLE, this.address1)).to.equal(false)
// emits a RoleRevoked event
await expect(this.logs).to.emit(this.cmtat, 'RoleRevoked').withArgs( PAUSER_ROLE, this.address1, this.admin);
})
Expand All @@ -36,34 +36,34 @@ function AuthorizationModuleCommon () {
*/
it('testCannotNonAdminGrantRole', async function () {
// Arrange - Assert
(await this.cmtat.hasRole(PAUSER_ROLE, this.address1)).should.equal(false)
expect(await this.cmtat.hasRole(PAUSER_ROLE, this.address1)).to.equal(false)
// Act
await expectRevertCustomError(
this.cmtat.connect(this.address2).grantRole(PAUSER_ROLE, this.address1),
'AccessControlUnauthorizedAccount',
[this.address2.address, DEFAULT_ADMIN_ROLE]
);
// Assert
(await this.cmtat.hasRole(PAUSER_ROLE, this.address1)).should.equal(false)
expect(await this.cmtat.hasRole(PAUSER_ROLE, this.address1)).to.equal(false)
})

/*
Already tested by OpenZeppelin library
*/
it('testCannotNonAdminRevokeRole', async function () {
// Arrange
(await this.cmtat.hasRole(PAUSER_ROLE, this.address1)).should.equal(false)
expect(await this.cmtat.hasRole(PAUSER_ROLE, this.address1)).to.equal(false)
await this.cmtat.connect(this.admin).grantRole(PAUSER_ROLE, this.address1);
// Arrange - Assert
(await this.cmtat.hasRole(PAUSER_ROLE, this.address1)).should.equal(true)
expect(await this.cmtat.hasRole(PAUSER_ROLE, this.address1)).to.equal(true)
// Act
await expectRevertCustomError(
this.cmtat.connect(this.address2).revokeRole(PAUSER_ROLE, this.address1),
'AccessControlUnauthorizedAccount',
[this.address2.address, DEFAULT_ADMIN_ROLE]
);
// Assert
(await this.cmtat.hasRole(PAUSER_ROLE, this.address1)).should.equal(true)
expect(await this.cmtat.hasRole(PAUSER_ROLE, this.address1)).to.equal(true)
})
})
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,37 +1,31 @@
const { expectEvent } = require('@openzeppelin/test-helpers')
const { expect } = require('chai');
const {
expectRevertCustomError
} = require('../../../openzeppelin-contracts-upgradeable/test/helpers/customError.js')
const { DEFAULT_ADMIN_ROLE } = require('../../utils.js')
const { should } = require('chai').should()

function AuthorizationModuleSetAuthorizationEngineCommon (
admin,
address1,
authorizationEngine
) {
function AuthorizationModuleSetAuthorizationEngineCommon () {
context('AuthorizationEngineSetTest', function () {
it('testCanBeSetByAdminIfNotAlreadySet', async function () {
// Act
this.logs = await this.cmtat.connect(this.admin).setAuthorizationEngine(
this.authorizationEngineMock.address
this.authorizationEngineMock
)
// Assert
// emits a RuleEngineSet event
expectEvent(this.logs, 'AuthorizationEngine', {
newAuthorizationEngine: this.authorizationEngineMock.address
})
// emits a AuthorizationEngin event
await expect(this.logs).to.emit(this.cmtat, 'AuthorizationEngine').withArgs(
this.authorizationEngineMock);
})

it('testCannotBeSetByAdminIfAlreadySet', async function () {
// Arrange
await this.cmtat.connect(this.admin).setAuthorizationEngine(
this.authorizationEngineMock.address
this.authorizationEngineMock
)
// Act
await expectRevertCustomError(
this.cmtat.connect(this.admin).setAuthorizationEngine(
this.authorizationEngineMock.address
this.authorizationEngineMock
),
'CMTAT_AuthorizationModule_AuthorizationEngineAlreadySet',
[]
Expand All @@ -41,27 +35,26 @@ function AuthorizationModuleSetAuthorizationEngineCommon (
it('testCannotNonAdminSetAuthorizationEngine', async function () {
// Act
await expectRevertCustomError(
this.cmtat.setAuthorizationEngine(
this.authorizationEngineMock.address,
{ from: address1 }
this.cmtat.connect(this.address1).setAuthorizationEngine(
this.authorizationEngineMock
),
'AccessControlUnauthorizedAccount',
[address1, DEFAULT_ADMIN_ROLE]
[this.address1.address, DEFAULT_ADMIN_ROLE]
)
})

// Mock
it('testCanTransferAdminIfAuthorizedByTheEngine', async function () {
// Arrange
await this.authorizationEngineMock.authorizeAdminChange(address1)
await this.authorizationEngineMock.authorizeAdminChange(this.address1)
// Act
await this.cmtat.connect(this.admin).setAuthorizationEngine(
this.authorizationEngineMock.address
)
// Assert
this.logs = await this.cmtat.connect(this.admin).grantRole(DEFAULT_ADMIN_ROLE, address1);
this.logs = await this.cmtat.connect(this.admin).grantRole(DEFAULT_ADMIN_ROLE, this.address1);
// Assert
(await this.cmtat.hasRole(DEFAULT_ADMIN_ROLE, address1)).should.equal(
(await this.cmtat.hasRole(DEFAULT_ADMIN_ROLE, this.address1)).to.equal(
true
)
})
Expand All @@ -70,27 +63,27 @@ function AuthorizationModuleSetAuthorizationEngineCommon (
it('testCannotTransferAdminIfNotAuthorizedByTheEngine', async function () {
// Arrange
await this.cmtat.connect(this.admin).setAuthorizationEngine(
this.authorizationEngineMock.address
this.authorizationEngineMock
)
// Act
await expectRevertCustomError(
this.cmtat.connect(this.admin).grantRole(DEFAULT_ADMIN_ROLE, address1),
this.cmtat.connect(this.admin).grantRole(DEFAULT_ADMIN_ROLE, this.address1),
'CMTAT_AuthorizationModule_InvalidAuthorization',
[]
)
})

it('testCanRevokeAdminIfAuthorizedByTheEngine', async function () {
// Arrange
await this.authorizationEngineMock.authorizeAdminChange(address1)
await this.authorizationEngineMock.authorizeAdminChange(this.address1)
// Act
await this.cmtat.connect(this.admin).setAuthorizationEngine(
this.authorizationEngineMock.address
this.authorizationEngineMock
)
// Assert
this.logs = await this.cmtat.connect(this.admin).revokeRole(DEFAULT_ADMIN_ROLE, address1);
this.logs = await this.cmtat.connect(this.admin).revokeRole(DEFAULT_ADMIN_ROLE, this.address1);
// Assert
(await this.cmtat.hasRole(DEFAULT_ADMIN_ROLE, address1)).should.equal(
expect(await this.cmtat.hasRole(DEFAULT_ADMIN_ROLE, this.address1)).to.equal(
false
)
})
Expand All @@ -99,12 +92,12 @@ function AuthorizationModuleSetAuthorizationEngineCommon (
it('testCannotRevokeAdminIfNotAuthorizedByTheEngine', async function () {
// Arrange
await this.cmtat.connect(this.admin).setAuthorizationEngine(
this.authorizationEngineMock.address
this.authorizationEngineMock
)
await this.authorizationEngineMock.setRevokeAdminRoleAuthorized(false)
// Act
await expectRevertCustomError(
this.cmtat.connect(this.admin).revokeRole(DEFAULT_ADMIN_ROLE, address1),
this.cmtat.connect(this.admin).revokeRole(DEFAULT_ADMIN_ROLE, this.address1),
'CMTAT_AuthorizationModule_InvalidAuthorization',
[]
)
Expand Down
2 changes: 1 addition & 1 deletion test/common/ERC20MintModuleCommon.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ function ERC20MintModuleCommon() {

expect(await this.cmtat.totalSupply()).to.equal(
TOKEN_SUPPLY_BY_HOLDERS.reduce((a, b) => {
return a+b;
return a + b;
})
);
// Assert event
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { time } = require('@openzeppelin/test-helpers')
const { should } = require('chai').should()
const { time } = require ("@nomicfoundation/hardhat-network-helpers");
const { expect } = require('chai');
const {
checkArraySnapshot
} = require('./ERC20SnapshotModuleUtils/ERC20SnapshotModuleUtils')
Expand All @@ -11,11 +11,11 @@ function ERC20SnapshotModuleCommonGetNextSnapshot () {
})
it('testCanGetAllNextSnapshots', async function () {
// Arrange
this.snapshotTime1 = this.currentTime.add(time.duration.seconds(10))
this.snapshotTime2 = this.currentTime.add(time.duration.seconds(15))
this.snapshotTime3 = this.currentTime.add(time.duration.seconds(20))
this.snapshotTime4 = this.currentTime.add(time.duration.seconds(25))
this.snapshotTime5 = this.currentTime.add(time.duration.seconds(30))
this.snapshotTime1 = this.currentTime + time.duration.seconds(10)
this.snapshotTime2 = this.currentTime + time.duration.seconds(15)
this.snapshotTime3 = this.currentTime + time.duration.seconds(20)
this.snapshotTime4 = this.currentTime + time.duration.seconds(25)
this.snapshotTime5 = this.currentTime + time.duration.seconds(30)
await this.cmtat.connect(this.admin).scheduleSnapshot(this.snapshotTime1)
await this.cmtat.connect(this.admin).scheduleSnapshot(this.snapshotTime2)
await this.cmtat.connect(this.admin).scheduleSnapshot(this.snapshotTime3)
Expand All @@ -24,7 +24,7 @@ function ERC20SnapshotModuleCommonGetNextSnapshot () {
// Act
const snapshots = await this.cmtat.getNextSnapshots()
// Assert
snapshots.length.should.equal(5)
expect(snapshots.length).to.equal(5)
checkArraySnapshot(snapshots, [
this.snapshotTime1,
this.snapshotTime2,
Expand All @@ -47,9 +47,9 @@ function ERC20SnapshotModuleCommonGetNextSnapshot () {
//
it('testCanReturnEmptyArrayIfAllSnapshotsAreInThePast', async function () {
// Arrange
this.snapshotTime1 = this.currentTime.add(time.duration.seconds(2))
this.snapshotTime2 = this.currentTime.add(time.duration.seconds(3))
this.snapshotTime3 = this.currentTime.add(time.duration.seconds(4))
this.snapshotTime1 = this.currentTime + time.duration.seconds(2)
this.snapshotTime2 = this.currentTime + time.duration.seconds(3)
this.snapshotTime3 = this.currentTime + time.duration.seconds(4)
await this.cmtat.connect(this.admin).scheduleSnapshot(this.snapshotTime1)
await this.cmtat.connect(this.admin).scheduleSnapshot(this.snapshotTime2)
await this.cmtat.connect(this.admin).scheduleSnapshot(this.snapshotTime3)
Expand All @@ -58,14 +58,14 @@ function ERC20SnapshotModuleCommonGetNextSnapshot () {
// Act
const snapshots = await this.cmtat.getNextSnapshots()
// Assert
snapshots.length.should.equal(0)
expect(snapshots.length).to.equal(0)
})

it('testCanReturnOnlyFutureSnapshotsIfSomeSnapshotsAreInThePast', async function () {
// Arrange
this.snapshotTime1 = this.currentTime.add(time.duration.seconds(2))
this.snapshotTime2 = this.currentTime.add(time.duration.seconds(20))
this.snapshotTime3 = this.currentTime.add(time.duration.seconds(300))
this.snapshotTime1 = this.currentTime + time.duration.seconds(2)
this.snapshotTime2 = this.currentTime + time.duration.seconds(20)
this.snapshotTime3 = this.currentTime + time.duration.seconds(300)
await this.cmtat.connect(this.admin).scheduleSnapshot(this.snapshotTime1)
// We jump into the future
await time.increase(3)
Expand All @@ -74,10 +74,10 @@ function ERC20SnapshotModuleCommonGetNextSnapshot () {
// Act
const snapshots = await this.cmtat.getNextSnapshots()
// Assert
snapshots.length.should.equal(2)
expect(snapshots.length).to.equal(2)
checkArraySnapshot(snapshots, [this.snapshotTime2, this.snapshotTime3])
snapshots[0].should.be.bignumber.equal(this.snapshotTime2)
snapshots[1].should.be.bignumber.equal(this.snapshotTime3)
expect(snapshots[0]).to.equal(this.snapshotTime2)
expect(snapshots[1]).to.equal(this.snapshotTime3)
})
})
}
Expand Down
Loading

0 comments on commit 689dbc6

Please sign in to comment.