Skip to content

Commit

Permalink
Additional modifications that weren't included in the merge.
Browse files Browse the repository at this point in the history
  • Loading branch information
conor10 committed Nov 22, 2016
1 parent 4542253 commit 0de4455
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void testContractCreation() throws Exception {
List<Type> uint = FunctionReturnDecoder.decode(
responseValue, function.getOutputParameters());
assertThat(uint.size(), is(1));
assertThat(uint.get(0).getValue(), equalTo(BigInteger.valueOf(13)));
assertThat((BigInteger) uint.get(0).getValue(), equalTo(BigInteger.valueOf(13)));
}

private String sendTransaction() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void testGreeterContract() throws Exception {
List<Type> response = FunctionReturnDecoder.decode(
responseValue, getFunction.getOutputParameters());
assertThat(response.size(), is(1));
assertThat(response.get(0).getValue(), is(VALUE));
assertThat((String) response.get(0).getValue(), is(VALUE));
}

private String sendCreateContractTransaction() throws Exception {
Expand Down Expand Up @@ -104,7 +104,7 @@ private static String getGreeterSolidityBinary() throws Exception {
Function createGreetFunction() {
return new Function(
"greet",
Collections.emptyList(),
Collections.singletonList(new TypeReference<Utf8String>() {}));
Collections.<Type>emptyList(),
Collections.<TypeReference<?>>singletonList(new TypeReference<Utf8String>() {}));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ private void confirmBalance(
List<Type> response = FunctionReturnDecoder.decode(
responseValue, function.getOutputParameters());
assertThat(response.size(), is(1));
assertThat(response.get(0), equalTo(new Uint256(expected)));
assertThat((Uint256) response.get(0), equalTo(new Uint256(expected)));
}

private void confirmAllowance(String owner, String spender, String contractAddress,
Expand All @@ -117,7 +117,7 @@ private void confirmAllowance(String owner, String spender, String contractAddre
responseValue, function.getOutputParameters());

assertThat(response.size(), is(function.getOutputParameters().size()));
assertThat(response.get(0), equalTo(new Uint256(expected)));
assertThat((Uint256) response.get(0), equalTo(new Uint256(expected)));
}

private String createContract(
Expand Down Expand Up @@ -301,43 +301,43 @@ private String callSmartContractFunction(
private Function totalSupply() {
return new Function(
"totalSupply",
Collections.emptyList(),
Collections.singletonList(new TypeReference<Uint256>() {}));
Collections.<Type>emptyList(),
Collections.<TypeReference<?>>singletonList(new TypeReference<Uint256>() {}));
}

private Function balanceOf(String owner) {
return new Function(
"balanceOf",
Collections.singletonList(new Address(owner)),
Collections.singletonList(new TypeReference<Uint256>() {}));
Collections.<Type>singletonList(new Address(owner)),
Collections.<TypeReference<?>>singletonList(new TypeReference<Uint256>() {}));
}

private Function transfer(String to, BigInteger value) {
return new Function(
"transfer",
Arrays.asList(new Address(to), new Uint256(value)),
Collections.singletonList(new TypeReference<Bool>() {}));
Arrays.<Type>asList(new Address(to), new Uint256(value)),
Collections.<TypeReference<?>>singletonList(new TypeReference<Bool>() {}));
}

private Function allowance(String owner, String spender) {
return new Function(
"allowance",
Arrays.asList(new Address(owner), new Address(spender)),
Collections.singletonList(new TypeReference<Uint256>() {}));
Arrays.<Type>asList(new Address(owner), new Address(spender)),
Collections.<TypeReference<?>>singletonList(new TypeReference<Uint256>() {}));
}

private Function approve(String spender, BigInteger value) {
return new Function(
"approve",
Arrays.asList(new Address(spender), new Uint256(value)),
Collections.singletonList(new TypeReference<Bool>() {}));
Arrays.<Type>asList(new Address(spender), new Uint256(value)),
Collections.<TypeReference<?>>singletonList(new TypeReference<Bool>() {}));
}

private Function transferFrom(String from, String to, BigInteger value) {
return new Function(
"transferFrom",
Arrays.asList(new Address(from), new Address(to), new Uint256(value)),
Collections.singletonList(new TypeReference<Bool>() {}));
Arrays.<Type>asList(new Address(from), new Address(to), new Uint256(value)),
Collections.<TypeReference<?>>singletonList(new TypeReference<Bool>() {}));
}

private Event transferEvent() {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/web3j/abi/Contract.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ public T call() throws Exception {
});
}

