diff --git a/contracts/test/mocks/AppStubPinnedStorage.sol b/contracts/test/mocks/AppProxyPinnedStorageMock.sol similarity index 94% rename from contracts/test/mocks/AppStubPinnedStorage.sol rename to contracts/test/mocks/AppProxyPinnedStorageMock.sol index 6c196b663..5de96a493 100644 --- a/contracts/test/mocks/AppStubPinnedStorage.sol +++ b/contracts/test/mocks/AppProxyPinnedStorageMock.sol @@ -20,7 +20,7 @@ contract KernelPinnedStorageMock is Kernel, FakeAppConstants { // Testing this contract is a bit of a pain... we can't overload anything to make the contract check // pass in the constructor, so we're forced to initialize this with a mocked Kernel that already // sets a contract for the fake app. -contract AppStubPinnedStorage is AppProxyPinned, FakeAppConstants { +contract AppProxyPinnedStorageMock is AppProxyPinned, FakeAppConstants { constructor(KernelPinnedStorageMock _mockKernel) AppProxyPinned(IKernel(_mockKernel), FAKE_APP_ID, new bytes(0)) public // solium-disable-line visibility-first diff --git a/contracts/test/mocks/AppStubStorage.sol b/contracts/test/mocks/AppStorageMock.sol similarity index 53% rename from contracts/test/mocks/AppStubStorage.sol rename to contracts/test/mocks/AppStorageMock.sol index e3939a9af..53d977e69 100644 --- a/contracts/test/mocks/AppStubStorage.sol +++ b/contracts/test/mocks/AppStorageMock.sol @@ -1,14 +1,9 @@ pragma solidity 0.4.24; -import "../../apps/UnsafeAragonApp.sol"; +import "../../apps/AppStorage.sol"; -// Need to use UnsafeAragonApp to allow initialization -contract AppStubStorage is UnsafeAragonApp { - function initialize() onlyInit public { - initialized(); - } - +contract AppStorageMock is AppStorage { function setKernelExt(IKernel _kernel) public { setKernel(_kernel); } @@ -24,8 +19,4 @@ contract AppStubStorage is UnsafeAragonApp { function getAppIdPosition() public pure returns (bytes32) { return APP_ID_POSITION; } - - function getInitializationBlockPosition() public pure returns (bytes32) { - return INITIALIZATION_BLOCK_POSITION; - } } diff --git a/contracts/test/mocks/InitializableStorageMock.sol b/contracts/test/mocks/InitializableStorageMock.sol new file mode 100644 index 000000000..7dd93f1a2 --- /dev/null +++ b/contracts/test/mocks/InitializableStorageMock.sol @@ -0,0 +1,14 @@ +pragma solidity 0.4.24; + +import "../../common/Initializable.sol"; + + +contract InitializableStorageMock is Initializable { + function initialize() onlyInit public { + initialized(); + } + + function getInitializationBlockPosition() public pure returns (bytes32) { + return INITIALIZATION_BLOCK_POSITION; + } +} diff --git a/test/keccak_constants.js b/test/keccak_constants.js index bf4ac613a..99e12031a 100644 --- a/test/keccak_constants.js +++ b/test/keccak_constants.js @@ -85,19 +85,23 @@ contract('Constants', accounts => { }) it('checks AppStorage unstructured storage constants', async () => { - const app = await getContract('AppStubStorage').new() + const appStorage = await getContract('AppStorageMock').new() - assert.equal(await app.getKernelPosition(), await keccakConstants.kernelPosition(), "kernelPosition doesn't match") - assert.equal(await app.getAppIdPosition(), await keccakConstants.appIdPosition(), "appIdPosition doesn't match") - assert.equal(await app.getInitializationBlockPosition(), await keccakConstants.initializationBlockPosition(), "initializationBlockPosition doesn't match") + assert.equal(await appStorage.getKernelPosition(), await keccakConstants.kernelPosition(), "kernelPosition doesn't match") + assert.equal(await appStorage.getAppIdPosition(), await keccakConstants.appIdPosition(), "appIdPosition doesn't match") }) it('checks AppProxyPinned unstructured storage constants', async () => { // Set up AppStubPinnedStorage const fakeApp = await getContract('AppStub').new() const kernelMock = await getContract('KernelPinnedStorageMock').new(fakeApp.address) - const app = await getContract('AppStubPinnedStorage').new(kernelMock.address) + const pinnedProxy = await getContract('AppProxyPinnedStorageMock').new(kernelMock.address) - assert.equal(await app.getPinnedCodePosition(), await keccakConstants.pinnedCodePosition(), "pinnedCodePosition doesn't match") + assert.equal(await pinnedProxy.getPinnedCodePosition(), await keccakConstants.pinnedCodePosition(), "pinnedCodePosition doesn't match") + }) + + it('checks Initializable unstructured storage constants', async () => { + const initializableMock = await getContract('InitializableStorageMock').new() + assert.equal(await initializableMock.getInitializationBlockPosition(), await keccakConstants.initializationBlockPosition(), "initializationBlockPosition doesn't match") }) }) diff --git a/test/unstructured_storage.js b/test/unstructured_storage.js index 823158469..18961c168 100644 --- a/test/unstructured_storage.js +++ b/test/unstructured_storage.js @@ -1,85 +1,115 @@ const AppStub = artifacts.require('AppStub') -const AppStubStorage = artifacts.require('AppStubStorage') -const AppStubPinnedStorage = artifacts.require('AppStubPinnedStorage') const Kernel = artifacts.require('Kernel') // Mocks +const AppStorageMock = artifacts.require('AppStorageMock') +const AppProxyPinnedStorageMock = artifacts.require('AppProxyPinnedStorageMock') +const InitializableStorageMock = artifacts.require('InitializableStorageMock') const KernelPinnedStorageMock = artifacts.require('KernelPinnedStorageMock') contract('Unstructured storage', accounts => { - let app, kernel + context('> AppStorage', () => { + let appStorage - beforeEach(async () => { - app = await AppStubStorage.new() - kernel = await Kernel.new(true) + beforeEach(async () => { + appStorage = await AppStorageMock.new() + }) - // Set up AppStubPinnedStorage - const fakeApp = await AppStub.new() - const kernelMock = await KernelPinnedStorageMock.new(fakeApp.address) - appPinned = await AppStubPinnedStorage.new(kernelMock.address) - }) + it('tests Kernel storage', async () => { + const kernel = await Kernel.new(true) + await appStorage.setKernelExt(kernel.address) + //checks + assert.equal( + await web3.eth.getStorageAt(appStorage.address, (await appStorage.getKernelPosition())), + (await appStorage.kernel()).toString(), + 'Kernel should match' + ) + assert.equal( + await web3.eth.getStorageAt(appStorage.address, (await appStorage.getKernelPosition())), + kernel.address, + 'Kernel original value should match' + ) + }) - it('tests init block', async () => { - // set values - await app.initialize() - const blockNumber = web3.eth.blockNumber - //checks - assert.equal( - parseInt(await web3.eth.getStorageAt(app.address, (await app.getInitializationBlockPosition())), 16), - blockNumber, - 'Init block should match' - ) - assert.equal( - parseInt(await web3.eth.getStorageAt(app.address, (await app.getInitializationBlockPosition())), 16), - (await app.getInitializationBlock()).toString(), - 'Init block should match' - ) + it('tests appID storage', async () => { + const appId = '0x1234000000000000000000000000000000000000000000000000000000000000' + await appStorage.setAppIdExt(appId) + //checks + assert.equal( + await web3.eth.getStorageAt(appStorage.address, (await appStorage.getAppIdPosition())), + (await appStorage.appId()).toString(), + 'appId should match' + ) + assert.equal( + await web3.eth.getStorageAt(appStorage.address, (await appStorage.getAppIdPosition())), + appId, + 'appId original value should match' + ) + }) }) - it('tests Kernel storage', async () => { - await app.setKernelExt(kernel.address) - //checks - assert.equal( - await web3.eth.getStorageAt(app.address, (await app.getKernelPosition())), - (await app.kernel()).toString(), - 'Kernel should match' - ) - assert.equal( - await web3.eth.getStorageAt(app.address, (await app.getKernelPosition())), - kernel.address, - 'Kernel original value should match' - ) + context('> AppProxyPinned', () => { + let appPinned + beforeEach(async () => { + // Set up AppStubPinnedStorage + const fakeApp = await AppStub.new() + const kernelMock = await KernelPinnedStorageMock.new(fakeApp.address) + appPinned = await AppProxyPinnedStorageMock.new(kernelMock.address) + }) + + it('tests pinnedCode storage', async () => { + const pinnedCode = '0x1200000000000000000000000000000000005678' + await appPinned.setPinnedCodeExt(pinnedCode) + //checks + assert.equal( + await web3.eth.getStorageAt(appPinned.address, (await appPinned.getPinnedCodePosition())), + (await appPinned.pinnedCodeExt()).toString(), + 'Pinned Code should match' + ) + assert.equal( + await web3.eth.getStorageAt(appPinned.address, (await appPinned.getPinnedCodePosition())), + pinnedCode, + 'Pinned Code original value should match' + ) + }) }) - it('tests appID storage', async () => { - const appId = '0x1234000000000000000000000000000000000000000000000000000000000000' - await app.setAppIdExt(appId) - //checks - assert.equal( - await web3.eth.getStorageAt(app.address, (await app.getAppIdPosition())), - (await app.appId()).toString(), - 'appId should match' - ) - assert.equal( - await web3.eth.getStorageAt(app.address, (await app.getAppIdPosition())), - appId, - 'appId original value should match' - ) }) - it('tests pinnedCode storage', async () => { - const pinnedCode = '0x1200000000000000000000000000000000005678' - await appPinned.setPinnedCodeExt(pinnedCode) - //checks - assert.equal( - await web3.eth.getStorageAt(appPinned.address, (await appPinned.getPinnedCodePosition())), - (await appPinned.pinnedCodeExt()).toString(), - 'Pinned Code should match' - ) - assert.equal( - await web3.eth.getStorageAt(appPinned.address, (await appPinned.getPinnedCodePosition())), - pinnedCode, - 'Pinned Code original value should match' - ) + context('> Initializable', () => { + let initializableMock + + beforeEach(async () => { + initializableMock = await InitializableStorageMock.new() + }) + + it('tests init block', async () => { + // set values + await initializableMock.initialize() + const blockNumber = web3.eth.blockNumber + //checks + assert.equal( + parseInt( + await web3.eth.getStorageAt( + initializableMock.address, + (await initializableMock.getInitializationBlockPosition()) + ), + 16 + ), + blockNumber, + 'Init block should match' + ) + assert.equal( + parseInt( + await web3.eth.getStorageAt( + initializableMock.address, + (await initializableMock.getInitializationBlockPosition()) + ), + 16 + ), + (await initializableMock.getInitializationBlock()).toString(), + 'Init block should match' + ) + }) }) })