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

chore: fix yahcli build, activate-staking bug #11501

Merged
merged 3 commits into from
Feb 13, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion hedera-node/test-clients/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ sourceSets {
main { resources { srcDir("src/main/resource") } }

create("rcdiff")
create("yahcli")
}

// IntelliJ uses adhoc-created JavaExec tasks when running a 'main()' method.
Expand Down Expand Up @@ -221,8 +222,9 @@ tasks.shadowJar {
val yahCliJar =
tasks.register<ShadowJar>("yahCliJar") {
exclude(listOf("META-INF/*.DSA", "META-INF/*.RSA", "META-INF/*.SF", "META-INF/INDEX.LIST"))

from(sourceSets["yahcli"].output)
archiveClassifier.set("yahcli")
configurations = listOf(project.configurations.getByName("yahcliRuntimeClasspath"))

manifest {
attributes(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import static com.hedera.services.bdd.spec.queries.QueryUtils.answerHeader;
import static com.hedera.services.bdd.spec.transactions.TxnUtils.asTokenId;
import static com.hedera.services.bdd.suites.HapiSuite.GENESIS;
import static com.hedera.services.yahcli.output.CommonMessages.COMMON_MESSAGES;
import static org.junit.jupiter.api.Assertions.assertEquals;

import com.google.common.base.MoreObjects;
Expand Down Expand Up @@ -311,7 +310,7 @@ protected void submitWith(HapiSpec spec, Transaction payment) throws Throwable {
log.info(message);
}
if (yahcliLogger) {
COMMON_MESSAGES.info(String.format("%20s | %20d |", repr, balance));
System.out.println(".i. " + String.format("%20s | %20d |", repr, balance));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import static com.hedera.services.bdd.spec.queries.QueryUtils.answerCostHeader;
import static com.hedera.services.bdd.spec.queries.QueryUtils.answerHeader;
import static com.hedera.services.yahcli.output.CommonMessages.COMMON_MESSAGES;

import com.google.common.base.MoreObjects;
import com.hedera.services.bdd.spec.HapiSpec;
Expand Down Expand Up @@ -106,9 +105,10 @@ protected void submitWith(HapiSpec spec, Transaction payment) {
}

if (yahcliLogger) {
COMMON_MESSAGES.info(String.format(
"Versions :: HAPI protobufs @ %s, Hedera Services @ %s",
asReadable(info.getHapiProtoVersion()), asReadable(info.getHederaServicesVersion())));
System.out.println(".i. "
+ String.format(
"Versions :: HAPI protobufs @ %s, Hedera Services @ %s",
asReadable(info.getHapiProtoVersion()), asReadable(info.getHederaServicesVersion())));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
import static com.hedera.services.bdd.suites.TargetNetworkType.HAPI_TEST_NETWORK;
import static com.hedera.services.bdd.suites.contract.Utils.asAddress;
import static com.hedera.services.bdd.suites.contract.traceability.TraceabilitySuite.SIDECARS_PROP;
import static com.hedera.services.yahcli.output.CommonMessages.COMMON_MESSAGES;
import static com.hederahashgraph.api.proto.java.FreezeType.FREEZE_ABORT;
import static com.hederahashgraph.api.proto.java.FreezeType.FREEZE_ONLY;
import static com.hederahashgraph.api.proto.java.FreezeType.FREEZE_UPGRADE;
Expand Down Expand Up @@ -981,7 +980,7 @@ private static ByteString defaultFeeSchedules() {
throw new IllegalArgumentException(e);
}
var stylized = new String(baos.toByteArray());
return ByteString.copyFrom(serde.toRawFile(stylized));
return ByteString.copyFrom(serde.toRawFile(stylized, null));
}

public static HapiSpecOperation createLargeFile(String payer, String fileName, ByteString byteString) {
Expand Down Expand Up @@ -1028,10 +1027,10 @@ public static HapiSpecOperation updateSpecialFile(
uploadProgress.initializeFor(appendsRequired);

if (appendsToSkip == 0) {
COMMON_MESSAGES.info(
"Beginning upload for " + fileName + " (" + appendsRequired + " appends required)");
System.out.println(
".i. Beginning upload for " + fileName + " (" + appendsRequired + " appends required)");
} else {
COMMON_MESSAGES.info("Continuing upload for "
System.out.println(".i. Continuing upload for "
+ fileName
+ " with "
+ appendsToSkip
Expand All @@ -1048,9 +1047,9 @@ public static HapiSpecOperation updateSpecialFile(
final var updateSubOp = fileUpdate(fileName)
.fee(ONE_HUNDRED_HBARS)
.contents(contents.substring(0, position))
.alertingPre(fid ->
COMMON_MESSAGES.info("Submitting initial update for file" + " 0.0." + fid.getFileNum()))
.alertingPost(code -> COMMON_MESSAGES.info("Finished initial update with " + code))
.alertingPre(fid -> System.out.println(
".i. Submitting initial update for file" + " 0.0." + fid.getFileNum()))
.alertingPost(code -> System.out.println(".i. Finished initial update with " + code))
.noLogging()
.payingWith(payer)
.signedBy(payer);
Expand Down Expand Up @@ -1132,8 +1131,8 @@ private static void finishAppendsFor(
final var fixedAppendsHere = appendsHere.get() + 1;
appendSubOp.alertingPre(fid -> {
burstStart.set(Instant.now());
COMMON_MESSAGES.info(
"Starting burst " + fixedBurstNo + "/" + numBursts + " (" + fixedAppendsHere + " ops)");
System.out.println(".i. Starting burst " + fixedBurstNo + "/" + numBursts + " ("
+ fixedAppendsHere + " ops)");
});
isFirstAppend = false;
}
Expand All @@ -1142,7 +1141,7 @@ private static void finishAppendsFor(
appendSubOp.alertingPost(code -> {
final var burstSecs = Duration.between(burstStart.get(), Instant.now())
.getSeconds();
COMMON_MESSAGES.info("Completed burst #"
System.out.println(".i. Completed burst #"
+ fixedBurstNo
+ "/"
+ numBursts
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
/*
* Copyright (C) 2024 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.hedera.services.bdd.spec.utilops.inventory;

import com.hedera.services.bdd.spec.persistence.SpecKey;
import edu.umd.cs.findbugs.annotations.NonNull;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.file.Paths;
import java.util.List;
import java.util.Optional;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.status.StatusConsoleListener;
import org.apache.logging.log4j.status.StatusLogger;

public class AccessoryUtils {
private AccessoryUtils() {
throw new UnsupportedOperationException("Utility Class");
}

public static Optional<File> keyFileAt(String sansExt) {
var pemFile = Paths.get(sansExt + ".pem").toFile();
if (pemFile.exists()) {
return Optional.of(pemFile);
}

var wordsFile = Paths.get(sansExt + ".words").toFile();
if (wordsFile.exists()) {
return Optional.of(wordsFile);
}

var hexedFile = Paths.get(sansExt + ".hex").toFile();
if (hexedFile.exists()) {
return Optional.of(hexedFile);
}

return Optional.empty();
}

public static boolean isValid(File keyFile, Optional<String> passphrase) {
return passphrase.isPresent() && unlocks(keyFile, passphrase.get());
}

public static Optional<File> passFileFor(File pemFile) {
var absPath = pemFile.getAbsolutePath();
var passFile = new File(absPath.replace(".pem", ".pass"));
return passFile.exists() ? Optional.of(passFile) : Optional.empty();
}

public static void setLogLevels(Level logLevel, @NonNull final List<Class<?>> suites) {
final var statusLogger = StatusLogger.getLogger();
statusLogger.registerListener(new StatusConsoleListener(logLevel));
suites.forEach(cls -> setLogLevel(cls, logLevel));
}

public static Optional<String> promptForPassphrase(String pemLoc, String prompt, int maxAttempts) {
var pemFile = new File(pemLoc);
String fullPrompt = prompt + ": ";
char[] passphrase;
while (maxAttempts-- > 0) {
passphrase = readCandidate(fullPrompt);
var asString = new String(passphrase);
if (unlocks(pemFile, asString)) {
return Optional.of(asString);
} else {
if (maxAttempts > 0) {
System.out.println(
"Sorry, that isn't it! (Don't worry, still " + maxAttempts + " attempts remaining.)");
} else {
return Optional.empty();
}
}
}
throw new AssertionError("Impossible!");
}

static boolean unlocks(File keyFile, String passphrase) {
try {
SpecKey.readFirstKpFromPem(keyFile, passphrase);
return true;
} catch (Exception ignore) {
return false;
}
}

private static void setLogLevel(Class<?> cls, Level logLevel) {
((org.apache.logging.log4j.core.Logger) LogManager.getLogger(cls)).setLevel(logLevel);
}

private static char[] readCandidate(String prompt) {
System.out.print(prompt);
System.out.flush();
if (System.console() != null) {
return System.console().readPassword();
} else {
var reader = new BufferedReader(new InputStreamReader(System.in));
try {
return reader.readLine().toCharArray();
} catch (IOException e) {
return new char[0];
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import static com.hedera.services.bdd.spec.keys.DefaultKeyGen.DEFAULT_KEY_GEN;
import static com.hedera.services.bdd.spec.keys.KeyFactory.KeyType;
import static com.hedera.services.yahcli.output.CommonMessages.COMMON_MESSAGES;
import static com.swirlds.common.utility.CommonUtils.hex;

import com.google.common.base.MoreObjects;
Expand Down Expand Up @@ -144,7 +143,7 @@ protected boolean submitOp(HapiSpec spec) throws Throwable {
final var exportPass = immediateExportPass.get();
exportWithPass(spec, name, exportLoc, exportPass);
if (verboseLoggingOn && yahcliLogger) {
COMMON_MESSAGES.info("Exported a newly generated key in PEM format to " + exportLoc);
System.out.println(".i. Exported a newly generated key in PEM format to " + exportLoc);
}
}
if (verboseLoggingOn && !yahcliLogger) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@

package com.hedera.services.bdd.spec.utilops.inventory;

import static com.hedera.services.bdd.spec.utilops.inventory.AccessoryUtils.isValid;
import static com.hedera.services.bdd.spec.utilops.inventory.AccessoryUtils.keyFileAt;
import static com.hedera.services.bdd.spec.utilops.inventory.AccessoryUtils.passFileFor;
import static com.hedera.services.bdd.spec.utilops.inventory.AccessoryUtils.promptForPassphrase;
import static com.hedera.services.bdd.spec.utilops.inventory.NewSpecKey.exportWithPass;
import static com.hedera.services.bdd.spec.utilops.inventory.SpecKeyFromMnemonic.createAndLinkFromMnemonic;
import static com.hedera.services.bdd.spec.utilops.inventory.SpecKeyFromMnemonic.createAndLinkSimpleKey;
import static com.hedera.services.bdd.spec.utilops.inventory.SpecKeyFromPem.incorporatePem;
import static com.hedera.services.yahcli.config.ConfigManager.isValid;
import static com.hedera.services.yahcli.config.ConfigUtils.*;
import static com.hedera.services.yahcli.output.CommonMessages.COMMON_MESSAGES;

import com.google.common.base.MoreObjects;
import com.hedera.services.bdd.spec.HapiSpec;
Expand Down Expand Up @@ -116,7 +117,7 @@ protected boolean submitOp(HapiSpec spec) throws Throwable {
final var exportPass = finalPassphrase.orElse(immediateExportPass.get());
exportWithPass(spec, name, exportLoc, exportPass);
if (verboseLoggingOn && yahcliLogger) {
COMMON_MESSAGES.info("Exported key from " + flexLoc + " to " + exportLoc);
System.out.println(".i. Exported key from " + flexLoc + " to " + exportLoc);
}
}
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
import static com.hedera.services.bdd.suites.contract.Utils.asToken;
import static com.hedera.services.bdd.suites.contract.precompile.AssociatePrecompileSuite.THE_CONTRACT;
import static com.hedera.services.bdd.suites.contract.precompile.AssociatePrecompileSuite.TOKEN_ASSOCIATE_FUNCTION;
import static com.hedera.services.bdd.suites.contract.precompile.ContractBurnHTSSuite.ALICE;
import static com.hedera.services.bdd.suites.contract.precompile.ContractBurnHTSSuite.BURN_TOKEN_WITH_EVENT;
import static com.hedera.services.bdd.suites.contract.precompile.ContractBurnHTSSuite.CREATION_TX;
import static com.hedera.services.bdd.suites.contract.precompile.ContractBurnHTSSuite.THE_BURN_CONTRACT;
Expand Down Expand Up @@ -78,7 +77,6 @@
import static com.hedera.services.bdd.suites.crypto.CryptoApproveAllowanceSuite.PAUSE_KEY;
import static com.hedera.services.bdd.suites.token.TokenAssociationSpecs.VANILLA_TOKEN;
import static com.hedera.services.bdd.suites.token.TokenTransactSpecs.SUPPLY_KEY;
import static com.hedera.services.yahcli.commands.validation.ValidationCommand.TOKEN;
import static com.hederahashgraph.api.proto.java.ResponseCodeEnum.CONTRACT_REVERT_EXECUTED;
import static com.hederahashgraph.api.proto.java.ResponseCodeEnum.INVALID_FULL_PREFIX_SIGNATURE_FOR_PRECOMPILE;
import static com.hederahashgraph.api.proto.java.ResponseCodeEnum.INVALID_SIGNATURE;
Expand Down Expand Up @@ -108,6 +106,7 @@ public class TopLevelSigsCanBeToggledByPrecompileTypeSuite extends HapiSuite {
public static final String TOKEN_DELETE_FUNCTION = "tokenDelete";
public static final String WIPE_CONTRACT = "WipeTokenAccount";
public static final String ADMIN_ACCOUNT = "admin";
public static final String TOKEN = "yahcliToken";
private static final String ACCOUNT = "anybody";
private static final String SECOND_ACCOUNT = "anybodySecond";
public static final String WIPE_KEY = "wipeKey";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ public class NonceSuite extends HapiSuite {
private static final String REVERTER_CONSTRUCTOR_CONTRACT = "ReverterConstructor";
private static final String REVERTER_CONSTRUCTOR_TRANSFER_CONTRACT = "ReverterConstructorTransfer";
private static final String REVERTER_CONSTRUCTOR_CALL_WITH_VALUE_TO_ETH_PRECOMPILE_CONTRACT =
"ReverterConstructorCallWithValueToEthPrecompile";
"ConsValueEthPrecompile";
private static final String REVERTER_CONSTRUCTOR_CALL_WITH_VALUE_TO_HEDERA_PRECOMPILE_CONTRACT =
"ReverterConstructorCallWithValueToHederaPrecompile";
"ConsValueSysContract";
private static final String EXTERNAL_FUNCTION = "externalFunction";
private static final String REVERT_WITH_REVERT_REASON_FUNCTION = "revertWithRevertReason";
private static final String TRANSFER_TO_FUNCTION = "transferTo";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,6 @@
import static com.hedera.services.bdd.suites.token.TokenTransactSpecs.SUPPLY_KEY;
import static com.hedera.services.bdd.suites.utils.contracts.AddressResult.hexedAddress;
import static com.hedera.services.bdd.suites.utils.contracts.precompile.HTSPrecompileResult.htsPrecompileResult;
import static com.hedera.services.yahcli.commands.validation.ValidationCommand.RECEIVER;
import static com.hedera.services.yahcli.commands.validation.ValidationCommand.SENDER;
import static com.hederahashgraph.api.proto.java.ResponseCodeEnum.CONTRACT_EXECUTION_EXCEPTION;
import static com.hederahashgraph.api.proto.java.ResponseCodeEnum.CONTRACT_REVERT_EXECUTED;
import static com.hederahashgraph.api.proto.java.ResponseCodeEnum.CUSTOM_FEE_DENOMINATION_MUST_BE_FUNGIBLE_COMMON;
Expand Down Expand Up @@ -259,6 +257,8 @@ public class LeakyContractTestsSuite extends HapiSuite {
public static final int GAS_TO_OFFER = 1_000_000;
private static final Logger log = LogManager.getLogger(LeakyContractTestsSuite.class);
private static final String PAYER = "payer";
public static final String SENDER = "yahcliSender";
public static final String RECEIVER = "yahcliReceiver";
private static final String CONTRACTS_NONCES_EXTERNALIZATION_ENABLED = "contracts.nonces.externalization.enabled";
private static final KeyShape DELEGATE_CONTRACT_KEY_SHAPE =
KeyShape.threshOf(1, KeyShape.SIMPLE, DELEGATE_CONTRACT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,13 @@
import static com.hedera.services.bdd.suites.crypto.CryptoCreateSuite.ED_25519_KEY;
import static com.hedera.services.bdd.suites.crypto.CryptoCreateSuite.LAZY_CREATION_ENABLED;
import static com.hedera.services.bdd.suites.file.FileUpdateSuite.CIVILIAN;
import static com.hedera.services.bdd.suites.leaky.LeakyContractTestsSuite.RECEIVER;
import static com.hedera.services.bdd.suites.token.TokenPauseSpecs.DEFAULT_MIN_AUTO_RENEW_PERIOD;
import static com.hedera.services.bdd.suites.token.TokenPauseSpecs.LEDGER_AUTO_RENEW_PERIOD_MIN_DURATION;
import static com.hedera.services.bdd.suites.token.TokenPauseSpecs.TokenIdOrderingAsserts.withOrderedTokenIds;
import static com.hedera.services.bdd.suites.token.TokenTransactSpecs.SUPPLY_KEY;
import static com.hedera.services.bdd.suites.token.TokenTransactSpecs.TRANSFER_TXN;
import static com.hedera.services.bdd.suites.token.TokenTransactSpecs.UNIQUE;
import static com.hedera.services.yahcli.commands.validation.ValidationCommand.RECEIVER;
import static com.hederahashgraph.api.proto.java.HederaFunctionality.ContractCreate;
import static com.hederahashgraph.api.proto.java.HederaFunctionality.CryptoCreate;
import static com.hederahashgraph.api.proto.java.HederaFunctionality.CryptoTransfer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ final HapiSpec ensureSystemStateAsExpectedWithSystemDefaultFiles() {
uploadDefaultFeeSchedules(GENESIS),
fileUpdate(API_PERMISSIONS)
.payingWith(GENESIS)
.contents(serde.toValidatedRawFile(stylized121)),
.contents(serde.toValidatedRawFile(stylized121, null)),
overridingAllOf(Map.of(
"scheduling.whitelist",
"ConsensusSubmitMessage,CryptoTransfer,TokenMint,TokenBurn,CryptoApproveAllowance,CryptoUpdate",
Expand Down