Skip to content

Commit

Permalink
fix tests after merging staking_router
Browse files Browse the repository at this point in the history
  • Loading branch information
arwer13 committed Jan 25, 2023
1 parent ad08f38 commit 55c673d
Show file tree
Hide file tree
Showing 8 changed files with 229 additions and 279 deletions.
4 changes: 4 additions & 0 deletions contracts/0.4.24/test_helpers/StETHPermitMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,8 @@ contract StETHPermitMock is StETHPermit, StETHMock {
function initializeEIP712StETH(address _eip712StETH) external {
_initializeEIP712StETH(_eip712StETH);
}

function getBlockTime() external view returns (uint256) {
return block.timestamp;
}
}
55 changes: 29 additions & 26 deletions test/0.4.24/lido.rewards-distribution.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ const OracleMock = artifacts.require('OracleMock.sol')
const DepositContractMock = artifacts.require('DepositContractMock.sol')
const StakingRouter = artifacts.require('StakingRouterMock.sol')
const ModuleSolo = artifacts.require('ModuleSolo.sol')
const IStakingModule = artifacts.require('contracts/0.8.9/interfaces/IStakingModule.sol:IStakingModule')
const EIP712StETH = artifacts.require('EIP712StETH')
const ELRewardsVault = artifacts.require('LidoExecutionLayerRewardsVault.sol')

const ETH = (value) => web3.utils.toWei(value + '', 'ether')

Expand All @@ -26,9 +27,8 @@ const cfgCommunity = {
targetShare: 5000
}

contract('Lido', ([appManager, voting, user2]) => {
contract('Lido', ([appManager, voting, treasury, depositor, user2]) => {
let appBase, nodeOperatorsRegistryBase, app, oracle, depositContract, curatedModule, stakingRouter, soloModule
let treasuryAddr
let dao, acl

before('deploy base app', async () => {
Expand Down Expand Up @@ -78,22 +78,9 @@ contract('Lido', ([appManager, voting, user2]) => {
from: appManager
})

// Initialize the app's proxy.
await app.initialize(oracle.address, ZERO_ADDRESS, ZERO_ADDRESS, ZERO_ADDRESS, ZERO_ADDRESS)

assert((await app.isStakingPaused()) === true)
assert((await app.isStopped()) === true)
await app.resume({ from: voting })
assert((await app.isStakingPaused()) === false)
assert((await app.isStopped()) === false)
const eip712StETH = await EIP712StETH.new()
const elRewardsVault = await ELRewardsVault.new(app.address, treasury)

treasuryAddr = await app.getTreasury()

await oracle.setPool(app.address)
await depositContract.reset()
})

beforeEach('setup staking router', async () => {
stakingRouter = await StakingRouter.new(depositContract.address)
// initialize
const wc = '0x'.padEnd(66, '1234')
Expand All @@ -104,8 +91,6 @@ contract('Lido', ([appManager, voting, user2]) => {

await stakingRouter.grantRole(STAKING_MODULE_MANAGE_ROLE, voting, { from: appManager })

await app.setStakingRouter(stakingRouter.address, { from: voting })

soloModule = await ModuleSolo.new(app.address, { from: appManager })

await stakingRouter.addStakingModule(
Expand Down Expand Up @@ -136,26 +121,44 @@ contract('Lido', ([appManager, voting, user2]) => {
await soloModule.setTotalKeys(100, { from: appManager })
await soloModule.setTotalUsedKeys(10, { from: appManager })
await soloModule.setTotalStoppedKeys(0, { from: appManager })

// Initialize the app's proxy.
await app.initialize(
oracle.address,
treasury,
stakingRouter.address,
depositor,
elRewardsVault.address,
ZERO_ADDRESS,
eip712StETH.address,
)

assert((await app.isStakingPaused()) === true)
assert((await app.isStopped()) === true)
await app.resume({ from: voting })
assert((await app.isStakingPaused()) === false)
assert((await app.isStopped()) === false)

await oracle.setPool(app.address)
await depositContract.reset()
})

it.skip('Rewards distribution fills treasury', async () => {
// TODO: fix. broken after merging
it('Rewards distribution fills treasury', async () => {
const beaconBalance = ETH(1)
const { stakingModuleFees, totalFee, precisionPoints } = await stakingRouter.getStakingRewardsDistribution()
const treasuryShare = stakingModuleFees.reduce((total, share) => total.sub(share), totalFee)
const treasuryRewards = bn(beaconBalance).mul(treasuryShare).div(precisionPoints)
await app.submit(ZERO_ADDRESS, { from: user2, value: ETH(32) })

const treasuryBalanceBefore = await app.balanceOf(treasuryAddr)
const treasuryBalanceBefore = await app.balanceOf(treasury)
await oracle.reportBeacon(100, 0, beaconBalance, { from: appManager })

const treasuryBalanceAfter = await app.balanceOf(treasuryAddr)
const treasuryBalanceAfter = await app.balanceOf(treasury)
assert(treasuryBalanceAfter.gt(treasuryBalanceBefore))
assertBn(fixRound(treasuryBalanceBefore.add(treasuryRewards)), fixRound(treasuryBalanceAfter))
})

it.skip('Rewards distribution fills modules', async () => {
// TODO: fix. broken after merging
it('Rewards distribution fills modules', async () => {
const beaconBalance = ETH(1)
const { recipients, stakingModuleFees, precisionPoints } = await stakingRouter.getStakingRewardsDistribution()

Expand Down
20 changes: 4 additions & 16 deletions test/0.4.24/lido.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ const { assertRevert } = require('../helpers/assertThrow')


const { newDao, newApp } = require('./helpers/dao')
const { ZERO_ADDRESS, bn, getEventAt } = require('@aragon/contract-helpers-test')
const { BN } = require('bn.js')
const { ZERO_ADDRESS, bn } = require('@aragon/contract-helpers-test')
const { formatEther } = require('ethers/lib/utils')
const { getEthBalance, formatStEth, formatBN, hexConcat, pad, ETH, tokens, div15, assertNoEvent, StETH } = require('../helpers/utils')
const { assert } = require('../helpers/assert')
Expand All @@ -20,11 +19,7 @@ const ELRewardsVault = artifacts.require('LidoExecutionLayerRewardsVault.sol')
const OracleMock = artifacts.require('OracleMock.sol')
const DepositContractMock = artifacts.require('DepositContractMock.sol')
const ERC20Mock = artifacts.require('ERC20Mock.sol')
const VaultMock = artifacts.require('VaultMock.sol')
// const VaultMock = artifacts.require('AragonVaultMock.sol')
const AragonVaultMock = artifacts.require('AragonVaultMock.sol')
const WithdrawalQueue = artifacts.require('WithdrawalQueue.sol')
const WstETH = artifacts.require('WstETH.sol')
const ERC20WrongTransferMock = artifacts.require('ERC20WrongTransferMock.sol')
const AragonNotPayableVaultMock = artifacts.require('AragonNotPayableVaultMock.sol')
const RewardEmulatorMock = artifacts.require('RewardEmulatorMock.sol')
Expand Down Expand Up @@ -365,9 +360,9 @@ contract('Lido', ([appManager, voting, user1, user2, user3, nobody, depositor, t
assertBn(await app.getTotalPooledEther(), ETH(depositAmount + elRewards + beaconRewards))
assertBn(await app.getTotalELRewardsCollected(), ETH(elRewards))

const protocolFeePrecisionPoints = await app.getFee()
const totalFee = await app.getFee()
const stakersReward = bn(ETH(elRewards + beaconRewards))
.mul(FEE_PRECISION_POINTS.sub(protocolFeePrecisionPoints))
.mul(FEE_PRECISION_POINTS.sub(totalFee))
.div(FEE_PRECISION_POINTS)
assertBn(await app.balanceOf(user2), bn(STETH(depositAmount)).add(stakersReward))
})
Expand Down Expand Up @@ -1166,10 +1161,6 @@ contract('Lido', ([appManager, voting, user1, user2, user3, nobody, depositor, t
await operators.addNodeOperator('1', ADDRESS_1, { from: voting })
await operators.addNodeOperator('2', ADDRESS_2, { from: voting })

// TODO: next 2 lines are from withdrawals
// const withdrawal = await WithdrawalVault.new(app.address, treasury)
// await app.setWithdrawalCredentials(hexConcat('0x01', pad(withdrawal.address, 31)), { from: voting })

await stakingRouter.setWithdrawalCredentials(pad('0x0202', 32), { from: voting })
await operators.addSigningKeys(0, 1, pad('0x010203', 48), pad('0x01', 96), { from: voting })
await operators.addSigningKeys(
Expand Down Expand Up @@ -1424,7 +1415,7 @@ contract('Lido', ([appManager, voting, user1, user2, user3, nobody, depositor, t
// await checkRewards({ treasury: tokens(33), operator: tokens(55) })
})

it.skip('deposits accounted properly during rewards distribution', async () => {
it('deposits accounted properly during rewards distribution', async () => {
await stakingRouter.setWithdrawalCredentials(pad('0x0202', 32), { from: voting })

await operators.addNodeOperator('1', ADDRESS_1, { from: voting })
Expand All @@ -1440,7 +1431,6 @@ contract('Lido', ([appManager, voting, user1, user2, user3, nobody, depositor, t
await app.methods['deposit(uint256,uint256,bytes)'](MAX_DEPOSITS, CURATED_MODULE_ID, CALLDATA, { from: depositor })
assertBn(await app.totalSupply(), tokens(64))

// TODO: fix reverting with REPORTED_MORE_DEPOSITED
await oracle.reportBeacon(300, 1, ETH(36))
await checkStat({ depositedValidators: 1, beaconValidators: 1, beaconBalance: ETH(36) })
assertBn(await app.totalSupply(), tokens(68))
Expand Down Expand Up @@ -1801,7 +1791,6 @@ contract('Lido', ([appManager, voting, user1, user2, user3, nobody, depositor, t
})

it(`treasury can't be set by an arbitrary address`, async () => {
// TODO: restore the test when function `transferToVault` is restored
await assertRevert(app.setProtocolContracts(await app.getOracle(), user1, ZERO_ADDRESS, ZERO_ADDRESS, { from: nobody }))
await assertRevert(app.setProtocolContracts(await app.getOracle(), user1, ZERO_ADDRESS, ZERO_ADDRESS, { from: user1 }))
})
Expand All @@ -1816,7 +1805,6 @@ contract('Lido', ([appManager, voting, user1, user2, user3, nobody, depositor, t
})

it('reverts when treasury is zero address', async () => {
// TODO: restore the test when function `setProtocolContracts` is restored
await assertRevert(
app.setProtocolContracts(await app.getOracle(), ZERO_ADDRESS, ZERO_ADDRESS, ZERO_ADDRESS, { from: voting }),
'TREASURY_ZERO_ADDRESS'
Expand Down
13 changes: 4 additions & 9 deletions test/0.4.24/stethpermit.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,10 @@ contract('StETHPermit', ([deployer, ...accounts]) => {
)
})


// TODO merge
it.skip('reverts if the permit is expired', async () => {
it('reverts if the permit is expired', async () => {
const { owner, spender, value, nonce } = permitParams
// create a signed permit that already invalid
const deadline = Math.floor(Date.now() / 1000) - 1
const deadline = (await stEthPermit.getBlockTime()).toString() - 1
const { v, r, s } = signPermit(owner, spender, value, nonce, deadline, domainSeparator, alice.key)

// try to submit the permit that is expired
Expand All @@ -178,15 +176,12 @@ contract('StETHPermit', ([deployer, ...accounts]) => {
)

{
// create a signed permit that valid for 1 minute
const deadline1min = Math.floor(Date.now() / 1000) + 60
// create a signed permit that valid for 1 minute (approximately)
const deadline1min = (await stEthPermit.getBlockTime()).toString() + 60
const { v, r, s } = signPermit(owner, spender, value, nonce, deadline1min, domainSeparator, alice.key)

// try to submit the permit that is expired
const receipt = await stEthPermit.permit(owner, spender, value, deadline1min, v, r, s, { from: charlie })

assertBn(await stEthPermit.nonces(owner), bn(1))

assertEvent(
receipt,
'Approval',
Expand Down
13 changes: 0 additions & 13 deletions test/scenario/execution_layer_rewards_after_the_merge.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@ contract('Lido: merge acceptance', (addresses) => {
// Total fee is 1%
const totalFeePoints = 0.01 * TOTAL_BASIS_POINTS

// TODO: next 2 lines from withdrawals
// const treasuryFeePoints = 0.3 * TOTAL_BASIS_POINTS
// const nodeOperatorsFeePoints = 0.7 * TOTAL_BASIS_POINTS

const withdrawalCredentials = pad('0x0202', 32)

// Each node operator has its Ethereum 1 address, a name and a set of registered
Expand Down Expand Up @@ -112,15 +108,6 @@ contract('Lido: merge acceptance', (addresses) => {

assertBn(await web3.eth.getBalance(rewarder.address), ETH(0), 'rewarder balance')
assertBn(await web3.eth.getBalance(elRewardsVault.address), ETH(0), 'Execution layer rewards vault balance')

// Fee and distribution were set

// assertBn(await pool.getFee({ from: nobody }), totalFeePoints, 'total fee')

// const distribution = await pool.getFeeDistribution({ from: nobody })
// assertBn(distribution.treasuryFeeBasisPoints, treasuryFeePoints, 'treasury fee')
// assertBn(distribution.operatorsFeeBasisPoints, nodeOperatorsFeePoints, 'node operators fee')

await stakingRouter.setWithdrawalCredentials(withdrawalCredentials, { from: voting })

// Withdrawal credentials were set
Expand Down
Loading

0 comments on commit 55c673d

Please sign in to comment.