Skip to content

Commit

Permalink
make validate generic
Browse files Browse the repository at this point in the history
  • Loading branch information
esaulpaugh committed Sep 19, 2024
1 parent ffcf1cb commit 2cfb2ad
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/main/java/com/esaulpaugh/headlong/abi/Function.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public final class Function implements ABIObject {

private final TypeEnum type;
private final String name;
private final TupleType<?> inputTypes;
private final TupleType<Tuple> inputTypes;
private final TupleType<?> outputTypes;
private final String stateMutability;

Expand Down Expand Up @@ -88,10 +88,11 @@ private Function(final String signature, final int nameLength, final TupleType<?
* @param messageDigest hash function with which to generate the 4-byte selector
* @throws IllegalArgumentException if the arguments do not specify a valid function
*/
@SuppressWarnings("unchecked")
public Function(TypeEnum type, String name, TupleType<?> inputs, TupleType<?> outputs, String stateMutability, MessageDigest messageDigest) {
this.type = Objects.requireNonNull(type);
this.name = name != null ? validateName(name) : null;
this.inputTypes = Objects.requireNonNull(inputs);
this.inputTypes = (TupleType<Tuple>) Objects.requireNonNull(inputs);
this.outputTypes = Objects.requireNonNull(outputs);
this.stateMutability = stateMutability;
this.hashAlgorithm = Objects.requireNonNull(messageDigest.getAlgorithm());
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/esaulpaugh/headlong/abi/TupleType.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ static int countBytes(boolean tuple, int len, IntUnaryOperator counter) {
}

@Override
public int validate(final Tuple value) {
public int validate(final J value) {
if (value.size() == this.size()) {
return countBytes(i -> validateObject(get(i), value.elements[i]));
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/com/esaulpaugh/headlong/abi/TupleTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ public void testGetElement() {

@Test
public void testTupleLengthMismatch() throws Throwable {
TupleType<?> tt = TupleType.parse("(bool)");
TupleType<Tuple> tt = TupleType.parse("(bool)");
assertThrown(IllegalArgumentException.class, "tuple length mismatch: expected length 1 but found 0", () -> tt.validate(Tuple.EMPTY));
assertThrown(IllegalArgumentException.class, "tuple length mismatch: expected length 1 but found 2", () -> tt.validate(Tuple.of("", "")));
}
Expand Down

0 comments on commit 2cfb2ad

Please sign in to comment.