github.com/linapex/ethereum-dpos-chinese@v0.0.0-20190316121959-b78b3a4a1ece/common/compiler/solidity_test.go (about) 1 2 //<developer> 3 // <name>linapex 曹一峰</name> 4 // <email>linapex@163.com</email> 5 // <wx>superexc</wx> 6 // <qqgroup>128148617</qqgroup> 7 // <url>https://jsq.ink</url> 8 // <role>pku engineer</role> 9 // <date>2019-03-16 12:09:32</date> 10 //</624342608117764096> 11 12 13 package compiler 14 15 import ( 16 "os/exec" 17 "testing" 18 ) 19 20 const ( 21 testSource = ` 22 contract test { 23 ///@注意将“+”`a`“+”乘以7。 24 function multiply(uint a) returns(uint d) { 25 return a * 7; 26 } 27 } 28 ` 29 ) 30 31 func skipWithoutSolc(t *testing.T) { 32 if _, err := exec.LookPath("solc"); err != nil { 33 t.Skip(err) 34 } 35 } 36 37 func TestCompiler(t *testing.T) { 38 skipWithoutSolc(t) 39 40 contracts, err := CompileSolidityString("", testSource) 41 if err != nil { 42 t.Fatalf("error compiling source. result %v: %v", contracts, err) 43 } 44 if len(contracts) != 1 { 45 t.Errorf("one contract expected, got %d", len(contracts)) 46 } 47 c, ok := contracts["test"] 48 if !ok { 49 c, ok = contracts["<stdin>:test"] 50 if !ok { 51 t.Fatal("info for contract 'test' not present in result") 52 } 53 } 54 if c.Code == "" { 55 t.Error("empty code") 56 } 57 if c.Info.Source != testSource { 58 t.Error("wrong source") 59 } 60 if c.Info.CompilerVersion == "" { 61 t.Error("empty version") 62 } 63 } 64 65 func TestCompileError(t *testing.T) { 66 skipWithoutSolc(t) 67 68 contracts, err := CompileSolidityString("", testSource[4:]) 69 if err == nil { 70 t.Errorf("error expected compiling source. got none. result %v", contracts) 71 } 72 t.Logf("error: %v", err) 73 } 74