Skip to content

Commit

Permalink
Merge pull request #617 from lidofinance/feature/shapella-upgrade-tes…
Browse files Browse the repository at this point in the history
…ts-accounting-oracle-handlers-refactor

test: AccountingOracle submit extra data handlers refactor
  • Loading branch information
manneredboor authored Feb 14, 2023
2 parents 89ad4cc + b353d08 commit 6b53867
Showing 1 changed file with 88 additions and 111 deletions.
199 changes: 88 additions & 111 deletions test/0.8.9/oracle/accounting-oracle-submit-report-extra-data.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const { assert } = require('../../helpers/assert')
const { assertEvent } = require('@aragon/contract-helpers-test/src/asserts')
const { e9, e18, e27 } = require('../../helpers/utils')

const {
Expand All @@ -14,74 +13,94 @@ const {
SLOTS_PER_FRAME
} = require('./accounting-oracle-deploy.test')

const getDefaultExtraData = () => ({
stuckKeys: [
{ moduleId: 1, nodeOpIds: [0], keysCounts: [1] },
{ moduleId: 2, nodeOpIds: [0], keysCounts: [2] },
{ moduleId: 3, nodeOpIds: [2], keysCounts: [3] }
],
exitedKeys: [
{ moduleId: 2, nodeOpIds: [1, 2], keysCounts: [1, 3] },
{ moduleId: 3, nodeOpIds: [1], keysCounts: [2] }
]
})

const getDefaultReportFields = (overrides) => ({
consensusVersion: CONSENSUS_VERSION,
numValidators: 10,
clBalanceGwei: e9(320),
stakingModuleIdsWithNewlyExitedValidators: [1],
numExitedValidatorsByStakingModule: [3],
withdrawalVaultBalance: e18(1),
elRewardsVaultBalance: e18(2),
lastWithdrawalRequestIdToFinalize: 1,
finalizationShareRate: e27(1),
isBunkerMode: true,
extraDataFormat: EXTRA_DATA_FORMAT_LIST,
// required override: refSlot,
// required override: extraDataHash,
// required override: extraDataItemsCount
...overrides
})

contract('AccountingOracle', ([admin, account1, account2, member1, member2, stranger]) => {
let consensus = null
let oracle = null
let reportItems = null
let reportFields = null
let extraDataList = null
let extraDataHash = null
let extraDataItems = null
let oracleVersion = null
let deadline = null
let extraData = null

const deploy = async (options = undefined) => {
const deployed = await deployAndConfigureAccountingOracle(admin)
const { refSlot } = await deployed.consensus.getCurrentFrame()

extraData = {
stuckKeys: [
{ moduleId: 1, nodeOpIds: [0], keysCounts: [1] },
{ moduleId: 2, nodeOpIds: [0], keysCounts: [2] },
{ moduleId: 3, nodeOpIds: [2], keysCounts: [3] }
],
exitedKeys: [
{ moduleId: 2, nodeOpIds: [1, 2], keysCounts: [1, 3] },
{ moduleId: 3, nodeOpIds: [1], keysCounts: [2] }
]
}

extraDataItems = encodeExtraDataItems(extraData)
extraDataList = packExtraDataList(extraDataItems)
extraDataHash = calcExtraDataListHash(extraDataList)
reportFields = {
consensusVersion: CONSENSUS_VERSION,
refSlot: +refSlot,
numValidators: 10,
clBalanceGwei: e9(320),
stakingModuleIdsWithNewlyExitedValidators: [1],
numExitedValidatorsByStakingModule: [3],
withdrawalVaultBalance: e18(1),
elRewardsVaultBalance: e18(2),
lastWithdrawalRequestIdToFinalize: 1,
finalizationShareRate: e27(1),
isBunkerMode: true,
extraDataFormat: EXTRA_DATA_FORMAT_LIST,
extraDataHash: extraDataHash,
extraDataItemsCount: extraDataItems.length
}
reportItems = getReportDataItems(reportFields)
const reportHash = calcReportDataHash(reportItems)
await deployed.consensus.addMember(member1, 1, { from: admin })
await deployed.consensus.submitReport(refSlot, reportHash, CONSENSUS_VERSION, { from: member1 })

oracleVersion = +(await deployed.oracle.getContractVersion())
deadline = (await deployed.oracle.getConsensusReport()).processingDeadlineTime

oracle = deployed.oracle
consensus = deployed.consensus
oracleVersion = +(await oracle.getContractVersion())
await consensus.addMember(member1, 1, { from: admin })
}

async function prepareNextReport(newReportFields) {
await consensus.setTime(deadline)
async function prepareNextReport({ extraData: extraDataArg = {}, reportFields: reportFieldsArg = {} }) {
const extraData = extraDataArg || getDefaultExtraData()

const extraDataItems = encodeExtraDataItems(extraData)
const extraDataList = packExtraDataList(extraDataItems)
const extraDataHash = calcExtraDataListHash(extraDataList)

const reportFields = getDefaultReportFields({
extraDataHash,
extraDataItemsCount: extraDataItems.length,
...reportFieldsArg
})

const newReportItems = getReportDataItems(newReportFields)
const reportHash = calcReportDataHash(newReportItems)
const reportItems = getReportDataItems(reportFields)
const reportHash = calcReportDataHash(reportItems)

await consensus.advanceTimeToNextFrameStart()
await consensus.submitReport(newReportFields.refSlot, reportHash, CONSENSUS_VERSION, { from: member1 })
await oracle.submitReportData(newReportItems, oracleVersion, { from: member1 })
await consensus.submitReport(reportFields.refSlot, reportHash, CONSENSUS_VERSION, { from: member1 })
const deadline = (await oracle.getConsensusReport()).processingDeadlineTime
await oracle.submitReportData(reportItems, oracleVersion, { from: member1 })

console.log(deadline)

return {
extraData,
extraDataItems,
extraDataList,
extraDataHash,
reportFields,
reportItems,
reportHash,
deadline
}
}

async function prepareNextReportInNextFrame({ extraData = {}, reportFields = {} }) {
const { refSlot } = await consensus.getCurrentFrame()
const next = await prepareNextReport({
extraData,
reportFields: {
...reportFields,
refSlot: +refSlot + SLOTS_PER_FRAME
}
})
return next
}

context('deploying', () => {
Expand All @@ -90,13 +109,7 @@ contract('AccountingOracle', ([admin, account1, account2, member1, member2, stra
it('deploying accounting oracle', async () => {
assert.isNotNull(oracle)
assert.isNotNull(consensus)
assert.isNotNull(reportItems)
assert.isNotNull(extraData)
assert.isNotNull(extraDataList)
assert.isNotNull(extraDataHash)
assert.isNotNull(extraDataItems)
assert.isNotNull(oracleVersion)
assert.isNotNull(deadline)
})
})

Expand All @@ -107,29 +120,17 @@ contract('AccountingOracle', ([admin, account1, account2, member1, member2, stra
beforeEach(deploy)

it('should revert if incorrect extra data list stuckKeys moduleId', async () => {
const { refSlot } = await consensus.getCurrentFrame()

const nextRefSlot = +refSlot + SLOTS_PER_FRAME
const extraDataDefault = getDefaultExtraData()
const invalidExtraData = {
...extraData,
...extraDataDefault,
stuckKeys: [
...extraData.stuckKeys,
...extraDataDefault.stuckKeys,
{ moduleId: 4, nodeOpIds: [1], keysCounts: [2] },
{ moduleId: 4, nodeOpIds: [1], keysCounts: [2] }
]
}
const extraDataItems = encodeExtraDataItems(invalidExtraData)
const extraDataList = packExtraDataList(extraDataItems)
const extraDataHash = calcExtraDataListHash(extraDataList)

const newReportFields = {
...reportFields,
refSlot: nextRefSlot,
extraDataHash: extraDataHash,
extraDataItemsCount: extraDataItems.length
}

await prepareNextReport(newReportFields)
const { extraDataList } = await prepareNextReportInNextFrame({ extraData: invalidExtraData })

await assert.reverts(
oracle.submitReportExtraDataList(extraDataList, {
Expand All @@ -140,29 +141,17 @@ contract('AccountingOracle', ([admin, account1, account2, member1, member2, stra
})

it('should revert if incorrect extra data list exitedKeys moduleId', async () => {
const { refSlot } = await consensus.getCurrentFrame()

const nextRefSlot = +refSlot + SLOTS_PER_FRAME
const extraDataDefault = getDefaultExtraData()
const invalidExtraData = {
...extraData,
...extraDataDefault,
exitedKeys: [
...extraData.exitedKeys,
...extraDataDefault.exitedKeys,
{ moduleId: 4, nodeOpIds: [1], keysCounts: [2] },
{ moduleId: 4, nodeOpIds: [1], keysCounts: [2] }
]
}
const extraDataItems = encodeExtraDataItems(invalidExtraData)
const extraDataList = packExtraDataList(extraDataItems)
const extraDataHash = calcExtraDataListHash(extraDataList)

const newReportFields = {
...reportFields,
refSlot: nextRefSlot,
extraDataHash: extraDataHash,
extraDataItemsCount: extraDataItems.length
}

await prepareNextReport(newReportFields)
const { extraDataList } = await prepareNextReportInNextFrame({ extraData: invalidExtraData })

await assert.reverts(
oracle.submitReportExtraDataList(extraDataList, {
Expand All @@ -172,37 +161,25 @@ contract('AccountingOracle', ([admin, account1, account2, member1, member2, stra
)
})

it('should should allow calling if correct extra data list moduleId', async () => {
const { refSlot } = await consensus.getCurrentFrame()

const nextRefSlot = +refSlot + SLOTS_PER_FRAME
it('should allow calling if correct extra data list moduleId', async () => {
const extraDataDefault = getDefaultExtraData()
const invalidExtraData = {
stuckKeys: [
...extraData.stuckKeys,
...extraDataDefault.stuckKeys,
{ moduleId: 4, nodeOpIds: [1], keysCounts: [2] },
{ moduleId: 5, nodeOpIds: [1], keysCounts: [2] }
],
exitedKeys: [
...extraData.exitedKeys,
...extraDataDefault.exitedKeys,
{ moduleId: 4, nodeOpIds: [1], keysCounts: [2] },
{ moduleId: 5, nodeOpIds: [1], keysCounts: [2] }
]
}
const extraDataItems = encodeExtraDataItems(invalidExtraData)
const extraDataList = packExtraDataList(extraDataItems)
const extraDataHash = calcExtraDataListHash(extraDataList)

const newReportFields = {
...reportFields,
refSlot: nextRefSlot,
extraDataHash: extraDataHash,
extraDataItemsCount: extraDataItems.length
}

await prepareNextReport(newReportFields)
const { extraDataList, reportFields } = await prepareNextReportInNextFrame({ extraData: invalidExtraData })

const tx = await oracle.submitReportExtraDataList(extraDataList, { from: member1 })
assertEvent(tx, 'ExtraDataSubmitted', { expectedArgs: { refSlot: newReportFields.refSlot } })
assert.emits(tx, 'ExtraDataSubmitted', { refSlot: reportFields.refSlot })
})
})
})
Expand Down

0 comments on commit 6b53867

Please sign in to comment.