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: add latest shortcut as targeted era for Cardano CLI commands #2085

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
22 changes: 13 additions & 9 deletions mithril-common/src/chain_observer/cli_observer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ impl CardanoCliRunner {
fn command_for_utxo(&self, address: &str, out_file: PathBuf) -> Command {
let mut command = self.get_command();
command
.arg("latest")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not obvious that this is the cardano era that is used, plus since it's used multiple times I think that you can add a LATEST_CARDANO_ERA static variable to encompass those concerns.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, I’ve addressed your comment in this commit.

.arg("query")
.arg("utxo")
.arg("--address")
Expand All @@ -79,7 +80,7 @@ impl CardanoCliRunner {

fn command_for_stake_distribution(&self) -> Command {
let mut command = self.get_command();
command.arg("query").arg("stake-distribution");
command.arg("latest").arg("query").arg("stake-distribution");
self.post_config_command(&mut command);

command
Expand All @@ -88,6 +89,7 @@ impl CardanoCliRunner {
fn command_for_stake_snapshot(&self, stake_pool_id: &str) -> Command {
let mut command = self.get_command();
command
.arg("latest")
.arg("query")
.arg("stake-snapshot")
.arg("--stake-pool-id")
Expand All @@ -100,6 +102,7 @@ impl CardanoCliRunner {
fn command_for_stake_snapshot_all_pools(&self) -> Command {
let mut command = self.get_command();
command
.arg("latest")
.arg("query")
.arg("stake-snapshot")
.arg("--all-stake-pools");
Expand All @@ -110,15 +113,15 @@ impl CardanoCliRunner {

fn command_for_epoch(&self) -> Command {
let mut command = self.get_command();
command.arg("query").arg("tip");
command.arg("latest").arg("query").arg("tip");
self.post_config_command(&mut command);

command
}

fn command_for_chain_point(&self) -> Command {
let mut command = self.get_command();
command.arg("query").arg("tip");
command.arg("latest").arg("query").arg("tip");
self.post_config_command(&mut command);

command
Expand All @@ -127,6 +130,7 @@ impl CardanoCliRunner {
fn command_for_kes_period(&self, opcert_file: &str) -> Command {
let mut command = self.get_command();
command
.arg("latest")
.arg("query")
.arg("kes-period-info")
.arg("--op-cert-file")
Expand Down Expand Up @@ -556,8 +560,8 @@ mod tests {
CardanoNetwork::TestNet(10),
);

assert_eq!("Command { std: CARDANO_NODE_SOCKET_PATH=\"/tmp/whatever.sock\" \"cardano-cli\" \"query\" \"tip\" \"--testnet-magic\" \"10\", kill_on_drop: false }", format!("{:?}", runner.command_for_epoch()));
assert_eq!("Command { std: CARDANO_NODE_SOCKET_PATH=\"/tmp/whatever.sock\" \"cardano-cli\" \"query\" \"stake-distribution\" \"--testnet-magic\" \"10\", kill_on_drop: false }", format!("{:?}", runner.command_for_stake_distribution()));
assert_eq!("Command { std: CARDANO_NODE_SOCKET_PATH=\"/tmp/whatever.sock\" \"cardano-cli\" \"latest\" \"query\" \"tip\" \"--testnet-magic\" \"10\", kill_on_drop: false }", format!("{:?}", runner.command_for_epoch()));
assert_eq!("Command { std: CARDANO_NODE_SOCKET_PATH=\"/tmp/whatever.sock\" \"cardano-cli\" \"latest\" \"query\" \"stake-distribution\" \"--testnet-magic\" \"10\", kill_on_drop: false }", format!("{:?}", runner.command_for_stake_distribution()));
}

#[tokio::test]
Expand All @@ -568,8 +572,8 @@ mod tests {
CardanoNetwork::DevNet(25),
);

assert_eq!("Command { std: CARDANO_NODE_SOCKET_PATH=\"/tmp/whatever.sock\" \"cardano-cli\" \"query\" \"tip\" \"--cardano-mode\" \"--testnet-magic\" \"25\", kill_on_drop: false }", format!("{:?}", runner.command_for_epoch()));
assert_eq!("Command { std: CARDANO_NODE_SOCKET_PATH=\"/tmp/whatever.sock\" \"cardano-cli\" \"query\" \"stake-distribution\" \"--cardano-mode\" \"--testnet-magic\" \"25\", kill_on_drop: false }", format!("{:?}", runner.command_for_stake_distribution()));
assert_eq!("Command { std: CARDANO_NODE_SOCKET_PATH=\"/tmp/whatever.sock\" \"cardano-cli\" \"latest\" \"query\" \"tip\" \"--cardano-mode\" \"--testnet-magic\" \"25\", kill_on_drop: false }", format!("{:?}", runner.command_for_epoch()));
assert_eq!("Command { std: CARDANO_NODE_SOCKET_PATH=\"/tmp/whatever.sock\" \"cardano-cli\" \"latest\" \"query\" \"stake-distribution\" \"--cardano-mode\" \"--testnet-magic\" \"25\", kill_on_drop: false }", format!("{:?}", runner.command_for_stake_distribution()));
}

#[tokio::test]
Expand All @@ -581,11 +585,11 @@ mod tests {
);

assert_eq!(
"Command { std: CARDANO_NODE_SOCKET_PATH=\"/tmp/whatever.sock\" \"cardano-cli\" \"query\" \"tip\" \"--mainnet\", kill_on_drop: false }",
"Command { std: CARDANO_NODE_SOCKET_PATH=\"/tmp/whatever.sock\" \"cardano-cli\" \"latest\" \"query\" \"tip\" \"--mainnet\", kill_on_drop: false }",
format!("{:?}", runner.command_for_epoch())
);
assert_eq!(
"Command { std: CARDANO_NODE_SOCKET_PATH=\"/tmp/whatever.sock\" \"cardano-cli\" \"query\" \"stake-distribution\" \"--mainnet\", kill_on_drop: false }",
"Command { std: CARDANO_NODE_SOCKET_PATH=\"/tmp/whatever.sock\" \"cardano-cli\" \"latest\" \"query\" \"stake-distribution\" \"--mainnet\", kill_on_drop: false }",
format!("{:?}", runner.command_for_stake_distribution())
);
}
Expand Down
8 changes: 4 additions & 4 deletions mithril-test-lab/mithril-devnet/query-cardano.sh
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
#!/usr/bin/env bash

echo ">> Query chain tip"
CARDANO_NODE_SOCKET_PATH=node-pool1/ipc/node.sock ./cardano-cli query tip \
CARDANO_NODE_SOCKET_PATH=node-pool1/ipc/node.sock ./cardano-cli latest query tip \
--cardano-mode \
--testnet-magic 42 | jq .

echo
echo ">> Query whole utxo"
CARDANO_NODE_SOCKET_PATH=node-pool1/ipc/node.sock ./cardano-cli query utxo \
CARDANO_NODE_SOCKET_PATH=node-pool1/ipc/node.sock ./cardano-cli latest query utxo \
--cardano-mode \
--testnet-magic 42 \
--whole-utxo
echo

echo ">> Query stake pools"
CARDANO_NODE_SOCKET_PATH=node-pool1/ipc/node.sock ./cardano-cli query stake-pools \
CARDANO_NODE_SOCKET_PATH=node-pool1/ipc/node.sock ./cardano-cli latest query stake-pools \
--cardano-mode \
--testnet-magic 42
echo

echo ">> Query stake distribution"
CARDANO_NODE_SOCKET_PATH=node-pool1/ipc/node.sock ./cardano-cli query stake-snapshot --all-stake-pools \
CARDANO_NODE_SOCKET_PATH=node-pool1/ipc/node.sock ./cardano-cli latest query stake-snapshot --all-stake-pools \
--cardano-mode \
--testnet-magic 42 | jq .
echo
Expand Down