From e67d2dbccc860cdd3268928971e5670ddeff7393 Mon Sep 17 00:00:00 2001 From: Derek Zuk Date: Sun, 14 Apr 2019 16:30:10 -0400 Subject: [PATCH 1/2] Unit test fixes for solc-0.5.x --- .../test/java/org/ethereum/core/ImportLightTest.java | 10 +++++----- .../src/test/java/org/ethereum/core/PruneTest.java | 12 ++++++------ .../java/org/ethereum/db/TransactionStoreTest.java | 4 ++-- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/ethereumj-core/src/test/java/org/ethereum/core/ImportLightTest.java b/ethereumj-core/src/test/java/org/ethereum/core/ImportLightTest.java index 4bf9529515..b2c59d9e87 100644 --- a/ethereumj-core/src/test/java/org/ethereum/core/ImportLightTest.java +++ b/ethereumj-core/src/test/java/org/ethereum/core/ImportLightTest.java @@ -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); @@ -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;" + " }" + "}"; @@ -574,7 +574,7 @@ public void prevBlockHashOnFork() throws Exception { String contractA = "contract A {" + " bytes32 public blockHash;" + - " function a(){" + + " function a() public {" + " blockHash = block.blockhash(block.number - 1);" + " }" + "}"; @@ -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) returns (address) public {" + " assembly {" + " mstore(0x100, hash)" + " mstore(0x120, v)" + diff --git a/ethereumj-core/src/test/java/org/ethereum/core/PruneTest.java b/ethereumj-core/src/test/java/org/ethereum/core/PruneTest.java index 3b529264c3..5ea4c2f83b 100644 --- a/ethereumj-core/src/test/java/org/ethereum/core/PruneTest.java +++ b/ethereumj-core/src/test/java/org/ethereum/core/PruneTest.java @@ -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(); @@ -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(); @@ -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); @@ -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(); diff --git a/ethereumj-core/src/test/java/org/ethereum/db/TransactionStoreTest.java b/ethereumj-core/src/test/java/org/ethereum/db/TransactionStoreTest.java index 626c960517..0bf6c4c89d 100644 --- a/ethereumj-core/src/test/java/org/ethereum/db/TransactionStoreTest.java +++ b/ethereumj-core/src/test/java/org/ethereum/db/TransactionStoreTest.java @@ -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 txDb = new HashMapDB<>(); @@ -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(); From e1365778aff398372feb8dd9bcd80362d53053c6 Mon Sep 17 00:00:00 2001 From: Derek Zuk Date: Mon, 15 Apr 2019 00:31:15 -0400 Subject: [PATCH 2/2] Unit test fixes for solc-0.5.x --- .../org/ethereum/core/ImportLightTest.java | 74 +++++++++---------- .../org/ethereum/core/PendingStateTest.java | 4 +- .../org/ethereum/core/TransactionTest.java | 14 ++-- 3 files changed, 46 insertions(+), 46 deletions(-) diff --git a/ethereumj-core/src/test/java/org/ethereum/core/ImportLightTest.java b/ethereumj-core/src/test/java/org/ethereum/core/ImportLightTest.java index b2c59d9e87..cc9ceb2384 100644 --- a/ethereumj-core/src/test/java/org/ethereum/core/ImportLightTest.java +++ b/ethereumj-core/src/test/java/org/ethereum/core/ImportLightTest.java @@ -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;" + " }" + "}"; @@ -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;" + " }" + "}"; @@ -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); @@ -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();" + @@ -575,7 +575,7 @@ public void prevBlockHashOnFork() throws Exception { "contract A {" + " bytes32 public blockHash;" + " function a() public {" + - " blockHash = block.blockhash(block.number - 1);" + + " blockHash = blockhash(block.number - 1);" + " }" + "}"; @@ -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();" + " }" + "}"; @@ -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));" + @@ -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();" + " }" + "}"; @@ -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();" + " }" + "}"; @@ -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) public {" + + " function f (bytes32 hash, bytes32 v, bytes32 r, bytes32 s) public returns (address) {" + " assembly {" + " mstore(0x100, hash)" + " mstore(0x120, v)" + @@ -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);" + " }" + "}"; diff --git a/ethereumj-core/src/test/java/org/ethereum/core/PendingStateTest.java b/ethereumj-core/src/test/java/org/ethereum/core/PendingStateTest.java index 858a7eac5c..1ca47a3658 100644 --- a/ethereumj-core/src/test/java/org/ethereum/core/PendingStateTest.java +++ b/ethereumj-core/src/test/java/org/ethereum/core/PendingStateTest.java @@ -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);" + " }" + "}"); diff --git a/ethereumj-core/src/test/java/org/ethereum/core/TransactionTest.java b/ethereumj-core/src/test/java/org/ethereum/core/TransactionTest.java index bf808643b2..b198d56231 100644 --- a/ethereumj-core/src/test/java/org/ethereum/core/TransactionTest.java +++ b/ethereumj-core/src/test/java/org/ethereum/core/TransactionTest.java @@ -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)();" + @@ -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(