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

Add json output to test CLI command output #1164

Merged
merged 7 commits into from
Nov 14, 2024
Merged

Conversation

ameba23
Copy link
Contributor

@ameba23 ameba23 commented Nov 13, 2024

Closes #1163

This adds optional JSON output to the test CLI.

This is activated with the --json or -j command line argument. Note that it must be given before the subcommand like this: entropy-test-cli --json status and not entropy-test-cli status --json.

Currently not all available information is given, for example the status command gives you the hashes of stored programs and account ids of registered accounts, but not the additional metadata you will see in the non-json output, such as which programs are associated with which account, who stored a program, how many times a program was used, etc. These fields could easily be added so please say if they would be useful.

Generally binary data is represented as hex.

Example output:

$ entropy-test-cli --json status
{
  "accounts": [
    "029d00ff44b70613228963e45a05fe743ea92beb8ece19d48fb6c60d66386fe03b",
    "024609b84f24cdf494c356e48390927df1fbd16cf893d21c9774561b9805a006ae",
    "03cecec00e1c008a1c16c8cbb175b8de3eb10ff03fd79ed82a04e4caa3d21c159d",
    "02c1fd5c996e716f4ad6a3651861ce0efc4db3da88bbff7b84328ecb772f4eddaf",
    "0229e6718ed1d9a1568b4d087f66a00612133b4652b9c03ae9ba62c1ead33dd5d4",
    "03dd0713f53f162e4ce01b064db664682a270ac3a17bccc47ea670ac2a1037f306",
    "037363e1634cd106a78027fa4b160e6430c52ddef27d60828f2483c8e203f56e86",
    "035c0e76a179f5340303e9b219a983a494ad80d2b16d422bd34173ee0281f2a08c",
    "032fc02cb38a2dc5f5bee6fb68600aa9b05f4e18b1b196c1f31d1fde21c06d1e3d",
    "036f424bacf0252ddc470dd797cd511ca5bd5c37845f7a0bef60c8afaedf176fd4",
    "03cc90e7fbcace6b2945ba6718a7e04dc296f76a3788eab223f9e666360829f385",
    "03d53398bf3efa12edebc212959b3b2442612b74c0f0c45c209ec9a664731dc66f",
    "038ad84e7bfdea764737319123f60019365616c48b4c1ef5230fd05e22390c702c",
    "03aee03ad9862e9f31d06f7d1b4b388ad1c66152ad17f919fc16fcc75929b08db3"
  ],
  "programs": [
    "3289435006003c3c83da5582d779d810c343f177fb1fecddbaca5d326ef9d9b3",
    "3a1d45fecdee990925286ccce71f78693ff2bb27eae62adf8cfb7d3d61e142aa",
    "0000000000000000000000000000000000000000000000000000000000000000"
  ]
}

$ entropy-test-cli --json register ../testing-utils/template_barebones.wasm -m //Peg
"035c0e76a179f5340303e9b219a983a494ad80d2b16d422bd34173ee0281f2a08c"

$ entropy-test-cli --json sign "035c0e76a179f5340303e9b219a983a494ad80d2b16d422bd34173ee0281f2a08c" "this is a message"
{
  "signature": "46C2821E3FD730D0B0030CBD89C7AE9265A31B7863C207E6AC971B349D52D5C65FEF136F6D80E375769D47C07CA6F6C8EC0344C7B1B9591DCFF0EE14875D495B",
  "recovery_id": 1
}

For commands which finish successfully with no output, an empty JSON object is displayed: {}. Im not sure if it would be more appropriate to just give no ouput.

Errors

Errors are currently not displayed as JSON. If a command fails, the exit status will be 1, and the original error message will be displayed to standard error. If needed we could wrap this in { "error": "error message" }, but actually serializing the errors to JSON is probably going to be tricky as i imagine they will not all implement Serialize.

@ameba23 ameba23 changed the title Add json output Add json output to test CLI command output Nov 13, 2024
@ameba23
Copy link
Contributor Author

ameba23 commented Nov 13, 2024

Since this is a breaking change it is paired with a PR in programs to update the CLI for deploying programs, which has entropy-test-cli as a dependency. entropyxyz/programs#96

program_info.bytecode.len(),
!program_info.configuration_schema.is_empty(),
!program_info.auxiliary_data_schema.is_empty(),
"{:<64} {:<48} {:<11} {:<14} {} {}",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unrelated to this PR but needed tidying

@@ -186,15 +191,22 @@ enum CliCommand {
},
}

impl Cli {
fn log(&self, text: String) {
Copy link
Member

Choose a reason for hiding this comment

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

curious why this was needed and not just a println macro?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah its a wierd way of doing it. just so it only logs when the json option is false, to prevent the log lines being parsed as json.

@cooldracula
Copy link
Contributor

This looks good to me, thank you!

@ameba23 ameba23 merged commit 9e76bc6 into master Nov 14, 2024
8 checks passed
@ameba23 ameba23 deleted the peg/test-cli-json-output branch November 14, 2024 07:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Add JSON output to select entropy-test-cli commands
3 participants