aboutsummaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/big_test.go6
-rw-r--r--common/bytes.go2
-rw-r--r--common/bytes_test.go4
-rw-r--r--common/compiler/solidity.go32
-rw-r--r--common/compiler/solidity_test.go28
-rw-r--r--common/format.go2
-rw-r--r--common/math/dist_test.go36
7 files changed, 48 insertions, 62 deletions
diff --git a/common/big_test.go b/common/big_test.go
index 1eb0c0c1f..4d04a8db3 100644
--- a/common/big_test.go
+++ b/common/big_test.go
@@ -27,7 +27,7 @@ func TestMisc(t *testing.T) {
c := []byte{1, 2, 3, 4}
z := BitTest(a, 1)
- if z != true {
+ if !z {
t.Error("Expected true got", z)
}
@@ -79,11 +79,11 @@ func TestBigCopy(t *testing.T) {
z := BigToBytes(c, 16)
zbytes := []byte{232, 212, 165, 16, 0}
- if bytes.Compare(y, ybytes) != 0 {
+ if !bytes.Equal(y, ybytes) {
t.Error("Got", ybytes)
}
- if bytes.Compare(z, zbytes) != 0 {
+ if !bytes.Equal(z, zbytes) {
t.Error("Got", zbytes)
}
}
diff --git a/common/bytes.go b/common/bytes.go
index b9fb3b2da..cbceea8b5 100644
--- a/common/bytes.go
+++ b/common/bytes.go
@@ -143,7 +143,7 @@ func Hex2BytesFixed(str string, flen int) []byte {
return h
} else {
if len(h) > flen {
- return h[len(h)-flen : len(h)]
+ return h[len(h)-flen:]
} else {
hh := make([]byte, flen)
copy(hh[flen-len(h):flen], h[:])
diff --git a/common/bytes_test.go b/common/bytes_test.go
index 2e5208477..98d402c48 100644
--- a/common/bytes_test.go
+++ b/common/bytes_test.go
@@ -181,7 +181,7 @@ func TestFromHex(t *testing.T) {
input := "0x01"
expected := []byte{1}
result := FromHex(input)
- if bytes.Compare(expected, result) != 0 {
+ if !bytes.Equal(expected, result) {
t.Errorf("Expected % x got % x", expected, result)
}
}
@@ -190,7 +190,7 @@ func TestFromHexOddLength(t *testing.T) {
input := "0x1"
expected := []byte{1}
result := FromHex(input)
- if bytes.Compare(expected, result) != 0 {
+ if !bytes.Equal(expected, result) {
t.Errorf("Expected % x got % x", expected, result)
}
}
diff --git a/common/compiler/solidity.go b/common/compiler/solidity.go
index b682107d9..d27bddd9f 100644
--- a/common/compiler/solidity.go
+++ b/common/compiler/solidity.go
@@ -22,9 +22,7 @@ import (
"encoding/json"
"errors"
"fmt"
- "io"
"io/ioutil"
- "os"
"os/exec"
"regexp"
"strings"
@@ -34,7 +32,7 @@ import (
)
var (
- versionRegexp = regexp.MustCompile("[0-9]+\\.[0-9]+\\.[0-9]+")
+ versionRegexp = regexp.MustCompile(`[0-9]+\.[0-9]+\.[0-9]+`)
solcParams = []string{
"--combined-json", "bin,abi,userdoc,devdoc",
"--add-std", // include standard lib contracts
@@ -96,27 +94,16 @@ func CompileSolidityString(solc, source string) (map[string]*Contract, error) {
if solc == "" {
solc = "solc"
}
- // Write source to a temporary file. Compiling stdin used to be supported
- // but seems to produce an exception with solc 0.3.5.
- infile, err := ioutil.TempFile("", "geth-compile-solidity")
- if err != nil {
- return nil, err
- }
- defer os.Remove(infile.Name())
- if _, err := io.WriteString(infile, source); err != nil {
- return nil, err
- }
- if err := infile.Close(); err != nil {
- return nil, err
- }
-
- return CompileSolidity(solc, infile.Name())
+ args := append(solcParams, "--")
+ cmd := exec.Command(solc, append(args, "-")...)
+ cmd.Stdin = strings.NewReader(source)
+ return runsolc(cmd, source)
}
// CompileSolidity compiles all given Solidity source files.
func CompileSolidity(solc string, sourcefiles ...string) (map[string]*Contract, error) {
if len(sourcefiles) == 0 {
- return nil, errors.New("solc: no source ")
+ return nil, errors.New("solc: no source files")
}
source, err := slurpFiles(sourcefiles)
if err != nil {
@@ -125,10 +112,13 @@ func CompileSolidity(solc string, sourcefiles ...string) (map[string]*Contract,
if solc == "" {
solc = "solc"
}
-
- var stderr, stdout bytes.Buffer
args := append(solcParams, "--")
cmd := exec.Command(solc, append(args, sourcefiles...)...)
+ return runsolc(cmd, source)
+}
+
+func runsolc(cmd *exec.Cmd, source string) (map[string]*Contract, error) {
+ var stderr, stdout bytes.Buffer
cmd.Stderr = &stderr
cmd.Stdout = &stdout
if err := cmd.Run(); err != nil {
diff --git a/common/compiler/solidity_test.go b/common/compiler/solidity_test.go
index e4d96bd01..8ba9e55d0 100644
--- a/common/compiler/solidity_test.go
+++ b/common/compiler/solidity_test.go
@@ -20,6 +20,7 @@ import (
"encoding/json"
"io/ioutil"
"os"
+ "os/exec"
"path"
"testing"
@@ -27,8 +28,7 @@ import (
)
const (
- supportedSolcVersion = "0.3.5"
- testSource = `
+ testSource = `
contract test {
/// @notice Will multiply ` + "`a`" + ` by 7.
function multiply(uint a) returns(uint d) {
@@ -36,23 +36,18 @@ contract test {
}
}
`
- testCode = "0x6060604052602a8060106000396000f3606060405260e060020a6000350463c6888fa18114601a575b005b6007600435026060908152602090f3"
testInfo = `{"source":"\ncontract test {\n /// @notice Will multiply ` + "`a`" + ` by 7.\n function multiply(uint a) returns(uint d) {\n return a * 7;\n }\n}\n","language":"Solidity","languageVersion":"0.1.1","compilerVersion":"0.1.1","compilerOptions":"--binary file --json-abi file --natspec-user file --natspec-dev file --add-std 1","abiDefinition":[{"constant":false,"inputs":[{"name":"a","type":"uint256"}],"name":"multiply","outputs":[{"name":"d","type":"uint256"}],"type":"function"}],"userDoc":{"methods":{"multiply(uint256)":{"notice":"Will multiply ` + "`a`" + ` by 7."}}},"developerDoc":{"methods":{}}}`
)
-func skipUnsupported(t *testing.T) {
- sol, err := SolidityVersion("")
- if err != nil {
+func skipWithoutSolc(t *testing.T) {
+ if _, err := exec.LookPath("solc"); err != nil {
t.Skip(err)
- return
- }
- if sol.Version != supportedSolcVersion {
- t.Skipf("unsupported version of solc found (%v, expect %v)", sol.Version, supportedSolcVersion)
}
}
func TestCompiler(t *testing.T) {
- skipUnsupported(t)
+ skipWithoutSolc(t)
+
contracts, err := CompileSolidityString("", testSource)
if err != nil {
t.Fatalf("error compiling source. result %v: %v", contracts, err)
@@ -64,19 +59,20 @@ func TestCompiler(t *testing.T) {
if !ok {
t.Fatal("info for contract 'test' not present in result")
}
- if c.Code != testCode {
- t.Errorf("wrong code: expected\n%s, got\n%s", testCode, c.Code)
+ if c.Code == "" {
+ t.Error("empty code")
}
if c.Info.Source != testSource {
t.Error("wrong source")
}
- if c.Info.CompilerVersion != supportedSolcVersion {
- t.Errorf("wrong version: expected %q, got %q", supportedSolcVersion, c.Info.CompilerVersion)
+ if c.Info.CompilerVersion == "" {
+ t.Error("empty version")
}
}
func TestCompileError(t *testing.T) {
- skipUnsupported(t)
+ skipWithoutSolc(t)
+
contracts, err := CompileSolidityString("", testSource[4:])
if err == nil {
t.Errorf("error expected compiling source. got none. result %v", contracts)
diff --git a/common/format.go b/common/format.go
index 119637d2e..fccc29962 100644
--- a/common/format.go
+++ b/common/format.go
@@ -27,7 +27,7 @@ import (
// the unnecessary precision off from the formatted textual representation.
type PrettyDuration time.Duration
-var prettyDurationRe = regexp.MustCompile("\\.[0-9]+")
+var prettyDurationRe = regexp.MustCompile(`\.[0-9]+`)
// String implements the Stringer interface, allowing pretty printing of duration
// values rounded to three decimals.
diff --git a/common/math/dist_test.go b/common/math/dist_test.go
index 826faea8b..f5857b6f8 100644
--- a/common/math/dist_test.go
+++ b/common/math/dist_test.go
@@ -41,24 +41,24 @@ func TestSum(t *testing.T) {
func TestDist(t *testing.T) {
var vectors = []Vector{
- Vector{big.NewInt(1000), big.NewInt(1234)},
- Vector{big.NewInt(500), big.NewInt(10023)},
- Vector{big.NewInt(1034), big.NewInt(1987)},
- Vector{big.NewInt(1034), big.NewInt(1987)},
- Vector{big.NewInt(8983), big.NewInt(1977)},
- Vector{big.NewInt(98382), big.NewInt(1887)},
- Vector{big.NewInt(12398), big.NewInt(1287)},
- Vector{big.NewInt(12398), big.NewInt(1487)},
- Vector{big.NewInt(12398), big.NewInt(1987)},
- Vector{big.NewInt(12398), big.NewInt(128)},
- Vector{big.NewInt(12398), big.NewInt(1987)},
- Vector{big.NewInt(1398), big.NewInt(187)},
- Vector{big.NewInt(12328), big.NewInt(1927)},
- Vector{big.NewInt(12398), big.NewInt(1987)},
- Vector{big.NewInt(22398), big.NewInt(1287)},
- Vector{big.NewInt(1370), big.NewInt(1981)},
- Vector{big.NewInt(12398), big.NewInt(1957)},
- Vector{big.NewInt(42198), big.NewInt(1987)},
+ {big.NewInt(1000), big.NewInt(1234)},
+ {big.NewInt(500), big.NewInt(10023)},
+ {big.NewInt(1034), big.NewInt(1987)},
+ {big.NewInt(1034), big.NewInt(1987)},
+ {big.NewInt(8983), big.NewInt(1977)},
+ {big.NewInt(98382), big.NewInt(1887)},
+ {big.NewInt(12398), big.NewInt(1287)},
+ {big.NewInt(12398), big.NewInt(1487)},
+ {big.NewInt(12398), big.NewInt(1987)},
+ {big.NewInt(12398), big.NewInt(128)},
+ {big.NewInt(12398), big.NewInt(1987)},
+ {big.NewInt(1398), big.NewInt(187)},
+ {big.NewInt(12328), big.NewInt(1927)},
+ {big.NewInt(12398), big.NewInt(1987)},
+ {big.NewInt(22398), big.NewInt(1287)},
+ {big.NewInt(1370), big.NewInt(1981)},
+ {big.NewInt(12398), big.NewInt(1957)},
+ {big.NewInt(42198), big.NewInt(1987)},
}
VectorsBy(GasSort).Sort(vectors)