Skip to content

Commit 9cd11f7

Browse files
committed
Merge branch 'phase/3/txExecution'
2 parents 2b9fec2 + e1cf171 commit 9cd11f7

File tree

203 files changed

+10742
-2595
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

203 files changed

+10742
-2595
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@ nodeId.keys
1111
*.sc
1212

1313
*.log
14+
*.log.zip
15+
.evm-runner_history

build.sbt

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
enablePlugins(JavaAppPackaging)
1+
enablePlugins(JavaAppPackaging, SolidityPlugin)
22

33
val commonSettings = Seq(
44
name := "etc-client",
@@ -9,6 +9,7 @@ val commonSettings = Seq(
99
val dep = {
1010
val akkaVersion = "2.4.17"
1111
val akkaHttpVersion = "10.0.3"
12+
val circeVersion = "0.7.0"
1213

1314
Seq(
1415
"com.typesafe.akka" %% "akka-actor" % akkaVersion,
@@ -22,23 +23,49 @@ val dep = {
2223
"org.consensusresearch" %% "scrypto" % "1.2.0-RC3",
2324
"com.madgag.spongycastle" % "core" % "1.54.0.0",
2425
"org.iq80.leveldb" % "leveldb" % "0.9",
25-
"org.scorexfoundation" %% "iodb" % "0.2.0",
26+
"org.scorexfoundation" %% "iodb" % "0.3.0",
2627
"ch.qos.logback" % "logback-classic" % "1.1.9",
2728
"org.scalatest" %% "scalatest" % "3.0.1" % "it,test",
2829
"org.scalacheck" %% "scalacheck" % "1.13.4" % "it,test",
30+
"org.scalacheck" %% "scalacheck" % "1.13.4" % "it,test",
31+
"ch.qos.logback" % "logback-classic" % "1.1.9",
32+
"org.jline" % "jline" % "3.1.2",
33+
"org.scala-lang.modules" %% "scala-parser-combinators" % "1.0.5",
34+
"io.circe" %% "circe-core" % circeVersion,
35+
"io.circe" %% "circe-generic" % circeVersion,
36+
"io.circe" %% "circe-parser" % circeVersion,
37+
"io.circe" %% "circe-generic-extras" % circeVersion,
2938
"com.miguno.akka" %% "akka-mock-scheduler" % "0.5.1" % "it,test"
3039
)
3140
}
3241

3342
val Integration = config("it") extend Test
3443

44+
val Evm = config("evm") extend Test
45+
3546
val root = project.in(file("."))
36-
.configs(Integration)
37-
.settings(commonSettings: _*)
38-
.settings(libraryDependencies ++= dep)
39-
.settings(inConfig(Integration)(Defaults.testSettings) : _*)
47+
.configs(Integration)
48+
.configs(Evm)
49+
.settings(commonSettings: _*)
50+
.settings(libraryDependencies ++= dep)
51+
.settings(inConfig(Integration)(Defaults.testSettings) : _*)
52+
.settings(inConfig(Evm)(Defaults.testSettings) : _*)
53+
54+
scalacOptions := Seq(
55+
"-unchecked",
56+
"-deprecation",
57+
"-feature",
58+
"-Xfatal-warnings"
59+
)
60+
61+
testOptions in Test += Tests.Argument("-oD")
4062

41-
scalacOptions := Seq("-unchecked", "-deprecation", "-feature")
63+
(test in Evm) := (test in Evm).dependsOn(solidityCompile).value
64+
(sourceDirectory in Evm) := baseDirectory.value / "src" / "evmTest"
4265

4366
(scalastyleConfig in Test) := baseDirectory.value / "scalastyle-test-config.xml"
4467
scalastyleSources in Test ++= {(unmanagedSourceDirectories in Integration).value}
68+
69+
mainClass in Compile := Some("io.iohk.ethereum.App")
70+
71+
coverageExcludedPackages := "io.iohk.ethereum.vmrunner.*"

circle.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
dependencies:
2+
pre:
3+
- sudo add-apt-repository -y ppa:ethereum/ethereum; sudo apt-get update; sudo apt-get install -y solc

project/SolidityPlugin.scala

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import java.io.PrintWriter
2+
3+
import sbt.TaskKey
4+
import sbt._
5+
import Keys._
6+
7+
object SolidityPlugin extends AutoPlugin {
8+
9+
object autoImport {
10+
lazy val solidityCompile = TaskKey[Unit]("solidityCompile", "Compiles solidity contracts")
11+
}
12+
13+
import autoImport._
14+
15+
override def projectSettings: Seq[Def.Setting[_]] = Seq(
16+
solidityCompile := {
17+
import sys.process._
18+
19+
val contractsDir = baseDirectory.value / "src" / "evmTest" / "resources" / "solidity"
20+
val outDir = baseDirectory.value / "target" / "contracts"
21+
22+
(contractsDir ** "*.sol").get.foreach { f =>
23+
Seq("solc", f.getPath, "--bin", "--overwrite", "-o", outDir.getPath).!!
24+
25+
// this is a temporary workaround, see: https://github.com/ethereum/solidity/issues/1732
26+
val abiOut = Seq("solc", f.getPath, "--abi").!!
27+
val abisLines = abiOut.split("\n").sliding(4, 4)
28+
abisLines.foreach { abiLines =>
29+
val contractName = abiLines(1)
30+
.replace(f.getPath, "")
31+
.dropWhile(_ != ':').drop(1)
32+
.takeWhile(_ != ' ')
33+
new PrintWriter(outDir / s"$contractName.abi") {
34+
write(abiLines.drop(3).mkString); close()
35+
}
36+
}
37+
}
38+
}
39+
)
40+
41+
}

project/plugins.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ addSbtPlugin("org.scoverage" %% "sbt-scoverage" % "1.5.0")
33
addSbtPlugin("org.scoverage" %% "sbt-coveralls" % "1.1.0")
44
addSbtPlugin("org.scalastyle" %% "scalastyle-sbt-plugin" % "0.8.0")
55
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.0.6")
6-
addSbtPlugin("com.thoughtworks.sbt-api-mappings" % "sbt-api-mappings" % "latest.release")
6+
addSbtPlugin("com.thoughtworks.sbt-api-mappings" % "sbt-api-mappings" % "latest.release")

scalastyle-test-config.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<parameter name="regex"><![CDATA[[A-Z][A-Za-z]*]]></parameter>
2525
</parameters>
2626
</check>
27-
<check level="error" class="org.scalastyle.scalariform.ObjectNamesChecker" enabled="true">
27+
<check level="error" class="org.scalastyle.scalariform.ObjectNamesChecker" enabled="false">
2828
<parameters>
2929
<parameter name="regex"><![CDATA[[A-Z][A-Za-z]*]]></parameter>
3030
</parameters>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
pragma solidity ^0.4.10;
2+
3+
contract CallSelfDestruct {
4+
5+
function callDestruct() {
6+
CallSelfDestruct firstCall = CallSelfDestruct(this);
7+
firstCall.doSelfdestruct();
8+
9+
CallSelfDestruct secondCall = CallSelfDestruct(this);
10+
secondCall.doSelfdestruct();
11+
}
12+
13+
function doSelfdestruct() {
14+
selfdestruct(msg.sender);
15+
}
16+
17+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
pragma solidity ^0.4.10;
2+
3+
contract Callee {
4+
5+
uint foo = 2;
6+
7+
function setFoo(uint v) {
8+
foo = v;
9+
}
10+
11+
function getFoo() constant returns (uint) {
12+
return foo;
13+
}
14+
15+
}
16+
17+
contract Caller {
18+
19+
function makeACall(address calleeAddr, uint fooVal) {
20+
Callee callee = Callee(calleeAddr);
21+
callee.setFoo(fooVal);
22+
}
23+
24+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
pragma solidity ^0.4.10;
2+
3+
contract ContractCallingItself {
4+
5+
uint someVar = 10;
6+
7+
function callSelf() {
8+
address selfAddress = this;
9+
ContractCallingItself selfContract = ContractCallingItself(selfAddress);
10+
selfContract.doubleSomeVar();
11+
}
12+
13+
function doubleSomeVar() {
14+
someVar = someVar * 2;
15+
}
16+
17+
function getSomeVar() constant returns (uint) {
18+
return someVar;
19+
}
20+
}

src/test/solidity/fibonacci.sol renamed to src/evmTest/resources/solidity/Fibonacci.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
pragma solidity ^0.4.8;
1+
pragma solidity ^0.4.10;
22

33
contract Fibonacci {
44
uint fib = 0;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
pragma solidity ^0.4.10;
2+
3+
contract MinimumViableToken {
4+
/* This creates an array with all balances */
5+
mapping (address => uint256) public balanceOf;
6+
7+
/* Initializes contract with initial supply tokens to the creator of the contract */
8+
function MinimumViableToken(uint256 initialSupply) {
9+
balanceOf[msg.sender] = initialSupply; // Give the creator all initial tokens
10+
}
11+
12+
/* Send coins */
13+
function transfer(address _to, uint256 _value) {
14+
if (balanceOf[msg.sender] < _value) throw; // Check if the sender has enough
15+
if (balanceOf[_to] + _value < balanceOf[_to]) throw; // Check for overflows
16+
balanceOf[msg.sender] -= _value; // Subtract from the sender
17+
balanceOf[_to] += _value; // Add the same to the recipient
18+
}
19+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
pragma solidity ^0.4.10;
2+
3+
contract MutualRecursion {
4+
5+
function isEven(uint n) returns (bool) {
6+
if (n == 0)
7+
return true;
8+
else
9+
return isOdd(n - 1);
10+
}
11+
12+
function isOdd(uint n) returns (bool) {
13+
if (n == 0)
14+
return false;
15+
else
16+
return isEven(n - 1);
17+
}
18+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
pragma solidity ^0.4.10;
2+
3+
contract PrecompiledContracts {
4+
function usePrecompiledContracts(bytes32 hash, uint8 v, bytes32 r, bytes32 s) returns (bytes20) {
5+
6+
// there is no function alias for Identity contract and we cannot get the return data using low-level call:
7+
// https://solidity.readthedocs.io/en/latest/types.html#address
8+
9+
return ripemd160(sha256(ecrecover(hash, v, r, s)));
10+
}
11+
}
12+
13+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
pragma solidity ^0.4.10;
2+
3+
contract Throw {
4+
function justThrow() {
5+
throw;
6+
}
7+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package io.iohk.ethereum.vm
2+
3+
import io.iohk.ethereum.vm.utils.EvmTestEnv
4+
import org.scalatest.{FreeSpec, Matchers}
5+
6+
class CallSelfDestructSpec extends FreeSpec with Matchers {
7+
8+
"EVM running CallSelfDestruct contract" - {
9+
10+
"should refund only once" in new EvmTestEnv {
11+
val (_, callSelfDestruct) = deployContract("CallSelfDestruct")
12+
13+
val callRes = callSelfDestruct.callDestruct().call()
14+
15+
callRes.error shouldBe None
16+
callRes.gasRefund shouldBe 24000
17+
}
18+
}
19+
20+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package io.iohk.ethereum.vm
2+
3+
import io.iohk.ethereum.vm.utils.EvmTestEnv
4+
import org.scalatest.{FreeSpec, Matchers}
5+
6+
// scalastyle:off magic.number
7+
class CallerSpec extends FreeSpec with Matchers {
8+
9+
"EVM running Caller contract" - {
10+
11+
"should handle a call to Callee" in new EvmTestEnv {
12+
val (_, callee) = deployContract("Callee")
13+
val (_, caller) = deployContract("Caller")
14+
15+
val callRes = caller.makeACall(callee.address, 123).call()
16+
callRes.error shouldBe None
17+
18+
callee.getFoo().call().returnData shouldBe UInt256(123).bytes
19+
}
20+
}
21+
22+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package io.iohk.ethereum.vm
2+
3+
import io.iohk.ethereum.vm.utils.EvmTestEnv
4+
import org.scalatest.{FreeSpec, Matchers}
5+
6+
// scalastyle:off magic.number
7+
class ContractCallingItselfSpec extends FreeSpec with Matchers {
8+
9+
"EVM running ContractCallingItself contract" - {
10+
11+
"should handle a call to itself" in new EvmTestEnv {
12+
val (_, contract) = deployContract("ContractCallingItself")
13+
14+
contract.getSomeVar().call().returnData shouldBe UInt256(10).bytes
15+
16+
val result = contract.callSelf().call()
17+
result.error shouldBe None
18+
19+
contract.getSomeVar().call().returnData shouldBe UInt256(20).bytes
20+
}
21+
}
22+
23+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package io.iohk.ethereum.vm
2+
3+
import io.iohk.ethereum.vm.utils.EvmTestEnv
4+
import org.scalatest.{FreeSpec, Matchers}
5+
6+
// scalastyle:off magic.number
7+
class FibonacciSpec extends FreeSpec with Matchers {
8+
9+
"EVM running Fibonacci contract" - {
10+
11+
"should handle getNewFib call" in new EvmTestEnv {
12+
val (_, contract) = deployContract("Fibonacci")
13+
14+
val result = contract.getNewFib(5).call()
15+
16+
result.error shouldBe None
17+
result.returnData shouldBe UInt256(5).bytes
18+
}
19+
20+
"should allow storage write/read" in new EvmTestEnv {
21+
val (_, contract) = deployContract("Fibonacci")
22+
23+
val getNewRes = contract.getNewFib(6).call()
24+
25+
getNewRes.error shouldBe None
26+
contract.storage.load(UInt256(0)) shouldBe UInt256(8)
27+
28+
val getStoredRes = contract.getStoredFib().call()
29+
30+
getStoredRes.error shouldBe None
31+
getStoredRes.returnData shouldBe UInt256(8).bytes
32+
}
33+
}
34+
35+
}

0 commit comments

Comments
 (0)