github.com/iotexproject/iotex-core@v1.14.1-rc1/ioctl/util/compiler_contract_test.go (about) 1 // Copyright (c) 2022 IoTeX Foundation 2 // This source code is provided 'as is' and no warranties are given as to title or non-infringement, merchantability 3 // or fitness for purpose and, to the extent permitted by law, all liability for your use of the code is disclaimed. 4 // This source code is governed by Apache License 2.0 that can be found in the LICENSE file. 5 6 package util 7 8 import ( 9 "os/exec" 10 "testing" 11 12 "github.com/stretchr/testify/require" 13 ) 14 15 const ( 16 testSource = ` 17 pragma solidity >0.0.0; 18 contract test { 19 /// @notice Will multiply ` + "`a`" + ` by 7. 20 function multiply(uint a) public returns(uint d) { 21 return a * 7; 22 } 23 } 24 ` 25 ) 26 27 func skipWithoutSolc(t *testing.T) { 28 if _, err := exec.LookPath("solc"); err != nil { 29 t.Skip(err) 30 } 31 } 32 33 func TestSolidityCompiler(t *testing.T) { 34 skipWithoutSolc(t) 35 36 require := require.New(t) 37 contracts, err := CompileSolidityString("", testSource) 38 require.NoError(err) 39 require.Len(contracts, 1) 40 41 c, ok := contracts["Test"] 42 require.False(ok) 43 c, ok = contracts["<stdin>:test"] 44 require.True(ok) 45 46 require.True(ok) 47 require.NotEmpty(c.Code) 48 require.Equal(testSource, c.Info.Source) 49 require.NotEmpty(c.Info.LanguageVersion) 50 51 contracts, err = CompileSolidityString("", testSource[4:]) 52 require.Error(err) 53 require.Contains(err.Error(), "exit status") 54 }