Skip to content

Commit 35282ab

Browse files
authored
feat: Implement nonzero shard/realm for yahcli DAB transactions (#19166)
Signed-off-by: Matt Hess <[email protected]>
1 parent 4b3e2f8 commit 35282ab

File tree

8 files changed

+87
-68
lines changed

8 files changed

+87
-68
lines changed

hedera-node/test-clients/src/yahcli/java/com/hedera/services/yahcli/commands/nodes/CreateCommand.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,11 @@ public Integer call() throws Exception {
8484
var config = ConfigUtils.configFrom(yahcli);
8585

8686
validateAdminKeyLoc(adminKeyPath);
87-
final var accountId = validatedAccountId(accountNum);
88-
final var feeAccountKeyFile = keyFileFor(config.keysLoc(), "account" + accountId.getAccountNum());
87+
final var accountId = Long.parseLong(accountNum);
88+
final var feeAccountKeyFile = keyFileFor(config.keysLoc(), "account" + accountId);
8989
final var maybeFeeAccountKeyPath = feeAccountKeyFile.map(File::getPath).orElse(null);
9090
if (maybeFeeAccountKeyPath == null) {
91-
COMMON_MESSAGES.warn("No key on disk for account 0.0." + accountId.getAccountNum()
91+
COMMON_MESSAGES.warn("No key on disk for account " + accountId
9292
+ ", payer and admin key signatures must meet its signing requirements");
9393
}
9494

@@ -97,7 +97,7 @@ public Integer call() throws Exception {
9797
// Throws if the cert is not valid
9898
validatedX509Cert(hapiCertificatePath, null, null, yahcli);
9999
final var delegate = new CreateNodeSuite(
100-
config.asSpecConfig(),
100+
config,
101101
accountId,
102102
Optional.ofNullable(description).orElse(""),
103103
asCsServiceEndpoints(gossipEndpoints),

hedera-node/test-clients/src/yahcli/java/com/hedera/services/yahcli/commands/nodes/DeleteCommand.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public Integer call() throws Exception {
4242
NodesCommand.validateKeyAt(adminKeyPath, yahcli);
4343
}
4444

45-
final var delegate = new DeleteNodeSuite(config.asSpecConfig(), targetId, adminKeyPath);
45+
final var delegate = new DeleteNodeSuite(config, targetId, adminKeyPath);
4646
delegate.runSuiteSync();
4747

4848
if (delegate.getFinalSpecs().getFirst().getStatus() == HapiSpec.SpecStatus.PASSED) {

hedera-node/test-clients/src/yahcli/java/com/hedera/services/yahcli/commands/nodes/UpdateCommand.java

+10-5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import static com.hedera.node.app.hapi.utils.CommonUtils.noThrowSha384HashOf;
55
import static com.hedera.services.bdd.spec.HapiPropertySource.asCsServiceEndpoints;
6+
import static com.hedera.services.bdd.spec.HapiPropertySource.asEntityString;
67
import static com.hedera.services.yahcli.commands.nodes.CreateCommand.allBytesAt;
78
import static com.hedera.services.yahcli.commands.nodes.NodesCommand.validateKeyAt;
89
import static com.hedera.services.yahcli.commands.nodes.NodesCommand.validatedX509Cert;
@@ -102,11 +103,12 @@ public Integer call() throws Exception {
102103
newAccountId = null;
103104
feeAccountKeyLoc = null;
104105
} else {
105-
newAccountId = validatedAccountId(accountId);
106+
newAccountId = validatedAccountId(
107+
config.shard().getShardNum(), config.realm().getRealmNum(), accountId);
106108
final var feeAccountKeyFile = keyFileFor(config.keysLoc(), "account" + newAccountId.getAccountNum());
107109
feeAccountKeyLoc = feeAccountKeyFile.map(File::getPath).orElse(null);
108110
if (feeAccountKeyLoc == null) {
109-
COMMON_MESSAGES.warn("No key on disk for account 0.0." + newAccountId.getAccountNum()
111+
COMMON_MESSAGES.warn("No key on disk for account " + newAccountId.getAccountNum()
110112
+ ", payer and admin key signatures must meet its signing requirements");
111113
}
112114
}
@@ -144,7 +146,7 @@ public Integer call() throws Exception {
144146
newHapiCertificateHash = null;
145147
}
146148
final var delegate = new UpdateNodeSuite(
147-
config.asSpecConfig(),
149+
config,
148150
targetNodeId,
149151
newAccountId,
150152
feeAccountKeyLoc,
@@ -176,14 +178,17 @@ private long validatedNodeId(@NonNull final String nodeId) {
176178
}
177179
}
178180

179-
private AccountID validatedAccountId(@NonNull final String accountNum) {
181+
private AccountID validatedAccountId(final long shard, final long realm, @NonNull final String accountNum) {
180182
try {
181183
return AccountID.newBuilder()
184+
.setShardNum(shard)
185+
.setRealmNum(realm)
182186
.setAccountNum(Long.parseLong(accountNum))
183187
.build();
184188
} catch (NumberFormatException e) {
185189
throw new CommandLine.ParameterException(
186-
nodesCommand.getYahcli().getSpec().commandLine(), "Invalid account number '" + accountNum + "'");
190+
nodesCommand.getYahcli().getSpec().commandLine(),
191+
"Invalid account number '" + asEntityString(shard, realm, accountNum) + "'");
187192
}
188193
}
189194
}

hedera-node/test-clients/src/yahcli/java/com/hedera/services/yahcli/suites/CreateNodeSuite.java

+33-27
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,22 @@
22
package com.hedera.services.yahcli.suites;
33

44
import static com.hedera.node.app.hapi.utils.CommonPbjConverters.fromPbj;
5+
import static com.hedera.services.bdd.spec.HapiPropertySource.asAccount;
56
import static com.hedera.services.bdd.spec.transactions.TxnVerbs.nodeCreate;
67
import static com.hedera.services.bdd.spec.utilops.UtilVerbs.keyFromFile;
78
import static com.hedera.services.bdd.spec.utilops.UtilVerbs.noOp;
89
import static java.util.Objects.requireNonNull;
910

1011
import com.hedera.hapi.node.base.ServiceEndpoint;
1112
import com.hedera.services.bdd.spec.HapiSpec;
13+
import com.hedera.services.bdd.spec.SpecOperation;
14+
import com.hedera.services.bdd.spec.props.MapPropertySource;
1215
import com.hedera.services.bdd.suites.HapiSuite;
13-
import com.hederahashgraph.api.proto.java.AccountID;
16+
import com.hedera.services.yahcli.config.ConfigManager;
17+
import com.hedera.services.yahcli.util.HapiSpecUtils;
1418
import edu.umd.cs.findbugs.annotations.NonNull;
1519
import edu.umd.cs.findbugs.annotations.Nullable;
1620
import java.util.List;
17-
import java.util.Map;
1821
import java.util.stream.Stream;
1922
import org.apache.logging.log4j.LogManager;
2023
import org.apache.logging.log4j.Logger;
@@ -23,8 +26,8 @@
2326
public class CreateNodeSuite extends HapiSuite {
2427
private static final Logger log = LogManager.getLogger(CreateNodeSuite.class);
2528

26-
private final Map<String, String> specConfig;
27-
private final AccountID accountId;
29+
private final ConfigManager configManager;
30+
private final long accountId;
2831
private final String description;
2932
private final String adminKeyLoc;
3033

@@ -40,17 +43,17 @@ public class CreateNodeSuite extends HapiSuite {
4043
private Long createdId;
4144

4245
public CreateNodeSuite(
43-
@NonNull final Map<String, String> specConfig,
44-
@NonNull final AccountID accountId,
46+
@NonNull final ConfigManager configManager,
47+
final long accountId,
4548
@NonNull final String description,
4649
@NonNull final List<ServiceEndpoint> gossipEndpoints,
4750
@NonNull final List<ServiceEndpoint> serviceEndpoints,
4851
@NonNull final byte[] gossipCaCertificate,
4952
@NonNull final byte[] grpcCertificateHash,
5053
@NonNull final String adminKeyLoc,
5154
@Nullable final String feeAccountKeyLoc) {
52-
this.specConfig = requireNonNull(specConfig);
53-
this.accountId = requireNonNull(accountId);
55+
this.configManager = requireNonNull(configManager);
56+
this.accountId = accountId;
5457
this.description = requireNonNull(description);
5558
this.gossipEndpoints = requireNonNull(gossipEndpoints);
5659
this.serviceEndpoints = requireNonNull(serviceEndpoints);
@@ -72,25 +75,28 @@ public List<Stream<DynamicTest>> getSpecsInSuite() {
7275
final Stream<DynamicTest> createNode() {
7376
final var adminKey = "adminKey";
7477
final var feeAccountKey = "feeAccountKey";
75-
return HapiSpec.customHapiSpec("CreateNode")
76-
.withProperties(specConfig)
77-
.given(
78-
keyFromFile(adminKey, adminKeyLoc).yahcliLogged(),
79-
feeAccountKeyLoc == null
80-
? noOp()
81-
: keyFromFile(feeAccountKey, feeAccountKeyLoc).yahcliLogged())
82-
.when()
83-
.then(nodeCreate("node")
84-
.signedBy(availableSigners())
85-
.accountId(accountId)
86-
.description(description)
87-
.gossipEndpoint(fromPbj(gossipEndpoints))
88-
.serviceEndpoint(fromPbj(serviceEndpoints))
89-
.gossipCaCertificate(gossipCaCertificate)
90-
.grpcCertificateHash(grpcCertificateHash)
91-
.adminKey(adminKey)
92-
.advertisingCreation()
93-
.exposingCreatedIdTo(createdId -> this.createdId = createdId));
78+
final var fqAcctId = asAccount(
79+
configManager.shard().getShardNum(), configManager.realm().getRealmNum(), accountId);
80+
81+
final var spec =
82+
new HapiSpec("CreateNode", new MapPropertySource(configManager.asSpecConfig()), new SpecOperation[] {
83+
keyFromFile(adminKey, adminKeyLoc).yahcliLogged(),
84+
feeAccountKeyLoc == null
85+
? noOp()
86+
: keyFromFile(feeAccountKey, feeAccountKeyLoc).yahcliLogged(),
87+
nodeCreate("node")
88+
.signedBy(availableSigners())
89+
.accountId(fqAcctId)
90+
.description(description)
91+
.gossipEndpoint(fromPbj(gossipEndpoints))
92+
.serviceEndpoint(fromPbj(serviceEndpoints))
93+
.gossipCaCertificate(gossipCaCertificate)
94+
.grpcCertificateHash(grpcCertificateHash)
95+
.adminKey(adminKey)
96+
.advertisingCreation()
97+
.exposingCreatedIdTo(createdId -> this.createdId = createdId)
98+
});
99+
return HapiSpecUtils.targeted(spec, configManager);
94100
}
95101

96102
private String[] availableSigners() {

hedera-node/test-clients/src/yahcli/java/com/hedera/services/yahcli/suites/DeleteNodeSuite.java

+13-9
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@
66
import static com.hedera.services.bdd.spec.utilops.UtilVerbs.noOp;
77

88
import com.hedera.services.bdd.spec.HapiSpec;
9+
import com.hedera.services.bdd.spec.SpecOperation;
10+
import com.hedera.services.bdd.spec.props.MapPropertySource;
911
import com.hedera.services.bdd.suites.HapiSuite;
12+
import com.hedera.services.yahcli.config.ConfigManager;
13+
import com.hedera.services.yahcli.util.HapiSpecUtils;
1014
import edu.umd.cs.findbugs.annotations.NonNull;
1115
import edu.umd.cs.findbugs.annotations.Nullable;
1216
import java.util.List;
13-
import java.util.Map;
1417
import java.util.stream.Stream;
1518
import org.apache.logging.log4j.LogManager;
1619
import org.apache.logging.log4j.Logger;
@@ -19,15 +22,15 @@
1922
public class DeleteNodeSuite extends HapiSuite {
2023
private static final Logger log = LogManager.getLogger(DeleteNodeSuite.class);
2124

22-
private final Map<String, String> specConfig;
25+
private final ConfigManager configManager;
2326
private final long nodeId;
2427

2528
@Nullable
2629
private final String adminKeyLoc;
2730

2831
public DeleteNodeSuite(
29-
@NonNull final Map<String, String> specConfig, final long nodeId, @Nullable final String adminKeyLoc) {
30-
this.specConfig = specConfig;
32+
@NonNull final ConfigManager configManager, final long nodeId, @Nullable final String adminKeyLoc) {
33+
this.configManager = configManager;
3134
this.nodeId = nodeId;
3235
this.adminKeyLoc = adminKeyLoc;
3336
}
@@ -39,11 +42,12 @@ public List<Stream<DynamicTest>> getSpecsInSuite() {
3942

4043
final Stream<DynamicTest> doDelete() {
4144
final var adminKey = "adminKey";
42-
return HapiSpec.customHapiSpec("DeleteNode")
43-
.withProperties(specConfig)
44-
.given(adminKeyLoc == null ? noOp() : keyFromFile(adminKey, adminKeyLoc))
45-
.when()
46-
.then(nodeDelete("" + nodeId).signedBy(availableSigners()));
45+
final var spec =
46+
new HapiSpec("NodeDelete", new MapPropertySource(configManager.asSpecConfig()), new SpecOperation[] {
47+
adminKeyLoc == null ? noOp() : keyFromFile(adminKey, adminKeyLoc),
48+
nodeDelete("" + nodeId).signedBy(availableSigners())
49+
});
50+
return HapiSpecUtils.targeted(spec, configManager);
4751
}
4852

4953
private String[] availableSigners() {

hedera-node/test-clients/src/yahcli/java/com/hedera/services/yahcli/suites/UpdateNodeSuite.java

+24-20
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
11
// SPDX-License-Identifier: Apache-2.0
22
package com.hedera.services.yahcli.suites;
33

4-
import static com.hedera.services.bdd.spec.HapiSpec.customHapiSpec;
4+
import static com.hedera.services.bdd.spec.HapiPropertySource.asEntityString;
55
import static com.hedera.services.bdd.spec.transactions.TxnVerbs.nodeUpdate;
66
import static com.hedera.services.bdd.spec.utilops.UtilVerbs.keyFromFile;
77
import static com.hedera.services.bdd.spec.utilops.UtilVerbs.noOp;
88
import static java.util.Objects.requireNonNull;
99

1010
import com.hedera.hapi.node.base.ServiceEndpoint;
11+
import com.hedera.services.bdd.spec.HapiSpec;
12+
import com.hedera.services.bdd.spec.SpecOperation;
13+
import com.hedera.services.bdd.spec.props.MapPropertySource;
1114
import com.hedera.services.bdd.spec.transactions.node.HapiNodeUpdate;
1215
import com.hedera.services.bdd.suites.HapiSuite;
16+
import com.hedera.services.yahcli.config.ConfigManager;
17+
import com.hedera.services.yahcli.util.HapiSpecUtils;
1318
import com.hederahashgraph.api.proto.java.AccountID;
1419
import edu.umd.cs.findbugs.annotations.NonNull;
1520
import edu.umd.cs.findbugs.annotations.Nullable;
1621
import java.util.ArrayList;
1722
import java.util.List;
18-
import java.util.Map;
1923
import java.util.stream.Stream;
2024
import org.apache.logging.log4j.LogManager;
2125
import org.apache.logging.log4j.Logger;
@@ -24,7 +28,7 @@
2428
public class UpdateNodeSuite extends HapiSuite {
2529
private static final Logger log = LogManager.getLogger(UpdateNodeSuite.class);
2630

27-
private final Map<String, String> specConfig;
31+
private final ConfigManager configManager;
2832
private final long nodeId;
2933

3034
@Nullable
@@ -55,7 +59,7 @@ public class UpdateNodeSuite extends HapiSuite {
5559
private final byte[] hapiCertificateHash;
5660

5761
public UpdateNodeSuite(
58-
@NonNull final Map<String, String> specConfig,
62+
@NonNull final ConfigManager configManager,
5963
final long nodeId,
6064
@Nullable final AccountID accountId,
6165
@Nullable final String feeAccountKeyLoc,
@@ -66,7 +70,7 @@ public UpdateNodeSuite(
6670
@Nullable final List<ServiceEndpoint> hapiEndpoints,
6771
@Nullable final byte[] gossipCaCertificate,
6872
@Nullable final byte[] hapiCertificateHash) {
69-
this.specConfig = requireNonNull(specConfig);
73+
this.configManager = requireNonNull(configManager);
7074
this.nodeId = nodeId;
7175
this.accountId = accountId;
7276
this.feeAccountKeyLoc = feeAccountKeyLoc;
@@ -88,26 +92,26 @@ final Stream<DynamicTest> doUpdate() {
8892
final var adminKey = "adminKey";
8993
final var newAdminKey = "newAdminKey";
9094
final var feeAccountKey = "feeAccountKey";
91-
return customHapiSpec("UpdateNode")
92-
.withProperties(specConfig)
93-
.given(
94-
feeAccountKeyLoc == null
95-
? noOp()
96-
: keyFromFile(feeAccountKey, feeAccountKeyLoc).yahcliLogged(),
97-
adminKeyLoc == null
98-
? noOp()
99-
: keyFromFile(adminKey, adminKeyLoc).yahcliLogged(),
100-
newAdminKeyLoc == null
101-
? noOp()
102-
: keyFromFile(newAdminKey, newAdminKeyLoc).yahcliLogged())
103-
.when()
104-
.then(updateOp());
95+
final var spec =
96+
new HapiSpec("UpdateNode", new MapPropertySource(configManager.asSpecConfig()), new SpecOperation[] {
97+
feeAccountKeyLoc == null
98+
? noOp()
99+
: keyFromFile(feeAccountKey, feeAccountKeyLoc).yahcliLogged(),
100+
adminKeyLoc == null
101+
? noOp()
102+
: keyFromFile(adminKey, adminKeyLoc).yahcliLogged(),
103+
newAdminKeyLoc == null
104+
? noOp()
105+
: keyFromFile(newAdminKey, newAdminKeyLoc).yahcliLogged(),
106+
updateOp()
107+
});
108+
return HapiSpecUtils.targeted(spec, configManager);
105109
}
106110

107111
private HapiNodeUpdate updateOp() {
108112
final var op = nodeUpdate("" + nodeId);
109113
if (accountId != null) {
110-
op.accountId("0.0." + accountId.getAccountNum());
114+
op.accountId(asEntityString(accountId));
111115
}
112116
if (newAdminKeyLoc != null) {
113117
op.adminKey("newAdminKey");

hedera-node/test-clients/yahcli/run/build.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env bash
22
set -eo pipefail
33

4-
TAG=${1:-'0.7.4'}
4+
TAG=${1:-'0.7.5'}
55
SCRIPT_SOURCE="${BASH_SOURCE[0]}"
66

77
READLINK_OPTS=""

hedera-node/test-clients/yahcli/run/publish.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env bash
22
set -eo pipefail
33

4-
TAG=${1:-'0.7.4'}
4+
TAG=${1:-'0.7.5'}
55
SCRIPT_SOURCE="${BASH_SOURCE[0]}"
66

77
READLINK_OPTS=""

0 commit comments

Comments
 (0)