From ea5d3612975ce656fab6edf2f623126e951efaa1 Mon Sep 17 00:00:00 2001 From: Abhishek Uniyal <56363630+uniyalabhishek@users.noreply.github.com> Date: Thu, 5 Feb 2026 13:19:01 +0530 Subject: [PATCH] feat: enhance address formatting in staking transactions refactor: update PrettyPrint function and staking address formatting tests --- cmd/common/json.go | 2 ++ cmd/common/json_test.go | 26 +++++++++++++++++++ examples/account/allow-negative.out.static | 2 +- examples/account/allow-paratime.y.out | 2 +- examples/account/allow.y.out | 2 +- .../account/transfer-named-no-paratime.y.out | 2 +- examples/transaction/show-invalid.out | 2 +- examples/transaction/show-unsigned.out | 2 +- examples/transaction/show.out | 2 +- examples/transaction/sign.y.out | 2 +- 10 files changed, 36 insertions(+), 8 deletions(-) diff --git a/cmd/common/json.go b/cmd/common/json.go index 248f1a67..3fc32098 100644 --- a/cmd/common/json.go +++ b/cmd/common/json.go @@ -13,6 +13,7 @@ import ( "github.com/oasisprotocol/oasis-core/go/common" coreSignature "github.com/oasisprotocol/oasis-core/go/common/crypto/signature" consensusPretty "github.com/oasisprotocol/oasis-core/go/common/prettyprint" + coreStaking "github.com/oasisprotocol/oasis-core/go/staking/api" "github.com/oasisprotocol/oasis-sdk/client-sdk/go/config" "github.com/oasisprotocol/oasis-sdk/client-sdk/go/crypto/signature" "github.com/oasisprotocol/oasis-sdk/client-sdk/go/types" @@ -191,6 +192,7 @@ func PrettyPrintWithTxDetails(npa *NPASelection, prefix string, blob interface{} ctx = context.WithValue(ctx, types.ContextKeyAccountNames, addrCtx.Names) ctx = context.WithValue(ctx, types.ContextKeyAccountEthMap, addrCtx.Eth) + ctx = context.WithValue(ctx, coreStaking.ContextKeyAccountNames, coreStaking.AccountNames(addrCtx.Names)) // Set up chain context for signature verification during pretty-printing. coreSignature.UnsafeResetChainContext() diff --git a/cmd/common/json_test.go b/cmd/common/json_test.go index d33ac6fb..c8fe1230 100644 --- a/cmd/common/json_test.go +++ b/cmd/common/json_test.go @@ -8,10 +8,12 @@ import ( "github.com/stretchr/testify/require" "github.com/oasisprotocol/oasis-core/go/common/quantity" + consensusStaking "github.com/oasisprotocol/oasis-core/go/staking/api" sdkConfig "github.com/oasisprotocol/oasis-sdk/client-sdk/go/config" sdkSignature "github.com/oasisprotocol/oasis-sdk/client-sdk/go/crypto/signature" "github.com/oasisprotocol/oasis-sdk/client-sdk/go/modules/accounts" + sdkTesting "github.com/oasisprotocol/oasis-sdk/client-sdk/go/testing" "github.com/oasisprotocol/oasis-sdk/client-sdk/go/types" ) @@ -53,3 +55,27 @@ func TestPrettyPrintWithTxDetails_PreservesUnnamedEthTo(t *testing.T) { require.Contains(out, "To: "+ethAddr.Hex()+" ("+to.String()+")") } + +func TestPrettyPrint_FormatsStakingAllowBeneficiary(t *testing.T) { + require := require.New(t) + + npa := &NPASelection{ + NetworkName: "testnet", + Network: &sdkConfig.Network{ + ChainContext: "test-chain-context", + Denomination: sdkConfig.DenominationInfo{ + Symbol: "TEST", + Decimals: 9, + }, + }, + } + + tx := consensusStaking.NewAllowTx(0, nil, &consensusStaking.Allow{ + Beneficiary: sdkTesting.Bob.Address.ConsensusAddress(), + AmountChange: *quantity.NewFromUint64(10), + }) + + out := PrettyPrint(npa, "", tx) + + require.Contains(out, "Beneficiary: test:bob ("+sdkTesting.Bob.Address.String()+")") +} diff --git a/examples/account/allow-negative.out.static b/examples/account/allow-negative.out.static index 749efa5e..ff69b76b 100644 --- a/examples/account/allow-negative.out.static +++ b/examples/account/allow-negative.out.static @@ -1,7 +1,7 @@ You are about to sign the following transaction: Method: staking.Allow Body: - Beneficiary: oasis1qpl4axynedmdrrgrg7dpw3yxc4a8crevr5dkuksl + Beneficiary: logan (oasis1qpl4axynedmdrrgrg7dpw3yxc4a8crevr5dkuksl) Amount change: -10.0 TEST Nonce: 0 Fee: diff --git a/examples/account/allow-paratime.y.out b/examples/account/allow-paratime.y.out index 9c5a91f5..f6b22928 100644 --- a/examples/account/allow-paratime.y.out +++ b/examples/account/allow-paratime.y.out @@ -1,7 +1,7 @@ You are about to sign the following transaction: Method: staking.Allow Body: - Beneficiary: oasis1qqczuf3x6glkgjuf0xgtcpjjw95r3crf7y2323xd + Beneficiary: paratime:sapphire (oasis1qqczuf3x6glkgjuf0xgtcpjjw95r3crf7y2323xd) Amount change: +10.0 TEST Nonce: 2 Fee: diff --git a/examples/account/allow.y.out b/examples/account/allow.y.out index 2c3ea136..c4a314b8 100644 --- a/examples/account/allow.y.out +++ b/examples/account/allow.y.out @@ -1,7 +1,7 @@ You are about to sign the following transaction: Method: staking.Allow Body: - Beneficiary: oasis1qpl4axynedmdrrgrg7dpw3yxc4a8crevr5dkuksl + Beneficiary: logan (oasis1qpl4axynedmdrrgrg7dpw3yxc4a8crevr5dkuksl) Amount change: +10.0 TEST Nonce: 2 Fee: diff --git a/examples/account/transfer-named-no-paratime.y.out b/examples/account/transfer-named-no-paratime.y.out index 58136449..37a7c654 100644 --- a/examples/account/transfer-named-no-paratime.y.out +++ b/examples/account/transfer-named-no-paratime.y.out @@ -1,7 +1,7 @@ You are about to sign the following transaction: Method: staking.Transfer Body: - To: oasis1qp87hflmelnpqhzcqcw8rhzakq4elj7jzv090p3e + To: oscar (oasis1qp87hflmelnpqhzcqcw8rhzakq4elj7jzv090p3e) Amount: 2.5 TEST Nonce: 0 Fee: diff --git a/examples/transaction/show-invalid.out b/examples/transaction/show-invalid.out index 1c614808..74f5ae09 100644 --- a/examples/transaction/show-invalid.out +++ b/examples/transaction/show-invalid.out @@ -5,7 +5,7 @@ Signer: NcPzNW3YU2T+ugNUtUWtoQnRvbOL9dYSaBfbjHLP1pE= Content: Method: staking.Transfer Body: - To: oasis1qrydpazemvuwtnp3efm7vmfvg3tde044qg6cxwzx + To: test:bob (oasis1qrydpazemvuwtnp3efm7vmfvg3tde044qg6cxwzx) Amount: 1.0 ROSE Nonce: 1 Fee: diff --git a/examples/transaction/show-unsigned.out b/examples/transaction/show-unsigned.out index fae60b02..b3cc724d 100644 --- a/examples/transaction/show-unsigned.out +++ b/examples/transaction/show-unsigned.out @@ -1,6 +1,6 @@ Method: staking.Transfer Body: - To: oasis1qrydpazemvuwtnp3efm7vmfvg3tde044qg6cxwzx + To: test:bob (oasis1qrydpazemvuwtnp3efm7vmfvg3tde044qg6cxwzx) Amount: 1.0 TEST Nonce: 32 Fee: diff --git a/examples/transaction/show.out b/examples/transaction/show.out index ee6bb9dc..4c9d8308 100644 --- a/examples/transaction/show.out +++ b/examples/transaction/show.out @@ -4,7 +4,7 @@ Signer: NcPzNW3YU2T+ugNUtUWtoQnRvbOL9dYSaBfbjHLP1pE= Content: Method: staking.Transfer Body: - To: oasis1qrydpazemvuwtnp3efm7vmfvg3tde044qg6cxwzx + To: test:bob (oasis1qrydpazemvuwtnp3efm7vmfvg3tde044qg6cxwzx) Amount: 1.0 TEST Nonce: 1 Fee: diff --git a/examples/transaction/sign.y.out b/examples/transaction/sign.y.out index 4f8c16f2..20258cb5 100644 --- a/examples/transaction/sign.y.out +++ b/examples/transaction/sign.y.out @@ -1,7 +1,7 @@ You are about to sign the following transaction: Method: staking.Transfer Body: - To: oasis1qrydpazemvuwtnp3efm7vmfvg3tde044qg6cxwzx + To: test:bob (oasis1qrydpazemvuwtnp3efm7vmfvg3tde044qg6cxwzx) Amount: 1.0 TEST Nonce: 32 Fee: