Skip to content

Commit

Permalink
chore: Refactor hapi tests to use hapiTest(...) instead of `default…
Browse files Browse the repository at this point in the history
…HapiSpec(...)` (Part 1) (#16613)

Signed-off-by: Matt Hess <[email protected]>
  • Loading branch information
mhess-swl authored Nov 15, 2024
1 parent a649547 commit 7d4e23a
Show file tree
Hide file tree
Showing 30 changed files with 3,461 additions and 3,904 deletions.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package com.hedera.services.bdd.suites.consensus;

import static com.hedera.services.bdd.spec.HapiSpec.defaultHapiSpec;
import static com.hedera.services.bdd.spec.HapiSpec.hapiTest;
import static com.hedera.services.bdd.spec.queries.QueryVerbs.getTopicInfo;
import static com.hedera.services.bdd.spec.transactions.TxnUtils.asTopicId;
Expand All @@ -38,29 +37,26 @@
public class TopicDeleteSuite {
@HapiTest
final Stream<DynamicTest> idVariantsTreatedAsExpected() {
return defaultHapiSpec("idVariantsTreatedAsExpected")
.given(newKeyNamed("adminKey"))
.when(createTopic("topic").adminKeyName("adminKey"))
.then(submitModified(withSuccessivelyVariedBodyIds(), () -> deleteTopic("topic")));
return hapiTest(
newKeyNamed("adminKey"),
createTopic("topic").adminKeyName("adminKey"),
submitModified(withSuccessivelyVariedBodyIds(), () -> deleteTopic("topic")));
}

@HapiTest
final Stream<DynamicTest> pureCheckFails() {
return defaultHapiSpec("CannotDeleteAccountAsTopic")
.given(cryptoCreate("nonTopicId"))
.when()
.then(
deleteTopic(spec -> asTopicId(spec.registry().getAccountID("nonTopicId")))
.hasPrecheck(INVALID_TOPIC_ID),
deleteTopic((String) null).hasPrecheck(INVALID_TOPIC_ID));
return hapiTest(
cryptoCreate("nonTopicId"),
deleteTopic(spec -> asTopicId(spec.registry().getAccountID("nonTopicId")))
.hasPrecheck(INVALID_TOPIC_ID),
deleteTopic((String) null).hasPrecheck(INVALID_TOPIC_ID));
}

@HapiTest
final Stream<DynamicTest> cannotDeleteAccountAsTopic() {
return defaultHapiSpec("CannotDeleteAccountAsTopic")
.given(cryptoCreate("nonTopicId"))
.when()
.then(deleteTopic(spec -> asTopicId(spec.registry().getAccountID("nonTopicId")))
return hapiTest(
cryptoCreate("nonTopicId"),
deleteTopic(spec -> asTopicId(spec.registry().getAccountID("nonTopicId")))
.hasKnownStatus(INVALID_TOPIC_ID));
}

Expand All @@ -74,41 +70,38 @@ final Stream<DynamicTest> topicIdIsValidated() {

@HapiTest
final Stream<DynamicTest> noAdminKeyCannotDelete() {
return defaultHapiSpec("noAdminKeyCannotDelete")
.given(createTopic("testTopic"))
.when(deleteTopic("testTopic").hasKnownStatus(UNAUTHORIZED))
.then();
return hapiTest(createTopic("testTopic"), deleteTopic("testTopic").hasKnownStatus(UNAUTHORIZED));
}

@HapiTest
final Stream<DynamicTest> deleteWithAdminKey() {
return defaultHapiSpec("deleteWithAdminKey")
.given(newKeyNamed("adminKey"), createTopic("testTopic").adminKeyName("adminKey"))
.when(deleteTopic("testTopic").hasPrecheck(ResponseCodeEnum.OK))
.then(getTopicInfo("testTopic").hasCostAnswerPrecheck(INVALID_TOPIC_ID));
return hapiTest(
newKeyNamed("adminKey"),
createTopic("testTopic").adminKeyName("adminKey"),
deleteTopic("testTopic").hasPrecheck(ResponseCodeEnum.OK),
getTopicInfo("testTopic").hasCostAnswerPrecheck(INVALID_TOPIC_ID));
}

@HapiTest
final Stream<DynamicTest> deleteFailedWithWrongKey() {
long PAYER_BALANCE = 1_999_999_999L;
return defaultHapiSpec("deleteFailedWithWrongKey")
.given(
newKeyNamed("adminKey"),
newKeyNamed("wrongKey"),
cryptoCreate("payer").balance(PAYER_BALANCE),
createTopic("testTopic").adminKeyName("adminKey"))
.when(deleteTopic("testTopic")
return hapiTest(
newKeyNamed("adminKey"),
newKeyNamed("wrongKey"),
cryptoCreate("payer").balance(PAYER_BALANCE),
createTopic("testTopic").adminKeyName("adminKey"),
deleteTopic("testTopic")
.payingWith("payer")
.signedBy("payer", "wrongKey")
.hasKnownStatus(ResponseCodeEnum.INVALID_SIGNATURE))
.then();
.hasKnownStatus(ResponseCodeEnum.INVALID_SIGNATURE));
}

@HapiTest
final Stream<DynamicTest> feeAsExpected() {
return defaultHapiSpec("feeAsExpected")
.given(cryptoCreate("payer"), createTopic("testTopic").adminKeyName("payer"))
.when(deleteTopic("testTopic").blankMemo().payingWith("payer").via("topicDelete"))
.then(validateChargedUsd("topicDelete", 0.005));
return hapiTest(
cryptoCreate("payer"),
createTopic("testTopic").adminKeyName("payer"),
deleteTopic("testTopic").blankMemo().payingWith("payer").via("topicDelete"),
validateChargedUsd("topicDelete", 0.005));
}
}
Loading

0 comments on commit 7d4e23a

Please sign in to comment.