diff options
author | Steve Waldman <swaldman@mchange.com> | 2017-01-26 06:57:13 +0800 |
---|---|---|
committer | Felix Lange <fjl@twurst.com> | 2017-03-16 19:18:38 +0800 |
commit | 728a299728aaaeaf14f21bdaa9171e857f716b68 (patch) | |
tree | 3a7af69b5304bc2bcdfed888db6c64886e2f7c43 /common/compiler/solidity_test.go | |
parent | 61ede86737d57f62cb09de013191fc430d1dd3a2 (diff) | |
download | dexon-728a299728aaaeaf14f21bdaa9171e857f716b68.tar.gz dexon-728a299728aaaeaf14f21bdaa9171e857f716b68.tar.zst dexon-728a299728aaaeaf14f21bdaa9171e857f716b68.zip |
common/compiler: add metadata output for solc > 0.4.6
Metadata is provided as JSON string, rather than as JSON object. This
ensures that we can decode to a set of bytes that will be consistent
with the swarm hash embedded in the code, without worrying about
ambiguities of spacing, ordering, or escaping.
Diffstat (limited to 'common/compiler/solidity_test.go')
-rw-r--r-- | common/compiler/solidity_test.go | 37 |
1 files changed, 4 insertions, 33 deletions
diff --git a/common/compiler/solidity_test.go b/common/compiler/solidity_test.go index f16637547..0da3bb337 100644 --- a/common/compiler/solidity_test.go +++ b/common/compiler/solidity_test.go @@ -17,14 +17,8 @@ package compiler import ( - "encoding/json" - "io/ioutil" - "os" "os/exec" - "path" "testing" - - "github.com/ethereum/go-ethereum/common" ) const ( @@ -36,7 +30,6 @@ contract test { } } ` - 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 --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 skipWithoutSolc(t *testing.T) { @@ -57,7 +50,10 @@ func TestCompiler(t *testing.T) { } c, ok := contracts["test"] if !ok { - t.Fatal("info for contract 'test' not present in result") + c, ok = contracts["<stdin>:test"] + if !ok { + t.Fatal("info for contract 'test' not present in result") + } } if c.Code == "" { t.Error("empty code") @@ -79,28 +75,3 @@ func TestCompileError(t *testing.T) { } t.Logf("error: %v", err) } - -func TestSaveInfo(t *testing.T) { - var cinfo ContractInfo - err := json.Unmarshal([]byte(testInfo), &cinfo) - if err != nil { - t.Errorf("%v", err) - } - filename := path.Join(os.TempDir(), "solctest.info.json") - os.Remove(filename) - cinfohash, err := SaveInfo(&cinfo, filename) - if err != nil { - t.Errorf("error extracting info: %v", err) - } - got, err := ioutil.ReadFile(filename) - if err != nil { - t.Errorf("error reading '%v': %v", filename, err) - } - if string(got) != testInfo { - t.Errorf("incorrect info.json extracted, expected:\n%s\ngot\n%s", testInfo, string(got)) - } - wantHash := common.HexToHash("0x22450a77f0c3ff7a395948d07bc1456881226a1b6325f4189cb5f1254a824080") - if cinfohash != wantHash { - t.Errorf("content hash for info is incorrect. expected %v, got %v", wantHash.Hex(), cinfohash.Hex()) - } -} |