Skip to content

Commit

Permalink
update tests to properly match/use latest blocks.
Browse files Browse the repository at this point in the history
  • Loading branch information
Brean0 committed Jul 24, 2024
1 parent 899fa09 commit f24ccb6
Show file tree
Hide file tree
Showing 2 changed files with 147 additions and 156 deletions.
59 changes: 26 additions & 33 deletions protocol/scripts/bips.js
Original file line number Diff line number Diff line change
Expand Up @@ -361,31 +361,24 @@ async function bipMiscellaneousImprovements(mock = true, account = undefined, ve
"FertilizerFacet"
],
libraryNames: [
'LibGauge',
'LibIncentive',
'LibLockedUnderlying',
'LibWellMinting',
'LibGerminate',
'LibConvert'
"LibGauge",
"LibIncentive",
"LibLockedUnderlying",
"LibWellMinting",
"LibGerminate",
"LibConvert"
],
facetLibraries: {
'UnripeFacet': [
'LibLockedUnderlying'
],
'ConvertFacet': [
'LibConvert',
],
'SeasonFacet': [
'LibGauge',
'LibIncentive',
'LibLockedUnderlying',
'LibWellMinting',
'LibGerminate'
],
'SeasonGettersFacet': [
'LibLockedUnderlying',
'LibWellMinting',
UnripeFacet: ["LibLockedUnderlying"],
ConvertFacet: ["LibConvert"],
SeasonFacet: [
"LibGauge",
"LibIncentive",
"LibLockedUnderlying",
"LibWellMinting",
"LibGerminate"
],
SeasonGettersFacet: ["LibLockedUnderlying", "LibWellMinting"]
},
selectorsToRemove: [],
bip: false,
Expand All @@ -396,14 +389,14 @@ async function bipMiscellaneousImprovements(mock = true, account = undefined, ve
});
}

exports.bip29 = bip29
exports.bip30 = bip30
exports.bip34 = bip34
exports.bipMorningAuction = bipMorningAuction
exports.bipNewSilo = bipNewSilo
exports.bipBasinIntegration = bipBasinIntegration
exports.bipSeedGauge = bipSeedGauge
exports.mockBeanstalkAdmin = mockBeanstalkAdmin
exports.bipMigrateUnripeBean3CrvToBeanEth = bipMigrateUnripeBean3CrvToBeanEth
exports.bipMigrateUnripeBeanEthToBeanSteth = bipMigrateUnripeBeanEthToBeanSteth
exports.bipMiscellaneousImprovements = bipMiscellaneousImprovements
exports.bip29 = bip29;
exports.bip30 = bip30;
exports.bip34 = bip34;
exports.bipMorningAuction = bipMorningAuction;
exports.bipNewSilo = bipNewSilo;
exports.bipBasinIntegration = bipBasinIntegration;
exports.bipSeedGauge = bipSeedGauge;
exports.mockBeanstalkAdmin = mockBeanstalkAdmin;
exports.bipMigrateUnripeBean3CrvToBeanEth = bipMigrateUnripeBean3CrvToBeanEth;
exports.bipMigrateUnripeBeanEthToBeanSteth = bipMigrateUnripeBeanEthToBeanSteth;
exports.bipMiscellaneousImprovements = bipMiscellaneousImprovements;
244 changes: 121 additions & 123 deletions protocol/test/LockedBeansMainnet.test.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
const { BEAN, UNRIPE_BEAN, UNRIPE_LP, BEAN_ETH_WELL, BEANSTALK } = require('./utils/constants.js');
const { EXTERNAL, INTERNAL } = require('./utils/balances.js')
const { impersonateSigner, impersonateBeanstalkOwner } = require('../utils/signer.js');
const { BEAN, UNRIPE_BEAN, UNRIPE_LP, BEAN_ETH_WELL, BARN_RAISE_WELL, BEANSTALK, WSTETH } = require("./utils/constants.js");
const { EXTERNAL, INTERNAL } = require("./utils/balances.js");
const { impersonateSigner, impersonateBeanstalkOwner } = require("../utils/signer.js");
const { takeSnapshot, revertToSnapshot } = require("./utils/snapshot.js");
const { getBeanstalk } = require('../utils/contracts.js');
const { getBeanstalk } = require("../utils/contracts.js");
const { upgradeWithNewFacets } = require("../scripts/diamond");
const { bipSeedGauge, bipMiscellaneousImprovements } = require('../scripts/bips.js');
const { to6, to18 } = require('./utils/helpers.js');
const { mintEth } = require('../utils')
const { ethers } = require('hardhat');
const { expect } = require('chai');
const { bipMiscellaneousImprovements } = require("../scripts/bips.js");
const { migrateBeanEthToBeanWSteth } = require("../scripts/beanWstethMigration.js");
const { impersonateWsteth } = require("../scripts/impersonate.js");
const { to6, to18 } = require("./utils/helpers.js");
const { mintEth } = require("../utils");
const { ethers } = require("hardhat");
const { expect } = require("chai");

