Skip to content

Commit 52a775f

Browse files
committed
test: re-add veBal tests, update blockNum
1 parent c86a04c commit 52a775f

7 files changed

+783
-2
lines changed

.circleci/config.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ jobs:
9898
e2e-test:
9999
working_directory: ~/repo
100100
executor: nodeimage
101-
parallelism: 7
101+
parallelism: 12
102102
steps:
103103
- attach_workspace:
104104
at: ./

block.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
15719111
1+
15732824
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
import { VeBalHelper } from '@custom-types/contracts';
2+
import { NamedAddresses, NamedContracts } from '@custom-types/types';
3+
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers';
4+
import { ProposalsConfig } from '@protocol/proposalsConfig';
5+
import { getAddresses, getImpersonatedSigner, time } from '@test/helpers';
6+
import { TestEndtoEndCoordinator } from '@test/integration/setup';
7+
import chai, { expect } from 'chai';
8+
import CBN from 'chai-bn';
9+
import { solidity } from 'ethereum-waffle';
10+
import { BigNumberish, Contract, Signer } from 'ethers';
11+
import { ethers } from 'hardhat';
12+
import { forceEth } from '../setup/utils';
13+
14+
const e18 = (x: BigNumberish) => ethers.constants.WeiPerEther.mul(x);
15+
16+
before(async () => {
17+
chai.use(CBN(ethers.BigNumber));
18+
chai.use(solidity);
19+
});
20+
21+
describe('e2e-veBalHelper-assetManagement', function () {
22+
const impersonatedSigners: { [key: string]: Signer } = {};
23+
let contracts: NamedContracts;
24+
let contractAddresses: NamedAddresses;
25+
let deployAddress: string;
26+
let e2eCoord: TestEndtoEndCoordinator;
27+
let doLogging: boolean;
28+
let vebalOtcHelper: Contract;
29+
let otcBuyerAddress: string;
30+
let otcBuyerSigner: SignerWithAddress;
31+
32+
let balWethBPTWhaleSigner: SignerWithAddress;
33+
const balWethBPTWhale = '0xC128a9954e6c874eA3d62ce62B468bA073093F25';
34+
35+
before(async function () {
36+
deployAddress = (await ethers.getSigners())[0].address;
37+
if (!deployAddress) throw new Error(`No deploy address!`);
38+
const addresses = await getAddresses();
39+
// add any addresses you want to impersonate here
40+
const impersonatedAddresses = [addresses.userAddress, addresses.pcvControllerAddress, addresses.governorAddress];
41+
42+
doLogging = Boolean(process.env.LOGGING);
43+
44+
const config = {
45+
logging: doLogging,
46+
deployAddress: deployAddress,
47+
version: 1
48+
};
49+
50+
e2eCoord = new TestEndtoEndCoordinator(config, ProposalsConfig);
51+
52+
doLogging && console.log(`Loading environment...`);
53+
({ contracts, contractAddresses } = await e2eCoord.loadEnvironment());
54+
55+
({ vebalOtcHelper } = contracts);
56+
doLogging && console.log(`Environment loaded.`);
57+
vebalOtcHelper = vebalOtcHelper as VeBalHelper;
58+
59+
for (const address of impersonatedAddresses) {
60+
impersonatedSigners[address] = await getImpersonatedSigner(address);
61+
}
62+
63+
otcBuyerAddress = contractAddresses.aaveCompaniesMultisig;
64+
otcBuyerSigner = await getImpersonatedSigner(otcBuyerAddress);
65+
66+
balWethBPTWhaleSigner = await getImpersonatedSigner(balWethBPTWhale);
67+
await forceEth(balWethBPTWhale);
68+
});
69+
70+
// Tests withdrawERC20() from pcvDeposit
71+
it('should be able to withdrawERC20() to receive B-80BAL-20WETH at end of lock', async () => {
72+
await time.increase(3600 * 24 * 365);
73+
await vebalOtcHelper.connect(otcBuyerSigner).exitLock();
74+
75+
// Can withdrawERC20() to receive B-80BAL-20WETH at end of lock
76+
const bpt80Bal20WethAmount = await contracts.bpt80Bal20Weth.balanceOf(contractAddresses.veBalDelegatorPCVDeposit);
77+
await vebalOtcHelper
78+
.connect(otcBuyerSigner)
79+
.withdrawERC20(contractAddresses.bpt80Bal20Weth, otcBuyerAddress, bpt80Bal20WethAmount);
80+
expect(await contracts.bpt80Bal20Weth.balanceOf(otcBuyerAddress)).to.be.equal(bpt80Bal20WethAmount);
81+
expect(bpt80Bal20WethAmount).to.be.at.least(e18(112_041));
82+
});
83+
84+
// Tests withdrawERC20() from staker
85+
it('can withdrawERC20 from staker', async () => {
86+
await forceEth(balWethBPTWhale);
87+
88+
// Transfer 1 balWETHBPT token to the balancerGaugeStaker, which we will later withdraw
89+
// via the vebalOtcHelper contract
90+
await contracts.balWethBPT.connect(balWethBPTWhaleSigner).transfer(contracts.balancerGaugeStaker.address, 1);
91+
await forceEth(contracts.balancerGaugeStaker.address);
92+
93+
const userBalanceBefore = await contracts.balWethBPT.balanceOf(otcBuyerAddress);
94+
95+
// Withdraw the 1 BPT token from the balancerGaugeStaker to the user
96+
await contracts.vebalOtcHelper
97+
.connect(otcBuyerSigner)
98+
.withdrawERC20fromStaker(contracts.balWethBPT.address, otcBuyerAddress, 1);
99+
100+
const userBalanceAfter = await contracts.balWethBPT.balanceOf(otcBuyerAddress);
101+
expect(userBalanceAfter).to.be.eq(userBalanceBefore.add(1));
102+
});
103+
104+
it('can withdrawETH from pcvDeposit', async () => {
105+
// Transfer 1 ETH to the veBalPCVDeposit
106+
await forceEth(contractAddresses.veBalDelegatorPCVDeposit);
107+
const oneEth = ethers.utils.parseEther('1');
108+
109+
const receiverAddress = '0x0000000000000000000000000000000000000001';
110+
const userEthBefore = await ethers.provider.getBalance(receiverAddress);
111+
112+
// Withdraw ETH from pcvDeposit to the user
113+
await vebalOtcHelper.connect(otcBuyerSigner).withdrawETH(receiverAddress, oneEth);
114+
115+
const userEthAfter = await ethers.provider.getBalance(receiverAddress);
116+
expect(userEthAfter.sub(userEthBefore)).to.equal(oneEth);
117+
});
118+
119+
it('can withdrawETH from staker', async () => {
120+
// Transfer 1 ETH to the staker
121+
await forceEth(contractAddresses.balancerGaugeStaker);
122+
const oneEth = ethers.utils.parseEther('1');
123+
124+
const receiverAddress = '0x0000000000000000000000000000000000000001';
125+
const userEthBefore = await ethers.provider.getBalance(receiverAddress);
126+
127+
// Withdraw ETH from pcvDeposit to the user
128+
await vebalOtcHelper.connect(otcBuyerSigner).withdrawETHfromStaker(receiverAddress, oneEth);
129+
130+
const userEthAfter = await ethers.provider.getBalance(receiverAddress);
131+
expect(userEthAfter.sub(userEthBefore)).to.equal(oneEth);
132+
});
133+
});
+151
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
import { VeBalHelper } from '@custom-types/contracts';
2+
import { NamedAddresses, NamedContracts } from '@custom-types/types';
3+
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers';
4+
import { ProposalsConfig } from '@protocol/proposalsConfig';
5+
import { getAddresses, getImpersonatedSigner, time } from '@test/helpers';
6+
import { TestEndtoEndCoordinator } from '@test/integration/setup';
7+
import chai, { expect } from 'chai';
8+
import CBN from 'chai-bn';
9+
import { solidity } from 'ethereum-waffle';
10+
import { Contract, Signer } from 'ethers';
11+
import { ethers } from 'hardhat';
12+
13+
before(async () => {
14+
chai.use(CBN(ethers.BigNumber));
15+
chai.use(solidity);
16+
});
17+
18+
describe('e2e-veBalHelper-boost-management', function () {
19+
const impersonatedSigners: { [key: string]: Signer } = {};
20+
let contracts: NamedContracts;
21+
let contractAddresses: NamedAddresses;
22+
let deployAddress: string;
23+
let e2eCoord: TestEndtoEndCoordinator;
24+
let doLogging: boolean;
25+
let vebalOtcHelper: Contract;
26+
let otcBuyerAddress: string;
27+
let otcBuyerSigner: SignerWithAddress;
28+
29+
beforeEach(async function () {
30+
deployAddress = (await ethers.getSigners())[0].address;
31+
if (!deployAddress) throw new Error(`No deploy address!`);
32+
const addresses = await getAddresses();
33+
// add any addresses you want to impersonate here
34+
const impersonatedAddresses = [addresses.userAddress, addresses.pcvControllerAddress, addresses.governorAddress];
35+
36+
doLogging = Boolean(process.env.LOGGING);
37+
38+
const config = {
39+
logging: doLogging,
40+
deployAddress: deployAddress,
41+
version: 1
42+
};
43+
44+
e2eCoord = new TestEndtoEndCoordinator(config, ProposalsConfig);
45+
46+
doLogging && console.log(`Loading environment...`);
47+
({ contracts, contractAddresses } = await e2eCoord.loadEnvironment());
48+
49+
({ vebalOtcHelper } = contracts);
50+
doLogging && console.log(`Environment loaded.`);
51+
vebalOtcHelper = vebalOtcHelper as VeBalHelper;
52+
53+
for (const address of impersonatedAddresses) {
54+
impersonatedSigners[address] = await getImpersonatedSigner(address);
55+
}
56+
57+
otcBuyerAddress = contractAddresses.aaveCompaniesMultisig;
58+
otcBuyerSigner = await getImpersonatedSigner(otcBuyerAddress);
59+
});
60+
61+
it('should be able to create_boost() to boost delegation to another address', async () => {
62+
await vebalOtcHelper.connect(otcBuyerSigner).create_boost(
63+
contractAddresses.veBalDelegatorPCVDeposit, // address _delegator
64+
contractAddresses.eswak, // address _receiver
65+
'10000', // int256 _percentage
66+
'1669852800', // uint256 _cancel_time = December 1 2022
67+
'1672272000', // uint256 _expire_time = December 29 2022
68+
'0' // uint256 _id
69+
);
70+
const expectedMinBoost = '70000000000000000000000'; // should be 77.5k with 18 decimals as of 14/09/2022
71+
expect(
72+
await contracts.balancerVotingEscrowDelegation.delegated_boost(contracts.veBalDelegatorPCVDeposit.address)
73+
).to.be.at.least(expectedMinBoost);
74+
expect(await contracts.balancerVotingEscrowDelegation.received_boost(contractAddresses.eswak)).to.be.at.least(
75+
expectedMinBoost
76+
);
77+
78+
// token id is uint256(delegatorAddress << 96 + boostId), and boostId = 0
79+
const tokenId = '0xc4eac760c2c631ee0b064e39888b89158ff808b2000000000000000000000000';
80+
expect(await contracts.balancerVotingEscrowDelegation.token_boost(tokenId)).to.be.at.least(expectedMinBoost);
81+
expect(await contracts.balancerVotingEscrowDelegation.token_expiry(tokenId)).to.equal('1672272000');
82+
expect(await contracts.balancerVotingEscrowDelegation.token_cancel_time(tokenId)).to.equal('1669852800');
83+
});
84+
85+
it('should be able to extend_boost', async () => {
86+
await vebalOtcHelper.connect(otcBuyerSigner).create_boost(
87+
contractAddresses.veBalDelegatorPCVDeposit, // address _delegator
88+
contractAddresses.eswak, // address _receiver
89+
'10000', // int256 _percentage
90+
'1669852800', // uint256 _cancel_time = December 1 2022
91+
'1672272000', // uint256 _expire_time = December 29 2022
92+
'0' // uint256 _id
93+
);
94+
const tokenId = '0xc4eac760c2c631ee0b064e39888b89158ff808b2000000000000000000000000';
95+
96+
await time.increase(86400 * 8);
97+
const boostedExpireTime = '1674998582'; // uint256 _expire_time = Jan 29 2023
98+
// - boostedExpireTime gets rounded down to nearest week
99+
const boostedCancelTime = '1672694348'; // uint256 _cancel_time = Jan 2 2023
100+
101+
// Extend the boost
102+
await vebalOtcHelper.connect(otcBuyerSigner).extend_boost(
103+
tokenId,
104+
'10000', // int256 _percentage
105+
boostedExpireTime,
106+
boostedCancelTime
107+
);
108+
109+
const recordedBoostedExpireTime = await contracts.balancerVotingEscrowDelegation.token_expiry(tokenId);
110+
111+
// Expected boosted expire time rounded down to nearest week
112+
const WEEK = 86400 * 7;
113+
const expectedBoostedExpire = Math.floor(Number(boostedExpireTime) / WEEK) * WEEK;
114+
expect(recordedBoostedExpireTime).to.equal(expectedBoostedExpire);
115+
expect(await contracts.balancerVotingEscrowDelegation.token_cancel_time(tokenId)).to.equal(boostedCancelTime);
116+
});
117+
118+
it('should be able to cancel_boost', async () => {
119+
await vebalOtcHelper.connect(otcBuyerSigner).create_boost(
120+
contractAddresses.veBalDelegatorPCVDeposit, // address _delegator
121+
contractAddresses.eswak, // address _receiver
122+
'10000', // int256 _percentage
123+
'1665432310', // uint256 _cancel_time = October 10 2022
124+
'1676495110', // uint256 _expire_time = February 15 2023
125+
'0' // uint256 _id
126+
);
127+
const tokenId = '0xc4eac760c2c631ee0b064e39888b89158ff808b2000000000000000000000000';
128+
expect(await contracts.balancerVotingEscrowDelegation.token_boost(tokenId)).to.be.at.least('1'); // non-zero check
129+
130+
// Cancel boost - fast forward past cancel time
131+
await time.increase(86400 * 30);
132+
await vebalOtcHelper.connect(otcBuyerSigner).cancel_boost(tokenId);
133+
134+
const balancerTokenBoost = await contracts.balancerVotingEscrowDelegation.token_boost(tokenId);
135+
expect(balancerTokenBoost).to.equal(0);
136+
});
137+
138+
it('should be able to burn a token', async () => {
139+
await vebalOtcHelper.connect(otcBuyerSigner).create_boost(
140+
contractAddresses.veBalDelegatorPCVDeposit, // address _delegator
141+
contractAddresses.veBalDelegatorPCVDeposit, // address _receiver (becomes owner, only owner can burn)
142+
'10000', // int256 _percentage
143+
'1669852800', // uint256 _cancel_time = December 1 2022
144+
'1672272000', // uint256 _expire_time = December 29 2022
145+
'0' // uint256 _id
146+
);
147+
const tokenId = '0xc4eac760c2c631ee0b064e39888b89158ff808b2000000000000000000000000';
148+
// Burn token
149+
await vebalOtcHelper.connect(otcBuyerSigner).burn(tokenId);
150+
});
151+
});

0 commit comments

Comments
 (0)