-
Notifications
You must be signed in to change notification settings - Fork 246
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: separate mocks for unstructured storage tests
- Loading branch information
Showing
5 changed files
with
124 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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' | ||
) | ||
}) | ||
}) | ||
}) |