Repository navigation
Restore missing Transfer event emission test - #9
creatingfire2026 with Copilot wants to merge 6 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR aims to restore a missing Hardhat test that validates ERC-20 Transfer event emission during token deployment, but it also includes broader token rebranding and deployment-default updates.
Changes:
- Adds (restores) a deployment test intended to validate mint
Transferemission. - Updates token name/symbol across contract, tests, docs, and package metadata.
- Updates the default deployment recipient address in the deploy script and README.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| test/ERC20_Token_Sample.test.js | Updates metadata assertions and adds a deployment-time event emission test. |
| contracts/ERC20_Token_Sample.sol | Changes ERC-20 name/symbol and updates NatSpec title. |
| scripts/deploy.js | Updates the hardcoded default initial recipient address. |
| README.md | Rebrands token name/symbol and updates example recipient address. |
| package.json | Updates package name/description to match the new token branding. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
@copilot Fix the code for all comments in this review thread. When a review comment includes a suggested change, apply the suggestion exactly. Do not make changes beyond what is described in the linked review thread. |
Updated the deployment test to use Hardhat chai matchers with |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
Suppressed comments (1)
test/ERC20_Token_Sample.test.js:50
Token.deploy(...)resolves to a deployed contract instance, not a transaction, so passing it directly toexpect(...).to.emit(...)is unlikely to work reliably. Assert against the deployment transaction (deploymentTransaction()) and use the deployed contract instance for event decoding.
const Token = await ethers.getContractFactory("ERC20_Token_Sample");
await expect(Token.deploy(recipient.address))
.to.emit(Token, "Transfer")
.withArgs(ethers.ZeroAddress, recipient.address, INITIAL_SUPPLY);
});
| it("emits the standard mint Transfer event for the recipient", async function () { | ||
| const Token = await ethers.getContractFactory("ERC20_Token_Sample"); | ||
| await expect(Token.deploy(recipient.address)) | ||
| .to.emit(Token, "Transfer") | ||
| .withArgs(ethers.ZeroAddress, recipient.address, INITIAL_SUPPLY); | ||
| }); |
There was a problem hiding this comment.
@copilot Fix the code for this review comment.
When a review comment includes a suggested change, apply the suggestion exactly.
Do not make changes beyond what is described in the linked review comment.
There was a problem hiding this comment.
Fixed in the latest commit. The test now deploys the contract to get the contract instance, then asserts against deployedToken.deploymentTransaction() using deployedToken as the emitter — the correct pattern for ethers v6/Hardhat deployment-time event assertions.
There was a problem hiding this comment.
The Copilot review comment points out a bug in how you are testing an event emitted during your contract's deployment (i.e., inside the constructor) using Hardhat and Ethers.js v6.
What the Comment Means
- Token.deploy(...) returns a contract instance, not a transaction: In Ethers v6, calling .deploy() on a contract factory resolves to the deployed contract object, not a transaction receipt or object.
- Passing the factory instead of the instance: .to.emit(Token, ...) is passing Token (the uninstantiated contract factory) instead of the actual deployed contract object, which prevents Chai matchers from tracking the events correctly.
How to Fix It
To assert against an event that fires during deployment in Ethers v6, you should capture the deployment transaction or use the deployed contract's .deploymentTransaction() method, and pass the deployed instance as the emitter.
Incorrect Pattern (What likely caused the warning):
// Trying to test an event in the constructor
const Token = await ethers.getContractFactory("Token");
await expect(Token.deploy(...)) // Returns instance, not tx
.to.emit(Token, "MyDeploymentEvent"); // Passing factory instead of instance
Correct Pattern:
const Token = await ethers.getContractFactory("Token");
const token = await Token.deploy(...); // Get the deployed contract instance
const deployTx = token.deploymentTransaction(); // Get the deployment transaction
// Assert against the transaction and use the deployed instance as the emitter
await expect(deployTx)
.to.emit(token, "MyDeploymentEvent")
.withArgs(...);
|
@creatingfire2026 Unfortunately I hit an unexpected error while processing your comment. I've automatically reported this to GitHub. You can ask me to try again later by mentioning me in a new comment. If you want to contact GitHub about this error, please mention the following identifier so they can better serve you: Sorry for the inconvenience! |
|
Agreeed done |
…" test Co-authored-by: creatingfire2026 <277700495+creatingfire2026@users.noreply.github.com>
Co-authored-by: creatingfire2026 <277700495+creatingfire2026@users.noreply.github.com>
Co-authored-by: creatingfire2026 <277700495+creatingfire2026@users.noreply.github.com>
Co-authored-by: creatingfire2026 <277700495+creatingfire2026@users.noreply.github.com>
…oyment test Co-authored-by: creatingfire2026 <277700495+creatingfire2026@users.noreply.github.com>
…ymentTransaction() Co-authored-by: creatingfire2026 <277700495+creatingfire2026@users.noreply.github.com>
558dda6 to
f7b5c02
Compare
The Hardhat test suite was failing because the test validating Transfer event emission during contract deployment had been removed. This test is part of the expected CI behavior.
Changes
Restored test in Deployment section: Added the missing test case
"emits the standard mint Transfer event for the recipient"which verifies that deploying the ERC20_Token_Sample contract emits the correct Transfer event from the zero address to the initial recipient.This ensures the contract follows the ERC20 standard by properly emitting Transfer events when minting the initial supply at deployment.