From bd21fe9f4d96e9c9f62f5af9b9c3bc622aaf2528 Mon Sep 17 00:00:00 2001 From: Maximilian Schmidt Date: Thu, 25 Oct 2018 17:56:09 +0200 Subject: [PATCH 1/3] Issue-1216: wrong method signature for multidimensional arrays - Fixed the canonical name creation for array types - added test --- .../org/ethereum/solidity/SolidityType.java | 16 +++++++-- .../test/java/org/ethereum/core/ABITest.java | 34 +++++++++++++++++++ 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/ethereumj-core/src/main/java/org/ethereum/solidity/SolidityType.java b/ethereumj-core/src/main/java/org/ethereum/solidity/SolidityType.java index ea9956d9f7..74154d67f2 100644 --- a/ethereumj-core/src/main/java/org/ethereum/solidity/SolidityType.java +++ b/ethereumj-core/src/main/java/org/ethereum/solidity/SolidityType.java @@ -156,7 +156,13 @@ 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 @@ -193,7 +199,13 @@ 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 diff --git a/ethereumj-core/src/test/java/org/ethereum/core/ABITest.java b/ethereumj-core/src/test/java/org/ethereum/core/ABITest.java index 80ea8c946d..03e59be128 100644 --- a/ethereumj-core/src/test/java/org/ethereum/core/ABITest.java +++ b/ethereumj-core/src/test/java/org/ethereum/core/ABITest.java @@ -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); + } } From 0790224d410c0e74b21e5d628d917e8e084000e4 Mon Sep 17 00:00:00 2001 From: Maximilian Schmidt Date: Thu, 25 Oct 2018 17:58:29 +0200 Subject: [PATCH 2/3] Issue-1216: wrong method signature for multidimensional arrays - fixed formatting --- .../src/main/java/org/ethereum/solidity/SolidityType.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ethereumj-core/src/main/java/org/ethereum/solidity/SolidityType.java b/ethereumj-core/src/main/java/org/ethereum/solidity/SolidityType.java index 74154d67f2..6c2a04d8ca 100644 --- a/ethereumj-core/src/main/java/org/ethereum/solidity/SolidityType.java +++ b/ethereumj-core/src/main/java/org/ethereum/solidity/SolidityType.java @@ -156,11 +156,11 @@ public StaticArrayType(String name) { @Override public String getCanonicalName() { - if(elementType instanceof ArrayType) { + if (elementType instanceof ArrayType) { String elementTypeName = elementType.getCanonicalName(); int idx1 = elementTypeName.indexOf("["); return elementTypeName.substring(0, idx1) + "[" + size + "]" + elementTypeName.substring(idx1); - }else { + } else { return elementType.getCanonicalName() + "[" + size + "]"; } } @@ -199,11 +199,11 @@ public DynamicArrayType(String name) { @Override public String getCanonicalName() { - if(elementType instanceof ArrayType) { + if (elementType instanceof ArrayType) { String elementTypeName = elementType.getCanonicalName(); int idx1 = elementTypeName.indexOf("["); return elementTypeName.substring(0, idx1) + "[]" + elementTypeName.substring(idx1); - }else { + } else { return elementType.getCanonicalName() + "[]"; } } From 24012e47b56b8638e0d1a9c239b1a32e7b7944ff Mon Sep 17 00:00:00 2001 From: Maximilian Schmidt Date: Fri, 26 Oct 2018 11:24:36 +0200 Subject: [PATCH 3/3] Issue-1216: wrong method signature for multidimensional arrays - review changes --- .../org/ethereum/solidity/SolidityType.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/ethereumj-core/src/main/java/org/ethereum/solidity/SolidityType.java b/ethereumj-core/src/main/java/org/ethereum/solidity/SolidityType.java index 6c2a04d8ca..86228abc39 100644 --- a/ethereumj-core/src/main/java/org/ethereum/solidity/SolidityType.java +++ b/ethereumj-core/src/main/java/org/ethereum/solidity/SolidityType.java @@ -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; @@ -164,6 +181,11 @@ public String getCanonicalName() { return elementType.getCanonicalName() + "[" + size + "]"; } } + + @Override + protected String getCanonicalDimension() { + return "[" + size + "]"; + } @Override public byte[] encodeList(List l) { @@ -207,6 +229,11 @@ public String getCanonicalName() { return elementType.getCanonicalName() + "[]"; } } + + @Override + protected String getCanonicalDimension() { + return "[]"; + } @Override public byte[] encodeList(List l) {