Skip to content

Commit

Permalink
Make tests less flaky
Browse files Browse the repository at this point in the history
  • Loading branch information
shahthepro committed May 3, 2024
1 parent e88f160 commit e6f9990
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
9 changes: 9 additions & 0 deletions contracts/deploy/mainnet/095_ogn_buyback.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const { isFork } = require("../../test/helpers");
const addresses = require("../../utils/addresses");
const {
deploymentWithGovernanceProposal,
Expand Down Expand Up @@ -46,6 +47,14 @@ module.exports = deploymentWithGovernanceProposal(

await cSwapper.approveAssets([addresses.mainnet.OGN]);

if (!isFork) {
// No Governance action on mainnet
// To be upgraded with the proposal from `ousd-governance` repo
return {
actions: [],
};
}

return {
name: "Upgrade contracts for OGN Buyback",
actions: [
Expand Down
20 changes: 12 additions & 8 deletions contracts/test/buyback/buyback.fork-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,28 +27,32 @@ describe("ForkTest: OETH Buyback", function () {
const cvxShareBefore = await oethBuyback.balanceForCVX();
const rewardsBalanceBefore = await ogn.balanceOf(rewardsSource.address);

const ognAmount = ognShareBefore.lte(oethUnits("1"))
? ognShareBefore
: oethUnits("1");

let data = await getIInchSwapData({
vault: oethVault,
fromAsset: oeth,
toAsset: ogn,
fromAmount: ognShareBefore,
// 20%, just so that fork-tests don't fail on
fromAmount: ognAmount,
// 5%, just so that fork-tests don't fail on
// CI randomly due to price volatility.
slippage: 20,
slippage: 5,
});
data = await recodeSwapData(data);

await oethBuyback
.connect(strategist)
.swapForOGN(ognShareBefore, oethUnits("100"), data);
.swapForOGN(ognAmount, oethUnits("100"), data);

const oethBalanceAfter = await oeth.balanceOf(oethBuyback.address);
const ognShareAfter = await oethBuyback.balanceForOGN();
const cvxShareAfter = await oethBuyback.balanceForCVX();
const rewardsBalanceAfter = await ogn.balanceOf(rewardsSource.address);

expect(ognShareAfter).to.eq(0);
expect(oethBalanceAfter).to.eq(oethBalanceBefore.sub(ognShareBefore));
expect(ognShareAfter).to.eq(ognShareBefore.sub(ognAmount));
expect(oethBalanceAfter).to.eq(oethBalanceBefore.sub(ognAmount));
expect(cvxShareAfter).to.eq(cvxShareBefore);
expect(rewardsBalanceAfter).to.be.gt(rewardsBalanceBefore);
});
Expand All @@ -70,9 +74,9 @@ describe("ForkTest: OETH Buyback", function () {
fromAsset: oeth,
toAsset: cvx,
fromAmount: cvxShareBefore,
// 20%, just so that fork-tests don't fail on
// 5%, just so that fork-tests don't fail on
// CI randomly due to price volatility.
slippage: 20,
slippage: 5,
});
data = await recodeSwapData(data);

Expand Down

0 comments on commit e6f9990

Please sign in to comment.