Skip to content

Commit 29e8afc

Browse files
Merge pull request #58 from Ndacyayisenga-droid/patch-6
Added test to verify NullPointerException for null transactions
2 parents 2d8d4b2 + 70d3e97 commit 29e8afc

File tree

3 files changed

+126
-5
lines changed

3 files changed

+126
-5
lines changed

hedera-base/src/main/java/com/openelements/hedera/base/protocol/ProtocolLayerClient.java

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,22 @@ public interface ProtocolLayerClient {
5858
@NonNull
5959
FileCreateResult executeFileCreateTransaction(@NonNull FileCreateRequest request) throws HederaException;
6060

61+
/**
62+
* Execute a file update transaction.
63+
*
64+
* @param request the request containing the details of the file update
65+
* @return the result of the file update transaction
66+
* @throws HederaException if the transaction could not be executed
67+
*/
6168
FileUpdateResult executeFileUpdateRequestTransaction(FileUpdateRequest request) throws HederaException;
6269

70+
/**
71+
* Execute a file info query.
72+
*
73+
* @param request the request containing the details of the file info query
74+
* @return the response containing the information about the file
75+
* @throws HederaException if the query could not be executed
76+
*/
6377
@NonNull
6478
FileInfoResponse executeFileInfoQuery(@NonNull FileInfoRequest request) throws HederaException;
6579

@@ -84,34 +98,128 @@ ContractCreateResult executeContractCreateTransaction(@NonNull ContractCreateReq
8498
@NonNull
8599
ContractCallResult executeContractCallTransaction(@NonNull ContractCallRequest request) throws HederaException;
86100

101+
/**
102+
* Executes a contract delete transaction.
103+
*
104+
* @param request the request containing the details of the contract delete transaction
105+
* @return the result of the contract delete transaction
106+
* @throws HederaException if the transaction could not be executed
107+
*/
87108
@NonNull
88109
ContractDeleteResult executeContractDeleteTransaction(@NonNull final ContractDeleteRequest request)
89110
throws HederaException;
90111

112+
/**
113+
* Executes an account create transaction.
114+
*
115+
* @param request the request containing the details of the account create transaction
116+
* @return the result of the account create transaction
117+
* @throws HederaException if the transaction could not be executed
118+
*/
91119
@NonNull
92120
AccountCreateResult executeAccountCreateTransaction(@NonNull final AccountCreateRequest request)
93121
throws HederaException;
94122

123+
/**
124+
* Executes an account delete transaction.
125+
*
126+
* @param request the request containing the details of the account delete transaction
127+
* @return the result of the account delete transaction
128+
* @throws HederaException if the transaction could not be executed
129+
*/
95130
@NonNull
96131
AccountDeleteResult executeAccountDeleteTransaction(@NonNull AccountDeleteRequest request) throws HederaException;
97132

133+
/**
134+
* Executes a token create transaction.
135+
*
136+
* @param request the request containing the details of the token create transaction
137+
* @return the result of the token create transaction
138+
* @throws HederaException if the transaction could not be executed
139+
*/
98140
@NonNull
99141
TokenCreateResult executeTokenCreateTransaction(@NonNull final TokenCreateRequest request) throws HederaException;
100142

143+
/**
144+
* Executes a token associate transaction.
145+
*
146+
* @param request the request containing the details of the token associate transaction
147+
* @return the result of the token associate transaction
148+
* @throws HederaException if the transaction could not be executed
149+
*/
101150
@NonNull
102151
TokenAssociateResult executeTokenAssociateTransaction(@NonNull final TokenAssociateRequest request)
103152
throws HederaException;
104153

154+
/**
155+
* Executes a token mint transaction.
156+
*
157+
* @param request the request containing the details of the token mint transaction
158+
* @return the result of the token mint transaction
159+
* @throws HederaException if the transaction could not be executed
160+
*/
105161
@NonNull
106162
TokenMintResult executeMintTokenTransaction(@NonNull final TokenMintRequest request) throws HederaException;
107163

164+
/**
165+
* Executes a token burn transaction.
166+
*
167+
* @param request the request containing the details of the token burn transaction
168+
* @return the result of the token burn transaction
169+
* @throws HederaException if the transaction could not be executed
170+
*/
108171
@NonNull
109172
TokenBurnResult executeBurnTokenTransaction(@NonNull final TokenBurnRequest request) throws HederaException;
110173

174+
/**
175+
* Executes a transfer transaction for an NFT.
176+
*
177+
* @param request the request containing the details of the token transfer transaction
178+
* @return the result of the token transfer transaction
179+
* @throws HederaException if the transaction could not be executed
180+
*/
111181
@NonNull
112182
TokenTransferResult executeTransferTransactionForNft(@NonNull final TokenTransferRequest request)
113183
throws HederaException;
114184

185+
/**
186+
* Executes a topic create transaction.
187+
*
188+
* @param request the request containing the details of the topic create transaction
189+
* @return the result of the topic create transaction
190+
* @throws HederaException if the transaction could not be executed
191+
*/
192+
@NonNull
193+
TopicCreateResult executeTopicCreateTransaction(@NonNull TopicCreateRequest request) throws HederaException;
194+
195+
/**
196+
* Executes a topic delete transaction.
197+
*
198+
* @param request the request containing the details of the topic delete transaction
199+
* @return the result of the topic delete transaction
200+
* @throws HederaException if the transaction could not be executed
201+
*/
202+
@NonNull
203+
TopicDeleteResult executeTopicDeleteTransaction(@NonNull TopicDeleteRequest request) throws HederaException;
204+
205+
/**
206+
* Executes a topic message submit transaction.
207+
*
208+
* @param request the request containing the details of the topic message submit transaction
209+
* @return the result of the topic message submit transaction
210+
* @throws HederaException if the transaction could not be executed
211+
*/
212+
@NonNull
213+
TopicSubmitMessageResult executeTopicMessageSubmitTransaction(@NonNull TopicSubmitMessageRequest request)
214+
throws HederaException;
215+
216+
/**
217+
* Adds a transaction listener to the protocol layer client. The listener will be notified when a transaction
218+
* is executed.
219+
*
220+
* @param listener the transaction listener to be added
221+
* @return a Runnable object that can be used to remove the listener
222+
*/
115223
@NonNull
116224
Runnable addTransactionListener(@NonNull TransactionListener listener);
117225
}

hedera-base/src/test/java/com/openelements/hedera/base/test/ProtocolLayerClientTests.java

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
11
package com.openelements.hedera.base.test;
22

3+
import com.openelements.hedera.base.protocol.ProtocolLayerClient;
4+
import org.junit.jupiter.api.Assertions;
5+
import org.junit.jupiter.api.Test;
6+
37
import com.hedera.hashgraph.sdk.AccountId;
48
import com.hedera.hashgraph.sdk.Client;
59
import com.hedera.hashgraph.sdk.PrivateKey;
610
import com.openelements.hedera.base.Account;
711
import com.openelements.hedera.base.implementation.ProtocolLayerClientImpl;
8-
import com.openelements.hedera.base.protocol.ProtocolLayerClient;
9-
import org.junit.jupiter.api.Assertions;
10-
import org.junit.jupiter.api.Test;
1112

1213
public class ProtocolLayerClientTests {
1314

1415
@Test
1516
void testNullConstructorParam() {
16-
//then
17+
//given
1718
final Client client = Client.forTestnet();
1819
final Account account = new Account(AccountId.fromString("0.0.12345"), PrivateKey.generateED25519().getPublicKey(), PrivateKey.generateED25519());
20+
21+
//then
1922
Assertions.assertThrows(NullPointerException.class, () -> new ProtocolLayerClientImpl(client, null));
2023
Assertions.assertThrows(NullPointerException.class, () -> new ProtocolLayerClientImpl(null, account));
2124
Assertions.assertThrows(NullPointerException.class, () -> new ProtocolLayerClientImpl(null, null));
@@ -38,5 +41,16 @@ void testNullParams() {
3841
Assertions.assertThrows(NullPointerException.class, () -> client.executeContractCallTransaction(null));
3942
Assertions.assertThrows(NullPointerException.class, () -> client.executeFileInfoQuery(null));
4043
Assertions.assertThrows(NullPointerException.class, () -> client.executeAccountDeleteTransaction(null));
44+
Assertions.assertThrows(NullPointerException.class, () -> client.executeContractDeleteTransaction(null));
45+
Assertions.assertThrows(NullPointerException.class, () -> client.executeAccountCreateTransaction(null));
46+
Assertions.assertThrows(NullPointerException.class, () -> client.executeTokenCreateTransaction(null));
47+
Assertions.assertThrows(NullPointerException.class, () -> client.executeTokenAssociateTransaction(null));
48+
Assertions.assertThrows(NullPointerException.class, () -> client.executeTopicCreateTransaction(null));
49+
Assertions.assertThrows(NullPointerException.class, () -> client.executeTopicDeleteTransaction(null));
50+
Assertions.assertThrows(NullPointerException.class, () -> client.executeTopicMessageSubmitTransaction(null));
51+
Assertions.assertThrows(NullPointerException.class, () -> client.executeTokenCreateTransaction(null));
52+
Assertions.assertThrows(NullPointerException.class, () -> client.executeBurnTokenTransaction(null));
53+
Assertions.assertThrows(NullPointerException.class, () -> client.executeMintTokenTransaction(null));
54+
Assertions.assertThrows(NullPointerException.class, () -> client.executeTransferTransactionForNft(null));
4155
}
4256
}

hedera-base/src/test/java/com/openelements/hedera/base/test/ProtocolLayerDataCreationTests.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import com.hedera.hashgraph.sdk.ContractFunctionResult;
1212
import com.hedera.hashgraph.sdk.TokenId;
1313
import com.hedera.hashgraph.sdk.TokenType;
14-
import com.hedera.hashgraph.sdk.TopicId;
1514
import com.hedera.hashgraph.sdk.proto.ContractFunctionResultOrBuilder;
1615
import com.openelements.hedera.base.Account;
1716
import com.openelements.hedera.base.ContractParam;

0 commit comments

Comments
 (0)