let user,user2, owner;
let user, user2, owner;

let snapshotId
let snapshotId;


describe('LockedBeansMainnet', function () {
describe("LockedBeansMainnet", function () {
before(async function () {

[user, user2] = await ethers.getSigners()

[user, user2] = await ethers.getSigners();

try {
await network.provider.request({
Expand All @@ -28,156 +27,155 @@ describe('LockedBeansMainnet', function () {
{
forking: {
jsonRpcUrl: process.env.FORKING_RPC,
blockNumber: 19785088 //a random semi-recent block close to Grown Stalk Per Bdv pre-deployment
},
},
],
blockNumber: 20375900
}
}
]
});
} catch(error) {
console.log('forking error in seed Gauge');
} catch (error) {
console.log("forking error in seed Gauge");
console.log(error);
return
return;
}

this.beanstalk = await getBeanstalk()
this.beanstalk = await getBeanstalk();
});

beforeEach(async function () {
snapshotId = await takeSnapshot()
snapshotId = await takeSnapshot();
});

afterEach(async function () {
await revertToSnapshot(snapshotId)
await revertToSnapshot(snapshotId);
});

/**
* the following tests are performed prior to the seed gauge deployment.
* upon the bips passing, the tests should be updated to the latest block and omit the seed gauge update.
*/
describe("chopRate change:", async function() {
describe("chopRate change:", async function () {
it("correctly updates chop", async function () {
// check chop rate:
expect(await this.beanstalk.getPercentPenalty(UNRIPE_BEAN)).to.eq(to6('0.010227'))
expect(await this.beanstalk.getPercentPenalty(UNRIPE_LP)).to.eq(to6('0.010215'))

// simulate a urBean chop:
address = await impersonateSigner('0xef764bac8a438e7e498c2e5fccf0f174c3e3f8db')
snapshotId = await takeSnapshot()
await this.beanstalk.connect(address).withdrawDeposit(
UNRIPE_BEAN,
'-28418',
to6('1'),
INTERNAL
expect(await this.beanstalk.getPercentPenalty(UNRIPE_BEAN)).to.eq(to6("0.013271"));
expect(await this.beanstalk.getPercentPenalty(UNRIPE_LP)).to.eq(to6("0.013264"));

// simulate a urBean chop:
address = await impersonateSigner("0xef764bac8a438e7e498c2e5fccf0f174c3e3f8db");
snapshotId = await takeSnapshot();
await this.beanstalk
.connect(address)
.withdrawDeposit(UNRIPE_BEAN, "-28418000000", to6("1"), INTERNAL);
await this.beanstalk.connect(address).chop(UNRIPE_BEAN, to6("1"), INTERNAL, EXTERNAL);
expect(await this.beanstalk.getExternalBalance(address.address, BEAN)).to.eq(to6("0.013271"));
await revertToSnapshot(snapshotId);

// simulate a urLP chop:
await this.beanstalk
.connect(address)
.withdrawDeposit(UNRIPE_LP, "-33292000000", to6("1"), INTERNAL);
await this.beanstalk.connect(address).chop(UNRIPE_LP, to6("1"), INTERNAL, EXTERNAL);
expect(await this.beanstalk.getExternalBalance(address.address, BEAN_ETH_WELL)).to.eq(
to18("0.000164043206705975")
);
await this.beanstalk.connect(address).chop(
UNRIPE_BEAN,
to6('1'),
INTERNAL,
EXTERNAL
)
expect(await this.beanstalk.getExternalBalance(address.address, BEAN)).to.eq(to6('0.010226'))
await revertToSnapshot(snapshotId)

// simulate a urLP chop:
await this.beanstalk.connect(address).withdrawDeposit(
UNRIPE_LP,
'-33292',
to6('1'),
INTERNAL
);
await this.beanstalk.connect(address).chop(
UNRIPE_LP,
to6('1'),
INTERNAL,
EXTERNAL
)
expect(await this.beanstalk.getExternalBalance(address.address, BEAN_ETH_WELL)).to.eq(to18('0.000126330680297571'))
await revertToSnapshot(snapshotId)
await revertToSnapshot(snapshotId);

// deploy seed gauge
await bipSeedGauge(true, undefined, false)
// migrate bean eth to bean wsteth:
this.wsteth = await ethers.getContractAt('MockWsteth', WSTETH)
const stethPerToken = await this.wsteth.stEthPerToken()
await impersonateWsteth()
await this.wsteth.setStEthPerToken(stethPerToken)
await migrateBeanEthToBeanWSteth();

// // deploy misc. improvements bip
await bipMiscellaneousImprovements(true, undefined, false)
// deploy misc. improvements bip:
await bipMiscellaneousImprovements(true, undefined, false);

// check chop rate:
expect(await this.beanstalk.getPercentPenalty(UNRIPE_BEAN)).to.eq(to6('0.050532'))
expect(await this.beanstalk.getPercentPenalty(UNRIPE_LP)).to.eq(to6('0.050473'))

// simulate a urBean chop:
snapshotId = await takeSnapshot()
await this.beanstalk.connect(address).withdrawDeposit(
UNRIPE_BEAN,
'-28418000000', // scaled by 1e6 due to silo v3.1.
to6('1'),
INTERNAL
);
await this.beanstalk.connect(address).chop(
UNRIPE_BEAN,
to6('1'),
INTERNAL,
EXTERNAL
)
expect(await this.beanstalk.getExternalBalance(address.address, BEAN)).to.eq(to6('0.050532'))
await revertToSnapshot(snapshotId)
expect(await this.beanstalk.getPercentPenalty(UNRIPE_BEAN)).to.eq(to6("0.050552"));
expect(await this.beanstalk.getPercentPenalty(UNRIPE_LP)).to.eq(to6("0.050526"));

// simulate a urBean chop:
snapshotId = await takeSnapshot();
await this.beanstalk
.connect(address)
.withdrawDeposit(UNRIPE_BEAN, "-28418000000", to6("1"), INTERNAL);
await this.beanstalk.connect(address).chop(UNRIPE_BEAN, to6("1"), INTERNAL, EXTERNAL);
expect(await this.beanstalk.getExternalBalance(address.address, BEAN)).to.eq(to6("0.050552"));
await revertToSnapshot(snapshotId);

// // simulate a urLP chop:
let initialBeanEthBal = await this.beanstalk.getExternalBalance(address.address, BEAN_ETH_WELL)
await this.beanstalk.connect(address).withdrawDeposit(
UNRIPE_LP,
'-33292000000',
to6('1'),
INTERNAL
let initialBeanEthBal = await this.beanstalk.getExternalBalance(
address.address,
BARN_RAISE_WELL
);
await this.beanstalk.connect(address).chop(
UNRIPE_LP,
to6('1'),
INTERNAL,
EXTERNAL
)
let newBeanEthBal = await this.beanstalk.getExternalBalance(address.address, BEAN_ETH_WELL)
await this.beanstalk
.connect(address)
.withdrawDeposit(UNRIPE_LP, "-33292000000", to6("1"), INTERNAL);
await this.beanstalk.connect(address).chop(UNRIPE_LP, to6("1"), INTERNAL, EXTERNAL);
let newBeanEthBal = await this.beanstalk.getExternalBalance(address.address, BARN_RAISE_WELL);
// beanEthBal should increase by ~4.94x the original chop rate.
expect(newBeanEthBal-initialBeanEthBal).to.eq(to18('0.000624219026576969'))
})
})
expect(newBeanEthBal - initialBeanEthBal).to.eq(to18("0.000576793427336659"));
});
});

describe("lockedBeans change", async function() {
describe("lockedBeans change", async function () {
it("correctly updates locked beans", async function () {
// deploy mockUnripeFacet, as `getLockedBeans()` was updated:
// deploy mockUnripeFacet, as `getLockedBeans()` was updated:
account = await impersonateBeanstalkOwner();
await mintEth(account.address);
await upgradeWithNewFacets({
diamondAddress: BEANSTALK,
facetNames: [
'MockUnripeFacet'
],
libraryNames: [
'LibLockedUnderlying'
],
facetNames: ["MockUnripeFacet"],
libraryNames: ["LibLockedUnderlying"],
facetLibraries: {
'MockUnripeFacet': [
'LibLockedUnderlying'
]
MockUnripeFacet: ["LibLockedUnderlying"]
},
selectorsToRemove: [],
bip: false,
object: false,
verbose: false,
account: account,
verify: false
})
});
// check underlying locked beans and locked LP:
this.unripe = await ethers.getContractAt('MockUnripeFacet', BEANSTALK)
expect(await this.unripe.getLegacyLockedUnderlyingBean()).to.eq(to6('22034476.333100'))
// expect(await this.unripe.getLegacyLockedUnderlyingLP()).to.be.within(to18('158853'),to18('158855'))
expect(await this.unripe.getLegacyLockedUnderlyingLP()).to.be.within(to18('208398'),to18('208400'))
this.unripe = await ethers.getContractAt("MockUnripeFacet", BEANSTALK);
expect(await this.unripe.getLegacyLockedUnderlyingBean()).to.eq(to6("22073747.489499"));
expect(await this.unripe.getLegacyLockedUnderlyingLP()).to.be.within(
to18("198522"),
to18("198600")
);

// migrate bean eth to bean wsteth:
this.wsteth = await ethers.getContractAt('MockWsteth', WSTETH)
const stethPerToken = await this.wsteth.stEthPerToken()
await impersonateWsteth()
await this.wsteth.setStEthPerToken(stethPerToken)
await migrateBeanEthToBeanWSteth();

// mine blocks + update timestamp for pumps to update:
for (let i = 0; i < 100; i++) {
await ethers.provider.send("evm_increaseTime", [12]);
await ethers.provider.send("evm_mine");
}

// call sunrise:
await this.beanstalk.sunrise();

for (let i = 0; i < 100; i++) {
await ethers.provider.send("evm_increaseTime", [12]);
await ethers.provider.send("evm_mine");
}

// deploy misc. improvements bip
await bipMiscellaneousImprovements(true, undefined, false)
await bipMiscellaneousImprovements(true, undefined, false);

// check underlying locked beans and locked LP:
expect(await this.beanstalk.getLockedBeansUnderlyingUnripeBean()).to.eq(to6('14978575.114249'))
expect(await this.beanstalk.getLockedBeansUnderlyingUnripeLP()).to.be.within('7668288289687','7868288289687')
})
})
})
expect(await this.beanstalk.getLockedBeansUnderlyingUnripeBean()).to.eq(
to6("15397373.979201")
);
expect(await this.beanstalk.getLockedBeansUnderlyingUnripeLP()).to.be.within(
"8372544877445",
"8372546877445"
);
});
});
});

0 comments on commit f24ccb6

Please sign in to comment.