Skip to content

Commit

Permalink
Update tests to work with hardhat
Browse files Browse the repository at this point in the history
  • Loading branch information
rya-sge committed Jul 31, 2024
1 parent 689dbc6 commit 2749325
Show file tree
Hide file tree
Showing 43 changed files with 1,129 additions and 2,847 deletions.
2 changes: 1 addition & 1 deletion contracts/deployment/CMTAT_BEACON_FACTORY.sol
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ contract CMTAT_BEACON_FACTORY is AccessControl {
* @notice get CMTAT proxy address
*
*/
function getAddress(uint256 cmtatID_) external view returns (address) {
function getCMTATAddress(uint256 cmtatID_) external view returns (address) {
return cmtats[cmtatID_];
}

Expand Down
2 changes: 1 addition & 1 deletion hardhat.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require("hardhat-contract-sizer");
require("@nomicfoundation/hardhat-chai-matchers")
module.exports = {
solidity: {
version: '0.8.24',
version: '0.8.26',
settings: {
optimizer: {
enabled: true,
Expand Down
2,768 changes: 574 additions & 2,194 deletions package-lock.json

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"test:base": "npx hardhat test test/standard/modules/BaseModule.test.js test/proxy/modules/BaseModule.test.js",
"test:pause": "npx hardhat test test/standard/modules/PauseModule.test.js test/proxy/modules/PauseModule.test.js",
"test:creditEvents": "npx hardhat test test/standard/modules/CreditEventsModule.test.js test/proxy/modules/CreditEventsModule.test.js",
"test:validation": "npx hardhat test test/standard/modules/ValidationModule/ValidationModule.test.js",
"test:validation": "npx hardhat test test/standard/modules/ValidationModule/ValidationModule.test.js test/proxy/modules/ValidationModule/ValidationModule.test.js test/standard/modules/ValidationModule/ValidationModuleConstructor.test.js test/proxy/modules/ValidationModule/ValidationModuleConstructor.test.js test/standard/modules/ValidationModule/ValidationModuleSetRuleEngine.test.js test/proxy/modules/ValidationModule/ValidationModuleSetRuleEngine.test.js",
"test:authorization": "npx hardhat test test/standard/modules/AuthorizationModule/AuthorizationModule.test.js test/proxy/modules/AuthorizationModule/AuthorizationModule.test.js",
"test:snapshot": "npx hardhat test test/standard/modules/ERC20SnapshotModule.test.js test/proxy/modules/ERC20SnapshotModule.test.js",
"test:enforcement": "npx hardhat test test/standard/modules/EnforcementModule.test.js test/proxy/modules/EnforcementModule.test.js",
Expand Down Expand Up @@ -64,8 +64,6 @@
"devDependencies": {
"@nomicfoundation/hardhat-chai-matchers": "^2.0.7",
"@nomicfoundation/hardhat-network-helpers": "^1.0.11",
"@nomiclabs/hardhat-truffle5": "^2.0.7",
"@nomiclabs/hardhat-web3": "^2.0.0",
"@openzeppelin/hardhat-upgrades": "^3.2.0",
"@openzeppelin/test-helpers": "^0.5.16",
"chai": "^4.3.7",
Expand All @@ -82,6 +80,7 @@
"ethereumjs-util": "^7.1.5",
"ethjs-abi": "^0.2.1",
"ethlint": "^1.2.5",
"hardhat": "^2.22.7",
"hardhat-contract-sizer": "^2.10.0",
"hardhat-gas-reporter": "^1.0.9",
"keccak256": "^1.0.6",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function AuthorizationModuleSetAuthorizationEngineCommon () {
it('testCanBeSetByAdminIfNotAlreadySet', async function () {
// Act
this.logs = await this.cmtat.connect(this.admin).setAuthorizationEngine(
this.authorizationEngineMock
this.authorizationEngineMock.target
)
// Assert
// emits a AuthorizationEngin event
Expand All @@ -20,12 +20,12 @@ function AuthorizationModuleSetAuthorizationEngineCommon () {
it('testCannotBeSetByAdminIfAlreadySet', async function () {
// Arrange
await this.cmtat.connect(this.admin).setAuthorizationEngine(
this.authorizationEngineMock
this.authorizationEngineMock.target
)
// Act
await expectRevertCustomError(
this.cmtat.connect(this.admin).setAuthorizationEngine(
this.authorizationEngineMock
this.authorizationEngineMock.target
),
'CMTAT_AuthorizationModule_AuthorizationEngineAlreadySet',
[]
Expand All @@ -36,7 +36,7 @@ function AuthorizationModuleSetAuthorizationEngineCommon () {
// Act
await expectRevertCustomError(
this.cmtat.connect(this.address1).setAuthorizationEngine(
this.authorizationEngineMock
this.authorizationEngineMock.target
),
'AccessControlUnauthorizedAccount',
[this.address1.address, DEFAULT_ADMIN_ROLE]
Expand All @@ -49,12 +49,12 @@ function AuthorizationModuleSetAuthorizationEngineCommon () {
await this.authorizationEngineMock.authorizeAdminChange(this.address1)
// Act
await this.cmtat.connect(this.admin).setAuthorizationEngine(
this.authorizationEngineMock.address
this.authorizationEngineMock.target
)
// Assert
this.logs = await this.cmtat.connect(this.admin).grantRole(DEFAULT_ADMIN_ROLE, this.address1);
// Assert
(await this.cmtat.hasRole(DEFAULT_ADMIN_ROLE, this.address1)).to.equal(
expect(await this.cmtat.hasRole(DEFAULT_ADMIN_ROLE, this.address1)).to.equal(
true
)
})
Expand All @@ -63,7 +63,7 @@ function AuthorizationModuleSetAuthorizationEngineCommon () {
it('testCannotTransferAdminIfNotAuthorizedByTheEngine', async function () {
// Arrange
await this.cmtat.connect(this.admin).setAuthorizationEngine(
this.authorizationEngineMock
this.authorizationEngineMock.target
)
// Act
await expectRevertCustomError(
Expand All @@ -78,7 +78,7 @@ function AuthorizationModuleSetAuthorizationEngineCommon () {
await this.authorizationEngineMock.authorizeAdminChange(this.address1)
// Act
await this.cmtat.connect(this.admin).setAuthorizationEngine(
this.authorizationEngineMock
this.authorizationEngineMock.target
)
// Assert
this.logs = await this.cmtat.connect(this.admin).revokeRole(DEFAULT_ADMIN_ROLE, this.address1);
Expand All @@ -92,7 +92,7 @@ function AuthorizationModuleSetAuthorizationEngineCommon () {
it('testCannotRevokeAdminIfNotAuthorizedByTheEngine', async function () {
// Arrange
await this.cmtat.connect(this.admin).setAuthorizationEngine(
this.authorizationEngineMock
this.authorizationEngineMock.target
)
await this.authorizationEngineMock.setRevokeAdminRoleAuthorized(false)
// Act
Expand Down
4 changes: 2 additions & 2 deletions test/common/ERC20MintModuleCommon.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ function ERC20MintModuleCommon() {
const TOKEN_SUPPLY_BY_HOLDERS = [10n, 100n, 1000n];

/**
The admin is assigned the MINTER role when the contract is deployed
*/
* The admin is assigned the MINTER role when the contract is deployed
*/
it("testCanBeMintedBatchByAdmin", async function () {
const TOKEN_HOLDER = [this.admin, this.address1, this.address2];
// Arrange - Assert
Expand Down
101 changes: 0 additions & 101 deletions test/common/MetaTxModuleCommon.js

This file was deleted.

145 changes: 145 additions & 0 deletions test/common/MetaTxModuleCommonOld
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
const helpers = require('@nomicfoundation/hardhat-network-helpers');
const {
getDomain,
domainType,
ForwardRequest,
} = require('../../openzeppelin-contracts-upgradeable/test/helpers/eip712')
/*const {
time
} = require('../../openzeppelin-contracts-upgradeable/test/helpers/time')*/
const { expect } = require('chai')
const { waffle} = require("hardhat");
function MetaTxModuleCommon (owner, address1) {
context('Transferring without paying gas', function () {
const AMOUNT_TO_TRANSFER = 11n
const ADDRESS1_INITIAL_BALANCE = 31n
const ADDRESS2_INITIAL_BALANCE = 32n

beforeEach(async function () {
//this.aliceWallet = ethers.Wallet.createRandom()
//this.address1 = this.aliceWallet.address

this.domain = await getDomain(this.forwarder)
/*ForwardRequest = {
from: 'address',
to: 'address',
value: 'uint256',
gas: 'uint256',
nonce: 'uint256',
deadline: 'uint48',
data: 'bytes',
};*/
//this.types = { ForwardRequest };
//this.types = { ForwardRequest };
/*this.types = {
EIP712Domain: domainType(this.domain),
ForwardRequest: [
{ name: 'from', type: 'address' },
{ name: 'to', type: 'address' },
{ name: 'value', type: 'uint256' },
{ name: 'gas', type: 'uint256' },
{ name: 'nonce', type: 'uint256' },
{ name: 'deadline', type: 'uint48' },
{ name: 'data', type: 'bytes' }
]
}*/
this.types = {
ForwardRequest: [
{ name: 'from', type: 'address' },
{ name: 'to', type: 'address' },
{ name: 'value', type: 'uint256' },
{ name: 'gas', type: 'uint256' },
{ name: 'nonce', type: 'uint256' },
{ name: 'deadline', type: 'uint48' },
{ name: 'data', type: 'bytes' }
]
}
await this.cmtat.connect(this.admin).mint(this.address1, ADDRESS1_INITIAL_BALANCE)
await this.cmtat.connect(this.admin).mint(this.address2, ADDRESS2_INITIAL_BALANCE);
expect(await this.cmtat.balanceOf(this.address1)).to.equal(
ADDRESS1_INITIAL_BALANCE
)
//this.timestamp = await time.latest()
/*const data = this.cmtat.ADDRESS2_INITIAL_BALANCE
.transfer(address1, AMOUNT_TO_TRANSFER)
.encodeABI()*/
this.data = this.cmtat.transfer.populateTransaction(this.address2, AMOUNT_TO_TRANSFER).data
this.request = {
from: this.address1.address,
to: this.cmtat.address,
value: 0n,
gas: 100000n,
data:this.data,
deadline: this.timestamp + 180,
nonce: (await this.forwarder.nonces(this.address1)),
...{}// 3 minute
}
/*this.requestData = {
...this.request,
nonce: (await this.forwarder.nonces(this.address1)).toString()
}*/

/*this.forgeData = (request) => ({
types: this.types,
domain: this.domain,
primaryType: 'ForwardRequest',
message: { ...this.requestData, ...request }

})*/
//const [sender, refundReceiver, another, ...accounts] = await ethers.getSigners();


/*this.sign = (privateKey, request) =>
ethSigUtil.signTypedMessage(privateKey, {
data: this.forgeData(request)
})*/

//this.requestData.signature = this.sign(this.aliceWallet.getPrivateKey())
this.forgeRequest = async (override = {}, signer = this.address1) => {
const req = {
from: await signer.getAddress(),
to: this.cmtat.address,
value: 0n,
data: this.data,
gas: 100000n,
deadline: (await helpers.time.latest()) + 60,
nonce: await this.forwarder.nonces(this.address1),
...override,
};
//req.signature = await signer.signTypedData(this.domain, this.types, req);
return req;
};
})

it('returns true without altering the nonce', async function () {
/*expect(
await this.forwarder.nonces(this.requestData.from)
).to.equal(web3.utils.toBN(this.requestData.nonce))
expect(await this.forwarder.verify(this.requestData)).to.be.equal(true)
expect(
await this.forwarder.nonces(this.requestData.from)
).to.equal(web3.utils.toBN(this.requestData.nonce))*/
})

it('can send a transfer transaction without paying gas', async function () {
// TODO : code for the new version of the library, it doesn't compile
// const sign = ethSigUtil.signTypedData( {privateKey : this.wallet.getPrivateKey(), data: { ...this.data, message: req }, version : 'V4'});
const provider = await ethers.getDefaultProvider();;
const balanceEtherBefore = await provider.getBalance(this.address1);
expect(await this.cmtat.balanceOf(this.address1)).to.equal(
ADDRESS1_INITIAL_BALANCE
)
const request = await this.forgeRequest();
//await this.forwarder.execute(request);
/*expect(await this.cmtat.balanceOf(this.address1)).to.equal(
ADDRESS1_INITIAL_BALANCE - AMOUNT_TO_TRANSFER
);
expect(await this.cmtat.balanceOf(this.address2)).to.equal(
ADDRESS2_INITIAL_BALANCE + AMOUNT_TO_TRANSFER
)
const balanceAfter = await ethers.getBalance(this.address1)
expect(balanceEtherBefore).to.equal(balanceAfter)*/
})
})
}
module.exports = MetaTxModuleCommon
Loading

0 comments on commit 2749325

Please sign in to comment.