Skip to content

Commit

Permalink
Add solc 0.6.x integration mocks (#461)
Browse files Browse the repository at this point in the history
  • Loading branch information
cgewecke authored Dec 22, 2019
1 parent d6b86fa commit 67a3a78
Show file tree
Hide file tree
Showing 10 changed files with 557 additions and 83 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@
"web3-utils": "^1.0.0"
},
"devDependencies": {
"@nomiclabs/buidler": "^1.0.1",
"@nomiclabs/buidler-truffle5": "^1.0.1",
"@nomiclabs/buidler-web3": "^1.0.1",
"@nomiclabs/buidler": "^1.0.2",
"@nomiclabs/buidler-truffle5": "^1.0.2",
"@nomiclabs/buidler-web3": "^1.0.2",
"@truffle/contract": "^4.0.36",
"decache": "^4.5.1",
"ganache-core-sc": "^2.7.0-sc.0",
Expand Down
8 changes: 8 additions & 0 deletions test/integration/projects/solc-6/.solcover.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Testing hooks
const fn = (msg, config) => config.logger.log(msg);

module.exports = {
skipFiles: ['Migrations.sol'],
silent: process.env.SILENT ? true : false,
istanbulReporter: ['json-summary', 'text'],
}
10 changes: 10 additions & 0 deletions test/integration/projects/solc-6/buidler.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const { loadPluginFile } = require("@nomiclabs/buidler/plugins-testing");
loadPluginFile(__dirname + "/../plugins/buidler.plugin");
usePlugin("@nomiclabs/buidler-truffle5");

module.exports={
defaultNetwork: "buidlerevm",
solc: {
version: "0.6.0"
}
};
56 changes: 56 additions & 0 deletions test/integration/projects/solc-6/contracts/ContractA.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
pragma solidity ^0.6.0;

import "./ContractB.sol";

/**
* New syntaxes in solc 0.6.x
*/
contract ContractA is ContractB {
uint counter;
uint errorCount;

modifier overridden() override {
require(true);
_;
}

constructor() public {
}

function simpleSet(uint i)
public
override(ContractB)
{
counter = counter + i;
}

function simpleView(uint i)
view
overridden
external
returns (uint, bool)
{
return (counter + i, true);
}

function tryCatch() public returns (uint, bool) {
try this.simpleView(5) returns (uint, bool) {
return (2, true);
} catch Error(string memory) {
errorCount++;
return (0, false);
} catch (bytes memory) {
errorCount++;
return (0, false);
}
}

function arraySlice() public pure {
abi.decode(msg.data[4:], (uint, uint));
}

function payableFn() public pure {
address x;
address y = payable(x);
}
}
18 changes: 18 additions & 0 deletions test/integration/projects/solc-6/contracts/ContractB.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
pragma solidity ^0.6.0;


contract ContractB {
uint value;

constructor() public {
}

modifier overridden() virtual {
require(true);
_;
}

function simpleSet(uint i) public virtual {
value = 5;
}
}
27 changes: 27 additions & 0 deletions test/integration/projects/solc-6/test/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const ContractA = artifacts.require("ContractA");

contract("contracta", function(accounts) {
let instance;

before(async () => instance = await ContractA.new())

it('simpleSet (overridden method)', async function(){
await instance.simpleSet(5);
});

it('simpleView (overridden modifier)', async function(){
await instance.simpleView(5);
});

it('tryCatch', async function(){
await instance.tryCatch();
});

it('arraySlice', async function(){
await instance.arraySlice();
});

it('payableFn', async function(){
await instance.payableFn();
})
});
9 changes: 9 additions & 0 deletions test/integration/projects/solc-6/truffle-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = {
networks: {},
mocha: {},
compilers: {
solc: {
version: "0.6.0"
}
}
}
1 change: 1 addition & 0 deletions test/sources/js/wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ contract('Wallet', accounts => {
from: accounts[0],
});

// Throws invalid opcode if compiled w/ solc >= 0.5.14 & default EVM version
const balance = await walletB.getBalance();
assert.equal(balance.toNumber(), 100);
});
Expand Down
3 changes: 3 additions & 0 deletions test/util/integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ function getDefaultBuidlerConfig() {
url: "http://127.0.0.1:8545",
}
},
solc: {
evmVersion: 'petersburg'
}
}

return vals;
Expand Down
Loading

0 comments on commit 67a3a78

Please sign in to comment.