protected <Type> Future<List<T>> executeCallMultipleValueReturnAsync(
protected Future<List<Type>> executeCallMultipleValueReturnAsync(
final Function function) {
return Async.run(new Callable<List<T>>() {
return Async.run(new Callable<List<Type>>() {
@Override
public List<Type> call() throws Exception {
return executeCallMultipleValueReturn(function);
Expand Down
11 changes: 6 additions & 5 deletions src/main/java/org/web3j/abi/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

import sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl;

Expand Down Expand Up @@ -83,10 +82,12 @@ static <T extends Type> Class<T> getParameterizedTypeFromArray(

@SuppressWarnings("unchecked")
public static List<TypeReference<Type>> convert(List<TypeReference<?>> input) {
List<TypeReference<Type>> result = new ArrayList<>(input.size());
result.addAll(input.stream()
.map(typeReference -> (TypeReference<Type>) typeReference)
.collect(Collectors.toList()));
List<TypeReference<Type>> result = new ArrayList<TypeReference<Type>>(input.size());

for (TypeReference<?> typeReference:input) {
result.add((TypeReference<Type>) typeReference);
}

return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ private static boolean isTrustedEndPoint(SSLSocket socket) throws IOException {
}
}

private static void deleteFileOnShutdown(File file) {
private static void deleteFileOnShutdown(final File file) {
Runtime.getRuntime().addShutdownHook(new Thread() {
public void run() {
try {
Expand Down
17 changes: 8 additions & 9 deletions src/main/java/org/web3j/protocol/infura/InfuraHttpService.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import java.security.*;
import java.security.cert.CertificateException;
import java.util.List;
import java.util.Optional;

import org.apache.http.Header;
import org.apache.http.impl.client.CloseableHttpClient;
Expand All @@ -26,7 +25,7 @@ public class InfuraHttpService extends HttpService {

private static final char[] TEMP_KEY_STORE_PASSWORD = "web3j runtime cert store".toCharArray();

private final Optional<Header> clientVersionHeader;
private final Header clientVersionHeader;

public InfuraHttpService(String url, String clientVersion, boolean required) {
super(url);
Expand All @@ -44,21 +43,21 @@ public InfuraHttpService(String url) {

@Override
protected void addHeaders(List<Header> headers) {
if (clientVersionHeader.isPresent()) {
headers.add(clientVersionHeader.get());
if (clientVersionHeader != null) {
headers.add(clientVersionHeader);
}
}

static Optional<Header> buildHeader(String clientVersion, boolean required) {
static Header buildHeader(String clientVersion, boolean required) {
if (clientVersion == null || clientVersion.equals("")) {
return Optional.empty();
return null;
}

if (required) {
return Optional.of(new BasicHeader(INFURA_ETHEREUM_PREFERRED_CLIENT, clientVersion));
return new BasicHeader(INFURA_ETHEREUM_PREFERRED_CLIENT, clientVersion);
} else {
return Optional.of(new BasicHeader(
INFURA_ETHEREUM_PREFERRED_CLIENT, clientVersion + "; required=false"));
return new BasicHeader(
INFURA_ETHEREUM_PREFERRED_CLIENT, clientVersion + "; required=false");
}
}

Expand Down
7 changes: 4 additions & 3 deletions src/test/java/org/web3j/abi/FunctionReturnDecoderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void testSimpleFunctionStringResultDecode() {
"6f6e65206d6f72652074696d6500000000000000000000000000000000000000",
function.getOutputParameters());

assertThat(utf8Strings.get(0).getValue(), is("one more time"));
assertThat((String) utf8Strings.get(0).getValue(), is("one more time"));
}

@Test
Expand All @@ -64,15 +64,16 @@ public void testFunctionEmptyStringResultDecode() {
"0000000000000000000000000000000000000000000000000000000000000000",
function.getOutputParameters());

assertThat(utf8Strings.get(0).getValue(), is(""));
assertThat((String) utf8Strings.get(0).getValue(), is(""));
}

@Test
public void testMultipleResultFunctionDecode() {
Function function = new Function(
"test",
Collections.<Type>emptyList(),
Arrays.asList(new TypeReference<Uint>() { }, new TypeReference<Uint>() { })
Arrays.<TypeReference<?>>asList(
new TypeReference<Uint>() { }, new TypeReference<Uint>() { })
);

assertThat(FunctionReturnDecoder.decode(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,23 @@
import org.junit.Test;

import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.web3j.protocol.infura.InfuraHttpService.buildHeader;

public class InfuraHttpServiceTest {

@Test
public void testBuildHeader() {
assertFalse(buildHeader("", false).isPresent());
assertFalse(buildHeader(null, false).isPresent());
assertNull(buildHeader("", false));
assertNull(buildHeader(null, false));

assertThat(buildHeader("geth 1.4.19", true).get().toString(),
assertThat(buildHeader("geth 1.4.19", true).toString(),
is(new BasicHeader(
"Infura-Ethereum-Preferred-Client",
"geth 1.4.19").toString()));

assertThat(buildHeader("geth 1.4.19", false).get().toString(),
assertThat(buildHeader("geth 1.4.19", false).toString(),
is(new BasicHeader(
"Infura-Ethereum-Preferred-Client",
"geth 1.4.19; required=false").toString()));
Expand Down

0 comments on commit 0de4455

Please sign in to comment.