From 8ae78f05fcd0b39d920cc68a259137146ebba58a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 25 Jul 2026 07:41:57 +0000 Subject: [PATCH 1/2] fix: use getAddress() for signer addresses in test expectations --- test/ERC20_Token_Sample.test.js | 40 ++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/test/ERC20_Token_Sample.test.js b/test/ERC20_Token_Sample.test.js index cc8f5e4..572a6d7 100644 --- a/test/ERC20_Token_Sample.test.js +++ b/test/ERC20_Token_Sample.test.js @@ -46,12 +46,14 @@ describe("ERC20_Token_Sample", function () { describe("Transfers", function () { it("transfers from the explicit recipient", async function () { const amount = ethers.parseUnits("1000", 18); - await expect(token.connect(recipient).transfer(alice.address, amount)) + const recipientAddr = await recipient.getAddress(); + const aliceAddr = await alice.getAddress(); + await expect(token.connect(recipient).transfer(aliceAddr, amount)) .to.emit(token, "Transfer") - .withArgs(recipient.address, alice.address, amount); + .withArgs(recipientAddr, aliceAddr, amount); - expect(await token.balanceOf(alice.address)).to.equal(amount); - expect(await token.balanceOf(recipient.address)).to.equal( + expect(await token.balanceOf(aliceAddr)).to.equal(amount); + expect(await token.balanceOf(recipientAddr)).to.equal( INITIAL_SUPPLY - amount ); }); @@ -91,17 +93,18 @@ describe("ERC20_Token_Sample", function () { describe("burnTokens", function () { it("burns from the caller and reduces supply", async function () { const amount = ethers.parseUnits("500", 18); - await expect(token.connect(recipient).burnTokens(amount)) - .to.emit(token, "TokensBurned") - .withArgs(recipient.address, amount) - .and.to.emit(token, "Transfer") - .withArgs(recipient.address, ethers.ZeroAddress, amount); - - expect(await token.balanceOf(recipient.address)).to.equal( - INITIAL_SUPPLY - amount - ); - expect(await token.totalSupply()).to.equal(INITIAL_SUPPLY - amount); - }); + const recipientAddr = await recipient.getAddress(); + await expect(token.connect(recipient).burnTokens(amount)) + .to.emit(token, "TokensBurned") + .withArgs(recipientAddr, amount) + .and.to.emit(token, "Transfer") + .withArgs(recipientAddr, ethers.ZeroAddress, amount); + + expect(await token.balanceOf(recipientAddr)).to.equal( + INITIAL_SUPPLY - amount + ); + expect(await token.totalSupply()).to.equal(INITIAL_SUPPLY - amount); + }); it("rejects zero and insufficient burn amounts", async function () { await expect( @@ -123,11 +126,12 @@ describe("ERC20_Token_Sample", function () { it("burns approved tokens and consumes allowance", async function () { const supplyBefore = await token.totalSupply(); - await expect(token.connect(bob).burnFrom(alice.address, amount)) + const aliceAddr = await alice.getAddress(); + await expect(token.connect(bob).burnFrom(aliceAddr, amount)) .to.emit(token, "TokensBurned") - .withArgs(alice.address, amount); + .withArgs(aliceAddr, amount); - expect(await token.allowance(alice.address, bob.address)).to.equal(0); + expect(await token.allowance(aliceAddr, await bob.getAddress())).to.equal(0); expect(await token.totalSupply()).to.equal(supplyBefore - amount); }); From 758c96c8329288db7ac394f6247c70b3793d62ab Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 25 Jul 2026 07:43:36 +0000 Subject: [PATCH 2/2] fix: use getAddress() consistently throughout test file for ethers v6 compatibility --- test/ERC20_Token_Sample.test.js | 69 ++++++++++++++++++++------------- 1 file changed, 42 insertions(+), 27 deletions(-) diff --git a/test/ERC20_Token_Sample.test.js b/test/ERC20_Token_Sample.test.js index 572a6d7..c2b53f4 100644 --- a/test/ERC20_Token_Sample.test.js +++ b/test/ERC20_Token_Sample.test.js @@ -13,7 +13,8 @@ describe("ERC20_Token_Sample", function () { "ERC20_Token_Sample", deployer ); - token = await Token.deploy(recipient.address); + const recipientAddr = await recipient.getAddress(); + token = await Token.deploy(recipientAddr); await token.waitForDeployment(); }); @@ -25,13 +26,15 @@ describe("ERC20_Token_Sample", function () { }); it("mints the complete supply to the explicit recipient", async function () { - expect(await token.balanceOf(recipient.address)).to.equal(INITIAL_SUPPLY); + const recipientAddr = await recipient.getAddress(); + expect(await token.balanceOf(recipientAddr)).to.equal(INITIAL_SUPPLY); expect(await token.totalSupply()).to.equal(INITIAL_SUPPLY); expect(await token.INITIAL_SUPPLY()).to.equal(INITIAL_SUPPLY); }); it("does not mint to the deployer", async function () { - expect(await token.balanceOf(deployer.address)).to.equal(0); + const deployerAddr = await deployer.getAddress(); + expect(await token.balanceOf(deployerAddr)).to.equal(0); }); it("rejects the zero-address recipient", async function () { @@ -59,8 +62,10 @@ describe("ERC20_Token_Sample", function () { }); it("reverts for an insufficient balance", async function () { + const aliceAddr = await alice.getAddress(); + const bobAddr = await bob.getAddress(); await expect( - token.connect(alice).transfer(bob.address, ethers.parseUnits("1", 18)) + token.connect(alice).transfer(bobAddr, ethers.parseUnits("1", 18)) ).to.be.reverted; }); }); @@ -68,24 +73,30 @@ describe("ERC20_Token_Sample", function () { describe("Allowances", function () { it("supports approve and transferFrom", async function () { const amount = ethers.parseUnits("100", 18); - await token.connect(recipient).approve(alice.address, amount); + const recipientAddr = await recipient.getAddress(); + const aliceAddr = await alice.getAddress(); + const bobAddr = await bob.getAddress(); + await token.connect(recipient).approve(aliceAddr, amount); expect( - await token.allowance(recipient.address, alice.address) + await token.allowance(recipientAddr, aliceAddr) ).to.equal(amount); await token .connect(alice) - .transferFrom(recipient.address, bob.address, amount); - expect(await token.balanceOf(bob.address)).to.equal(amount); + .transferFrom(recipientAddr, bobAddr, amount); + expect(await token.balanceOf(bobAddr)).to.equal(amount); }); it("reverts when allowance is exceeded", async function () { const amount = ethers.parseUnits("100", 18); - await token.connect(recipient).approve(alice.address, amount); + const recipientAddr = await recipient.getAddress(); + const aliceAddr = await alice.getAddress(); + const bobAddr = await bob.getAddress(); + await token.connect(recipient).approve(aliceAddr, amount); await expect( token .connect(alice) - .transferFrom(recipient.address, bob.address, amount + 1n) + .transferFrom(recipientAddr, bobAddr, amount + 1n) ).to.be.reverted; }); }); @@ -93,18 +104,18 @@ describe("ERC20_Token_Sample", function () { describe("burnTokens", function () { it("burns from the caller and reduces supply", async function () { const amount = ethers.parseUnits("500", 18); - const recipientAddr = await recipient.getAddress(); - await expect(token.connect(recipient).burnTokens(amount)) - .to.emit(token, "TokensBurned") - .withArgs(recipientAddr, amount) - .and.to.emit(token, "Transfer") - .withArgs(recipientAddr, ethers.ZeroAddress, amount); - - expect(await token.balanceOf(recipientAddr)).to.equal( - INITIAL_SUPPLY - amount - ); - expect(await token.totalSupply()).to.equal(INITIAL_SUPPLY - amount); - }); + const recipientAddr = await recipient.getAddress(); + await expect(token.connect(recipient).burnTokens(amount)) + .to.emit(token, "TokensBurned") + .withArgs(recipientAddr, amount) + .and.to.emit(token, "Transfer") + .withArgs(recipientAddr, ethers.ZeroAddress, amount); + + expect(await token.balanceOf(recipientAddr)).to.equal( + INITIAL_SUPPLY - amount + ); + expect(await token.totalSupply()).to.equal(INITIAL_SUPPLY - amount); + }); it("rejects zero and insufficient burn amounts", async function () { await expect( @@ -118,29 +129,33 @@ describe("ERC20_Token_Sample", function () { const amount = ethers.parseUnits("300", 18); beforeEach(async function () { + const aliceAddr = await alice.getAddress(); + const bobAddr = await bob.getAddress(); await token .connect(recipient) - .transfer(alice.address, ethers.parseUnits("1000", 18)); - await token.connect(alice).approve(bob.address, amount); + .transfer(aliceAddr, ethers.parseUnits("1000", 18)); + await token.connect(alice).approve(bobAddr, amount); }); it("burns approved tokens and consumes allowance", async function () { const supplyBefore = await token.totalSupply(); const aliceAddr = await alice.getAddress(); + const bobAddr = await bob.getAddress(); await expect(token.connect(bob).burnFrom(aliceAddr, amount)) .to.emit(token, "TokensBurned") .withArgs(aliceAddr, amount); - expect(await token.allowance(aliceAddr, await bob.getAddress())).to.equal(0); + expect(await token.allowance(aliceAddr, bobAddr)).to.equal(0); expect(await token.totalSupply()).to.equal(supplyBefore - amount); }); it("rejects zero and excessive allowance burns", async function () { + const aliceAddr = await alice.getAddress(); await expect( - token.connect(bob).burnFrom(alice.address, 0) + token.connect(bob).burnFrom(aliceAddr, 0) ).to.be.revertedWithCustomError(token, "ZeroBurnAmount"); await expect( - token.connect(bob).burnFrom(alice.address, amount + 1n) + token.connect(bob).burnFrom(aliceAddr, amount + 1n) ).to.be.reverted; }); });