Skip to content
This repository has been archived by the owner on Dec 5, 2024. It is now read-only.

Commit

Permalink
Adding JavaDoc ... more assertions with test
Browse files Browse the repository at this point in the history
  • Loading branch information
tglaeser committed Mar 9, 2018
1 parent c1294de commit ccbadb4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ public class CompilationResult {
}
}

/**
* @return the contract's path given this compilation result contains exactly one contract
*/
@JsonIgnore public Path getContractPath() {
if (contracts.size() > 1) {
throw new UnsupportedOperationException("Source contains more than 1 contact. Please specify the contract name. Available keys (" + getContractKeys() + ").");
Expand All @@ -57,6 +60,9 @@ public class CompilationResult {
}
}

/**
* @return the contract's name given this compilation result contains exactly one contract
*/
@JsonIgnore public String getContractName() {
if (contracts.size() > 1) {
throw new UnsupportedOperationException("Source contains more than 1 contact. Please specify the contract name. Available keys (" + getContractKeys() + ").");
Expand All @@ -66,6 +72,10 @@ public class CompilationResult {
}
}

/**
* @param contractName The contract name
* @return the first contract found for a given contract name; use {@link #getContract(Path, String)} if this compilation result contains more than one contract with the same name
*/
@JsonIgnore public ContractMetadata getContract(String contractName) {
if (contractName == null && contracts.size() == 1) {
return contracts.values().iterator().next();
Expand All @@ -79,17 +89,28 @@ public class CompilationResult {
return entry.getValue();
}
}
throw new UnsupportedOperationException("Source contains more than 1 contact. Please specify a valid contract name. Available keys (" + getContractKeys() + ").");
throw new UnsupportedOperationException("No contract found with name '" + contractName + "'. Please specify a valid contract name. Available keys (" + getContractKeys() + ").");
}

/**
* @param contractPath The contract path
* @param contractName The contract name
* @return the contract with key {@code contractPath:contractName} if it exists; {@code null} otherwise
*/
@JsonIgnore public ContractMetadata getContract(Path contractPath, String contractName) {
return contracts.get(contractPath.toAbsolutePath().toString() + ':' + contractName);
}

/**
* @return all contracts from this compilation result
*/
@JsonIgnore public List<ContractMetadata> getContracts() {
return new ArrayList<>(contracts.values());
}

/**
* @return all keys from this compilation result
*/
@JsonIgnore public List<String> getContractKeys() {
return new ArrayList<>(contracts.keySet());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ public void compileFilesTest() throws IOException {
System.out.println("Err: '" + res.errors + "'");
CompilationResult result = CompilationResult.parse(res.output);

Assert.assertEquals(2, result.getContractKeys().size());
Assert.assertEquals(result.getContract("test3"), result.getContract(source,"test3"));
Assert.assertNotNull(result.getContract("test1"));

CompilationResult.ContractMetadata a = result.getContract(source, "test3");
CallTransaction.Contract contract = new CallTransaction.Contract(a.abi);
System.out.print(contract.functions[0].toString());
Expand Down

0 comments on commit ccbadb4

Please sign in to comment.