Repository navigation
test(p1): add edge case suite for BasketHandlerP1 uninitialized state #1295
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,43 @@ | ||||||
| import { expect } from "chai"; | ||||||
| import { ethers } from "hardhat"; | ||||||
|
|
||||||
| describe("BasketHandler Edge Cases & Security Audit", function () { | ||||||
| let basketHandler: any; | ||||||
| let basketLib: any; | ||||||
|
|
||||||
| beforeEach(async function () { | ||||||
| const BasketLib = await ethers.getContractFactory("contracts/p1/mixins/BasketLib.sol:BasketLibP1"); | ||||||
| basketLib = await BasketLib.deploy(); | ||||||
| await basketLib.deployed(); | ||||||
|
|
||||||
| const BasketHandler = await ethers.getContractFactory("BasketHandlerP1", { | ||||||
| libraries: { | ||||||
| "contracts/p1/mixins/BasketLib.sol:BasketLibP1": basketLib.address, | ||||||
| }, | ||||||
| }); | ||||||
|
|
||||||
| basketHandler = await BasketHandler.deploy(); | ||||||
| await basketHandler.deployed(); | ||||||
| }); | ||||||
|
|
||||||
| describe("Critical Edge Case Validations", function () { | ||||||
| it("1. Should safely handle unregistered collateral quantity queries", async function () { | ||||||
| const fakeToken = "0x0000000000000000000000000000000000000001"; | ||||||
|
|
||||||
| // Henüz set edilmemiş token için revert yerine güvenli 0 dönmeli veya açık revert mesajı almalı | ||||||
| await expect(basketHandler.quantity(fakeToken)).to.be.reverted; | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win Assert the documented zero result for an unregistered token.
Proposed test correction- await expect(basketHandler.quantity(fakeToken)).to.be.reverted;
+ expect(await basketHandler.quantity(fakeToken)).to.equal(0);📝 Committable suggestion
Suggested change
🧰 Tools🪛 ESLint[error] 28-28: Delete (prettier/prettier) 🤖 Prompt for AI Agents |
||||||
| }); | ||||||
|
|
||||||
| it("2. Should prevent precision loss / zero-division on micro collateral amounts", async function () { | ||||||
| const status = await basketHandler.status(); | ||||||
| expect(status).to.not.be.undefined; | ||||||
|
Comment on lines
+32
to
+33
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win Exercise the division path instead of checking that the call returns. This test creates no collateral and only checks that 🧰 Tools🪛 ESLint[error] 32-32: Delete (prettier/prettier) [error] 33-33: Delete (prettier/prettier) 🤖 Prompt for AI Agents |
||||||
| }); | ||||||
|
|
||||||
| it("3. Should handle uncollateralized status transition safely", async function () { | ||||||
| if (basketHandler.basketsHeld) { | ||||||
| const held = await basketHandler.basketsHeld(); | ||||||
| expect(held).to.equal(0); | ||||||
| } | ||||||
|
Comment on lines
+37
to
+40
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win Trigger the uncollateralized transition before asserting state. The test never changes basket state. It only reads the default 🧰 Tools🪛 ESLint[error] 38-38: Delete (prettier/prettier) [error] 39-39: Delete (prettier/prettier) 🤖 Prompt for AI Agents |
||||||
| }); | ||||||
| }); | ||||||
| }); | ||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: reserve-protocol/protocol
Length of output: 50381
🏁 Script executed:
Repository: reserve-protocol/protocol
Length of output: 13119
Reuse the production proxy fixture
test/Main.test.tsdeploysBasketHandlerP1withupgrades.deployProxy(...)and then callsinit(...). This fixture deploysBasketHandlerP1directly and never callsinit(...), so its peer addresses and initialization state remain unset. Reuse the proxy fixture and initialization path.🧰 Tools
🪛 ESLint
[error] 19-19: Delete
;(prettier/prettier)
[error] 20-20: Delete
;(prettier/prettier)
🤖 Prompt for AI Agents