Skip to content

Commit 67a3a78

Browse files
authored
Add solc 0.6.x integration mocks (#461)
1 parent d6b86fa commit 67a3a78

File tree

10 files changed

+557
-83
lines changed

10 files changed

+557
-83
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@
4444
"web3-utils": "^1.0.0"
4545
},
4646
"devDependencies": {
47-
"@nomiclabs/buidler": "^1.0.1",
48-
"@nomiclabs/buidler-truffle5": "^1.0.1",
49-
"@nomiclabs/buidler-web3": "^1.0.1",
47+
"@nomiclabs/buidler": "^1.0.2",
48+
"@nomiclabs/buidler-truffle5": "^1.0.2",
49+
"@nomiclabs/buidler-web3": "^1.0.2",
5050
"@truffle/contract": "^4.0.36",
5151
"decache": "^4.5.1",
5252
"ganache-core-sc": "^2.7.0-sc.0",
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Testing hooks
2+
const fn = (msg, config) => config.logger.log(msg);
3+
4+
module.exports = {
5+
skipFiles: ['Migrations.sol'],
6+
silent: process.env.SILENT ? true : false,
7+
istanbulReporter: ['json-summary', 'text'],
8+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const { loadPluginFile } = require("@nomiclabs/buidler/plugins-testing");
2+
loadPluginFile(__dirname + "/../plugins/buidler.plugin");
3+
usePlugin("@nomiclabs/buidler-truffle5");
4+
5+
module.exports={
6+
defaultNetwork: "buidlerevm",
7+
solc: {
8+
version: "0.6.0"
9+
}
10+
};
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
pragma solidity ^0.6.0;
2+
3+
import "./ContractB.sol";
4+
5+
/**
6+
* New syntaxes in solc 0.6.x
7+
*/
8+
contract ContractA is ContractB {
9+
uint counter;
10+
uint errorCount;
11+
12+
modifier overridden() override {
13+
require(true);
14+
_;
15+
}
16+
17+
constructor() public {
18+
}
19+
20+
function simpleSet(uint i)
21+
public
22+
override(ContractB)
23+
{
24+
counter = counter + i;
25+
}
26+
27+
function simpleView(uint i)
28+
view
29+
overridden
30+
external
31+
returns (uint, bool)
32+
{
33+
return (counter + i, true);
34+
}
35+
36+
function tryCatch() public returns (uint, bool) {
37+
try this.simpleView(5) returns (uint, bool) {
38+
return (2, true);
39+
} catch Error(string memory) {
40+
errorCount++;
41+
return (0, false);
42+
} catch (bytes memory) {
43+
errorCount++;
44+
return (0, false);
45+
}
46+
}
47+
48+
function arraySlice() public pure {
49+
abi.decode(msg.data[4:], (uint, uint));
50+
}
51+
52+
function payableFn() public pure {
53+
address x;
54+
address y = payable(x);
55+
}
56+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
pragma solidity ^0.6.0;
2+
3+
4+
contract ContractB {
5+
uint value;
6+
7+
constructor() public {
8+
}
9+
10+
modifier overridden() virtual {
11+
require(true);
12+
_;
13+
}
14+
15+
function simpleSet(uint i) public virtual {
16+
value = 5;
17+
}
18+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
const ContractA = artifacts.require("ContractA");
2+
3+
contract("contracta", function(accounts) {
4+
let instance;
5+
6+
before(async () => instance = await ContractA.new())
7+
8+
it('simpleSet (overridden method)', async function(){
9+
await instance.simpleSet(5);
10+
});
11+
12+
it('simpleView (overridden modifier)', async function(){
13+
await instance.simpleView(5);
14+
});
15+
16+
it('tryCatch', async function(){
17+
await instance.tryCatch();
18+
});
19+
20+
it('arraySlice', async function(){
21+
await instance.arraySlice();
22+
});
23+
24+
it('payableFn', async function(){
25+
await instance.payableFn();
26+
})
27+
});
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module.exports = {
2+
networks: {},
3+
mocha: {},
4+
compilers: {
5+
solc: {
6+
version: "0.6.0"
7+
}
8+
}
9+
}

test/sources/js/wallet.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ contract('Wallet', accounts => {
1717
from: accounts[0],
1818
});
1919

20+
// Throws invalid opcode if compiled w/ solc >= 0.5.14 & default EVM version
2021
const balance = await walletB.getBalance();
2122
assert.equal(balance.toNumber(), 100);
2223
});

test/util/integration.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,9 @@ function getDefaultBuidlerConfig() {
152152
url: "http://127.0.0.1:8545",
153153
}
154154
},
155+
solc: {
156+
evmVersion: 'petersburg'
157+
}
155158
}
156159

157160
return vals;

0 commit comments

Comments
 (0)