Skip to content

Conversation

@blueogin
Copy link
Collaborator

Description

Added a GenericDistributionHelper XDC-fork test to verify that swapping G$ to XDC through xswap is working correctly.

About # (link your issue here)

How Has This Been Tested?

Please describe the tests that you ran to verify your changes.

Checklist:

  • PR title matches follow: (Feature|Bug|Chore) Task Name
  • My code follows the style guidelines of this project
  • I have followed all the instructions described in the initial task (check Definitions of Done)
  • I have performed a self-review of my own code
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have added reference to a related issue in the repository
  • I have added a detailed description of the changes proposed in the pull request. I am as descriptive as possible, assisting reviewers as much as possible.
  • I have added screenshots related to my pull request (for frontend tasks)
  • I have pasted a gif showing the feature.
  • @mentions of the person or team responsible for reviewing proposed changes

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey there - I've reviewed your changes and they look great!

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location> `test/reserve/GenericDistributionHelper.e2e.test.ts:275-284` </location>
<code_context>
+  it("should correctly calculate swap amounts using XSWAP pools", async function () {
</code_context>

<issue_to_address>
**suggestion (testing):** Missing test for edge cases in calcGDToSell (e.g., zero input, very large input).

Add tests for calcGDToSell with zero and very large G$ inputs to verify correct handling of boundary conditions.
</issue_to_address>

### Comment 2
<location> `test/reserve/GenericDistributionHelper.e2e.test.ts:322-331` </location>
<code_context>
+  it("should handle swap with correct slippage protection", async function () {
</code_context>

<issue_to_address>
**suggestion (testing):** Missing test for slippage exceeding maxSlippage.

Add a test case where slippage exceeds maxSlippage and verify that the swap is reverted, confirming slippage protection works correctly.
</issue_to_address>

### Comment 3
<location> `test/reserve/GenericDistributionHelper.e2e.test.ts:343` </location>
<code_context>
    const maxSlippage = feeSettings.maxSlippage;

</code_context>

<issue_to_address>
**suggestion (code-quality):** Prefer object destructuring when accessing and using properties. ([`use-object-destructuring`](https://docs.sourcery.ai/Reference/Rules-and-In-Line-Suggestions/TypeScript/Default-Rules/use-object-destructuring))

```suggestion
    const {maxSlippage} = feeSettings;
```

<br/><details><summary>Explanation</summary>Object destructuring can often remove an unnecessary temporary reference, as well as making your code more succinct.

From the [Airbnb Javascript Style Guide](https://airbnb.io/javascript/#destructuring--object)
</details>
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@sirpy sirpy force-pushed the feat/fork-test/distribution-with-xswap branch from 71b4c84 to d74faa9 Compare December 24, 2025 09:34
@openzeppelin-code
Copy link

openzeppelin-code bot commented Dec 24, 2025

Add xdc fork test for GenericDistributionHelper

Generated at commit: 6fcd6a8aa966b3ef2d8054206b0ac8e9b2da5a3f

🚨 Report Summary

Severity Level Results
Contracts Critical
High
Medium
Low
Note
Total
3
5
0
16
44
68
Dependencies Critical
High
Medium
Low
Note
Total
0
0
1
0
130
131

For more details view the full report in OpenZeppelin Code Inspector

minReceived: ethers.utils.formatEther(minReceived)
});

expect(quoteWXDC).to.be.equal(minReceived);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why does the quote need to equal minreceived?
also see the AI comment that you arenot testing a case where slippage is larger

Copy link
Collaborator Author

@blueogin blueogin Jan 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because they are using:
Same input: amountToSell (100 G$)
Same path: G$ -> CUSD -> WXDC
Same oracle: STATIC_ORACLE.quoteAllAvailablePoolsWithTimePeriod
Same pools: both use the same G$/CUSD and CUSD/WXDC pools

I will add large slippage test


before(async function () {
await networkHelpers.reset(XDC_RPC_URL);
const chainId = await ethers.provider.getNetwork().then(network => network.chainId);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it should use network.reset to always test on xdc

Copy link
Collaborator Author

@blueogin blueogin Jan 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not working with "hardhat test".
I tried with another hardhat version(2.28.3 - the one which is used mostly) but it still shows the same err (Error: Storage overrides are not supported for forked blocks yet. See NomicFoundation/edr#911)

I ran the tests against an XDC fork, and all tests passed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i've downgraded hardhat and it works.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I thought the same
Thanks you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants