Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix oracle test setup #556

Merged
merged 1 commit into from
Feb 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions test/helpers/factories.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ async function hashConsensusTimeTravellableFactory({ legacyOracle, voting, repor
return consensus
}

async function accountingOracleFactory({ voting, pool, consensusContract, legacyOracle }) {
const base = await AccountingOracle.new(pool.address, SECONDS_PER_SLOT, GENESIS_TIME)
async function accountingOracleFactory({ voting, pool, lidoLocator, consensusContract, legacyOracle }) {
const base = await AccountingOracle.new(lidoLocator.address, SECONDS_PER_SLOT, GENESIS_TIME)
const proxy = await OssifiableProxy.new(base.address, voting.address, '0x')
const oracle = await AccountingOracle.at(proxy.address)

Expand Down Expand Up @@ -257,13 +257,14 @@ async function elRewardsVaultFactory({ pool, treasury }) {
return await LidoExecutionLayerRewardsVault.new(pool.address, treasury.address)
}

async function withdrawalQueueFactory({ appManager, wsteth }) {
async function withdrawalQueueFactory({ appManager, oracle, wsteth }) {
const withdrawalQueue = (await withdrawals.deploy(appManager.address, wsteth.address)).queue

await withdrawalQueue.initialize(appManager.address, appManager.address, appManager.address, appManager.address)

const BUNKER_MODE_REPORT_ROLE = await withdrawalQueue.BUNKER_MODE_REPORT_ROLE()
await withdrawalQueue.grantRole(BUNKER_MODE_REPORT_ROLE, appManager.address, { from: appManager.address })
await withdrawalQueue.grantRole(BUNKER_MODE_REPORT_ROLE, oracle.address, { from: appManager.address })

return withdrawalQueue
}
Expand Down Expand Up @@ -301,19 +302,24 @@ async function selfOwnedStETHBurnerFactory({ appManager, treasury, pool, voting
return burner
}

async function lidoLocatorMockFactory(protocol) {
async function lidoLocatorFactory(protocol) {
const base = await lidoLocatorMockImplFactory(protocol)
return await OssifiableProxy.new(base.address, protocol.appManager.address, '0x')
}

async function lidoLocatorMockImplFactory(protocol) {
return LidoLocatorMock.new({
lido: protocol.pool.address,
depositSecurityModule: protocol.depositSecurityModule.address,
elRewardsVault: protocol.elRewardsVault.address,
accountingOracle: protocol.oracle.address,
accountingOracle: protocol.oracle ? protocol.oracle.address : ZERO_ADDRESS,
legacyOracle: protocol.legacyOracle.address,
safetyNetsRegistry: ZERO_ADDRESS,
selfOwnedStEthBurner: protocol.selfOwnedStETHBurner.address,
validatorExitBus: ZERO_ADDRESS,
stakingRouter: protocol.stakingRouter.address,
treasury: protocol.treasury.address,
withdrawalQueue: protocol.withdrawalQueue.address,
withdrawalQueue: protocol.withdrawalQueue ? protocol.withdrawalQueue.address : ZERO_ADDRESS,
withdrawalVault: protocol.withdrawalVault.address,
postTokenRebaseReceiver: protocol.legacyOracle.address
})
Expand Down Expand Up @@ -347,12 +353,13 @@ module.exports = {
withdrawalCredentialsFactory,
stakingModulesFactory,
guardiansFactory,
lidoLocatorMockFactory,
lidoLocatorMockImplFactory,
selfOwnedStETHBurnerFactory,
postSetup,
legacyOracleFactory,
legacyOracleMockFactory,
hashConsensusFactory,
hashConsensusTimeTravellableFactory,
reportProcessorFactory
reportProcessorFactory,
lidoLocatorFactory
}
23 changes: 19 additions & 4 deletions test/helpers/protocol.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ const { ethers } = require('hardhat')

const { newDao } = require('./dao')

const OssifiableProxy = artifacts.require('OssifiableProxy')

const factories = require('./factories')
const DEAFAULT_FACTORIES = {
appManagerFactory: factories.appManagerFactory,
Expand All @@ -23,9 +25,10 @@ const DEAFAULT_FACTORIES = {
withdrawalCredentialsFactory: factories.withdrawalCredentialsFactory,
stakingModulesFactory: factories.stakingModulesFactory,
guardiansFactory: factories.guardiansFactory,
lidoLocatorFactory: factories.lidoLocatorMockFactory,
lidoLocatorMockImplFactory: factories.lidoLocatorMockImplFactory,
selfOwnedStETHBurnerFactory: factories.selfOwnedStETHBurnerFactory,
postSetup: factories.postSetup
postSetup: factories.postSetup,
lidoLocatorFactory: factories.lidoLocatorFactory
}

const getFactory = (config, factoryName) => {
Expand Down Expand Up @@ -54,7 +57,6 @@ async function deployProtocol(config = {}) {

protocol.reportProcessor = await getFactory(config, 'reportProcessorFactory')(protocol)
protocol.consensusContract = await getFactory(config, 'hashConsensusFactory')(protocol)
protocol.oracle = await getFactory(config, 'accountingOracleFactory')(protocol)

protocol.depositContract = await getFactory(config, 'depositContractFactory')(protocol)

Expand All @@ -65,11 +67,18 @@ async function deployProtocol(config = {}) {

protocol.depositSecurityModule = await getFactory(config, 'depositSecurityModuleFactory')(protocol)
protocol.elRewardsVault = await getFactory(config, 'elRewardsVaultFactory')(protocol)
protocol.withdrawalQueue = await getFactory(config, 'withdrawalQueueFactory')(protocol)
protocol.withdrawalVault = await getFactory(config, 'withdrawalVaultFactory')(protocol)
protocol.eip712StETH = await getFactory(config, 'eip712StETHFactory')(protocol)
protocol.selfOwnedStETHBurner = await getFactory(config, 'selfOwnedStETHBurnerFactory')(protocol)

protocol.lidoLocator = await getFactory(config, 'lidoLocatorFactory')(protocol)
protocol.oracle = await getFactory(config, 'accountingOracleFactory')(protocol)
protocol.withdrawalQueue = await getFactory(config, 'withdrawalQueueFactory')(protocol)
await upgradeOssifiableProxy(
protocol.lidoLocator.address,
(await getFactory(config, 'lidoLocatorMockImplFactory')(protocol)).address,
protocol.appManager.address
)

await getFactory(config, 'postSetup')(protocol)

Expand All @@ -93,6 +102,12 @@ async function addStakingModules(stakingModulesFactory, protocol) {
return stakingModules.map(({ module }) => module)
}

async function upgradeOssifiableProxy(proxyAddress, newImplemantation, proxyOwner) {
const proxy = await OssifiableProxy.at(proxyAddress)

await proxy.proxy__upgradeTo(newImplemantation, { from: proxyOwner })
}

module.exports = {
deployProtocol
}