Skip to content

Commit b66d53f

Browse files
Merge pull request #56 from ashleyfletcher76/issue-43-topic-create-request-tests
Add tests for TopicCreateRequest
2 parents 84ed03e + 1218415 commit b66d53f

File tree

4 files changed

+26
-6
lines changed

4 files changed

+26
-6
lines changed

hedera-base/pom.xml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@
2222
<dependency>
2323
<groupId>com.hedera.hashgraph</groupId>
2424
<artifactId>sdk</artifactId>
25+
</dependency>
26+
<dependency>
27+
<groupId>io.github.cdimascio</groupId>
28+
<artifactId>dotenv-java</artifactId>
29+
<version>2.3.2</version>
30+
<scope>test</scope>
2531
</dependency>
2632
<dependency>
2733
<groupId>org.slf4j</groupId>
@@ -47,11 +53,6 @@
4753
<artifactId>grpc-inprocess</artifactId>
4854
<scope>test</scope>
4955
</dependency>
50-
<dependency>
51-
<groupId>io.github.cdimascio</groupId>
52-
<artifactId>dotenv-java</artifactId>
53-
<scope>test</scope>
54-
</dependency>
5556
<dependency>
5657
<groupId>org.slf4j</groupId>
5758
<artifactId>slf4j-simple</artifactId>

hedera-base/src/main/java/com/openelements/hedera/base/implementation/ProtocolLayerClientImpl.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,8 @@ public AccountDeleteResult executeAccountDeleteTransaction(@NonNull final Accoun
310310
public TopicCreateResult executeTopicCreateTransaction(@NonNull final TopicCreateRequest request)
311311
throws HederaException {
312312
Objects.requireNonNull(request, "request must not be null");
313+
Objects.requireNonNull(request.maxTransactionFee(), "maxTransactionFee must not be null");
314+
Objects.requireNonNull(request.transactionValidDuration(), "transactionValidDuration must not be null");
313315
try {
314316
final TopicCreateTransaction transaction = new TopicCreateTransaction()
315317
.setMaxTransactionFee(request.maxTransactionFee())

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ public record TopicCreateRequest(@NonNull Hbar maxTransactionFee,
99
@NonNull Duration transactionValidDuration) implements TransactionRequest {
1010

1111
public TopicCreateRequest {
12-
12+
if (maxTransactionFee == null) {
13+
throw new NullPointerException("maxTransactionFee cannot be null");
14+
}
15+
if (transactionValidDuration == null) {
16+
throw new NullPointerException("transactionValidDuration cannot be null");
17+
}
1318
}
1419

1520
public static TopicCreateRequest of() {

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import com.openelements.hedera.base.protocol.FileDeleteRequest;
4949
import com.openelements.hedera.base.protocol.FileCreateRequest;
5050
import com.openelements.hedera.base.protocol.TopicSubmitMessageResult;
51+
import com.openelements.hedera.base.protocol.TopicCreateRequest;
5152

5253
import java.lang.reflect.Constructor;
5354
import java.nio.charset.StandardCharsets;
@@ -175,6 +176,17 @@ void testAccountDeleteResultCreation() {
175176
Assertions.assertThrows(NullPointerException.class, () -> new AccountDeleteResult(transactionId, status, null, consensusTimestamp, transactionFee));
176177
}
177178

179+
@Test
180+
void testTopicCreateRequestCreation() {
181+
//given
182+
final Hbar validMaxTransactionFee = Hbar.fromTinybars(1000);
183+
final Duration validTransactionDuration = Duration.ofSeconds(120);
184+
185+
Assertions.assertDoesNotThrow(() -> new TopicCreateRequest(validMaxTransactionFee, validTransactionDuration));
186+
Assertions.assertThrows(NullPointerException.class, () -> new TopicCreateRequest(null, validTransactionDuration));
187+
Assertions.assertThrows(NullPointerException.class, () -> new TopicCreateRequest(validMaxTransactionFee, null));
188+
}
189+
178190
@Test
179191
void testContractCallRequestCreation() {
180192
//given

0 commit comments

Comments
 (0)