vyper_test.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // Copyright 2019 The go-ethereum Authors
  2. // This file is part of the go-ethereum library.
  3. //
  4. // The go-ethereum library is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU Lesser General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // The go-ethereum library is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU Lesser General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Lesser General Public License
  15. // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
  16. package compiler
  17. import (
  18. "os/exec"
  19. "testing"
  20. )
  21. func skipWithoutVyper(t *testing.T) {
  22. if _, err := exec.LookPath("vyper"); err != nil {
  23. t.Skip(err)
  24. }
  25. }
  26. func TestVyperCompiler(t *testing.T) {
  27. skipWithoutVyper(t)
  28. testSource := []string{"test.v.py"}
  29. source, err := slurpFiles(testSource)
  30. if err != nil {
  31. t.Error("couldn't read test files")
  32. }
  33. contracts, err := CompileVyper("", testSource...)
  34. if err != nil {
  35. t.Fatalf("error compiling test.v.py. result %v: %v", contracts, err)
  36. }
  37. if len(contracts) != 1 {
  38. t.Errorf("one contract expected, got %d", len(contracts))
  39. }
  40. c, ok := contracts["test.v.py"]
  41. if !ok {
  42. c, ok = contracts["<stdin>:test"]
  43. if !ok {
  44. t.Fatal("info for contract 'test.v.py' not present in result")
  45. }
  46. }
  47. if c.Code == "" {
  48. t.Error("empty code")
  49. }
  50. if c.Info.Source != source {
  51. t.Error("wrong source")
  52. }
  53. if c.Info.CompilerVersion == "" {
  54. t.Error("empty version")
  55. }
  56. }
  57. func TestVyperCompileError(t *testing.T) {
  58. skipWithoutVyper(t)
  59. contracts, err := CompileVyper("", "test_bad.v.py")
  60. if err == nil {
  61. t.Errorf("error expected compiling test_bad.v.py. got none. result %v", contracts)
  62. }
  63. t.Logf("error: %v", err)
  64. }