Skip to content

Commit

Permalink
Fixed issue hyperledger-web3j#98.
Browse files Browse the repository at this point in the history
  • Loading branch information
conor10 committed May 30, 2017
1 parent 42c56cd commit 3050d7f
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 6 deletions.
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ Java 8:
<dependency>
<groupId>org.web3j</groupId>
<artifactId>core</artifactId>
<version>2.2.1</version>
<version>2.2.2</version>
</dependency>
Android:
Expand All @@ -105,7 +105,7 @@ Java 8:

.. code-block:: groovy
compile ('org.web3j:core:2.2.1')
compile ('org.web3j:core:2.2.2')
Android:

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ apply plugin: 'application'
apply plugin: 'checkstyle'

group 'org.web3j'
version '2.2.1'
version '2.2.2'

sourceCompatibility = 1.8

Expand Down
4 changes: 2 additions & 2 deletions docs/source/getting_started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Java 8:
<dependency>
<groupId>org.web3j</groupId>
<artifactId>core</artifactId>
<version>2.2.1</version>
<version>2.2.2</version>
</dependency>
Android:
Expand All @@ -33,7 +33,7 @@ Java 8:

.. code-block:: groovy
compile ('org.web3j:core:2.2.1')
compile ('org.web3j:core:2.2.2')
Android:

Expand Down
6 changes: 5 additions & 1 deletion src/main/java/org/web3j/tx/Contract.java
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,11 @@ protected CompletableFuture<List<Type>> executeCallMultipleValueReturnAsync(
protected <T extends Type> T executeCallSingleValueReturn(
Function function) throws InterruptedException, ExecutionException {
List<Type> values = executeCall(function);
return (T) values.get(0);
if (!values.isEmpty()) {
return (T) values.get(0);
} else {
return null;
}
}

protected List<Type> executeCallMultipleValueReturn(
Expand Down
22 changes: 22 additions & 0 deletions src/test/java/org/web3j/tx/ContractTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any;
Expand Down Expand Up @@ -147,6 +148,17 @@ public void testCallSingleValue() throws Exception {
assertThat(contract.callSingleValue().get(), equalTo(new Utf8String("")));
}

@Test
public void testCallSingleValueEmpty() throws Exception {
// Example taken from FunctionReturnDecoderTest

EthCall ethCall = new EthCall();
ethCall.setResult("0x");
prepareCall(ethCall);

assertNull(contract.callSingleValue().get());
}

@Test
public void testCallMultipleValue() throws Exception {
EthCall ethCall = new EthCall();
Expand All @@ -160,6 +172,16 @@ public void testCallMultipleValue() throws Exception {
new Uint256(BigInteger.valueOf(7)))));
}

@Test
public void testCallMultipleValueEmpty() throws Exception {
EthCall ethCall = new EthCall();
ethCall.setResult("0x");
prepareCall(ethCall);

assertThat(contract.callMultipleValue().get(),
equalTo(Collections.emptyList()));
}

private void prepareCall(EthCall ethCall) {
Request request = mock(Request.class);
when(request.sendAsync()).thenReturn(Async.run(() -> ethCall));
Expand Down

0 comments on commit 3050d7f

Please sign in to comment.