This document provides a detailed description of the test suite created for the MyFirstTokenERC20RWA smart contract. The tests are written using the Hardhat framework, leveraging Ethers v6 and Chai for assertions.
- Framework: Hardhat (
^2.28.6) - Assertions: Mocha / Chai plugin (
@nomicfoundation/hardhat-chai-matchers) - Local Network: Hardhat EVM (target: Cancun)
- Location:
hardhat2/test/MyFirstTokenERC20RWA.test.js
The test cases comprehensively check the access control integration and standard OpenZeppelin community extensions logic. The coverage reaches extensive limits with an automated 93.75% statement coverage.
- Name and Symbol Verification: Asserts that the deployed token correctly initializes its fundamental metadata (
MyFirstTokenERC20RWA/1stRWA). - Roles Initialization: Grants and verifies all Access Control Roles initially granted to the specific initialization accounts (
DEFAULT_ADMIN_ROLE,PAUSER_ROLE,MINTER_ROLE,FREEZER_ROLE,LIMITER_ROLE,RECOVERY_ROLE).
- Authorized Minting: Validates that an account strictly with the
MINTER_ROLEcan invokemint()and distribute new tokens to users securely, verifying theTransferevent and target balances. - Unauthorized Minting: Confirms that if a regular user tries to call
mint(), the transaction reverts precisely with anAccessControlUnauthorizedAccountcustom error.
- Pause & Unpause Cycle: Verifies that an account with
PAUSER_ROLEcan toggle the global paused state of the contract by emitting the correspondingPausedandUnpausedevents. - Enforced Transfer Blocks: Evaluates whether token transfers appropriately abort with the standard
EnforcedPausecustom error while the token is actively suspended.
- State Immobilization: Confirms that an address with the
FREEZER_ROLEis permitted to restrict a certain numerical amount of a specific user’s wallet (via thefreeze()mechanism). - Balance Lock Logic: Demonstrates that attempting to transfer a volume of tokens that falls exclusively into the frozen threshold correctly prevents the action and reverts the transaction. Unfrozen balances, however, can remain active.
- State Reporting: Monitors the state behavior of
allowUseranddisallowUserinteractions made by the designatedLIMITER_ROLE. - Inherited Contract Behavior Check: Confirms that checking
isUserAllowed(address)correctly assesses whether the address state was manually flipped totrue(Allowed) or stays in its defaultfalsearrangement. The implementation contract includes acanTransactoverwrite that enforces the allowlist; this section verifies that token transfers revert if the sender is not explicitly allowed, ensuring the RWA restriction logic is active.
- Emergency Override: Vouchsafes the execution capabilities of an administrator holding the elite
RECOVERY_ROLE. - Allowance Bypass Assessment: Asserts that this specific role can initiate a
forcedTransfer(from, to, amount)safely pulling assets directly without requiring standard allowance grants (approve) from the original holder, successfully depositing them into a given target wallet.
Ensure you operate inside the hardhat2 project directory correctly installed.
To comfortably execute the full comprehensive suite, use:
npx hardhat test test/MyFirstTokenERC20RWA.test.jsTo run a deep code coverage analysis test on this document, use:
npx hardhat coverage --testfiles test/MyFirstTokenERC20RWA.test.js