Skip to content

Commit

Permalink
fix: acceptance test for empty proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
krogla committed Oct 19, 2023
1 parent 023676a commit b838209
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 39 deletions.
64 changes: 35 additions & 29 deletions scripts/simpledvt/01-deploy-app-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ const chalk = require('chalk')

const runOrWrapScript = require('../helpers/run-or-wrap-script')
const { log, yl } = require('../helpers/log')
const { getDeployer, readStateAppAddress } = require('./helpers')
const { getDeployer, readStateAppAddress, _checkEq } = require('./helpers')
const {
readNetworkState,
assertRequiredNetworkState,
persistNetworkState2,
} = require('../helpers/persisted-network-state')

const { hash: namehash } = require('eth-ens-namehash')
const { ZERO_ADDRESS } = require('../../test/helpers/utils')

const APP_TRG = process.env.APP_TRG || 'simple-dvt'
const DEPLOYER = process.env.DEPLOYER || ''
Expand Down Expand Up @@ -48,38 +49,43 @@ async function deployEmptyProxy({ web3, artifacts, trgAppName = APP_TRG }) {
trgProxyAddress = readStateAppAddress(state, `app:${trgAppName}`)
}

if (trgProxyAddress && (await web3.eth.getCode(trgProxyAddress)) !== '0x') {
log.error(`Target app proxy is already deployed at ${yl(trgProxyAddress)}`)
return
}

const kernel = await artifacts.require('Kernel').at(kernelAddress)
const tx = await log.tx(
`Deploying proxy for ${trgAppName}`,
kernel.newAppProxy(kernelAddress, trgAppId, { from: deployer })
)
// Find the deployed proxy address in the tx logs.
const e = tx.logs.find((l) => l.event === 'NewAppProxy')
trgProxyAddress = e.args.proxy

// upd deployed state
persistNetworkState2(network.name, netId, state, {
[`app:${trgAppName}`]: {
aragonApp: {
name: trgAppName,
fullName: trgAppFullName,
id: trgAppId,
if (!trgProxyAddress || (await web3.eth.getCode(trgProxyAddress)) === '0x') {
const kernel = await artifacts.require('Kernel').at(kernelAddress)
const tx = await log.tx(
`Deploying proxy for ${trgAppName}`,
kernel.newAppProxy(kernelAddress, trgAppId, { from: deployer })
)
// Find the deployed proxy address in the tx logs.
const e = tx.logs.find((l) => l.event === 'NewAppProxy')
trgProxyAddress = e.args.proxy

// upd deployed state
persistNetworkState2(network.name, netId, state, {
[`app:${trgAppName}`]: {
aragonApp: {
name: trgAppName,
fullName: trgAppFullName,
id: trgAppId,
},
proxy: {
address: trgProxyAddress,
contract: '@aragon/os/contracts/apps/AppProxyUpgradeable.sol',
constructorArgs: [kernelAddress, trgAppId, '0x'],
},
},
proxy: {
address: trgProxyAddress,
contract: '@aragon/os/contracts/apps/AppProxyUpgradeable.sol',
constructorArgs: [kernelAddress, trgAppId, '0x'],
},
},
})
})
}

log(`Target app proxy deployed at`, yl(trgProxyAddress))

log.splitter()
log('Checking deployed proxy...')

const proxy = await artifacts.require('AppProxyUpgradeable').at(trgProxyAddress)

_checkEq(await proxy.kernel(), kernelAddress, 'App proxy kernel address matches Lido DAO')
_checkEq(await proxy.appId(), trgAppId, 'App proxy AppId matches SimpleDVT')
_checkEq(await proxy.implementation(), ZERO_ADDRESS, 'App proxy has ZERO_ADDRESS implementations')
}

module.exports = runOrWrapScript(deployEmptyProxy, module)
4 changes: 2 additions & 2 deletions scripts/simpledvt/02-clone-nor.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const REQUIRED_NET_STATE = [
`app:${APP_NAMES.ARAGON_TOKEN_MANAGER}`,
]

async function deployNORClone({ web3, artifacts, trgAppName = APP_TRG, ipfsCid = APP_IPFS_CID }) {
async function deploySimpleDVT({ web3, artifacts, trgAppName = APP_TRG, ipfsCid = APP_IPFS_CID }) {
const netId = await web3.eth.net.getId()

const srcAppName = APP_NAMES.NODE_OPERATORS_REGISTRY
Expand Down Expand Up @@ -471,4 +471,4 @@ function getVoters(agentAddress, vestingParams, daoTokenTotalSupply, quorumPcnt)

return voters
}
module.exports = runOrWrapScript(deployNORClone, module)
module.exports = runOrWrapScript(deploySimpleDVT, module)
11 changes: 3 additions & 8 deletions scripts/simpledvt/03-check-deployed.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const { network, ethers } = require('hardhat')
const { Contract, utils } = require('ethers')
const chalk = require('chalk')
const { assert } = require('chai')
const runOrWrapScript = require('../helpers/run-or-wrap-script')
const { log, yl, gr } = require('../helpers/log')
const {
getDeployer,
readStateAppAddress,
_checkEq,
MANAGE_SIGNING_KEYS,
MANAGE_NODE_OPERATOR_ROLE,
SET_NODE_OPERATOR_LIMIT_ROLE,
Expand Down Expand Up @@ -37,12 +37,7 @@ const REQUIRED_NET_STATE = [
`app:${APP_NAMES.ARAGON_TOKEN_MANAGER}`,
]

function _checkEq(a, b, descr = '') {
assert.equal(a, b, descr)
log.success(descr)
}

async function deployNORClone({ web3, artifacts, trgAppName = APP_TRG, ipfsCid = APP_IPFS_CID }) {
async function checkSimpleDVT({ web3, artifacts, trgAppName = APP_TRG, ipfsCid = APP_IPFS_CID }) {
const netId = await web3.eth.net.getId()

log.splitter()
Expand Down Expand Up @@ -455,4 +450,4 @@ async function deployNORClone({ web3, artifacts, trgAppName = APP_TRG, ipfsCid =
}
}

module.exports = runOrWrapScript(deployNORClone, module)
module.exports = runOrWrapScript(checkSimpleDVT, module)
9 changes: 9 additions & 0 deletions scripts/simpledvt/helpers.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
const { assert } = require('chai')
const { log } = require('../helpers/log')

const KERNEL_APP_BASES_NAMESPACE = '0xf1f3eb40f5bc1ad1344716ced8b8a0431d840b5783aea1fd01786bc26f35ac0f'

const MANAGE_SIGNING_KEYS = '0x75abc64490e17b40ea1e66691c3eb493647b24430b358bd87ec3e5127f1621ee'
Expand Down Expand Up @@ -30,10 +33,16 @@ function getSignature(instance, method) {
return methodAbi.signature
}

function _checkEq(a, b, descr = '') {
assert.equal(a, b, descr)
log.success(descr)
}

module.exports = {
readStateAppAddress,
getDeployer,
getSignature,
_checkEq,
KERNEL_APP_BASES_NAMESPACE,
MANAGE_SIGNING_KEYS,
MANAGE_NODE_OPERATOR_ROLE,
Expand Down

0 comments on commit b838209

Please sign in to comment.