From cd64efff5262bb7fa8fe1addefb080e6c5fa4609 Mon Sep 17 00:00:00 2001 From: Murisi Tarusenga Date: Mon, 11 Sep 2023 15:04:36 +0200 Subject: [PATCH 1/2] Test vector formatting changes. --- scripts/generator.sh | 318 +++++++++++---------------- shared/src/sdk/signing.rs | 452 ++++++++++++++++++++++++++------------ shared/src/sdk/tx.rs | 11 +- 3 files changed, 437 insertions(+), 344 deletions(-) diff --git a/scripts/generator.sh b/scripts/generator.sh index 3fe1792a49..c9635d498d 100755 --- a/scripts/generator.sh +++ b/scripts/generator.sh @@ -9,8 +9,10 @@ # vectors. NAMADA_DIR="$(pwd)" +NAMADA_BASE_DIR_FILE="$(pwd)/namada_base_dir" export NAMADA_LEDGER_LOG_PATH="$(pwd)/vectors.json" export NAMADA_TX_LOG_PATH="$(pwd)/debugs.txt" +export NAMADA_DEV=false if [ "$#" -ne 1 ]; then echo "Illegal number of parameters" @@ -19,11 +21,14 @@ elif [ "$1" = "server" ]; then sed -i 's/^epochs_per_year = 31_536_000$/epochs_per_year = 262_800/' genesis/test-vectors-single-node.toml - NAMADA_GENESIS_FILE=$(cargo run --bin namadac -- utils init-network --genesis-path genesis/test-vectors-single-node.toml --wasm-checksums-path wasm/checksums.json --chain-prefix e2e-test --unsafe-dont-encrypt --localhost --allow-duplicate-ip | grep 'Genesis file generated at ' | sed 's/^Genesis file generated at //') + NAMADA_GENESIS_FILE=$(cargo run --bin namadac --package namada_apps --manifest-path Cargo.toml -- utils init-network --genesis-path genesis/test-vectors-single-node.toml --wasm-checksums-path wasm/checksums.json --chain-prefix e2e-test --unsafe-dont-encrypt --localhost --dont-archive --allow-duplicate-ip | grep 'Genesis file generated at ' | sed 's/^Genesis file generated at //') rm genesis/test-vectors-single-node.toml NAMADA_BASE_DIR=${NAMADA_GENESIS_FILE%.toml} + echo $NAMADA_BASE_DIR > $NAMADA_BASE_DIR_FILE + + sed -i 's/^mode = "RemoteEndpoint"$/mode = "Off"/' $NAMADA_BASE_DIR/config.toml cp wasm/*.wasm $NAMADA_BASE_DIR/wasm/ @@ -31,8 +36,14 @@ elif [ "$1" = "server" ]; then cp $NAMADA_BASE_DIR/setup/other/wallet.toml $NAMADA_BASE_DIR/wallet.toml - cargo run --bin namadan -- --base-dir $NAMADA_BASE_DIR/setup/validator-0/.namada/ ledger + sed -i 's/^mode = "RemoteEndpoint"$/mode = "Off"/' $NAMADA_BASE_DIR/setup/validator-0/.namada/$(basename $NAMADA_BASE_DIR)/config.toml + + cargo run --bin namadan --package namada_apps --manifest-path Cargo.toml -- --base-dir $NAMADA_BASE_DIR/setup/validator-0/.namada/ ledger elif [ "$1" = "client" ]; then + if test -f "$NAMADA_BASE_DIR_FILE"; then + NAMADA_BASE_DIR="$(cat $NAMADA_BASE_DIR_FILE)" + fi + echo > $NAMADA_TX_LOG_PATH echo $'[' > $NAMADA_LEDGER_LOG_PATH @@ -40,120 +51,49 @@ elif [ "$1" = "client" ]; then ALBERT_ADDRESS=$(cargo run --bin namadaw -- address find --alias albert | sed 's/^Found address Established: //') echo '{ - "author":"'$ALBERT_ADDRESS'", - "content":{ - "abstract":"Ut convallis eleifend orci vel venenatis. Duis vulputate metus in lacus sollicitudin vestibulum. Suspendisse vel velit ac est consectetur feugiat nec ac urna. Ut faucibus ex nec dictum fermentum. Morbi aliquet purus at sollicitudin ultrices. Quisque viverra varius cursus. Praesent sed mauris gravida, pharetra turpis non, gravida eros. Nullam sed ex justo. Ut at placerat ipsum, sit amet rhoncus libero. Sed blandit non purus non suscipit. Phasellus sed quam nec augue bibendum bibendum ut vitae urna. Sed odio diam, ornare nec sapien eget, congue viverra enim.", - "authors":"test@test.com", - "created":"2022-03-10T08:54:37Z", - "details":"Ut convallis eleifend orci vel venenatis. Duis vulputate metus in lacus sollicitudin vestibulum. Suspendisse vel velit ac est consectetur feugiat nec ac urna. Ut faucibus ex nec dictum fermentum. Morbi aliquet purus at sollicitudin ultrices. Quisque viverra varius cursus. Praesent sed mauris gravida, pharetra turpis non, gravida eros.", - "discussions-to":"www.github.com/anoma/aip/1", - "license":"MIT", - "motivation":"Ut convallis eleifend orci vel venenatis. Duis vulputate metus in lacus sollicitudin vestibulum. Suspendisse vel velit ac est consectetur feugiat nec ac urna. Ut faucibus ex nec dictum fermentum. Morbi aliquet purus at sollicitudin ultrices.", - "requires":"2", - "title":"TheTitle" - }, - "grace_epoch":30, - "type":{ - "Default":"'$NAMADA_DIR'/wasm_for_tests/tx_proposal_code.wasm" - }, - "voting_end_epoch":24, - "voting_start_epoch":12 -} -' > proposal_submission_valid_proposal.json - + "proposal": { + "author":"'$ALBERT_ADDRESS'", + "content":{ + "abstract":"Ut convallis eleifend orci vel venenatis. Duis vulputate metus in lacus sollicitudin vestibulum. Suspendisse vel velit ac est consectetur feugiat nec ac urna. Ut faucibus ex nec dictum fermentum. Morbi aliquet purus at sollicitudin ultrices. Quisque viverra varius cursus. Praesent sed mauris gravida, pharetra turpis non, gravida eros. Nullam sed ex justo. Ut at placerat ipsum, sit amet rhoncus libero. Sed blandit non purus non suscipit. Phasellus sed quam nec augue bibendum bibendum ut vitae urna. Sed odio diam, ornare nec sapien eget, congue viverra enim.", + "authors":"test@test.com", + "created":"2022-03-10T08:54:37Z", + "details":"Ut convallis eleifend orci vel venenatis. Duis vulputate metus in lacus sollicitudin vestibulum. Suspendisse vel velit ac est consectetur feugiat nec ac urna. Ut faucibus ex nec dictum fermentum. Morbi aliquet purus at sollicitudin ultrices. Quisque viverra varius cursus. Praesent sed mauris gravida, pharetra turpis non, gravida eros.", + "discussions-to":"www.github.com/anoma/aip/1", + "license":"MIT", + "motivation":"Ut convallis eleifend orci vel venenatis. Duis vulputate metus in lacus sollicitudin vestibulum. Suspendisse vel velit ac est consectetur feugiat nec ac urna. Ut faucibus ex nec dictum fermentum. Morbi aliquet purus at sollicitudin ultrices.", + "requires":"2", + "title":"TheTitle" + }, + "grace_epoch":30, + "voting_end_epoch":24, + "voting_start_epoch":12 + } + }' > proposal_default.json + echo '{ - "content": { - "abstract": "Ut convallis eleifend orci vel venenatis. Duis vulputate metus in lacus sollicitudin vestibulum. Suspendisse vel velit ac est consectetur feugiat nec ac urna. Ut faucibus ex nec dictum fermentum. Morbi aliquet purus at sollicitudin ultrices. Quisque viverra varius cursus. Praesent sed mauris gravida, pharetra turpis non, gravida eros. Nullam sed ex justo. Ut at placerat ipsum, sit amet rhoncus libero. Sed blandit non purus non suscipit. Phasellus sed quam nec augue bibendum bibendum ut vitae urna. Sed odio diam, ornare nec sapien eget, congue viverra enim.", - "authors": "test@test.com", - "created": "2022-03-10T08:54:37Z", - "details": "Ut convallis eleifend orci vel venenatis. Duis vulputate metus in lacus sollicitudin vestibulum. Suspendisse vel velit ac est consectetur feugiat nec ac urna. Ut faucibus ex nec dictum fermentum. Morbi aliquet purus at sollicitudin ultrices. Quisque viverra varius cursus. Praesent sed mauris gravida, pharetra turpis non, gravida eros.", - "discussions-to": "www.github.com/anoma/aip/1", - "license": "MIT", - "motivation": "Ut convallis eleifend orci vel venenatis. Duis vulputate metus in lacus sollicitudin vestibulum. Suspendisse vel velit ac est consectetur feugiat nec ac urna. Ut faucibus ex nec dictum fermentum. Morbi aliquet purus at sollicitudin ultrices.", - "requires": "2", - "title": "TheTitle" - }, - "author": "'$ALBERT_ADDRESS'", - "tally_epoch": 18, - "signature": { - "Ed25519": { - "R_bytes": [ - 113, - 196, - 231, - 134, - 101, - 191, - 75, - 17, - 245, - 19, - 50, - 231, - 183, - 80, - 162, - 38, - 108, - 72, - 72, - 2, - 116, - 112, - 121, - 33, - 197, - 67, - 64, - 116, - 21, - 250, - 196, - 121 - ], - "s_bytes": [ - 87, - 163, - 134, - 87, - 42, - 156, - 121, - 211, - 189, - 19, - 255, - 5, - 23, - 178, - 143, - 39, - 118, - 249, - 37, - 53, - 121, - 136, - 59, - 103, - 190, - 91, - 121, - 95, - 46, - 54, - 168, - 9 - ] + "data":['$(od -An -tu1 -v wasm_for_tests/tx_proposal_code.wasm | tr '\n' ' ' | sed 's/\b\s\+\b/,/g')'], + "proposal": { + "author":"'$ALBERT_ADDRESS'", + "content":{ + "abstract":"Ut convallis eleifend orci vel venenatis. Duis vulputate metus in lacus sollicitudin vestibulum. Suspendisse vel velit ac est consectetur feugiat nec ac urna. Ut faucibus ex nec dictum fermentum. Morbi aliquet purus at sollicitudin ultrices. Quisque viverra varius cursus. Praesent sed mauris gravida, pharetra turpis non, gravida eros. Nullam sed ex justo. Ut at placerat ipsum, sit amet rhoncus libero. Sed blandit non purus non suscipit. Phasellus sed quam nec augue bibendum bibendum ut vitae urna. Sed odio diam, ornare nec sapien eget, congue viverra enim.", + "authors":"test@test.com", + "created":"2022-03-10T08:54:37Z", + "details":"Ut convallis eleifend orci vel venenatis. Duis vulputate metus in lacus sollicitudin vestibulum. Suspendisse vel velit ac est consectetur feugiat nec ac urna. Ut faucibus ex nec dictum fermentum. Morbi aliquet purus at sollicitudin ultrices. Quisque viverra varius cursus. Praesent sed mauris gravida, pharetra turpis non, gravida eros.", + "discussions-to":"www.github.com/anoma/aip/1", + "license":"MIT", + "motivation":"Ut convallis eleifend orci vel venenatis. Duis vulputate metus in lacus sollicitudin vestibulum. Suspendisse vel velit ac est consectetur feugiat nec ac urna. Ut faucibus ex nec dictum fermentum. Morbi aliquet purus at sollicitudin ultrices.", + "requires":"2", + "title":"TheTitle" + }, + "grace_epoch":30, + "voting_end_epoch":24, + "voting_start_epoch":12 } - }, - "address": "'$ALBERT_ADDRESS'" -} -' > proposal_offline_proposal + }' > proposal_default_with_data.json echo '{ - "author":"'$ALBERT_ADDRESS'", - "content":{ + "author":"'$ALBERT_ADDRESS'", + "content":{ "abstract":"Ut convallis eleifend orci vel venenatis. Duis vulputate metus in lacus sollicitudin vestibulum. Suspendisse vel velit ac est consectetur feugiat nec ac urna. Ut faucibus ex nec dictum fermentum. Morbi aliquet purus at sollicitudin ultrices. Quisque viverra varius cursus. Praesent sed mauris gravida, pharetra turpis non, gravida eros. Nullam sed ex justo. Ut at placerat ipsum, sit amet rhoncus libero. Sed blandit non purus non suscipit. Phasellus sed quam nec augue bibendum bibendum ut vitae urna. Sed odio diam, ornare nec sapien eget, congue viverra enim.", "authors":"test@test.com", "created":"2022-03-10T08:54:37Z", @@ -164,59 +104,41 @@ elif [ "$1" = "client" ]; then "requires":"2", "title":"TheTitle" }, - "grace_epoch":18, - "type":{ - "Default":null - }, - "voting_end_epoch":9, - "voting_start_epoch":3 -}' > proposal_offline_valid_proposal.json + "tally_epoch":1 + }' > proposal_offline.json echo '{ - "author":"'$ALBERT_ADDRESS'", - "content":{ - "abstract":"Ut convallis eleifend orci vel venenatis. Duis vulputate metus in lacus sollicitudin vestibulum. Suspendisse vel velit ac est consectetur feugiat nec ac urna. Ut faucibus ex nec dictum fermentum. Morbi aliquet purus at sollicitudin ultrices. Quisque viverra varius cursus. Praesent sed mauris gravida, pharetra turpis non, gravida eros. Nullam sed ex justo. Ut at placerat ipsum, sit amet rhoncus libero. Sed blandit non purus non suscipit. Phasellus sed quam nec augue bibendum bibendum ut vitae urna. Sed odio diam, ornare nec sapien eget, congue viverra enim.", - "authors":"test@test.com", - "created":"2022-03-10T08:54:37Z", - "details":"Ut convallis eleifend orci vel venenatis. Duis vulputate metus in lacus sollicitudin vestibulum. Suspendisse vel velit ac est consectetur feugiat nec ac urna. Ut faucibus ex nec dictum fermentum. Morbi aliquet purus at sollicitudin ultrices. Quisque viverra varius cursus. Praesent sed mauris gravida, pharetra turpis non, gravida eros.", - "discussions-to":"www.github.com/anoma/aip/1", - "license":"MIT", - "motivation":"Ut convallis eleifend orci vel venenatis. Duis vulputate metus in lacus sollicitudin vestibulum. Suspendisse vel velit ac est consectetur feugiat nec ac urna. Ut faucibus ex nec dictum fermentum. Morbi aliquet purus at sollicitudin ultrices.", - "requires":"2", - "title":"TheTitle" + "proposal": { + "author":"'$ALBERT_ADDRESS'", + "content":{ + "abstract":"Ut convallis eleifend orci vel venenatis. Duis vulputate metus in lacus sollicitudin vestibulum. Suspendisse vel velit ac est consectetur feugiat nec ac urna. Ut faucibus ex nec dictum fermentum. Morbi aliquet purus at sollicitudin ultrices. Quisque viverra varius cursus. Praesent sed mauris gravida, pharetra turpis non, gravida eros. Nullam sed ex justo. Ut at placerat ipsum, sit amet rhoncus libero. Sed blandit non purus non suscipit. Phasellus sed quam nec augue bibendum bibendum ut vitae urna. Sed odio diam, ornare nec sapien eget, congue viverra enim.", + "authors":"test@test.com", + "created":"2022-03-10T08:54:37Z", + "details":"Ut convallis eleifend orci vel venenatis. Duis vulputate metus in lacus sollicitudin vestibulum. Suspendisse vel velit ac est consectetur feugiat nec ac urna. Ut faucibus ex nec dictum fermentum. Morbi aliquet purus at sollicitudin ultrices. Quisque viverra varius cursus. Praesent sed mauris gravida, pharetra turpis non, gravida eros.", + "discussions-to":"www.github.com/anoma/aip/1", + "license":"MIT", + "motivation":"Ut convallis eleifend orci vel venenatis. Duis vulputate metus in lacus sollicitudin vestibulum. Suspendisse vel velit ac est consectetur feugiat nec ac urna. Ut faucibus ex nec dictum fermentum. Morbi aliquet purus at sollicitudin ultrices.", + "requires":"2", + "title":"TheTitle" + }, + "grace_epoch":30, + "voting_end_epoch":24, + "voting_start_epoch":12 }, - "grace_epoch":30, - "type":"ETHBridge", - "voting_end_epoch":24, - "voting_start_epoch":12 -}' > eth_governance_proposal_valid_proposal.json + "data": {"add":"'$ALBERT_ADDRESS'","remove":[]} + }' > proposal_pgf_steward_add.json - echo '{ - "author":"'$ALBERT_ADDRESS'", - "content":{ - "abstract":"Ut convallis eleifend orci vel venenatis. Duis vulputate metus in lacus sollicitudin vestibulum. Suspendisse vel velit ac est consectetur feugiat nec ac urna. Ut faucibus ex nec dictum fermentum. Morbi aliquet purus at sollicitudin ultrices. Quisque viverra varius cursus. Praesent sed mauris gravida, pharetra turpis non, gravida eros. Nullam sed ex justo. Ut at placerat ipsum, sit amet rhoncus libero. Sed blandit non purus non suscipit. Phasellus sed quam nec augue bibendum bibendum ut vitae urna. Sed odio diam, ornare nec sapien eget, congue viverra enim.", - "authors":"test@test.com", - "created":"2022-03-10T08:54:37Z", - "details":"Ut convallis eleifend orci vel venenatis. Duis vulputate metus in lacus sollicitudin vestibulum. Suspendisse vel velit ac est consectetur feugiat nec ac urna. Ut faucibus ex nec dictum fermentum. Morbi aliquet purus at sollicitudin ultrices. Quisque viverra varius cursus. Praesent sed mauris gravida, pharetra turpis non, gravida eros.", - "discussions-to":"www.github.com/anoma/aip/1", - "license":"MIT", - "motivation":"Ut convallis eleifend orci vel venenatis. Duis vulputate metus in lacus sollicitudin vestibulum. Suspendisse vel velit ac est consectetur feugiat nec ac urna. Ut faucibus ex nec dictum fermentum. Morbi aliquet purus at sollicitudin ultrices.", - "requires":"2", - "title":"TheTitle" - }, - "grace_epoch":30, - "type":"PGFCouncil", - "voting_end_epoch":24, - "voting_start_epoch":12 -}' > pgf_governance_proposal_valid_proposal.json + # proposal_default - # proposal_submission + cargo run --bin namadac --features std -- bond --validator validator-0 --source Bertha --amount 900 --gas-token NAM --node 127.0.0.1:27657 - cargo run --bin namadac --features std -- bond --validator validator-0 --source Bertha --amount 900 --gas-amount 0 --gas-limit 0 --gas-token NAM --node 127.0.0.1:27657 + cargo run --bin namadac --features std -- unjail-validator --validator Bertha --gas-token NAM --force --node 127.0.0.1:27657 - cargo run --bin namadac --features std -- change-commission-rate --validator Bertha --commission-rate 0.02 --gas-amount 0 --gas-limit 0 --gas-token NAM --force --node 127.0.0.1:27657 + cargo run --bin namadac --features std -- change-commission-rate --validator Bertha --commission-rate 0.02 --gas-token NAM --force --node 127.0.0.1:27657 - PROPOSAL_ID_0=$(cargo run --bin namadac --features std -- init-proposal --force --data-path proposal_submission_valid_proposal.json --node 127.0.0.1:27657 | grep -o -P '(?<=/proposal/).*(?=/author)') + PROPOSAL_ID_0=$(cargo run --bin namadac --features std -- init-proposal --force --data-path proposal_default.json --node 127.0.0.1:27657 | grep -o -P '(?<=/proposal/).*(?=/author)') + + cargo run --bin namadac --features std -- init-proposal --force --data-path proposal_default_with_data.json --node 127.0.0.1:27657 cargo run --bin namadac --features std -- --base-dir $NAMADA_BASE_DIR/setup/validator-0/.namada vote-proposal --force --proposal-id $PROPOSAL_ID_0 --vote yay --address validator-0 --node 127.0.0.1:27657 @@ -226,41 +148,29 @@ elif [ "$1" = "client" ]; then # proposal_offline - cargo run --bin namadac --features std -- bond --validator validator-0 --source Albert --amount 900 --gas-amount 0 --gas-limit 0 --gas-token NAM --node 127.0.0.1:27657 - - cargo run --bin namadac --features std -- change-commission-rate --validator Albert --commission-rate 0.05 --gas-amount 0 --gas-limit 0 --gas-token NAM --force --node 127.0.0.1:27657 - - cargo run --bin namadac --features std -- init-proposal --force --data-path proposal_offline_valid_proposal.json --offline --node 127.0.0.1:27657 + cargo run --bin namadac --features std -- bond --validator validator-0 --source Albert --amount 900 --gas-token NAM --node 127.0.0.1:27657 - cargo run --bin namadac --features std -- vote-proposal --data-path proposal_offline_proposal --vote yay --address Albert --offline --node 127.0.0.1:27657 + cargo run --bin namadac --features std -- change-commission-rate --validator Albert --commission-rate 0.05 --gas-token NAM --force --node 127.0.0.1:27657 - # eth_governance_proposal + PROPOSAL_OFFLINE_SIGNED=$(cargo run --bin namadac --features std -- init-proposal --force --data-path proposal_offline.json --signing-keys albert-key --offline --node 127.0.0.1:27657 | grep -o -P '(?<=Proposal serialized to:\s).*') - cargo run --bin namadac --features std -- bond --validator validator-0 --source Bertha --amount 900 --gas-amount 0 --gas-limit 0 --gas-token NAM --ledger-address 127.0.0.1:27657 - - cargo run --bin namadac --features std -- change-commission-rate --validator Bertha --commission-rate 0.07 --gas-amount 0 --gas-limit 0 --gas-token NAM --force --node 127.0.0.1:27657 - - PROPOSAL_ID_0=$(cargo run --bin namadac --features std -- init-proposal --force --data-path eth_governance_proposal_valid_proposal.json --ledger-address 127.0.0.1:27657 | grep -o -P '(?<=/proposal/).*(?=/author)') - - cargo run --bin namadac --features std -- vote-proposal --force --proposal-id 0 --vote yay --eth '011586062748ba53bc53155e817ec1ea708de75878dcb9a5713bf6986d87fe14e7 fd34672ab5' --address Bertha --ledger-address 127.0.0.1:27657 - - cargo run --bin namadac --features std -- --base-dir $NAMADA_BASE_DIR/setup/validator-0/.namada vote-proposal --force --proposal-id $PROPOSAL_ID_0 --vote yay --eth '011586062748ba53bc53155e817ec1ea708de75878dcb9a5713bf6986d87fe14e7 fd34672ab5' --address validator-0 --ledger-address 127.0.0.1:27657 + cargo run --bin namadac --features std -- vote-proposal --data-path $PROPOSAL_OFFLINE_SIGNED --vote yay --address Albert --offline --node 127.0.0.1:27657 # pgf_governance_proposal - cargo run --bin namadac --features std -- bond --validator validator-0 --source Bertha --amount 900 --gas-amount 0 --gas-limit 0 --gas-token NAM --ledger-address 127.0.0.1:27657 + cargo run --bin namadac --features std -- bond --validator validator-0 --source Bertha --amount 900 --gas-token NAM --ledger-address 127.0.0.1:27657 - cargo run --bin namadac --features std -- change-commission-rate --validator Bertha --commission-rate 0.09 --gas-amount 0 --gas-limit 0 --gas-token NAM --force --node 127.0.0.1:27657 + cargo run --bin namadac --features std -- change-commission-rate --validator Bertha --commission-rate 0.09 --gas-token NAM --force --node 127.0.0.1:27657 - PROPOSAL_ID_0=$(cargo run --bin namadac --features std -- init-proposal --force --data-path pgf_governance_proposal_valid_proposal.json --ledger-address 127.0.0.1:27657 | grep -o -P '(?<=/proposal/).*(?=/author)') + PROPOSAL_ID_0=$(cargo run --bin namadac --features std -- init-proposal --pgf-stewards --force --data-path proposal_pgf_steward_add.json --ledger-address 127.0.0.1:27657 | grep -o -P '(?<=/proposal/).*(?=/author)') - PROPOSAL_ID_1=$(cargo run --bin namadac --features std -- init-proposal --force --data-path pgf_governance_proposal_valid_proposal.json --ledger-address 127.0.0.1:27657 | grep -o -P '(?<=/proposal/).*(?=/author)') + PROPOSAL_ID_1=$(cargo run --bin namadac --features std -- init-proposal --pgf-stewards --force --data-path proposal_pgf_steward_add.json --ledger-address 127.0.0.1:27657 | grep -o -P '(?<=/proposal/).*(?=/author)') - cargo run --bin namadac --features std -- --base-dir $NAMADA_BASE_DIR/setup/validator-0/.namada vote-proposal --force --proposal-id $PROPOSAL_ID_0 --vote yay --pgf "$ALBERT_ADDRESS 1000" --address validator-0 --ledger-address 127.0.0.1:27657 + cargo run --bin namadac --features std -- --base-dir $NAMADA_BASE_DIR/setup/validator-0/.namada vote-proposal --force --proposal-id $PROPOSAL_ID_0 --vote yay --address validator-0 --ledger-address 127.0.0.1:27657 - cargo run --bin namadac --features std -- vote-proposal --force --proposal-id $PROPOSAL_ID_0 --vote yay --pgf "$ALBERT_ADDRESS 900" --address Bertha --ledger-address 127.0.0.1:27657 + cargo run --bin namadac --features std -- vote-proposal --force --proposal-id $PROPOSAL_ID_0 --vote yay --address Bertha --signing-keys bertha-key --ledger-address 127.0.0.1:27657 - cargo run --bin namadac --features std -- vote-proposal --force --proposal-id $PROPOSAL_ID_1 --vote yay --pgf "$ALBERT_ADDRESS 900" --address Bertha --ledger-address 127.0.0.1:27657 + cargo run --bin namadac --features std -- vote-proposal --force --proposal-id $PROPOSAL_ID_1 --vote yay --address Bertha --signing-keys bertha-key --ledger-address 127.0.0.1:27657 # non-proposal tests @@ -268,24 +178,38 @@ elif [ "$1" = "client" ]; then cargo run --bin namadac --features std -- bond --validator bertha --amount 25 --signing-keys bertha-key --force --ledger-address 127.0.0.1:27657 - cargo run --bin namadac --features std -- change-commission-rate --validator Bertha --commission-rate 0.11 --gas-amount 0 --gas-limit 0 --gas-token NAM --force --node 127.0.0.1:27657 + cargo run --bin namadac --features std -- change-commission-rate --validator Bertha --commission-rate 0.11 --gas-token NAM --force --node 127.0.0.1:27657 cargo run --bin namadac --features std -- reveal-pk --public-key albert-key --gas-payer albert-key --force --ledger-address 127.0.0.1:27657 cargo run --bin namadac --features std -- update-account --code-path vp_user.wasm --address bertha --signing-keys bertha-key --force --ledger-address 127.0.0.1:27657 - cargo run --bin namadac --features std -- init-validator --alias bertha-validator --account-keys bertha --commission-rate 0.05 --max-commission-rate-change 0.01 --signing-keys bertha-key --unsafe-dont-encrypt --force --ledger-address 127.0.0.1:27657 + cargo run --bin namadac --features std -- update-account --code-path vp_user.wasm --address bertha --public-keys albert-key,bertha-key --force --ledger-address 127.0.0.1:27657 + + cargo run --bin namadac --features std -- update-account --code-path vp_user.wasm --address bertha --public-keys albert-key,bertha-key,christel-key --threshold 2 --force --ledger-address 127.0.0.1:27657 + + cargo run --bin namadac --features std -- init-validator --alias bertha-validator --account-keys bertha-key --commission-rate 0.05 --max-commission-rate-change 0.01 --signing-keys bertha-key --unsafe-dont-encrypt --force --ledger-address 127.0.0.1:27657 + + cargo run --bin namadac --features std -- init-validator --alias validator-mult --account-keys albert-key,bertha-key --commission-rate 0.05 --max-commission-rate-change 0.01 --signing-keys albert-key,bertha-key --threshold 2 --unsafe-dont-encrypt --force --ledger-address 127.0.0.1:27657 + # TODO works but panics cargo run --bin namadac --features std -- unbond --validator christel --amount 5 --signing-keys christel-key --force --ledger-address 127.0.0.1:27657 cargo run --bin namadac --features std -- withdraw --validator albert --signing-keys albert-key --force --ledger-address 127.0.0.1:27657 cargo run --bin namadac --features std -- init-account --alias albert-account --public-keys albert-key --signing-keys albert-key --force --ledger-address 127.0.0.1:27657 - cargo run --bin namadac --features std -- tx --code-path $NAMADA_DIR/wasm_for_tests/tx_no_op.wasm --data-path README.md --signing-keys albert-key --owner albert --force --ledger-address 127.0.0.1:27657 + cargo run --bin namadac --features std -- init-account --alias account-mul --public-keys albert-key,bertha-key,christel-key --signing-keys albert-key,bertha-key,christel-key --threshold 2 --force --ledger-address 127.0.0.1:27657 + + # TODO panics, no vector produced + # cargo run --bin namadac --features std -- tx --code-path $NAMADA_DIR/wasm_for_tests/tx_no_op.wasm --data-path README.md --signing-keys albert-key --owner albert --force --ledger-address 127.0.0.1:27657 cargo run --bin namadac --features std -- ibc-transfer --source bertha --receiver christel --token btc --amount 24 --channel-id channel-141 --signing-keys bertha-key --force --ledger-address 127.0.0.1:27657 + cargo run --bin namadac --features std -- ibc-transfer --source albert --receiver bertha --token nam --amount 100000 --channel-id channel-0 --port-id transfer --signing-keys albert-key --force --ledger-address 127.0.0.1:27657 + + cargo run --bin namadac --features std -- ibc-transfer --source albert --receiver bertha --token nam --amount 100000 --channel-id channel-0 --port-id transfer --signing-keys albert-key --timeout-sec-offset 5 --force --ledger-address 127.0.0.1:27657 + cargo run --bin namadaw -- masp add --alias a_spending_key --value xsktest1qqqqqqqqqqqqqq9v0sls5r5de7njx8ehu49pqgmqr9ygelg87l5x8y4s9r0pjlvu69au6gn3su5ewneas486hdccyayx32hxvt64p3d0hfuprpgcgv2q9gdx3jvxrn02f0nnp3jtdd6f5vwscfuyum083cvfv4jun75ak5sdgrm2pthzj3sflxc0jx0edrakx3vdcngrfjmru8ywkguru8mxss2uuqxdlglaz6undx5h8w7g70t2es850g48xzdkqay5qs0yw06rtxcvedhsv --unsafe-dont-encrypt cargo run --bin namadaw -- masp add --alias b_spending_key --value xsktest1qqqqqqqqqqqqqqpagte43rsza46v55dlz8cffahv0fnr6eqacvnrkyuf9lmndgal7c2k4r7f7zu2yr5rjwr374unjjeuzrh6mquzy6grfdcnnu5clzaq2llqhr70a8yyx0p62aajqvrqjxrht3myuyypsvm725uyt5vm0fqzrzuuedtf6fala4r4nnazm9y9hq5yu6pq24arjskmpv4mdgfn3spffxxv8ugvym36kmnj45jcvvmm227vqjm5fq8882yhjsq97p7xrwqqd82s0 --unsafe-dont-encrypt @@ -296,27 +220,31 @@ elif [ "$1" = "client" ]; then cargo run --bin namadaw -- masp add --alias bb_payment_address --value patest1vqe0vyxh6wmhahwa52gthgd6edgqxfmgyv8e94jtwn55mdvpvylcyqnp59595272qrz3zxn0ysg + # TODO vector produced only when epoch boundaries not straddled cargo run --bin namadac --features std -- transfer --source albert --target aa_payment_address --token btc --amount 20 --force --ledger-address 127.0.0.1:27657 - cargo run --bin namadac --features std -- transfer --source a_spending_key --target ab_payment_address --token btc --amount 7 --force --ledger-address 127.0.0.1:27657 + # TODO vector produced only when epoch boundaries not straddled + cargo run --bin namadac --features std -- transfer --gas-payer albert-key --source a_spending_key --target ab_payment_address --token btc --amount 7 --force --ledger-address 127.0.0.1:27657 - until cargo run --bin namadac -- epoch --ledger-address 127.0.0.1:27657 | grep -m1 "Last committed epoch: 2" ; do sleep 10 ; done; + # TODO fragile + until cargo run --bin namadac -- epoch --ledger-address 127.0.0.1:27657 | grep -m1 "Last committed epoch: 2" ; do sleep 10 ; done; - cargo run --bin namadac --features std -- transfer --source a_spending_key --target bb_payment_address --token btc --amount 7 --force --ledger-address 127.0.0.1:27657 + # TODO vector produced only when epoch boundaries not straddled + cargo run --bin namadac --features std -- transfer --gas-payer albert-key --source a_spending_key --target bb_payment_address --token btc --amount 7 --force --ledger-address 127.0.0.1:27657 - cargo run --bin namadac --features std -- transfer --source a_spending_key --target bb_payment_address --token btc --amount 6 --force --ledger-address 127.0.0.1:27657 + # TODO vector produced only when epoch boundaries not straddled + cargo run --bin namadac --features std -- transfer --gas-payer albert-key --source a_spending_key --target bb_payment_address --token btc --amount 6 --force --ledger-address 127.0.0.1:27657 - cargo run --bin namadac --features std -- transfer --source b_spending_key --target bb_payment_address --token btc --amount 6 --force --ledger-address 127.0.0.1:27657 + # TODO vector produced only when epoch boundaries not straddled + cargo run --bin namadac --features std -- transfer --gas-payer albert-key --source b_spending_key --target bb_payment_address --token btc --amount 6 --force --ledger-address 127.0.0.1:27657 - rm proposal_submission_valid_proposal.json - - rm proposal_offline_proposal - - rm proposal_offline_valid_proposal.json + rm -f proposal_default.json + + rm -f proposal_default_with_data.json - rm eth_governance_proposal_valid_proposal.json + rm -f proposal_offline.json - rm pgf_governance_proposal_valid_proposal.json + rm -f proposal_pgf_steward_add.json perl -0777 -i.original -pe 's/,\s*$//igs' $NAMADA_LEDGER_LOG_PATH diff --git a/shared/src/sdk/signing.rs b/shared/src/sdk/signing.rs index 042be03a63..a4e984077b 100644 --- a/shared/src/sdk/signing.rs +++ b/shared/src/sdk/signing.rs @@ -1,5 +1,6 @@ //! Functions to sign transactions use std::collections::{BTreeMap, HashMap}; +use std::fmt::Display; use std::path::PathBuf; use borsh::{BorshDeserialize, BorshSerialize}; @@ -23,6 +24,10 @@ use serde::{Deserialize, Serialize}; use sha2::Digest; use zeroize::Zeroizing; +use crate::core::ledger::governance::storage::proposal::ProposalType; +use crate::core::ledger::governance::storage::vote::{ + StorageProposalVote, VoteType, +}; use crate::display_line; use crate::ibc::applications::transfer::msgs::transfer::MsgTransfer; use crate::ibc_proto::google::protobuf::Any; @@ -38,8 +43,8 @@ use crate::sdk::rpc::{ use crate::sdk::tx::{ TX_BOND_WASM, TX_CHANGE_COMMISSION_WASM, TX_IBC_WASM, TX_INIT_ACCOUNT_WASM, TX_INIT_PROPOSAL, TX_INIT_VALIDATOR_WASM, TX_REVEAL_PK, TX_TRANSFER_WASM, - TX_UNBOND_WASM, TX_UPDATE_ACCOUNT_WASM, TX_VOTE_PROPOSAL, TX_WITHDRAW_WASM, - VP_USER_WASM, + TX_UNBOND_WASM, TX_UNJAIL_VALIDATOR_WASM, TX_UPDATE_ACCOUNT_WASM, + TX_VOTE_PROPOSAL, TX_WITHDRAW_WASM, VP_USER_WASM, }; pub use crate::sdk::wallet::store::AddressVpType; use crate::sdk::wallet::{Wallet, WalletUtils}; @@ -603,11 +608,20 @@ fn make_ledger_amount_addr( prefix: &str, ) { if let Some(token) = tokens.get(token) { - output.push(format!("{}Amount {}: {}", prefix, token, amount)); + output.push(format!( + "{}Amount : {} {}", + prefix, + token.to_uppercase(), + to_ledger_decimal(&amount.to_string()), + )); } else { output.extend(vec![ - format!("{}Token: {}", prefix, token), - format!("{}Amount: {}", prefix, amount), + format!("{}Token : {}", prefix, token), + format!( + "{}Amount : {}", + prefix, + to_ledger_decimal(&amount.to_string()) + ), ]); } } @@ -632,21 +646,31 @@ async fn make_ledger_amount_asset< format_denominated_amount::<_, IO>(client, token, amount.into()) .await; if let Some(token) = tokens.get(token) { - output - .push( - format!("{}Amount: {} {}", prefix, token, formatted_amt,), - ); + output.push(format!( + "{}Amount : {} {}", + prefix, + token.to_uppercase(), + to_ledger_decimal(&formatted_amt), + )); } else { output.extend(vec![ - format!("{}Token: {}", prefix, token), - format!("{}Amount: {}", prefix, formatted_amt), + format!("{}Token : {}", prefix, token), + format!( + "{}Amount : {}", + prefix, + to_ledger_decimal(&formatted_amt) + ), ]); } } else { // Otherwise display the raw AssetTypes output.extend(vec![ - format!("{}Token: {}", prefix, token), - format!("{}Amount: {}", prefix, amount), + format!("{}Token : {}", prefix, token), + format!( + "{}Amount : {}", + prefix, + to_ledger_decimal(&amount.to_string()) + ), ]); } } @@ -654,54 +678,44 @@ async fn make_ledger_amount_asset< /// Split the lines in the vector that are longer than the Ledger device's /// character width fn format_outputs(output: &mut Vec) { - const LEDGER_WIDTH: usize = 60; + const MAX_KEY_LEN: usize = 39; + const MAX_VALUE_LEN: usize = 39; let mut i = 0; let mut pos = 0; // Break down each line that is too long one-by-one while pos < output.len() { - let prefix_len = i.to_string().len() + 3; let curr_line = output[pos].clone(); - if curr_line.len() + prefix_len < LEDGER_WIDTH { + let (key, mut value) = + curr_line.split_once(':').unwrap_or(("", &curr_line)); + // Truncate the key length to the declared maximum + let key = key.trim().chars().take(MAX_KEY_LEN - 1).collect::(); + // Trim value because we will insert spaces later + value = value.trim(); + if value.is_empty() { + value = "(none)" + } + if value.chars().count() < MAX_VALUE_LEN { // No need to split the line in this case - output[pos] = format!("{} | {}", i, curr_line); + output[pos] = format!("{} | {} : {}", i, key, value); pos += 1; } else { // Line is too long so split it up. Repeat the key on each line - let (mut key, mut value) = - curr_line.split_once(':').unwrap_or(("", &curr_line)); - key = key.trim(); - value = value.trim(); - if value.is_empty() { - value = "(none)" - } - - // First comput how many lines we will break the current one up into - let mut digits = 1; - let mut line_space; - let mut lines; - loop { - let prefix_len = prefix_len + 7 + 2 * digits + key.len(); - line_space = LEDGER_WIDTH - prefix_len; - lines = (value.len() + line_space - 1) / line_space; - if lines.to_string().len() <= digits { - break; - } else { - digits += 1; - } - } - - // Then break up this line according to the above plan output.remove(pos); - for (idx, part) in - value.chars().chunks(line_space).into_iter().enumerate() + let part_count = (value.chars().count() + MAX_VALUE_LEN - 2) + / (MAX_VALUE_LEN - 1); + for (idx, part) in value + .chars() + .chunks(MAX_VALUE_LEN - 1) + .into_iter() + .enumerate() { let line = format!( "{} | {} [{}/{}] : {}", i, key, idx + 1, - lines, + part_count, part.collect::(), ); output.insert(pos, line); @@ -847,6 +861,64 @@ pub async fn generate_test_vector< Ok(()) } +/// Convert decimal numbers into the format used by Ledger. Specifically remove +/// all insignificant zeros occuring after decimal point. +fn to_ledger_decimal(amount: &str) -> String { + if amount.contains('.') { + let mut amount = amount.trim_end_matches('0').to_string(); + if amount.ends_with('.') { + amount.push('0') + } + amount + } else { + amount.to_string() + ".0" + } +} + +/// A ProposalVote wrapper that prints the spending cap with Ledger decimal +/// formatting. +struct LedgerProposalVote<'a>(&'a StorageProposalVote); + +impl<'a> Display for LedgerProposalVote<'a> { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match &self.0 { + StorageProposalVote::Yay(vote_type) => match vote_type { + VoteType::Default => write!(f, "yay"), + VoteType::PGFSteward => write!(f, "yay for PGF steward"), + VoteType::PGFPayment => { + write!(f, "yay for PGF payment proposal") + } + }, + + StorageProposalVote::Nay => write!(f, "nay"), + } + } +} + +/// A ProposalType wrapper that prints the hash of the contained WASM code if it +/// is present. +struct LedgerProposalType<'a>(&'a ProposalType, &'a Tx); + +impl<'a> Display for LedgerProposalType<'a> { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + match self.0 { + ProposalType::Default(None) => write!(f, "Default"), + ProposalType::Default(Some(hash)) => { + let extra = self + .1 + .get_section(hash) + .and_then(|x| Section::extra_data_sec(x.as_ref())) + .expect("unable to load vp code") + .code + .hash(); + write!(f, "{}", HEXLOWER.encode(&extra.0)) + } + ProposalType::PGFSteward(_) => write!(f, "PGF Steward"), + ProposalType::PGFPayment(_) => write!(f, "PGF Payment"), + } + } +} + /// Converts the given transaction to the form that is displayed on the Ledger /// device pub async fn to_ledger_vector< @@ -882,18 +954,14 @@ pub async fn to_ledger_vector< query_wasm_code_hash::<_, IO>(client, TX_CHANGE_COMMISSION_WASM) .await?; let user_hash = query_wasm_code_hash::<_, IO>(client, VP_USER_WASM).await?; + let unjail_validator_hash = + query_wasm_code_hash::<_, IO>(client, TX_UNJAIL_VALIDATOR_WASM).await?; // To facilitate lookups of human-readable token names let tokens: HashMap = wallet - .get_addresses_with_vp_type(AddressVpType::Token) + .get_addresses() .into_iter() - .map(|addr| { - let alias = match wallet.find_alias(&addr) { - Some(alias) => alias.to_string(), - None => addr.to_string(), - }; - (addr, alias) - }) + .map(|(alias, addr)| (addr, alias)) .collect(); let mut tv = LedgerVector { @@ -902,7 +970,7 @@ pub async fn to_ledger_vector< })?), index: 0, valid: true, - name: "Custom 0".to_string(), + name: "Custom_0".to_string(), ..Default::default() }; @@ -928,7 +996,7 @@ pub async fn to_ledger_vector< .map_err(|err| { Error::from(EncodingError::Conversion(err.to_string())) })?; - tv.name = "Init Account 0".to_string(); + tv.name = "Init_Account_0".to_string(); let extra = tx .get_section(&init_account.vp_code_hash) @@ -941,15 +1009,26 @@ pub async fn to_ledger_vector< } else { HEXLOWER.encode(&extra.0) }; - + tv.output.extend(vec![format!("Type : Init Account")]); + tv.output.extend( + init_account + .public_keys + .iter() + .map(|k| format!("Public key : {}", k)), + ); tv.output.extend(vec![ - format!("Type : Init Account"), - format!("Public key : {:?}", init_account.public_keys), + format!("Threshold : {}", init_account.threshold), format!("VP type : {}", vp_code), ]); + tv.output_expert.extend( + init_account + .public_keys + .iter() + .map(|k| format!("Public key : {}", k)), + ); tv.output_expert.extend(vec![ - format!("Public key : {:?}", init_account.public_keys), + format!("Threshold : {}", init_account.threshold), format!("VP type : {}", HEXLOWER.encode(&extra.0)), ]); } else if code_hash == init_validator_hash { @@ -961,7 +1040,7 @@ pub async fn to_ledger_vector< Error::from(EncodingError::Conversion(err.to_string())) })?; - tv.name = "Init Validator 0".to_string(); + tv.name = "Init_Validator_0".to_string(); let extra = tx .get_section(&init_validator.validator_vp_code_hash) @@ -975,10 +1054,18 @@ pub async fn to_ledger_vector< HEXLOWER.encode(&extra.0) }; + tv.output.extend(vec!["Type : Init Validator".to_string()]); + tv.output.extend( + init_validator + .account_keys + .iter() + .map(|k| format!("Account key : {}", k)), + ); tv.output.extend(vec![ - format!("Type : Init Validator"), - format!("Account key : {:?}", init_validator.account_keys), + format!("Threshold : {}", init_validator.threshold), format!("Consensus key : {}", init_validator.consensus_key), + format!("Ethereum cold key : {}", init_validator.eth_cold_key), + format!("Ethereum hot key : {}", init_validator.eth_hot_key), format!("Protocol key : {}", init_validator.protocol_key), format!("DKG key : {}", init_validator.dkg_key), format!("Commission rate : {}", init_validator.commission_rate), @@ -989,9 +1076,17 @@ pub async fn to_ledger_vector< format!("Validator VP type : {}", vp_code,), ]); + tv.output_expert.extend( + init_validator + .account_keys + .iter() + .map(|k| format!("Account key : {}", k)), + ); tv.output_expert.extend(vec![ - format!("Account key : {:?}", init_validator.account_keys), + format!("Threshold : {}", init_validator.threshold), format!("Consensus key : {}", init_validator.consensus_key), + format!("Ethereum cold key : {}", init_validator.eth_cold_key), + format!("Ethereum hot key : {}", init_validator.eth_hot_key), format!("Protocol key : {}", init_validator.protocol_key), format!("DKG key : {}", init_validator.dkg_key), format!("Commission rate : {}", init_validator.commission_rate), @@ -1010,16 +1105,24 @@ pub async fn to_ledger_vector< Error::from(EncodingError::Conversion(err.to_string())) })?; - tv.name = "Init Proposal 0".to_string(); + tv.name = "Init_Proposal_0".to_string(); + + let extra = tx + .get_section(&init_proposal_data.content) + .and_then(|x| Section::extra_data_sec(x.as_ref())) + .expect("unable to load vp code") + .code + .hash(); - let init_proposal_data_id = init_proposal_data - .id - .as_ref() - .map(u64::to_string) - .unwrap_or_else(|| "(none)".to_string()); + tv.output.push("Type : Init proposal".to_string()); + if let Some(id) = init_proposal_data.id.as_ref() { + tv.output.push(format!("ID : {}", id)); + } tv.output.extend(vec![ - format!("Type : Init proposal"), - format!("ID : {}", init_proposal_data_id), + format!( + "Proposal type : {}", + LedgerProposalType(&init_proposal_data.r#type, tx) + ), format!("Author : {}", init_proposal_data.author), format!( "Voting start epoch : {}", @@ -1030,12 +1133,17 @@ pub async fn to_ledger_vector< init_proposal_data.voting_end_epoch ), format!("Grace epoch : {}", init_proposal_data.grace_epoch), + format!("Content : {}", HEXLOWER.encode(&extra.0)), ]); - tv.output - .push(format!("Content: {}", init_proposal_data.content)); + if let Some(id) = init_proposal_data.id.as_ref() { + tv.output_expert.push(format!("ID : {}", id)); + } tv.output_expert.extend(vec![ - format!("ID : {}", init_proposal_data_id), + format!( + "Proposal type : {}", + LedgerProposalType(&init_proposal_data.r#type, tx) + ), format!("Author : {}", init_proposal_data.author), format!( "Voting start epoch : {}", @@ -1046,9 +1154,8 @@ pub async fn to_ledger_vector< init_proposal_data.voting_end_epoch ), format!("Grace epoch : {}", init_proposal_data.grace_epoch), + format!("Content : {}", HEXLOWER.encode(&extra.0)), ]); - tv.output - .push(format!("Content: {}", init_proposal_data.content)); } else if code_hash == vote_proposal_hash { let vote_proposal = VoteProposalData::try_from_slice( &tx.data() @@ -1058,26 +1165,26 @@ pub async fn to_ledger_vector< Error::from(EncodingError::Conversion(err.to_string())) })?; - tv.name = "Vote Proposal 0".to_string(); + tv.name = "Vote_Proposal_0".to_string(); tv.output.extend(vec![ format!("Type : Vote Proposal"), format!("ID : {}", vote_proposal.id), - format!("Vote : {}", vote_proposal.vote), + format!("Vote : {}", LedgerProposalVote(&vote_proposal.vote)), format!("Voter : {}", vote_proposal.voter), ]); for delegation in &vote_proposal.delegations { - tv.output.push(format!("Delegations : {}", delegation)); + tv.output.push(format!("Delegation : {}", delegation)); } tv.output_expert.extend(vec![ format!("ID : {}", vote_proposal.id), - format!("Vote : {}", vote_proposal.vote), + format!("Vote : {}", LedgerProposalVote(&vote_proposal.vote)), format!("Voter : {}", vote_proposal.voter), ]); for delegation in vote_proposal.delegations { tv.output_expert - .push(format!("Delegations : {}", delegation)); + .push(format!("Delegation : {}", delegation)); } } else if code_hash == reveal_pk_hash { let public_key = common::PublicKey::try_from_slice( @@ -1088,17 +1195,17 @@ pub async fn to_ledger_vector< Error::from(EncodingError::Conversion(err.to_string())) })?; - tv.name = "Init Account 0".to_string(); + tv.name = "Reveal_Pubkey_0".to_string(); tv.output.extend(vec![ - format!("Type : Reveal PK"), + format!("Type : Reveal Pubkey"), format!("Public key : {}", public_key), ]); tv.output_expert .extend(vec![format!("Public key : {}", public_key)]); } else if code_hash == update_account_hash { - let transfer = UpdateAccount::try_from_slice( + let update_account = UpdateAccount::try_from_slice( &tx.data() .ok_or_else(|| Error::Other("Invalid Data".to_string()))?, ) @@ -1106,9 +1213,9 @@ pub async fn to_ledger_vector< Error::from(EncodingError::Conversion(err.to_string())) })?; - tv.name = "Update VP 0".to_string(); + tv.name = "Update_VP_0".to_string(); - match &transfer.vp_code_hash { + match &update_account.vp_code_hash { Some(hash) => { let extra = tx .get_section(hash) @@ -1125,14 +1232,40 @@ pub async fn to_ledger_vector< }; tv.output.extend(vec![ format!("Type : Update VP"), - format!("Address : {}", transfer.addr), - format!("VP type : {}", vp_code), - ]); - - tv.output_expert.extend(vec![ - format!("Address : {}", transfer.addr), - format!("VP type : {}", HEXLOWER.encode(&extra.0)), + format!("Address : {}", update_account.addr), ]); + tv.output.extend( + update_account + .public_keys + .iter() + .map(|k| format!("Public key : {}", k)), + ); + if update_account.threshold.is_some() { + tv.output.extend(vec![format!( + "Threshold : {}", + update_account.threshold.unwrap() + )]) + } + tv.output.extend(vec![format!("VP type : {}", vp_code)]); + + tv.output_expert + .extend(vec![format!("Address : {}", update_account.addr)]); + tv.output_expert.extend( + update_account + .public_keys + .iter() + .map(|k| format!("Public key : {}", k)), + ); + if update_account.threshold.is_some() { + tv.output_expert.extend(vec![format!( + "Threshold : {}", + update_account.threshold.unwrap() + )]) + } + tv.output_expert.extend(vec![format!( + "VP type : {}", + HEXLOWER.encode(&extra.0) + )]); } None => (), }; @@ -1171,7 +1304,7 @@ pub async fn to_ledger_vector< None }; - tv.name = "Transfer 0".to_string(); + tv.name = "Transfer_0".to_string(); tv.output.push("Type : Transfer".to_string()); make_ledger_masp_endpoints::<_, IO>( @@ -1200,7 +1333,7 @@ pub async fn to_ledger_vector< ) .map_err(|x| Error::from(EncodingError::Conversion(x.to_string())))?; - tv.name = "IBC 0".to_string(); + tv.name = "IBC_0".to_string(); tv.output.push("Type : IBC".to_string()); match MsgTransfer::try_from(any_msg.clone()) { @@ -1222,7 +1355,11 @@ pub async fn to_ledger_vector< ), format!( "Timeout timestamp : {}", - transfer.timeout_timestamp_on_b + transfer + .timeout_timestamp_on_b + .into_tm_time() + .map_or("(none)".to_string(), |time| time + .to_rfc3339()) ), ]); tv.output_expert.extend(vec![ @@ -1237,7 +1374,11 @@ pub async fn to_ledger_vector< ), format!( "Timeout timestamp : {}", - transfer.timeout_timestamp_on_b + transfer + .timeout_timestamp_on_b + .into_tm_time() + .map_or("(none)".to_string(), |time| time + .to_rfc3339()) ), ]); } @@ -1258,24 +1399,29 @@ pub async fn to_ledger_vector< Error::from(EncodingError::Conversion(err.to_string())) })?; - tv.name = "Bond 0".to_string(); + tv.name = "Bond_0".to_string(); - let bond_source = bond - .source - .as_ref() - .map(Address::to_string) - .unwrap_or_else(|| "(none)".to_string()); + tv.output.push("Type : Bond".to_string()); + if let Some(source) = bond.source.as_ref() { + tv.output.push(format!("Source : {}", source)); + } tv.output.extend(vec![ - format!("Type : Bond"), - format!("Source : {}", bond_source), format!("Validator : {}", bond.validator), - format!("Amount : {}", bond.amount.to_string_native()), + format!( + "Amount : NAM {}", + to_ledger_decimal(&bond.amount.to_string_native()) + ), ]); + if let Some(source) = bond.source.as_ref() { + tv.output_expert.push(format!("Source : {}", source)); + } tv.output_expert.extend(vec![ - format!("Source : {}", bond_source), format!("Validator : {}", bond.validator), - format!("Amount : {}", bond.amount.to_string_native()), + format!( + "Amount : NAM {}", + to_ledger_decimal(&bond.amount.to_string_native()) + ), ]); } else if code_hash == unbond_hash { let unbond = pos::Unbond::try_from_slice( @@ -1286,24 +1432,29 @@ pub async fn to_ledger_vector< Error::from(EncodingError::Conversion(err.to_string())) })?; - tv.name = "Unbond 0".to_string(); + tv.name = "Unbond_0".to_string(); - let unbond_source = unbond - .source - .as_ref() - .map(Address::to_string) - .unwrap_or_else(|| "(none)".to_string()); + tv.output.push("Type : Unbond".to_string()); + if let Some(source) = unbond.source.as_ref() { + tv.output.push(format!("Source : {}", source)); + } tv.output.extend(vec![ - format!("Code : Unbond"), - format!("Source : {}", unbond_source), format!("Validator : {}", unbond.validator), - format!("Amount : {}", unbond.amount.to_string_native()), + format!( + "Amount : NAM {}", + to_ledger_decimal(&unbond.amount.to_string_native()) + ), ]); + if let Some(source) = unbond.source.as_ref() { + tv.output_expert.push(format!("Source : {}", source)); + } tv.output_expert.extend(vec![ - format!("Source : {}", unbond_source), format!("Validator : {}", unbond.validator), - format!("Amount : {}", unbond.amount.to_string_native()), + format!( + "Amount : NAM {}", + to_ledger_decimal(&unbond.amount.to_string_native()) + ), ]); } else if code_hash == withdraw_hash { let withdraw = pos::Withdraw::try_from_slice( @@ -1314,23 +1465,20 @@ pub async fn to_ledger_vector< Error::from(EncodingError::Conversion(err.to_string())) })?; - tv.name = "Withdraw 0".to_string(); + tv.name = "Withdraw_0".to_string(); - let withdraw_source = withdraw - .source - .as_ref() - .map(Address::to_string) - .unwrap_or_else(|| "(none)".to_string()); - tv.output.extend(vec![ - format!("Type : Withdraw"), - format!("Source : {}", withdraw_source), - format!("Validator : {}", withdraw.validator), - ]); + tv.output.push("Type : Withdraw".to_string()); + if let Some(source) = withdraw.source.as_ref() { + tv.output.push(format!("Source : {}", source)); + } + tv.output + .push(format!("Validator : {}", withdraw.validator)); - tv.output_expert.extend(vec![ - format!("Source : {}", withdraw_source), - format!("Validator : {}", withdraw.validator), - ]); + if let Some(source) = withdraw.source.as_ref() { + tv.output_expert.push(format!("Source : {}", source)); + } + tv.output_expert + .push(format!("Validator : {}", withdraw.validator)); } else if code_hash == change_commission_hash { let commission_change = pos::CommissionChange::try_from_slice( &tx.data() @@ -1340,7 +1488,7 @@ pub async fn to_ledger_vector< Error::from(EncodingError::Conversion(err.to_string())) })?; - tv.name = "Change Commission 0".to_string(); + tv.name = "Change_Commission_0".to_string(); tv.output.extend(vec![ format!("Type : Change commission"), @@ -1352,6 +1500,26 @@ pub async fn to_ledger_vector< format!("New rate : {}", commission_change.new_rate), format!("Validator : {}", commission_change.validator), ]); + } else if code_hash == unjail_validator_hash { + let address = Address::try_from_slice( + &tx.data() + .ok_or_else(|| Error::Other("Invalid Data".to_string()))?, + ) + .map_err(|err| { + Error::from(EncodingError::Conversion(err.to_string())) + })?; + + tv.name = "Unjail_Validator_0".to_string(); + + tv.output.extend(vec![ + format!("Type : Unjail Validator"), + format!("Validator : {}", address), + ]); + + tv.output_expert.push(format!("Validator : {}", address)); + } else { + tv.name = "Custom_0".to_string(); + tv.output.push("Type : Custom".to_string()); } if let Some(wrapper) = tx.header.wrapper() { @@ -1370,21 +1538,21 @@ pub async fn to_ledger_vector< .await; tv.output_expert.extend(vec![ format!("Timestamp : {}", tx.header.timestamp.0), - format!("PK : {}", wrapper.pk), + format!("Pubkey : {}", wrapper.pk), format!("Epoch : {}", wrapper.epoch), format!("Gas limit : {}", gas_limit), - format!("Fee token : {}", gas_token), ]); if let Some(token) = tokens.get(&wrapper.fee.token) { tv.output_expert.push(format!( - "Fee amount per gas unit : {} {}", - token, fee_amount_per_gas_unit + "Fees/gas unit : {} {}", + token.to_uppercase(), + to_ledger_decimal(&fee_amount_per_gas_unit), )); } else { - tv.output_expert.push(format!( - "Fee amount per gas unit : {}", - fee_amount_per_gas_unit - )); + tv.output_expert.extend(vec![ + format!("Fee token : {}", gas_token), + format!("Fees/gas unit : {}", fee_amount_per_gas_unit), + ]); } } diff --git a/shared/src/sdk/tx.rs b/shared/src/sdk/tx.rs index 9d7fe0cfe4..b5489aaddc 100644 --- a/shared/src/sdk/tx.rs +++ b/shared/src/sdk/tx.rs @@ -70,6 +70,8 @@ use crate::{display_line, edisplay_line, vm}; pub const TX_INIT_ACCOUNT_WASM: &str = "tx_init_account.wasm"; /// Initialize validator transaction WASM path pub const TX_INIT_VALIDATOR_WASM: &str = "tx_init_validator.wasm"; +/// Unjail validator transaction WASM path +pub const TX_UNJAIL_VALIDATOR_WASM: &str = "tx_unjail_validator.wasm"; /// Initialize proposal transaction WASM path pub const TX_INIT_PROPOSAL: &str = "tx_init_proposal.wasm"; /// Vote transaction WASM path @@ -738,13 +740,8 @@ pub async fn build_unjail_validator< let validator_state_at_pipeline = rpc::get_validator_state(client, &validator, Some(pipeline_epoch)) - .await? - .ok_or_else(|| { - Error::from(TxError::Other( - "Validator state should be defined.".to_string(), - )) - })?; - if validator_state_at_pipeline != ValidatorState::Jailed { + .await?; + if validator_state_at_pipeline != Some(ValidatorState::Jailed) { edisplay_line!( IO, "The given validator address {} is not jailed at the pipeline \ From 4d0d333d55d9e26f06a287359332756c34e3afdd Mon Sep 17 00:00:00 2001 From: Murisi Tarusenga Date: Fri, 22 Sep 2023 17:30:36 +0200 Subject: [PATCH 2/2] Added a changelog record. --- .../1888-ledger-test-vector-generator-fix-0.22.0.md | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .changelog/unreleased/improvements/1888-ledger-test-vector-generator-fix-0.22.0.md diff --git a/.changelog/unreleased/improvements/1888-ledger-test-vector-generator-fix-0.22.0.md b/.changelog/unreleased/improvements/1888-ledger-test-vector-generator-fix-0.22.0.md new file mode 100644 index 0000000000..0aeb7196d1 --- /dev/null +++ b/.changelog/unreleased/improvements/1888-ledger-test-vector-generator-fix-0.22.0.md @@ -0,0 +1,2 @@ +- Updated the generation of hardware wallet test vectors to cover current + codebase ([\#1888](https://github.com/anoma/namada/pull/1888)) \ No newline at end of file