github.com/neatlab/neatio@v1.7.3-0.20220425043230-d903e92fcc75/utilities/common/compiler/vyper_test.go (about) 1 package compiler 2 3 import ( 4 "os/exec" 5 "testing" 6 ) 7 8 func skipWithoutVyper(t *testing.T) { 9 if _, err := exec.LookPath("vyper"); err != nil { 10 t.Skip(err) 11 } 12 } 13 14 func TestVyperCompiler(t *testing.T) { 15 skipWithoutVyper(t) 16 17 testSource := []string{"test.v.py"} 18 source, err := slurpFiles(testSource) 19 if err != nil { 20 t.Error("couldn't read test files") 21 } 22 contracts, err := CompileVyper("", testSource...) 23 if err != nil { 24 t.Fatalf("error compiling test.v.py. result %v: %v", contracts, err) 25 } 26 if len(contracts) != 1 { 27 t.Errorf("one contract expected, got %d", len(contracts)) 28 } 29 c, ok := contracts["test.v.py"] 30 if !ok { 31 c, ok = contracts["<stdin>:test"] 32 if !ok { 33 t.Fatal("info for contract 'test.v.py' not present in result") 34 } 35 } 36 if c.Code == "" { 37 t.Error("empty code") 38 } 39 if c.Info.Source != source { 40 t.Error("wrong source") 41 } 42 if c.Info.CompilerVersion == "" { 43 t.Error("empty version") 44 } 45 } 46 47 func TestVyperCompileError(t *testing.T) { 48 skipWithoutVyper(t) 49 50 contracts, err := CompileVyper("", "test_bad.v.py") 51 if err == nil { 52 t.Errorf("error expected compiling test_bad.v.py. got none. result %v", contracts) 53 } 54 t.Logf("error: %v", err) 55 }