Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: HIP-904 Additional e2e test cases where sender is a contract #17459

Merged
merged 1 commit into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading