Skip to content

Commit

Permalink
Merge pull request #258 from aragon/isInit_modifier
Browse files Browse the repository at this point in the history
Add modifier to check for already initialized apps
  • Loading branch information
bingen committed Mar 26, 2018
2 parents c5ad061 + fcfe8a2 commit 4c03845
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
5 changes: 5 additions & 0 deletions contracts/common/Initializable.sol
Expand Up @@ -9,6 +9,11 @@ contract Initializable is AppStorage {
_;
}

modifier isInitialized {
require(initializationBlock > 0);
_;
}

/**
* @return Block number in which the contract was initialized
*/
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "@aragon/os",
"version": "3.1.1",
"version": "3.1.2",
"description": "Core contracts for Aragon",
"scripts": {
"compile": "truffle compile",
Expand Down
12 changes: 12 additions & 0 deletions test/kernel_apps.js
Expand Up @@ -132,12 +132,24 @@ contract('Kernel apps', accounts => {
await kernel.setApp(APP_BASE_NAMESPACE, appId, appCode1.address)
})

it('fails calling function with isInitialized (if it\'s not)', async () => {
return assertRevert(async () => {
await app.requiresInitialization()
})
})

it('can initialize', async () => {
await app.initialize()

assert.isAbove(await app.getInitializationBlock(), 0, 'app should have been initialized')
})

it('allows calls with isInitialized modifier', async () => {
await app.initialize()
const result = await app.requiresInitialization()
assert.equal(result, true, "Should return true")
})

it('app call works if sent from authed entity', async () => {
await app.setValue(10)
assert.equal(await app.getValue(), 10, 'should have returned correct value')
Expand Down
4 changes: 4 additions & 0 deletions test/mocks/AppStub.sol
Expand Up @@ -15,6 +15,10 @@ contract AppStub is AragonApp, AppSt {
stringTest = "hola";
}

function requiresInitialization() isInitialized view returns (bool) {
return true;
}

function setValue(uint i) auth(ROLE) {
a = i;
}
Expand Down

0 comments on commit 4c03845

Please sign in to comment.