@@ -173,6 +173,36 @@ public void testGetEventNativeTypeParameterized() {
173173 (TypeName .get (byte [].class )));
174174 }
175175
176+ @ Test
177+ public void testGetEventNativeTypeBytes32Array () {
178+ // bytes32[] maps to byte[] representing the Keccak-256 hash
179+ assertEquals (
180+ getEventNativeType (
181+ ParameterizedTypeName .get (
182+ ClassName .get (DynamicArray .class ), TypeName .get (Bytes32 .class ))),
183+ (TypeName .get (byte [].class )));
184+ }
185+
186+ @ Test
187+ public void testBuildEventWithIndexedArray () throws Exception {
188+ NamedType array = new NamedType ("array" , "uint256[]" , true ); // indexed = true
189+
190+ AbiDefinition functionDefinition =
191+ new AbiDefinition (
192+ false , Arrays .asList (array ), "Transfer" , new ArrayList <>(), "event" , false );
193+ TypeSpec .Builder builder = TypeSpec .classBuilder ("TestClass" );
194+
195+ builder .addMethods (
196+ solidityFunctionWrapper .buildEventFunctions (
197+ functionDefinition ,
198+ builder ,
199+ solidityFunctionWrapper .getDuplicatedEventNames (
200+ Collections .singletonList (functionDefinition ))));
201+
202+ String expected = loadExpected ("TestBuildEventWithIndexedArray.java" );
203+ assertEquals (expected , builder .build ().toString ());
204+ }
205+
176206 @ Test
177207 public void testBuildFunctionTransaction () throws Exception {
178208 AbiDefinition functionDefinition =
@@ -1260,4 +1290,102 @@ public void testBuildCustomErrorDefinitionsWithDuplicateNames() throws Exception
12601290
12611291 assertEquals (expectedJavaCode , builder .build ().toString ());
12621292 }
1293+
1294+ @ Test
1295+ public void testBuildEventWithIndexedStaticArray () throws Exception {
1296+ NamedType array = new NamedType ("array" , "bytes32[2]" , true );
1297+
1298+ AbiDefinition functionDefinition =
1299+ new AbiDefinition (
1300+ false , Arrays .asList (array ), "Transfer" , new ArrayList <>(), "event" , false );
1301+ TypeSpec .Builder builder = TypeSpec .classBuilder ("TestClass" );
1302+
1303+ builder .addMethods (
1304+ solidityFunctionWrapper .buildEventFunctions (
1305+ functionDefinition ,
1306+ builder ,
1307+ solidityFunctionWrapper .getDuplicatedEventNames (
1308+ Collections .singletonList (functionDefinition ))));
1309+
1310+ String expected = loadExpected ("TestBuildEventWithIndexedStaticArray.java" );
1311+ assertEquals (expected , builder .build ().toString ());
1312+ }
1313+
1314+ @ Test
1315+ public void testBuildEventWithIndexedNestedArray () throws Exception {
1316+ NamedType array = new NamedType ("array" , "uint256[][]" , true );
1317+
1318+ AbiDefinition functionDefinition =
1319+ new AbiDefinition (
1320+ false , Arrays .asList (array ), "Transfer" , new ArrayList <>(), "event" , false );
1321+ TypeSpec .Builder builder = TypeSpec .classBuilder ("TestClass" );
1322+
1323+ builder .addMethods (
1324+ solidityFunctionWrapper .buildEventFunctions (
1325+ functionDefinition ,
1326+ builder ,
1327+ solidityFunctionWrapper .getDuplicatedEventNames (
1328+ Collections .singletonList (functionDefinition ))));
1329+
1330+ String expected = loadExpected ("TestBuildEventWithIndexedNestedArray.java" );
1331+ assertEquals (expected , builder .build ().toString ());
1332+ }
1333+
1334+ @ Test
1335+ public void testBuildEventWithIndexedArrayWithoutNativeTypes () throws Exception {
1336+ SolidityFunctionWrapper nonNativeWrapper =
1337+ new SolidityFunctionWrapper (
1338+ false , false , false , Address .DEFAULT_LENGTH , generationReporter );
1339+
1340+ NamedType array = new NamedType ("array" , "uint256[]" , true );
1341+
1342+ AbiDefinition functionDefinition =
1343+ new AbiDefinition (
1344+ false , Arrays .asList (array ), "Transfer" , new ArrayList <>(), "event" , false );
1345+ TypeSpec .Builder builder = TypeSpec .classBuilder ("TestClass" );
1346+
1347+ builder .addMethods (
1348+ nonNativeWrapper .buildEventFunctions (
1349+ functionDefinition ,
1350+ builder ,
1351+ nonNativeWrapper .getDuplicatedEventNames (
1352+ Collections .singletonList (functionDefinition ))));
1353+
1354+ String expected = loadExpected ("TestBuildEventWithIndexedArrayWithoutNativeTypes.java" );
1355+ assertEquals (expected , builder .build ().toString ());
1356+ }
1357+
1358+ @ Test
1359+ public void testBuildEventWithIndexedStruct () throws Exception {
1360+ java .lang .reflect .Field mapField = SolidityFunctionWrapper .class .getDeclaredField ("structClassNameMap" );
1361+ mapField .setAccessible (true );
1362+ java .util .Map <String , ClassName > map =
1363+ (java .util .Map <String , ClassName >) mapField .get (solidityFunctionWrapper );
1364+ map .put ("struct MyContract.SomeStruct" , ClassName .get ("" , "SomeStruct" ));
1365+
1366+ NamedType struct = new NamedType ("myStruct" , "tuple" , new ArrayList <>(), "struct MyContract.SomeStruct" , true );
1367+
1368+ AbiDefinition functionDefinition =
1369+ new AbiDefinition (
1370+ false , Arrays .asList (struct ), "Transfer" , new ArrayList <>(), "event" , false );
1371+ TypeSpec .Builder builder = TypeSpec .classBuilder ("TestClass" );
1372+
1373+ builder .addMethods (
1374+ solidityFunctionWrapper .buildEventFunctions (
1375+ functionDefinition ,
1376+ builder ,
1377+ solidityFunctionWrapper .getDuplicatedEventNames (
1378+ Collections .singletonList (functionDefinition ))));
1379+
1380+ String expected = loadExpected ("TestBuildEventWithIndexedStruct.java" );
1381+ assertEquals (expected , builder .build ().toString ());
1382+ }
1383+
1384+ private String loadExpected (String filename ) throws Exception {
1385+ java .net .URL url = getClass ().getResource ("/expected/" + filename );
1386+ if (url == null ) {
1387+ throw new java .io .FileNotFoundException ("Resource not found: /expected/" + filename );
1388+ }
1389+ return new String (java .nio .file .Files .readAllBytes (java .nio .file .Paths .get (url .toURI ()))).replace ("\r \n " , "\n " );
1390+ }
12631391}
0 commit comments