Skip to content

Commit

Permalink
Merge 25fa080 into ed0a3d0
Browse files Browse the repository at this point in the history
  • Loading branch information
facuspagnuolo committed May 23, 2019
2 parents ed0a3d0 + 25fa080 commit 164e12f
Show file tree
Hide file tree
Showing 22 changed files with 176 additions and 153 deletions.
30 changes: 14 additions & 16 deletions apps/agent/test/agent_shared.js
Expand Up @@ -3,8 +3,8 @@ const ethUtil = require('ethereumjs-util')
const ethABI = new (require('web3-eth-abi').AbiCoder)()
const { assertRevert } = require('@aragon/test-helpers/assertThrow')
const { encodeCallScript } = require('@aragon/test-helpers/evmScript')
const assertEvent = require('@aragon/test-helpers/assertEvent')
const getEvent = (receipt, event, arg) => { return receipt.logs.filter(l => l.event == event)[0].args[arg] }
const { getEventArgument, getNewProxyAddress } = require('@aragon/test-helpers/events')
const { assertAmountOfEvents } = require('@aragon/test-helpers/assertEvent')(web3)

// Allow for sharing this test across other agent implementations and subclasses
module.exports = (
Expand Down Expand Up @@ -67,7 +67,7 @@ module.exports = (

beforeEach(async () => {
const r = await daoFact.newDAO(root)
dao = Kernel.at(getEvent(r, 'DeployDAO', 'dao'))
dao = Kernel.at(getEventArgument(r, 'DeployDAO', 'dao'))
acl = ACL.at(await dao.acl())

await acl.createPermission(root, dao.address, APP_MANAGER_ROLE, root, { from: root })
Expand All @@ -76,8 +76,7 @@ module.exports = (
agentAppId = namehash(`${agentName}.aragonpm.test`)

const agentReceipt = await dao.newAppInstance(agentAppId, agentBase.address, '0x', false)
const agentProxyAddress = getEvent(agentReceipt, 'NewAppProxy', 'proxy')
agent = AgentLike.at(agentProxyAddress)
agent = AgentLike.at(getNewProxyAddress(agentReceipt))

await agent.initialize()
})
Expand Down Expand Up @@ -107,7 +106,7 @@ module.exports = (
const data = executionTarget.contract.setCounter.getData(N)
const receipt = await agent.execute(executionTarget.address, depositAmount, data, { from: executor })

assertEvent(receipt, 'Execute')
assertAmountOfEvents(receipt, 'Execute')
assert.equal(await executionTarget.counter(), N, `expected counter to be ${N}`)
assert.equal((await getBalance(executionTarget.address)).toString(), depositAmount, 'expected ending balance of execution target to be correct')
assert.equal((await getBalance(agent.address)).toString(), 0, 'expected ending balance of agent at end to be 0')
Expand All @@ -117,7 +116,7 @@ module.exports = (
const noData = '0x'
const receipt = await agent.execute(executionTarget.address, depositAmount, noData, { from: executor })

assertEvent(receipt, 'Execute')
assertAmountOfEvents(receipt, 'Execute')
// Fallback just runs ExecutionTarget.execute()
assert.equal(await executionTarget.counter(), 1, 'expected counter to be 1')
assert.equal((await getBalance(executionTarget.address)).toString(), depositAmount, 'expected ending balance of execution target to be correct')
Expand All @@ -129,7 +128,7 @@ module.exports = (
const noData = '0x'
const receipt = await agent.execute(cheapFallbackTarget.address, depositAmount, noData, { from: executor })

assertEvent(receipt, 'Execute')
assertAmountOfEvents(receipt, 'Execute')
assert.equal((await getBalance(cheapFallbackTarget.address)).toString(), depositAmount, 'expected ending balance of execution target to be correct')
assert.equal((await getBalance(agent.address)).toString(), 0, 'expected ending balance of agent at end to be 0')
})
Expand All @@ -141,7 +140,7 @@ module.exports = (
const noData = '0x'
const receipt = await agent.execute(expensiveFallbackTarget.address, depositAmount, noData, { from: executor })

assertEvent(receipt, 'Execute')
assertAmountOfEvents(receipt, 'Execute')
// Fallback increments counter
assert.equal(await expensiveFallbackTarget.counter(), 1)
assert.equal((await getBalance(expensiveFallbackTarget.address)).toString(), depositAmount, 'expected ending balance of execution target to be correct')
Expand All @@ -155,7 +154,7 @@ module.exports = (

const receipt = await agent.execute(nonContract, depositAmount, randomData, { from: executor })

assertEvent(receipt, 'Execute')
assertAmountOfEvents(receipt, 'Execute')
assert.equal((await getBalance(nonContract)).toString(), nonContractBalance.add(depositAmount).toString(), 'expected ending balance of non-contract to be correct')
assert.equal((await getBalance(agent.address)).toString(), 0, 'expected ending balance of agent at end to be 0')
})
Expand All @@ -167,7 +166,7 @@ module.exports = (

const receipt = await agent.execute(nonContract, depositAmount, noData, { from: executor })

assertEvent(receipt, 'Execute')
assertAmountOfEvents(receipt, 'Execute')
assert.equal((await getBalance(nonContract)).toString(), nonContractBalance.add(depositAmount).toString(), 'expected ending balance of non-contract to be correct')
assert.equal((await getBalance(agent.address)).toString(), 0, 'expected ending balance of agent at end to be 0')
})
Expand Down Expand Up @@ -227,7 +226,7 @@ module.exports = (
const data = executionTarget.contract.setCounter.getData(N)
const receipt = await agent.execute(executionTarget.address, depositAmount, data, { from: granteeEqualToSig })

assertEvent(receipt, 'Execute')
assertAmountOfEvents(receipt, 'Execute')
assert.equal(await executionTarget.counter(), N, `expected counter to be ${N}`)
assert.equal((await getBalance(executionTarget.address)).toString(), depositAmount, 'expected ending balance of execution target to be correct')
assert.equal((await getBalance(agent.address)).toString(), 0, 'expected ending balance of agent at end to be 0')
Expand All @@ -237,7 +236,7 @@ module.exports = (
const data = executionTarget.contract.execute.getData()
const receipt = await agent.execute(executionTarget.address, depositAmount, data, { from: granteeUnequalToSig })

assertEvent(receipt, 'Execute')
assertAmountOfEvents(receipt, 'Execute')
assert.equal(await executionTarget.counter(), 1, `expected counter to be ${1}`)
assert.equal((await getBalance(executionTarget.address)).toString(), depositAmount, 'expected ending balance of execution target to be correct')
assert.equal((await getBalance(agent.address)).toString(), 0, 'expected ending balance of agent at end to be 0')
Expand Down Expand Up @@ -281,7 +280,7 @@ module.exports = (

// Should execute ExecutionTarget.execute() twice
assert.equal(await executionTarget.counter(), 2)
assertEvent(receipt, 'ScriptResult')
assertAmountOfEvents(receipt, 'ScriptResult')
})

it('fails to run script without permissions', async () => {
Expand Down Expand Up @@ -390,8 +389,7 @@ module.exports = (
const createChildAgentGenerator = (designatedSigner) =>
async () => {
const agentReceipt = await dao.newAppInstance(agentAppId, agentBase.address, '0x', false)
const agentProxyAddress = getEvent(agentReceipt, 'NewAppProxy', 'proxy')
const childAgent = AgentLike.at(agentProxyAddress)
const childAgent = AgentLike.at(getNewProxyAddress(agentReceipt))

await childAgent.initialize()
await acl.createPermission(signerDesignator, childAgent.address, DESIGNATE_SIGNER_ROLE, root, { from: root })
Expand Down

0 comments on commit 164e12f

Please sign in to comment.