Search in sources :

Example 1 with CompilationResult

use of org.ethereum.solidity.compiler.CompilationResult in project rskj by rsksmart.

the class CompilerTest method simpleTest.

@Test
@Ignore
public void simpleTest() throws IOException {
    SystemProperties systemProperties = Mockito.mock(SystemProperties.class);
    String solc = System.getProperty("solc");
    if (StringUtils.isEmpty(solc))
        solc = "/usr/bin/solc";
    Mockito.when(systemProperties.customSolcPath()).thenReturn(solc);
    SolidityCompiler solidityCompiler = new SolidityCompiler(systemProperties);
    String contract = "contract a {" + "  int i1;" + "  function i() returns (int) {" + "    return i1;" + "  }" + "}";
    SolidityCompiler.Result res = solidityCompiler.compile(contract.getBytes(), true, SolidityCompiler.Options.ABI, SolidityCompiler.Options.BIN, SolidityCompiler.Options.INTERFACE);
    System.out.println("Out: '" + res.output + "'");
    System.out.println("Err: '" + res.errors + "'");
    CompilationResult result = CompilationResult.parse(res.output);
    CompilationResult.ContractMetadata cmeta = result.contracts.get("a");
    if (cmeta == null)
        cmeta = result.contracts.get("<stdin>:a");
    if (cmeta != null)
        System.out.println(cmeta.bin);
    else
        Assert.fail();
}
Also used : SystemProperties(org.ethereum.config.SystemProperties) CompilationResult(org.ethereum.solidity.compiler.CompilationResult) SolidityCompiler(org.ethereum.solidity.compiler.SolidityCompiler) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

SystemProperties (org.ethereum.config.SystemProperties)1 CompilationResult (org.ethereum.solidity.compiler.CompilationResult)1 SolidityCompiler (org.ethereum.solidity.compiler.SolidityCompiler)1 Ignore (org.junit.Ignore)1 Test (org.junit.Test)1