Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unit test fixes for solc-0.5.x #1275

Open
wants to merge 2 commits into
base: feature/solc-0.5.x
Choose a base branch
from
Open
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
82 changes: 41 additions & 41 deletions ethereumj-core/src/test/java/org/ethereum/core/ImportLightTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ public void simpleDbTest() {
StandaloneBlockchain bc = new StandaloneBlockchain();
SolidityContract parent = bc.submitNewContract("contract A {" +
" uint public a;" +
" function set(uint a_) { a = a_;}" +
" function set(uint a_) public { a = a_;}" +
"}");
bc.createBlock();
parent.callFunction("set", 123);
Expand All @@ -354,18 +354,18 @@ public void createContractFork() throws Exception {
" int a;" +
" int b;" +
" int public c;" +
" function Child(int i) {" +
" constructor (int i) public {" +
" a = 333 + i;" +
" b = 444 + i;" +
" }" +
" function sum() {" +
" function sum() public {" +
" c = a + b;" +
" }" +
"}" +
"contract Parent {" +
" address public child;" +
" function createChild(int a) returns (address) {" +
" child = new Child(a);" +
" function createChild(int a) public returns (address) {" +
" child = address(new Child(a));" +
" return child;" +
" }" +
"}";
Expand All @@ -391,13 +391,13 @@ public void createContractFork1() throws Exception {
String contractSrc =
"contract A {" +
" int public a;" +
" function A() {" +
" constructor () public {" +
" a = 333;" +
" }" +
"}" +
"contract B {" +
" int public a;" +
" function B() {" +
" constructor () public {" +
" a = 111;" +
" }" +
"}";
Expand All @@ -424,19 +424,19 @@ public void createContractFork1() throws Exception {
public void createValueTest() throws IOException, InterruptedException {
// checks that correct msg.value is passed when contract internally created with value
String contract =
"pragma solidity ^0.4.3;\n" +
"pragma solidity ^0.5.0;\n" +
"contract B {\n" +
" uint public valReceived;\n" +
" \n" +
" function B() payable {\n" +
" constructor () public payable {\n" +
" valReceived = msg.value;\n" +
" }\n" +
"}\n" +
"contract A {\n" +
" function () payable { }\n" +
" function () external payable { }\n" +
" address public child;\n" +
" function create() payable {\n" +
" child = (new B).value(20)();\n" +
" function create() public payable {\n" +
" child = address((new B).value(20)());\n" +
" }\n" +
"}";
StandaloneBlockchain bc = new StandaloneBlockchain().withAutoblock(true);
Expand All @@ -453,14 +453,14 @@ public void createValueTest() throws IOException, InterruptedException {
public void contractCodeForkTest() throws IOException, InterruptedException {
String contractA =
"contract A {" +
" function call() returns (uint) {" +
" function call() public returns (uint) {" +
" return 111;" +
" }" +
"}";

String contractB =
"contract B {" +
" function call() returns (uint) {" +
" function call() public returns (uint) {" +
" return 222222;" +
" }" +
"}";
Expand All @@ -484,14 +484,14 @@ public void operateNotExistingContractTest() throws IOException, InterruptedExce
// and the subsequent call to that non-existent address costs 25K gas
byte[] addr = Hex.decode("0101010101010101010101010101010101010101");
String contractA =
"pragma solidity ^0.4.3;" +
"contract B { function dummy() {}}" +
"pragma solidity ^0.5.0;" +
"contract B { function dummy() public {}}" +
"contract A {" +
" function callBalance() returns (uint) {" +
" function callBalance() public returns (uint) {" +
" address addr = 0x" + Hex.toHexString(addr) + ";" +
" uint bal = addr.balance;" +
" }" +
" function callMethod() returns (uint) {" +
" function callMethod() public returns (uint) {" +
" address addr = 0x" + Hex.toHexString(addr) + ";" +
" B b = B(addr);" +
" b.dummy();" +
Expand Down Expand Up @@ -574,8 +574,8 @@ public void prevBlockHashOnFork() throws Exception {
String contractA =
"contract A {" +
" bytes32 public blockHash;" +
" function a(){" +
" blockHash = block.blockhash(block.number - 1);" +
" function a() public {" +
" blockHash = blockhash(block.number - 1);" +
" }" +
"}";

Expand Down Expand Up @@ -603,15 +603,15 @@ public void rollbackInternalTx() throws Exception {
"contract A {" +
" uint public a;" +
" uint public b;" +
" function f() {" +
" function f() public {" +
" b = 1;" +
" this.call.gas(10000)(bytes4(sha3('exception()')));" +
" address(this).call.gas(10000)(abi.encode('exception()'));" +
" a = 2;" +
" }" +

" function exception() {" +
" function exception() public {" +
" b = 2;" +
" throw;" +
" revert();" +
" }" +
"}";

Expand All @@ -630,15 +630,15 @@ public void rollbackInternalTx() throws Exception {
@Test()
public void selfdestructAttack() throws Exception {
String contractSrc = "" +
"pragma solidity ^0.4.3;" +
"pragma solidity ^0.5.0;" +
"contract B {" +
" function suicide(address benefic) {" +
" function suicide(address payable benefic) public {" +
" selfdestruct(benefic);" +
" }" +
"}" +
"contract A {" +
" uint public a;" +
" function f() {" +
" function f() public {" +
" B b = new B();" +
" for (uint i = 0; i < 3500; i++) {" +
" b.suicide.gas(10000)(address(i));" +
Expand Down Expand Up @@ -757,18 +757,18 @@ public void suicideInFailedCall() throws Exception {
// the refund for this suicide is not added
String contractA =
"contract B {" +
" function f(){" +
" suicide(msg.sender);" +
" function f() public {" +
" selfdestruct(msg.sender);" +
" }" +
"}" +
"contract A {" +
" function f(){" +
" this.call(bytes4(sha3('bad()')));" +
" function f() public {" +
" address(this).call(abi.encode('bad()'));" +
" }" +
" function bad() {" +
" function bad() public {" +
" B b = new B();" +
" b.call(bytes4(sha3('f()')));" +
" throw;" +
" address(b).call(abi.encode('f()'));" +
" revert();" +
" }" +
"}";

Expand Down Expand Up @@ -796,12 +796,12 @@ public void logInFailedCall() throws Exception {
// the refund for this suicide is not added
String contractA =
"contract A {" +
" function f(){" +
" this.call(bytes4(sha3('bad()')));" +
" function f() public {" +
" address(this).call(abi.encode('bad()'));" +
" }" +
" function bad() {" +
" log0(1234);" +
" throw;" +
" function bad() public {" +
" log0(\"1234\");" +
" revert();" +
" }" +
"}";

Expand All @@ -828,7 +828,7 @@ public void ecRecoverTest() throws Exception {
// checks that ecrecover precompile contract rejects v > 255
String contractA =
"contract A {" +
" function f (bytes32 hash, bytes32 v, bytes32 r, bytes32 s) returns (address) {" +
" function f (bytes32 hash, bytes32 v, bytes32 r, bytes32 s) public returns (address) {" +
" assembly {" +
" mstore(0x100, hash)" +
" mstore(0x120, v)" +
Expand Down Expand Up @@ -873,7 +873,7 @@ public void functionTypeTest() throws IOException, InterruptedException {
" }" +
" function fInc(int a) external returns (int) { return a + 1;}" +
" function fDec(int a) external returns (int) { return a - 1;}" +
" function test() {" +
" function test() public {" +
" res = this.calc.gas(100000)(111, this.fInc);" +
" }" +
"}";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -480,8 +480,8 @@ public void testPrevBlock() throws InterruptedException {
ECKey bob = new ECKey();

SolidityContract contract = bc.submitNewContract("contract A {" +
" function getPrevBlockHash() returns (bytes32) {" +
" return block.blockhash(block.number - 1);" +
" function getPrevBlockHash() public returns (bytes32) {" +
" return blockhash(block.number - 1);" +
" }" +
"}");

Expand Down
12 changes: 6 additions & 6 deletions ethereumj-core/src/test/java/org/ethereum/core/PruneTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ public void contractTest() throws Exception {
SolidityContract contr = bc.submitNewContract(
"contract Simple {" +
" uint public n;" +
" function set(uint _n) { n = _n; } " +
" function set(uint _n) public { n = _n; } " +
"}");
bc.createBlock();

Expand Down Expand Up @@ -297,8 +297,8 @@ public void twoContractsTest() throws Exception {
String src =
"contract Simple {" +
" uint public n;" +
" function set(uint _n) { n = _n; } " +
" function inc() { n++; } " +
" function set(uint _n) public { n = _n; } " +
" function inc() public { n++; } " +
"}";

StandaloneBlockchain bc = new StandaloneBlockchain();
Expand Down Expand Up @@ -395,7 +395,7 @@ public void branchTest() throws Exception {
SolidityContract contr = bc.submitNewContract(
"contract Simple {" +
" uint public n;" +
" function set(uint _n) { n = _n; } " +
" function set(uint _n) public { n = _n; } " +
"}");
Block b1 = bc.createBlock();
contr.callFunction("set", 0xaaaaaaaaaaaaL);
Expand Down Expand Up @@ -432,8 +432,8 @@ public void storagePruneTest() throws Exception {
"contract Simple {" +
" uint public n;" +
" mapping(uint => uint) largeMap;" +
" function set(uint _n) { n = _n; } " +
" function put(uint k, uint v) { largeMap[k] = v; }" +
" function set(uint _n) public { n = _n; } " +
" function put(uint k, uint v) public { largeMap[k] = v; }" +
"}");
Block b1 = bc.createBlock();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -555,13 +555,13 @@ function get() returns (uint) {
@Test
public void multiSuicideTest() throws IOException, InterruptedException {
String contract =
"pragma solidity ^0.4.3;" +
"pragma solidity ^0.5.0;" +
"contract PsychoKiller {" +
" function () payable {}" +
" function homicide() {" +
" suicide(msg.sender);" +
" function () external payable {}" +
" function homicide() public {" +
" selfdestruct(msg.sender);" +
" }" +
" function multipleHomocide() {" +
" function multipleHomocide() public {" +
" PsychoKiller k = this;" +
" k.homicide.gas(10000)();" +
" k.homicide.gas(10000)();" +
Expand Down Expand Up @@ -657,9 +657,9 @@ public void receiptErrorTest() throws Exception {
{
String contract =
"contract GasConsumer {" +
" function GasConsumer() {" +
" constructor () public {" +
" int i = 0;" +
" while(true) sha3(i++);" +
" while(true) abi.encode(i++);" +
" }" +
"}";
SolidityCompiler.Result res = SolidityCompiler.compile(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public static void cleanup() {
public void simpleTest() {
String contractSrc =
"contract Adder {" +
" function add(int a, int b) returns (int) {return a + b;}" +
" function add(int a, int b) public returns (int) {return a + b;}" +
"}";
HashMapDB<byte[]> txDb = new HashMapDB<>();

Expand Down Expand Up @@ -89,7 +89,7 @@ public void forkTest() {
String contractSrc =
"contract Adder {" +
" int public lastResult;" +
" function add(int a, int b) returns (int) {lastResult = a + b; return lastResult; }" +
" function add(int a, int b) public returns (int) {lastResult = a + b; return lastResult; }" +
"}";
HashMapDB txDb = new HashMapDB();

Expand Down