use of org.ethereum.solidity.compiler.SolidityCompiler in project rskj by rsksmart.
the class Web3ImplTest method eth_compileSolidity.
@Test
@Ignore
public void eth_compileSolidity() throws Exception {
RskSystemProperties systemProperties = Mockito.mock(RskSystemProperties.class);
String solc = System.getProperty("solc");
if (StringUtils.isEmpty(solc))
solc = "/usr/bin/solc";
Mockito.when(systemProperties.customSolcPath()).thenReturn(solc);
Ethereum eth = Mockito.mock(Ethereum.class);
EthModule ethModule = new EthModule(config, null, null, new ExecutionBlockRetriever(null, null, null), new EthModuleSolidityEnabled(new SolidityCompiler(systemProperties)), null);
PersonalModule personalModule = new PersonalModuleWalletDisabled();
TxPoolModule txPoolModule = new TxPoolModuleImpl(Web3Mocks.getMockTransactionPool());
Web3Impl web3 = new Web3RskImpl(eth, null, null, systemProperties, null, null, personalModule, ethModule, txPoolModule, Web3Mocks.getMockChannelManager(), Web3Mocks.getMockRepository(), null, null, null, null, null, null, null, null);
String contract = "pragma solidity ^0.4.1; contract rsk { function multiply(uint a) returns(uint d) { return a * 7; } }";
Map<String, CompilationResultDTO> result = web3.eth_compileSolidity(contract);
org.junit.Assert.assertNotNull(result);
CompilationResultDTO dto = result.get("rsk");
if (dto == null)
dto = result.get("<stdin>:rsk");
org.junit.Assert.assertEquals(contract, dto.info.getSource());
}
use of org.ethereum.solidity.compiler.SolidityCompiler 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 (solc == null || solc.isEmpty())
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();
}
Aggregations