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

feat: set test clients and embedded node to use non-zero shard/realm #17601

Merged
merged 14 commits into from
Feb 3, 2025
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,13 @@ public HederaNode start() {
"bootstrap.nodeAdminKeys.path",
getExternalPath(NODE_ADMIN_KEYS_JSON).toAbsolutePath().toString());
System.setProperty("hedera.profiles.active", "DEV");

// We get the shard/realm from the metadata account which is coming from the property file
var shard = metadata().accountId().shardNum();
var realm = metadata().accountId().realmNum();
System.setProperty("hedera.shard", String.valueOf(shard));
System.setProperty("hedera.realm", String.valueOf(realm));

final var log4j2ConfigLoc = getExternalPath(LOG4J2_XML).toString();
if (isForShared(log4j2ConfigLoc)) {
System.setProperty("log4j.configurationFile", log4j2ConfigLoc);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.hedera.pbj.runtime.io.buffer.Bytes;
import com.hedera.services.bdd.junit.hedera.HederaNode;
import com.hedera.services.bdd.junit.hedera.NodeMetadata;
import com.hedera.services.bdd.spec.props.JutilPropertySource;
import com.hederahashgraph.api.proto.java.ServiceEndpoint;
import com.swirlds.platform.crypto.CryptoStatic;
import com.swirlds.platform.system.address.AddressBook;
Expand All @@ -49,6 +50,9 @@ public class AddressBookUtils {
public static final String[] CLASSIC_NODE_NAMES =
new String[] {"node1", "node2", "node3", "node4", "node5", "node6", "node7", "node8"};

private static final String REALM = JutilPropertySource.getDefaultInstance().get("default.realm");
private static final String SHARD = JutilPropertySource.getDefaultInstance().get("default.shard");

private AddressBookUtils() {
throw new UnsupportedOperationException("Utility Class");
}
Expand Down Expand Up @@ -140,7 +144,7 @@ public static String configTxtForLocal(
.append(", 127.0.0.1, ")
.append(nextExternalGossipPort + (node.getNodeId() * 2))
.append(", ")
.append("0.0.")
.append(SHARD + "." + REALM + ".")
.append(node.getAccountId().accountNumOrThrow())
.append('\n');
maxNodeId = Math.max(node.getNodeId(), maxNodeId);
Expand Down Expand Up @@ -225,6 +229,8 @@ public static NodeMetadata classicMetadataFor(
nodeId,
CLASSIC_NODE_NAMES[nodeId],
AccountID.newBuilder()
.shardNum(Long.parseLong(SHARD))
.realmNum(Long.parseLong(REALM))
.accountNum(CLASSIC_FIRST_NODE_ACCOUNT_NUM + nodeId)
.build(),
host,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
// SPDX-License-Identifier: Apache-2.0
/*
* Copyright (C) 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.
* 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;

import static com.hedera.node.app.hapi.utils.CommonPbjConverters.fromByteString;
Expand Down Expand Up @@ -84,15 +99,15 @@ default HapiSpec.UTF8Mode getUTF8Mode(String property) {

default FileID getFile(String property) {
try {
return asFile(get(property));
return asFile(get("default.shard"), get("default.realm"), get(property));
} catch (Exception ignore) {
}
return FileID.getDefaultInstance();
}

default AccountID getAccount(String property) {
try {
return asAccount(get(property));
return asAccount(get("default.shard"), get("default.realm"), get(property));
} catch (Exception ignore) {
}
return AccountID.getDefaultInstance();
Expand Down Expand Up @@ -229,6 +244,54 @@ static AccountID asAccount(String v) {
.build();
}

static AccountID asAccount(String shard, String realm, String num) {
return AccountID.newBuilder()
.setShardNum(Long.parseLong(shard))
.setRealmNum(Long.parseLong(realm))
.setAccountNum(Long.parseLong(num))
.build();
}

static ContractID asContract(String shard, String realm, String num) {
return ContractID.newBuilder()
.setShardNum(Long.parseLong(shard))
.setRealmNum(Long.parseLong(realm))
.setContractNum(Long.parseLong(num))
.build();
}

static FileID asFile(String shard, String realm, String num) {
return FileID.newBuilder()
.setShardNum(Long.parseLong(shard))
.setRealmNum(Long.parseLong(realm))
.setFileNum(Long.parseLong(num))
.build();
}

static ScheduleID asSchedule(String shard, String realm, String num) {
return ScheduleID.newBuilder()
.setShardNum(Long.parseLong(shard))
.setRealmNum(Long.parseLong(realm))
.setScheduleNum(Long.parseLong(num))
.build();
}

static TokenID asToken(String shard, String realm, String num) {
return TokenID.newBuilder()
.setShardNum(Long.parseLong(shard))
.setRealmNum(Long.parseLong(realm))
.setTokenNum(Long.parseLong(num))
.build();
}

static TopicID asTopic(String shard, String realm, String num) {
return TopicID.newBuilder()
.setShardNum(Long.parseLong(shard))
.setRealmNum(Long.parseLong(realm))
.setTopicNum(Long.parseLong(num))
.build();
}

static AccountID asAccount(ByteString v) {
return AccountID.newBuilder().setAlias(v).build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1002,7 +1002,7 @@ public static void runInCiMode(
txnFromCi = envTxn;
dynamicNodes = nodes;
defaultPayer = payer;
defaultNodeAccount = String.format("0.0.%s", suggestedNode);
defaultNodeAccount = suggestedNode;
nodeSelectorFromCi = envNodeSelector;
otherOverrides = overrides;
ciPropsSource = null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020-2024 Hedera Hashgraph, LLC
* Copyright (C) 2020-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 @@ -73,7 +73,7 @@ public class SuiteRunner {
private static final HapiSpecSetup.TxnProtoStructure DEFAULT_TXN_CONFIG = HapiSpecSetup.TxnProtoStructure.ALTERNATE;
private static final HapiSpecSetup.NodeSelection DEFAULT_NODE_SELECTOR = FIXED;
private static final int EXPECTED_CI_NETWORK_SIZE = 4;
private static final String DEFAULT_PAYER_ID = "0.0.2";
private static final String DEFAULT_PAYER_ID = "2";

private static final List<HapiSuite> SUITES_TO_DETAIL = new ArrayList<>();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020-2024 Hedera Hashgraph, LLC
* Copyright (C) 2020-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 @@ -73,7 +73,7 @@ public List<Stream<DynamicTest>> getSpecsInSuite() {
final Stream<DynamicTest> createAccount() {
int maxRetries = 5;
return customHapiSpec("CreatePayerAccountForEachClient")
.withProperties(Map.of("nodes", nodes, "default.node", "0.0." + defaultNode))
.withProperties(Map.of("nodes", nodes, "default.node", defaultNode))
.given()
.when()
.then(withOpContext((spec, log) -> {
Expand Down Expand Up @@ -133,12 +133,10 @@ final Stream<DynamicTest> createAccount() {
// TODO Should be modified in a different way to avoid setting a
// static variable of
// other class
SuiteRunner.setPayerId(String.format(
"0.0.%s",
spec.registry()
.getAccountInfo("payerAccountInfo")
.getAccountID()
.getAccountNum()));
SuiteRunner.setPayerId(String.valueOf(spec.registry()
.getAccountInfo("payerAccountInfo")
.getAccountID()
.getAccountNum()));
}));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020-2024 Hedera Hashgraph, LLC
* Copyright (C) 2020-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 @@ -72,8 +72,8 @@ final Stream<DynamicTest> runCryptoTransfers() {
do {
re = r.nextInt(settings.getTotalAccounts());
} while (re == s);
sender = String.format("0.0.%d", TEST_ACCOUNT_STARTS_FROM + s);
receiver = String.format("0.0.%d", TEST_ACCOUNT_STARTS_FROM + re);
sender = String.format("%d", TEST_ACCOUNT_STARTS_FROM + s);
receiver = String.format("%d", TEST_ACCOUNT_STARTS_FROM + re);
}

return new HapiSpecOperation[] {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020-2024 Hedera Hashgraph, LLC
* Copyright (C) 2020-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 @@ -180,7 +180,7 @@ public class ValidationScenarios extends HapiSuite {
public static final long FEE_TO_OFFER_IN_HBAR = 100;
public static final long TINYBARS_PER_HBAR = 100_000_000L;
private static final String DEFAULT_CONFIG_LOC = "config.yml";
private static final String PATTERN = "0.0.%d";
private static final String PATTERN = "%d";
private static final String DEFAULT_PAYER_KEY = "default.payer.key";
private static final String TRANSFER_TXN = "transferTxn";
private static final String FEES_USE_FIXED_OFFER = "fees.useFixedOffer";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
address.book.id=0.0.101
address.book.id=101
address.book.name=ADDRESS_BOOK
address.book.controlAccount.id=0.0.55
address.book.controlAccount.id=55
address.book.controlAccount.name=ADDRESS_BOOK_CONTROL
api.permissions.id=0.0.122
api.permissions.id=122
api.permissions.name=API_PERMISSIONS
app.properties.id=0.0.121
app.properties.id=121
app.properties.name=APP_PROPERTIES
### JrsRestartTestTemplate ###
ci.properties.map=restartTest=true,postRestart=false
Expand All @@ -26,14 +26,14 @@ default.max.localCall.retBytes=1024
default.memo=cellar door
default.useMemoUTF8=TRUE
default.memoUtf8Charset=î·ùtF8®JËÐÎ
default.node=0.0.3
default.node=3
default.node.name=DEFAULT_NODE
default.nodePayment.tinyBars=5000
default.payer=0.0.2
default.payer=2
recordStream.autoSnapshotManagement=false
recordStream.overrideExistingSnapshot=false
#default.payer=0.0.50
#default.payer=0.0.950
#default.payer=50
#default.payer=950
default.payer.key=
default.payer.mnemonic=
default.payer.mnemonicFile=
Expand All @@ -51,38 +51,38 @@ default.thresholdKey.N=3
default.token.initialSupply=10000
default.token.decimals=0
default.topic.runningHash.version=3
default.transfer=0.0.2
default.transfer=2
default.transfer.name=GENESIS
default.validDuration.secs=120
default.gossipEndpoint.internal=127.0.0.1:50204
default.gossipEndpoint.external=127.0.0.1:50204
default.serviceEndpoint=127.0.0.1:50211
default.gossipCaCertificate=gossipCaCert
exchange.rates.id=0.0.112
exchange.rates.id=112
exchange.rates.name=EXCHANGE_RATES
exchange.rates.controlAccount.id=0.0.57
exchange.rates.controlAccount.id=57
exchange.rates.controlAccount.name=EXCHANGE_RATES_CONTROL
expected.final.status=PASSED
fee.schedule.controlAccount.id=0.0.56
fee.schedule.controlAccount.id=56
fee.schedule.controlAccount.name=FEE_SCHEDULE_CONTROL
fee.schedule.fetch.fee=100000000
fee.schedule.id=0.0.111
fee.schedule.id=111
fee.schedule.name=FEE_SCHEDULE
fees.tokenTransferUsageMultiplier=380
fees.useFixedOffer=false
fees.fixedOffer=100000000
freeze.admin.name=FREEZE_ADMIN
freeze.admin.id=0.0.58
update.feature.id=0.0.150
freeze.admin.id=58
update.feature.id=150
update.feature.name=UPDATE_FEATURE
funding.account=0.0.98
funding.account=98
funding.account.name=FUNDING
genesis.account=0.0.2
genesis.account=2
genesis.account.name=GENESIS
invalid.contract=1.1.1
invalid.contract.name=INVALID_CONTRACT
node.addressBook.name=NODE_ADDRESS_BOOK
node.details.id=0.0.102
node.details.id=102
node.details.name=NODE_DETAILS
# Valid settings are { fixed, random }
node.selector=fixed
Expand All @@ -95,20 +95,20 @@ nodes=localhost
#nodes=35.237.200.180
num.opFinisher.threads=8
softwareUpdate.admin.name=SOFTWARE_UPDATE_ADMIN
softwareUpdate.admin.id=0.0.54
softwareUpdate.admin.id=54
spec.streamlinedIngestChecks=INVALID_FILE_ID,ENTITY_NOT_ALLOWED_TO_DELETE,AUTHORIZATION_FAILED,INVALID_PRNG_RANGE,INVALID_STAKING_ID,NOT_SUPPORTED,TOKEN_ID_REPEATED_IN_TOKEN_LIST,ALIAS_ALREADY_ASSIGNED,INVALID_ALIAS_KEY,KEY_REQUIRED,BAD_ENCODING,AUTORENEW_DURATION_NOT_IN_RANGE,INVALID_ZERO_BYTE_IN_STRING,INVALID_ADMIN_KEY,ACCOUNT_DELETED,BUSY,INSUFFICIENT_PAYER_BALANCE,INSUFFICIENT_TX_FEE,INVALID_ACCOUNT_ID,INVALID_NODE_ACCOUNT,INVALID_SIGNATURE,INVALID_TRANSACTION,INVALID_TRANSACTION_BODY,INVALID_TRANSACTION_DURATION,INVALID_TRANSACTION_ID,INVALID_TRANSACTION_START,KEY_PREFIX_MISMATCH,MEMO_TOO_LONG,PAYER_ACCOUNT_NOT_FOUND,PLATFORM_NOT_ACTIVE,TRANSACTION_EXPIRED,TRANSACTION_HAS_UNKNOWN_FIELDS,TRANSACTION_ID_FIELD_NOT_ALLOWED,TRANSACTION_OVERSIZE,TRANSFER_ACCOUNT_SAME_AS_DELETE_ACCOUNT,EMPTY_ALLOWANCES,REQUESTED_NUM_AUTOMATIC_ASSOCIATIONS_EXCEEDS_ASSOCIATION_LIMIT,TOKEN_HAS_NO_FREEZE_KEY,TOKEN_HAS_NO_SUPPLY_KEY,INVALID_TOKEN_INITIAL_SUPPLY,INVALID_TOKEN_DECIMALS,INVALID_TOKEN_MAX_SUPPLY,ACCOUNT_REPEATED_IN_ACCOUNT_AMOUNTS,TRANSFERS_NOT_ZERO_SUM_FOR_TOKEN,INVALID_ACCOUNT_AMOUNTS,TOKEN_NAME_TOO_LONG,TOKEN_SYMBOL_TOO_LONG,INVALID_TOKEN_NFT_SERIAL_NUMBER,PERMANENT_REMOVAL_REQUIRES_SYSTEM_INITIATION,MISSING_TOKEN_SYMBOL,MISSING_TOKEN_NAME,INVALID_EXPIRATION_TIME,EMPTY_TOKEN_TRANSFER_ACCOUNT_AMOUNTS,INVALID_ALLOWANCE_OWNER_ID,FUNGIBLE_TOKEN_IN_NFT_ALLOWANCES,TOKEN_NOT_ASSOCIATED_TO_ACCOUNT,MAX_ALLOWANCES_EXCEEDED,INVALID_ALLOWANCE_SPENDER_ID,AMOUNT_EXCEEDS_TOKEN_MAX_SUPPLY,NFT_IN_FUNGIBLE_TOKEN_ALLOWANCES,NEGATIVE_ALLOWANCE_AMOUNT,DELEGATING_SPENDER_DOES_NOT_HAVE_APPROVE_FOR_ALL,DELEGATING_SPENDER_CANNOT_GRANT_APPROVE_FOR_ALL,INVALID_TOKEN_MINT_AMOUNT,INVALID_TOKEN_BURN_AMOUNT,INVALID_WIPING_AMOUNT,INVALID_NFT_ID,BATCH_SIZE_LIMIT_EXCEEDED,METADATA_TOO_LONG,INVALID_RENEWAL_PERIOD,INVALID_CUSTOM_FEE_SCHEDULE_KEY,MAX_GAS_LIMIT_EXCEEDED,CONTRACT_DELETED,INVALID_ETHEREUM_TRANSACTION,INSUFFICIENT_ACCOUNT_BALANCE,INVALID_CONTRACT_ID,INVALID_TOPIC_ID,UPDATE_NODE_ACCOUNT_NOT_ALLOWED,INVALID_NODE_ACCOUNT_ID,INVALID_NODE_ID
status.deferredResolves.doAsync=true
status.preResolve.pause.ms=0
status.wait.sleep.ms=500
status.wait.timeout.ms=90000
strong.control.account=0.0.50
strong.control.account=50
strong.control.name=strong-control
systemDeleteAdmin.account=0.0.59
systemDeleteAdmin.account=59
systemDeleteAdmin.name=sysDelAdmin
systemUndeleteAdmin.account=0.0.60
systemUndeleteAdmin.account=60
systemUndeleteAdmin.name=sysUndelAdmin
warnings.suppressUnrecoverableNetworkFailures=false
throttle.definitions.id=0.0.123
throttle.definitions.id=123
throttle.definitions.name=THROTTLE_DEFINITIONS
txn.start.offset.secs=-60
# Valid settings are { on, off, alternate }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2021-2024 Hedera Hashgraph, LLC
* Copyright (C) 2021-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 @@ -145,7 +145,7 @@ public Long getFixedFee() {
}

public String getNodeAccount() {
return nodeAccount == null ? nodeAccount : ("0.0." + nodeAccount);
return nodeAccount;
}

public Level getLogLevel() {
Expand Down