github.com/core-coin/go-core/v2@v2.1.9/common/compiler/ylem_test.go (about)

     1  // Copyright 2015 by the Authors
     2  // This file is part of the go-core library.
     3  //
     4  // The go-core 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-core 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-core library. If not, see <http://www.gnu.org/licenses/>.
    16  
    17  package compiler
    18  
    19  import (
    20  	"os/exec"
    21  	"testing"
    22  )
    23  
    24  const (
    25  	testSource = `
    26  pragma solidity >0.0.0;
    27  contract test {
    28     /// @notice Will multiply ` + "`a`" + ` by 7.
    29     function multiply(uint a) public returns(uint d) {
    30         return a * 7;
    31     }
    32  }
    33  `
    34  )
    35  
    36  func skipWithoutYlem(t *testing.T) {
    37  	if _, err := exec.LookPath("ylem"); err != nil {
    38  		t.Skip(err)
    39  	}
    40  }
    41  
    42  func TestYlemCompiler(t *testing.T) {
    43  	t.Skip("")
    44  	skipWithoutYlem(t)
    45  
    46  	contracts, err := CompileYlemString("", testSource)
    47  	if err != nil {
    48  		t.Fatalf("error compiling source. result %v: %v", contracts, err)
    49  	}
    50  	if len(contracts) != 1 {
    51  		t.Errorf("one contract expected, got %d", len(contracts))
    52  	}
    53  	c, ok := contracts["test"]
    54  	if !ok {
    55  		c, ok = contracts["<stdin>:test"]
    56  		if !ok {
    57  			t.Fatal("info for contract 'test' not present in result")
    58  		}
    59  	}
    60  	if c.Code == "" {
    61  		t.Error("empty code")
    62  	}
    63  	if c.Info.Source != testSource {
    64  		t.Error("wrong source")
    65  	}
    66  	if c.Info.CompilerVersion == "" {
    67  		t.Error("empty version")
    68  	}
    69  }
    70  
    71  func TestYlemCompileError(t *testing.T) {
    72  	skipWithoutYlem(t)
    73  
    74  	contracts, err := CompileYlemString("", testSource[4:])
    75  	if err == nil {
    76  		t.Errorf("error expected compiling source. got none. result %v", contracts)
    77  	}
    78  	t.Logf("error: %v", err)
    79  }