Skip to content
This repository has been archived by the owner on Jan 24, 2022. It is now read-only.

Support solidity 0.6 in Initializable contract #1413

Merged
merged 3 commits into from
Jan 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"tests/cli/test",
"tests/cli/workdir",
"tests/kits/test",
"tests/kits/workdir"
"tests/kits/workdir",
"tests/mocks/*"
],
"nohoist": [
"**/mock-stdlib"
Expand Down
10 changes: 5 additions & 5 deletions packages/cli/test/utils/solidity.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ require('../setup');

import { getImports } from '../../src/utils/solidity';

describe('utils.solidity', function () {
describe('getImports', function () {
it('returns no imports from empty file', function () {
describe('utils.solidity', function() {
describe('getImports', function() {
it('returns no imports from empty file', function() {
getImports('').should.be.empty;
});

it.skip('returns no imports from commented out file', function () {
it.skip('returns no imports from commented out file', function() {
getImports(`// import "Foo.sol";`).should.be.empty;
});
});
});
});
5 changes: 3 additions & 2 deletions packages/lib/contracts/Initializable.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity >=0.4.24 <0.6.0;
pragma solidity >=0.4.24 <0.7.0;


/**
Expand Down Expand Up @@ -51,8 +51,9 @@ contract Initializable {
// deployed when running a constructor, any checks on its code size will
// yield zero, making it an effective way to detect if a contract is
// under construction or not.
address self = address(this);
uint256 cs;
assembly { cs := extcodesize(address) }
assembly { cs := extcodesize(self) }
return cs == 0;
}

Expand Down
4 changes: 2 additions & 2 deletions packages/lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@
"lodash.times": "^4.3.2",
"lodash.zipwith": "^4.2.0",
"mocha": "^6.2.2",
"mock-dependency": "file:test/mocks/mock-dependency",
"mock-solc-0.6": "file:test/mocks/mock-solc-0.6",
"mock-dependency": "file:../../tests/mocks/mock-dependency",
"mock-solc-0.6": "file:../../tests/mocks/mock-solc-0.6",
"prettier": "^1.19.1",
"sinon": "^6.1.4",
"sinon-chai": "^3.3.0",
Expand Down
120 changes: 63 additions & 57 deletions packages/lib/test/contracts/Initializable.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,81 +6,87 @@ import assertRevert from '../../src/test/helpers/assertRevert';

import { assert } from 'chai';

const InitializableMock = Contracts.getFromLocal('InitializableMock');
const SampleMother = Contracts.getFromLocal('SampleMother');
const SampleGramps = Contracts.getFromLocal('SampleGramps');
const SampleFather = Contracts.getFromLocal('SampleFather');
const SampleChild = Contracts.getFromLocal('SampleChild');

describe('Initializable', function() {
describe('basic testing without inheritance', function() {
beforeEach('deploying', async function() {
this.contract = await InitializableMock.new();
});
testInitializable(`Initializable on solc 0.5`, {
InitializableMock: Contracts.getFromLocal('InitializableMock'),
SampleChild: Contracts.getFromLocal('SampleChild'),
});

context('before initialize', function() {
it('initializer has not run', async function() {
assert.isFalse(await this.contract.methods.initializerRan().call());
});
});
testInitializable(`Initializable on solc 0.6`, {
InitializableMock: Contracts.getFromNodeModules('mock-solc-0.6', 'InitializableMock'),
SampleChild: Contracts.getFromNodeModules('mock-solc-0.6', 'SampleChild'),
});

context('after initialize', function() {
beforeEach('initializing', async function() {
await this.contract.methods.initialize().send();
function testInitializable(description, { InitializableMock, SampleChild }) {
describe(description, function() {
describe('basic testing without inheritance', function() {
beforeEach('deploying', async function() {
this.contract = await InitializableMock.new();
});

it('initializer has run', async function() {
assert.isTrue(await this.contract.methods.initializerRan().call());
context('before initialize', function() {
it('initializer has not run', async function() {
assert.isFalse(await this.contract.methods.initializerRan().call());
});
});

it('initializer does not run again', async function() {
await assertRevert(this.contract.methods.initialize().send());
});
});
context('after initialize', function() {
beforeEach('initializing', async function() {
await this.contract.methods.initialize().send();
});

context('after nested initialize', function() {
beforeEach('initializing', async function() {
await this.contract.methods.initializeNested().send();
it('initializer has run', async function() {
assert.isTrue(await this.contract.methods.initializerRan().call());
});

it('initializer does not run again', async function() {
await assertRevert(this.contract.methods.initialize().send());
});
});

it('initializer has run', async function() {
assert.isTrue(await this.contract.methods.initializerRan().call());
context('after nested initialize', function() {
beforeEach('initializing', async function() {
await this.contract.methods.initializeNested().send();
});

it('initializer has run', async function() {
assert.isTrue(await this.contract.methods.initializerRan().call());
});
});
});
});

describe('complex testing with inheritance', function() {
const mother = 12;
const gramps = 56;
const father = 34;
const child = 78;
describe('complex testing with inheritance', function() {
const mother = 12;
const gramps = 56;
const father = 34;
const child = 78;

beforeEach('deploying', async function() {
this.contract = await SampleChild.new();
});
beforeEach('deploying', async function() {
this.contract = await SampleChild.new();
});

beforeEach('initializing', async function() {
await this.contract.methods.initialize(mother, gramps, father, child).send();
});
beforeEach('initializing', async function() {
await this.contract.methods.initialize(mother, gramps, father, child).send();
});

it('initializes human', async function() {
assert.equal(await this.contract.methods.isHuman().call(), true);
});
it('initializes human', async function() {
assert.equal(await this.contract.methods.isHuman().call(), true);
});

it('initializes mother', async function() {
assert.equal(await this.contract.methods.mother().call(), mother);
});
it('initializes mother', async function() {
assert.equal(await this.contract.methods.mother().call(), mother);
});

it('initializes gramps', async function() {
assert.equal(await this.contract.methods.gramps().call(), gramps);
});
it('initializes gramps', async function() {
assert.equal(await this.contract.methods.gramps().call(), gramps);
});

it('initializes father', async function() {
assert.equal(await this.contract.methods.father().call(), father);
});
it('initializes father', async function() {
assert.equal(await this.contract.methods.father().call(), father);
});

it('initializes child', async function() {
assert.equal(await this.contract.methods.child().call(), child);
it('initializes child', async function() {
assert.equal(await this.contract.methods.child().call(), child);
});
});
});
});
}
1 change: 1 addition & 0 deletions tests/mocks/mock-solc-0.6/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
!build/
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@
"telemetryOptIn": false,
"compiler": {
"manager": "openzeppelin",
"solcVersion": "0.6.0",
"solcVersion": "0.6.2",
"compilerSettings": {
"optimizer": {
"enabled": false,
"runs": "200"
}
}
},
"artifactsDir": "build/contracts",
"contractsDir": "contracts",
"typechain": {}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -653,11 +653,11 @@
],
"src": "0:462:0"
},
"bytecode": "0x6080604052348015600f57600080fd5b5060818061001e6000396000f3fe60806040526004361060265760003560e01c806310c82ddf14602b578063f77df40a14603f575b600080fd5b348015603657600080fd5b50603d6047565b005b60456049565b005b565b56fea26469706673582212201883a9831b1f8f6f26caaa345bbf964728ba05ae549373d0f00a92006fd05bff64736f6c63430006000033",
"deployedBytecode": "0x60806040526004361060265760003560e01c806310c82ddf14602b578063f77df40a14603f575b600080fd5b348015603657600080fd5b50603d6047565b005b60456049565b005b565b56fea26469706673582212201883a9831b1f8f6f26caaa345bbf964728ba05ae549373d0f00a92006fd05bff64736f6c63430006000033",
"bytecode": "0x6080604052348015600f57600080fd5b5060818061001e6000396000f3fe60806040526004361060265760003560e01c806310c82ddf14602b578063f77df40a14603f575b600080fd5b348015603657600080fd5b50603d6047565b005b60456049565b005b565b56fea2646970667358221220b27de1792583c12c3ac075a9c535f5d05aa936d0924b6652561ab809b1252a4064736f6c63430006020033",
"deployedBytecode": "0x60806040526004361060265760003560e01c806310c82ddf14602b578063f77df40a14603f575b600080fd5b348015603657600080fd5b50603d6047565b005b60456049565b005b565b56fea2646970667358221220b27de1792583c12c3ac075a9c535f5d05aa936d0924b6652561ab809b1252a4064736f6c63430006020033",
"compiler": {
"name": "solc",
"version": "0.6.0+commit.26b70077.Emscripten.clang",
"version": "0.6.2+commit.bacdbe57.Linux.g++",
"optimizer": {
"enabled": false,
"runs": 200
Expand Down
Loading