Skip to content

Commit

Permalink
Merge pull request #1221 from eth-events/develop
Browse files Browse the repository at this point in the history
Fix issue-1216: wrong signature generated for multidimensional arrays
  • Loading branch information
Nashatyrev authored Oct 26, 2018
2 parents 3ae595f + 24012e4 commit 561582b
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,23 @@ public byte[] encode(Object value) {
throw new RuntimeException("List value expected for type " + getName());
}
}

@Override
public String getCanonicalName() {
return getArrayCanonicalName("");
}

String getArrayCanonicalName(String parentDimStr) {
String myDimStr = parentDimStr + getCanonicalDimension();
if (getElementType() instanceof ArrayType) {
return ((ArrayType) getElementType()).
getArrayCanonicalName(myDimStr);
} else {
return getElementType().getCanonicalName() + myDimStr;
}
}

protected abstract String getCanonicalDimension();

public SolidityType getElementType() {
return elementType;
Expand All @@ -156,7 +173,18 @@ public StaticArrayType(String name) {

@Override
public String getCanonicalName() {
return elementType.getCanonicalName() + "[" + size + "]";
if (elementType instanceof ArrayType) {
String elementTypeName = elementType.getCanonicalName();
int idx1 = elementTypeName.indexOf("[");
return elementTypeName.substring(0, idx1) + "[" + size + "]" + elementTypeName.substring(idx1);
} else {
return elementType.getCanonicalName() + "[" + size + "]";
}
}

@Override
protected String getCanonicalDimension() {
return "[" + size + "]";
}

@Override
Expand Down Expand Up @@ -193,7 +221,18 @@ public DynamicArrayType(String name) {

@Override
public String getCanonicalName() {
return elementType.getCanonicalName() + "[]";
if (elementType instanceof ArrayType) {
String elementTypeName = elementType.getCanonicalName();
int idx1 = elementTypeName.indexOf("[");
return elementTypeName.substring(0, idx1) + "[]" + elementTypeName.substring(idx1);
} else {
return elementType.getCanonicalName() + "[]";
}
}

@Override
protected String getCanonicalDimension() {
return "[]";
}

@Override
Expand Down
34 changes: 34 additions & 0 deletions ethereumj-core/src/test/java/org/ethereum/core/ABITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -335,4 +335,38 @@ public void decodeWithUnknownFunctionTypeTest() {
Assert.assertArrayEquals((Object[]) objects[1], strings);
Assert.assertEquals(((Number) objects[2]).intValue(), 222);
}

@Test
public void twoDimensionalArrayType_hasDimensionDefinitionInCorrectOrder() {
String funcJson = "{ \n" +
" 'constant':false,\n" +
" 'inputs':[ \n" +
" { \n" +
" 'name':'param1',\n" +
" 'type':'address[5][]'\n" +
" },\n" +
" { \n" +
" 'name':'param2',\n" +
" 'type':'uint256[6][2]'\n" +
" },\n" +
" { \n" +
" 'name':'param2',\n" +
" 'type':'uint256[][]'\n" +
" },\n" +
" { \n" +
" 'name':'param3',\n" +
" 'type':'uint256[][2]'\n" +
" }\n" +
" ],\n" +
" 'name':'testTwoDimArray',\n" +
" 'outputs':[],\n" +
" 'payable':false,\n" +
" 'type':'function'\n" +
"}";
funcJson = funcJson.replaceAll("'", "\"");
CallTransaction.Function function = CallTransaction.Function.fromJsonInterface(funcJson);
String expected = "testTwoDimArray(address[5][],uint256[6][2],uint256[][],uint256[][2])";
String actual = function.toString();
Assert.assertEquals(expected, actual);
}
}

0 comments on commit 561582b

Please sign in to comment.