Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/main/java/com/algorand/algosdk/abi/ABIType.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public static List<String> parseTupleContent(String str) {
return new ArrayList<>();

if (str.startsWith(",") || str.endsWith(","))
throw new IllegalArgumentException("parsing error: tuple content should not start with comma");
throw new IllegalArgumentException("parsing error: tuple content should not start or end with comma");

if (str.contains(",,"))
throw new IllegalArgumentException("parsing error: tuple content should not have consecutive commas");
Expand All @@ -118,8 +118,15 @@ else if (str.charAt(i) == ')') {
if (parenStack.isEmpty())
throw new IllegalArgumentException("parsing error: tuple parentheses are not balanced: " + str);
int leftParenIndex = parenStack.pop();
if (parenStack.isEmpty())
if (parenStack.isEmpty()) {
// iterate through the byte str, include all the bytes after closing round bracket, for array indicator
// increase the index until it meets comma, or end of string
int forwardIndex = i + 1;
while (forwardIndex < str.length() && str.charAt(forwardIndex) != ',')
forwardIndex++;
i = forwardIndex - 1;
parenSegments.add(new Segment(leftParenIndex, i));
}
}
}
if (!parenStack.isEmpty())
Expand Down
48 changes: 48 additions & 0 deletions src/test/java/com/algorand/algosdk/abi/TestTypes.java
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,54 @@ public void TestTypeFromStringValid() {
)
)
);
assertThat(ABIType.valueOf("(uint32,(uint64,bool)[10],byte)")).isEqualTo(
new TypeTuple(
Arrays.asList(
new TypeUint(32),
new TypeArrayStatic(
new TypeTuple(
Arrays.asList(
new TypeUint(64),
new TypeBool()
)
),
10),
new TypeByte()
)
)
);
assertThat(ABIType.valueOf("(uint32,byte,(uint64,bool)[10])")).isEqualTo(
new TypeTuple(
Arrays.asList(
new TypeUint(32),
new TypeByte(),
new TypeArrayStatic(
new TypeTuple(
Arrays.asList(
new TypeUint(64),
new TypeBool()
)
),
10)
)
)
);
assertThat(ABIType.valueOf("((uint64,bool)[10],uint32,byte)")).isEqualTo(
new TypeTuple(
Arrays.asList(
new TypeArrayStatic(
new TypeTuple(
Arrays.asList(
new TypeUint(64),
new TypeBool()
)
),
10),
new TypeUint(32),
new TypeByte()
)
)
);
}

@Test
Expand Down