Skip to content

Commit

Permalink
test: HIP-904 Additional e2e test cases where receiver contract and a…
Browse files Browse the repository at this point in the history
…lready associated

Signed-off-by: Lyuben Ivanov <[email protected]>
  • Loading branch information
bubo committed Jan 8, 2025
1 parent 293a28d commit 92eb63c
Show file tree
Hide file tree
Showing 3 changed files with 320 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2024 Hedera Hashgraph, LLC
* Copyright (C) 2024-2025 Hedera Hashgraph, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -42,6 +42,7 @@
import com.hedera.services.bdd.spec.dsl.operations.queries.GetContractInfoOperation;
import com.hedera.services.bdd.spec.dsl.operations.queries.StaticCallContractOperation;
import com.hedera.services.bdd.spec.dsl.operations.transactions.AssociateTokensOperation;
import com.hedera.services.bdd.spec.dsl.operations.transactions.AuthorizeContractOperation;
import com.hedera.services.bdd.spec.dsl.operations.transactions.CallContractOperation;
import com.hedera.services.bdd.spec.dsl.operations.transactions.DissociateTokensOperation;
import com.hedera.services.bdd.spec.dsl.operations.transactions.TransferTokenOperation;
Expand Down Expand Up @@ -203,7 +204,7 @@ public StaticCallContractOperation staticCall(@NonNull final String function, @N
* @param args the arguments
*/
public void setConstructorArgs(@NonNull final Object... args) {
this.constructorArgs = args;
constructorArgs = args;
}

/**
Expand All @@ -216,6 +217,17 @@ public Account contractOrThrow(@NonNull final HederaNetwork network) {
return modelOrThrow(network);
}

/**
* Returns an operation to authorize the given contract to act on behalf of this account.
*
* @param contract the contract to authorize
* @return the operation
*/
public AuthorizeContractOperation authorizeContract(@NonNull final SpecContract contract) {
requireNonNull(contract);
return new AuthorizeContractOperation(this, contract);
}

/**
* {@inheritDoc}
*/
Expand Down Expand Up @@ -249,9 +261,9 @@ protected Creation<SpecOperation, Account> newCreation(@NonNull final HapiSpec s
*/
@Override
protected Result<Account> resultForSuccessful(
@NonNull Creation<SpecOperation, Account> creation, @NonNull HapiSpec spec) {
@NonNull final Creation<SpecOperation, Account> creation, @NonNull final HapiSpec spec) {
final HapiContractCreate contractCreate;
if (creation.op() instanceof HapiContractCreate inlineCreate) {
if (creation.op() instanceof final HapiContractCreate inlineCreate) {
contractCreate = inlineCreate;
} else {
contractCreate = (HapiContractCreate) ((InBlockingOrder) creation.op()).last();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2024 Hedera Hashgraph, LLC
* Copyright (C) 2024-2025 Hedera Hashgraph, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -21,6 +21,7 @@
import static com.hedera.services.bdd.spec.keys.KeyShape.ED25519;
import static com.hedera.services.bdd.spec.keys.KeyShape.sigs;
import static com.hedera.services.bdd.spec.keys.SigControl.ED25519_ON;
import static com.hedera.services.bdd.spec.transactions.TxnVerbs.contractUpdate;
import static com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoUpdate;
import static com.hedera.services.bdd.spec.transactions.TxnVerbs.tokenUpdate;
import static com.hedera.services.bdd.suites.utils.contracts.precompile.TokenKeyType.FEE_SCHEDULE_KEY;
Expand Down Expand Up @@ -64,7 +65,7 @@ public AuthorizeContractOperation(@NonNull final SpecEntity target, @NonNull fin
});
this.target = target;
this.contracts = requireNonNull(contracts);
this.managedKeyName = target.name() + "_"
managedKeyName = target.name() + "_"
+ Arrays.stream(contracts).map(SpecContract::name).collect(joining("|")) + "ManagedKey";
}

Expand All @@ -85,8 +86,9 @@ protected SpecOperation computeDelegate(@NonNull final HapiSpec spec) {
final var key = spec.keys().generateSubjectTo(spec, controller);
spec.registry().saveKey(managedKeyName, key);
return switch (target) {
case SpecAccount account -> cryptoUpdate(account.name()).key(managedKeyName);
case SpecToken token -> {
case final SpecAccount account -> cryptoUpdate(account.name()).key(managedKeyName);
case final SpecContract contract -> contractUpdate(contract.name()).newKey(managedKeyName);
case final SpecToken token -> {
final var op = tokenUpdate(token.name()).adminKey(managedKeyName);
if (extraTokenAuthorizations.contains(TokenKeyType.KYC_KEY)) {
op.kycKey(managedKeyName);
Expand Down Expand Up @@ -118,11 +120,12 @@ protected SpecOperation computeDelegate(@NonNull final HapiSpec spec) {
@Override
protected void onSuccess(@NonNull final HapiSpec spec) {
switch (target) {
case SpecAccount account -> account.updateKeyFrom(
case final SpecAccount account -> account.updateKeyFrom(
toPbj(spec.registry().getKey(managedKeyName)), spec);
case SpecToken token -> {
case final SpecToken token -> {
// (FUTURE) - update the admin key on the token model
}
case final SpecContract contract -> {}
default -> throw new IllegalStateException("Cannot authorize contract for " + target);
}
}
Expand Down
Loading

0 comments on commit 92eb63c

Please sign in to comment.