Use service Msgs in CLI tx commands (#8512)
* Use service Msgs in CLI tx commands * Update comment * Gracefully support amino signing * CLI to use svc msg * Fix lint * Use fq method name in events * Update tests * Fix quering events * Add docs * Fix test build * Fix events * Fix search for events * Handle old andd new event quering * Use merge events * Better encCfg * Add page in search * Fix tests * Update test and comments * Update x/auth/legacy/legacytx/stdsign.go Co-authored-by: atheeshp <59333759+atheeshp@users.noreply.github.com> * Fix conflict for weighted vote * Make CopyTx actually run * Fix CopyTx * Fix test * Add changelog entry * Remove useless code * Add msgs tests * Remove testing proto Msg via CLI * Fix lint * Fix test * Implement GetSignBytes on ServiceMsg * Fix %T Co-authored-by: atheeshp <59333759+atheeshp@users.noreply.github.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
This commit is contained in:
co-authored by
atheeshp
mergify[bot]
parent
b4820fe491
commit
73e38e4009
+30
-11
@@ -13,6 +13,7 @@ import (
|
||||
"github.com/cosmos/cosmos-sdk/simapp/params"
|
||||
"github.com/cosmos/cosmos-sdk/testutil/testdata"
|
||||
"github.com/cosmos/cosmos-sdk/types"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
signing2 "github.com/cosmos/cosmos-sdk/types/tx/signing"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth/legacy/legacytx"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth/signing"
|
||||
@@ -23,14 +24,13 @@ import (
|
||||
const (
|
||||
memo = "waboom"
|
||||
gas = uint64(10000)
|
||||
timeoutHeight = 5
|
||||
timeoutHeight = uint64(5)
|
||||
)
|
||||
|
||||
var (
|
||||
fee = types.NewCoins(types.NewInt64Coin("bam", 100))
|
||||
_, pub1, addr1 = testdata.KeyTestPubAddr()
|
||||
_, _, addr2 = testdata.KeyTestPubAddr()
|
||||
msg = banktypes.NewMsgSend(addr1, addr2, types.NewCoins(types.NewInt64Coin("wack", 10000)))
|
||||
sig = signing2.SignatureV2{
|
||||
PubKey: pub1,
|
||||
Data: &signing2.SingleSignatureData{
|
||||
@@ -38,13 +38,18 @@ var (
|
||||
Signature: []byte("dummy"),
|
||||
},
|
||||
}
|
||||
msg0 = banktypes.NewMsgSend(addr1, addr2, types.NewCoins(types.NewInt64Coin("wack", 1)))
|
||||
msg1 = sdk.ServiceMsg{
|
||||
MethodName: "/cosmos.bank.v1beta1.Msg/Send",
|
||||
Request: banktypes.NewMsgSend(addr1, addr2, types.NewCoins(types.NewInt64Coin("wack", 2))),
|
||||
}
|
||||
)
|
||||
|
||||
func buildTestTx(t *testing.T, builder client.TxBuilder) {
|
||||
builder.SetMemo(memo)
|
||||
builder.SetGasLimit(gas)
|
||||
builder.SetFeeAmount(fee)
|
||||
err := builder.SetMsgs(msg)
|
||||
err := builder.SetMsgs(msg0, msg1)
|
||||
require.NoError(t, err)
|
||||
err = builder.SetSignatures(sig)
|
||||
require.NoError(t, err)
|
||||
@@ -75,11 +80,15 @@ func (s *TestSuite) TestCopyTx() {
|
||||
protoBuilder2 := s.protoCfg.NewTxBuilder()
|
||||
err = tx2.CopyTx(aminoBuilder.GetTx(), protoBuilder2, false)
|
||||
s.Require().NoError(err)
|
||||
bz, err := s.protoCfg.TxEncoder()(protoBuilder.GetTx())
|
||||
// Check sigs, signers and msgs.
|
||||
sigsV2_1, err := protoBuilder.GetTx().GetSignaturesV2()
|
||||
s.Require().NoError(err)
|
||||
bz2, err := s.protoCfg.TxEncoder()(protoBuilder2.GetTx())
|
||||
sigsV2_2, err := protoBuilder2.GetTx().GetSignaturesV2()
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(bz, bz2)
|
||||
s.Require().Equal(sigsV2_1, sigsV2_2)
|
||||
s.Require().Equal(protoBuilder.GetTx().GetSigners(), protoBuilder2.GetTx().GetSigners())
|
||||
s.Require().Equal(protoBuilder.GetTx().GetMsgs()[0], protoBuilder2.GetTx().GetMsgs()[0])
|
||||
s.Require().Equal(protoBuilder.GetTx().GetMsgs()[1].(sdk.ServiceMsg).Request, protoBuilder2.GetTx().GetMsgs()[1]) // We lose the "ServiceMsg" information
|
||||
|
||||
// amino -> proto -> amino
|
||||
aminoBuilder = s.aminoCfg.NewTxBuilder()
|
||||
@@ -90,11 +99,15 @@ func (s *TestSuite) TestCopyTx() {
|
||||
aminoBuilder2 := s.aminoCfg.NewTxBuilder()
|
||||
err = tx2.CopyTx(protoBuilder.GetTx(), aminoBuilder2, false)
|
||||
s.Require().NoError(err)
|
||||
bz, err = s.aminoCfg.TxEncoder()(aminoBuilder.GetTx())
|
||||
// Check sigs, signers, and msgs
|
||||
sigsV2_1, err = aminoBuilder.GetTx().GetSignaturesV2()
|
||||
s.Require().NoError(err)
|
||||
bz2, err = s.aminoCfg.TxEncoder()(aminoBuilder2.GetTx())
|
||||
sigsV2_2, err = aminoBuilder2.GetTx().GetSignaturesV2()
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(bz, bz2)
|
||||
s.Require().Equal(sigsV2_1, sigsV2_2)
|
||||
s.Require().Equal(aminoBuilder.GetTx().GetSigners(), aminoBuilder2.GetTx().GetSigners())
|
||||
s.Require().Equal(aminoBuilder.GetTx().GetMsgs()[0], aminoBuilder2.GetTx().GetMsgs()[0])
|
||||
s.Require().Equal(aminoBuilder.GetTx().GetMsgs()[1], aminoBuilder2.GetTx().GetMsgs()[1]) // We lose the "ServiceMsg" information
|
||||
}
|
||||
|
||||
func (s *TestSuite) TestConvertTxToStdTx() {
|
||||
@@ -106,7 +119,8 @@ func (s *TestSuite) TestConvertTxToStdTx() {
|
||||
s.Require().Equal(memo, stdTx.Memo)
|
||||
s.Require().Equal(gas, stdTx.Fee.Gas)
|
||||
s.Require().Equal(fee, stdTx.Fee.Amount)
|
||||
s.Require().Equal(msg, stdTx.Msgs[0])
|
||||
s.Require().Equal(msg0, stdTx.Msgs[0])
|
||||
s.Require().Equal(msg1.Request, stdTx.Msgs[1])
|
||||
s.Require().Equal(timeoutHeight, stdTx.TimeoutHeight)
|
||||
s.Require().Equal(sig.PubKey, stdTx.Signatures[0].PubKey)
|
||||
s.Require().Equal(sig.Data.(*signing2.SingleSignatureData).Signature, stdTx.Signatures[0].Signature)
|
||||
@@ -125,7 +139,8 @@ func (s *TestSuite) TestConvertTxToStdTx() {
|
||||
s.Require().Equal(memo, stdTx.Memo)
|
||||
s.Require().Equal(gas, stdTx.Fee.Gas)
|
||||
s.Require().Equal(fee, stdTx.Fee.Amount)
|
||||
s.Require().Equal(msg, stdTx.Msgs[0])
|
||||
s.Require().Equal(msg0, stdTx.Msgs[0])
|
||||
s.Require().Equal(msg1.Request, stdTx.Msgs[1])
|
||||
s.Require().Equal(timeoutHeight, stdTx.TimeoutHeight)
|
||||
s.Require().Empty(stdTx.Signatures)
|
||||
|
||||
@@ -158,3 +173,7 @@ func (s *TestSuite) TestConvertAndEncodeStdTx() {
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(stdTx, decodedTx)
|
||||
}
|
||||
|
||||
func TestTestSuite(t *testing.T) {
|
||||
suite.Run(t, new(TestSuite))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user