@@ -685,7 +685,11 @@ public void testBuildEventConstantMultipleValueReturn() throws Exception {
685
685
TypeSpec .Builder builder = TypeSpec .classBuilder ("testClass" );
686
686
687
687
builder .addMethods (
688
- solidityFunctionWrapper .buildEventFunctions (functionDefinition , builder ));
688
+ solidityFunctionWrapper .buildEventFunctions (
689
+ functionDefinition ,
690
+ builder ,
691
+ solidityFunctionWrapper .getDuplicatedEventNames (
692
+ Collections .singletonList (functionDefinition ))));
689
693
690
694
String expected =
691
695
"class testClass {\n "
@@ -773,7 +777,11 @@ public void testBuildEventWithNamedAndNoNamedParameters() throws Exception {
773
777
TypeSpec .Builder builder = TypeSpec .classBuilder ("testClass" );
774
778
775
779
builder .addMethods (
776
- solidityFunctionWrapper .buildEventFunctions (functionDefinition , builder ));
780
+ solidityFunctionWrapper .buildEventFunctions (
781
+ functionDefinition ,
782
+ builder ,
783
+ solidityFunctionWrapper .getDuplicatedEventNames (
784
+ Collections .singletonList (functionDefinition ))));
777
785
778
786
String expected =
779
787
"class testClass {\n "
@@ -853,7 +861,11 @@ public void testBuildEventWithNativeList() throws Exception {
853
861
TypeSpec .Builder builder = TypeSpec .classBuilder ("testClass" );
854
862
855
863
builder .addMethods (
856
- solidityFunctionWrapper .buildEventFunctions (functionDefinition , builder ));
864
+ solidityFunctionWrapper .buildEventFunctions (
865
+ functionDefinition ,
866
+ builder ,
867
+ solidityFunctionWrapper .getDuplicatedEventNames (
868
+ Collections .singletonList (functionDefinition ))));
857
869
858
870
String expected =
859
871
"class testClass {\n "
@@ -926,6 +938,140 @@ public void testBuildFuncNameConstants() throws Exception {
926
938
assertEquals (builder .build ().toString (), (expected ));
927
939
}
928
940
941
+ @ Test
942
+ public void testBuildFunctionDuplicatedEventNames () throws Exception {
943
+ AbiDefinition firstEventDefinition =
944
+ new AbiDefinition (
945
+ false ,
946
+ Arrays .asList (
947
+ new NamedType ("action" , "string" , false ),
948
+ new NamedType ("pauseState" , "bool" , false )),
949
+ "eventName" ,
950
+ Collections .emptyList (),
951
+ "event" ,
952
+ false );
953
+ AbiDefinition secondEventDefinition =
954
+ new AbiDefinition (
955
+ false ,
956
+ Arrays .asList (
957
+ new NamedType ("cToken" , "address" , false ),
958
+ new NamedType ("action" , "string" , false ),
959
+ new NamedType ("pauseState" , "bool" , false )),
960
+ "eventName" ,
961
+ Collections .emptyList (),
962
+ "event" ,
963
+ false );
964
+ TypeSpec .Builder builder = TypeSpec .classBuilder ("testClass" );
965
+ builder .addMethods (
966
+ solidityFunctionWrapper .buildFunctionDefinitions (
967
+ "testClass" ,
968
+ builder ,
969
+ Arrays .asList (firstEventDefinition , secondEventDefinition )));
970
+
971
+ String expected =
972
+ "class testClass {\n " +
973
+ " public static final org.web3j.abi.datatypes.Event EVENTNAME1_EVENT = new org.web3j.abi.datatypes.Event(\" eventName\" , \n " +
974
+ " java.util.Arrays.<org.web3j.abi.TypeReference<?>>asList(new org.web3j.abi.TypeReference<org.web3j.abi.datatypes.Utf8String>() {}, new org.web3j.abi.TypeReference<org.web3j.abi.datatypes.Bool>() {}));\n " +
975
+ " ;\n " +
976
+ "\n " +
977
+ " public static final org.web3j.abi.datatypes.Event EVENTNAME_EVENT = new org.web3j.abi.datatypes.Event(\" eventName\" , \n " +
978
+ " java.util.Arrays.<org.web3j.abi.TypeReference<?>>asList(new org.web3j.abi.TypeReference<org.web3j.abi.datatypes.Address>() {}, new org.web3j.abi.TypeReference<org.web3j.abi.datatypes.Utf8String>() {}, new org.web3j.abi.TypeReference<org.web3j.abi.datatypes.Bool>() {}));\n " +
979
+ " ;\n " +
980
+ "\n " +
981
+ " public static java.util.List<EventName1EventResponse> getEventName1Events(\n " +
982
+ " org.web3j.protocol.core.methods.response.TransactionReceipt transactionReceipt) {\n " +
983
+ " java.util.List<org.web3j.tx.Contract.EventValuesWithLog> valueList = staticExtractEventParametersWithLog(EVENTNAME1_EVENT, transactionReceipt);\n " +
984
+ " java.util.ArrayList<EventName1EventResponse> responses = new java.util.ArrayList<EventName1EventResponse>(valueList.size());\n " +
985
+ " for (org.web3j.tx.Contract.EventValuesWithLog eventValues : valueList) {\n " +
986
+ " EventName1EventResponse typedResponse = new EventName1EventResponse();\n " +
987
+ " typedResponse.log = eventValues.getLog();\n " +
988
+ " typedResponse.action = (java.lang.String) eventValues.getNonIndexedValues().get(0).getValue();\n " +
989
+ " typedResponse.pauseState = (java.lang.Boolean) eventValues.getNonIndexedValues().get(1).getValue();\n " +
990
+ " responses.add(typedResponse);\n " +
991
+ " }\n " +
992
+ " return responses;\n " +
993
+ " }\n " +
994
+ "\n " +
995
+ " public static EventName1EventResponse getEventName1EventFromLog(\n " +
996
+ " org.web3j.protocol.core.methods.response.Log log) {\n " +
997
+ " org.web3j.tx.Contract.EventValuesWithLog eventValues = staticExtractEventParametersWithLog(EVENTNAME1_EVENT, log);\n " +
998
+ " EventName1EventResponse typedResponse = new EventName1EventResponse();\n " +
999
+ " typedResponse.log = log;\n " +
1000
+ " typedResponse.action = (java.lang.String) eventValues.getNonIndexedValues().get(0).getValue();\n " +
1001
+ " typedResponse.pauseState = (java.lang.Boolean) eventValues.getNonIndexedValues().get(1).getValue();\n " +
1002
+ " return typedResponse;\n " +
1003
+ " }\n " +
1004
+ "\n " +
1005
+ " public io.reactivex.Flowable<EventName1EventResponse> eventName1EventFlowable(\n " +
1006
+ " org.web3j.protocol.core.methods.request.EthFilter filter) {\n " +
1007
+ " return web3j.ethLogFlowable(filter).map(log -> getEventName1EventFromLog(log));\n " +
1008
+ " }\n " +
1009
+ "\n " +
1010
+ " public io.reactivex.Flowable<EventName1EventResponse> eventName1EventFlowable(\n " +
1011
+ " org.web3j.protocol.core.DefaultBlockParameter startBlock,\n " +
1012
+ " org.web3j.protocol.core.DefaultBlockParameter endBlock) {\n " +
1013
+ " org.web3j.protocol.core.methods.request.EthFilter filter = new org.web3j.protocol.core.methods.request.EthFilter(startBlock, endBlock, getContractAddress());\n " +
1014
+ " filter.addSingleTopic(org.web3j.abi.EventEncoder.encode(EVENTNAME1_EVENT));\n " +
1015
+ " return eventName1EventFlowable(filter);\n " +
1016
+ " }\n " +
1017
+ "\n " +
1018
+ " public static java.util.List<EventNameEventResponse> getEventNameEvents(\n " +
1019
+ " org.web3j.protocol.core.methods.response.TransactionReceipt transactionReceipt) {\n " +
1020
+ " java.util.List<org.web3j.tx.Contract.EventValuesWithLog> valueList = staticExtractEventParametersWithLog(EVENTNAME_EVENT, transactionReceipt);\n " +
1021
+ " java.util.ArrayList<EventNameEventResponse> responses = new java.util.ArrayList<EventNameEventResponse>(valueList.size());\n " +
1022
+ " for (org.web3j.tx.Contract.EventValuesWithLog eventValues : valueList) {\n " +
1023
+ " EventNameEventResponse typedResponse = new EventNameEventResponse();\n " +
1024
+ " typedResponse.log = eventValues.getLog();\n " +
1025
+ " typedResponse.cToken = (java.lang.String) eventValues.getNonIndexedValues().get(0).getValue();\n " +
1026
+ " typedResponse.action = (java.lang.String) eventValues.getNonIndexedValues().get(1).getValue();\n " +
1027
+ " typedResponse.pauseState = (java.lang.Boolean) eventValues.getNonIndexedValues().get(2).getValue();\n " +
1028
+ " responses.add(typedResponse);\n " +
1029
+ " }\n " +
1030
+ " return responses;\n " +
1031
+ " }\n " +
1032
+ "\n " +
1033
+ " public static EventNameEventResponse getEventNameEventFromLog(\n " +
1034
+ " org.web3j.protocol.core.methods.response.Log log) {\n " +
1035
+ " org.web3j.tx.Contract.EventValuesWithLog eventValues = staticExtractEventParametersWithLog(EVENTNAME_EVENT, log);\n " +
1036
+ " EventNameEventResponse typedResponse = new EventNameEventResponse();\n " +
1037
+ " typedResponse.log = log;\n " +
1038
+ " typedResponse.cToken = (java.lang.String) eventValues.getNonIndexedValues().get(0).getValue();\n " +
1039
+ " typedResponse.action = (java.lang.String) eventValues.getNonIndexedValues().get(1).getValue();\n " +
1040
+ " typedResponse.pauseState = (java.lang.Boolean) eventValues.getNonIndexedValues().get(2).getValue();\n " +
1041
+ " return typedResponse;\n " +
1042
+ " }\n " +
1043
+ "\n " +
1044
+ " public io.reactivex.Flowable<EventNameEventResponse> eventNameEventFlowable(\n " +
1045
+ " org.web3j.protocol.core.methods.request.EthFilter filter) {\n " +
1046
+ " return web3j.ethLogFlowable(filter).map(log -> getEventNameEventFromLog(log));\n " +
1047
+ " }\n " +
1048
+ "\n " +
1049
+ " public io.reactivex.Flowable<EventNameEventResponse> eventNameEventFlowable(\n " +
1050
+ " org.web3j.protocol.core.DefaultBlockParameter startBlock,\n " +
1051
+ " org.web3j.protocol.core.DefaultBlockParameter endBlock) {\n " +
1052
+ " org.web3j.protocol.core.methods.request.EthFilter filter = new org.web3j.protocol.core.methods.request.EthFilter(startBlock, endBlock, getContractAddress());\n " +
1053
+ " filter.addSingleTopic(org.web3j.abi.EventEncoder.encode(EVENTNAME_EVENT));\n " +
1054
+ " return eventNameEventFlowable(filter);\n " +
1055
+ " }\n " +
1056
+ "\n " +
1057
+ " public static class EventName1EventResponse extends org.web3j.protocol.core.methods.response.BaseEventResponse {\n " +
1058
+ " public java.lang.String action;\n " +
1059
+ "\n " +
1060
+ " public java.lang.Boolean pauseState;\n " +
1061
+ " }\n " +
1062
+ "\n " +
1063
+ " public static class EventNameEventResponse extends org.web3j.protocol.core.methods.response.BaseEventResponse {\n " +
1064
+ " public java.lang.String cToken;\n " +
1065
+ "\n " +
1066
+ " public java.lang.String action;\n " +
1067
+ "\n " +
1068
+ " public java.lang.Boolean pauseState;\n " +
1069
+ " }\n " +
1070
+ "}\n " ;
1071
+
1072
+ assertEquals (builder .build ().toString (), (expected ));
1073
+ }
1074
+
929
1075
@ Test
930
1076
public void testBuildFunctionTransactionAndCall () throws Exception {
931
1077
AbiDefinition functionDefinition =
0 commit comments