refactor: don't break SignModeHandler API (#14087)
* refactor: Make SignModeHandler update not API breaking * changelog * fix tests * add comment * Revert rosetta * address reviews * shorter name * Fix test build
This commit is contained in:
parent
37a9bc3bb6
commit
fb4d964f7e
@ -58,6 +58,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
|
||||
|
||||
### Improvements
|
||||
|
||||
* (signing) [#14087](https://github.com/cosmos/cosmos-sdk/pull/14087) Add SignModeHandlerWithContext interface with a new `GetSignBytesWithContext` to get the sign bytes using `context.Context` as an argument to access state.
|
||||
* (server) [#14062](https://github.com/cosmos/cosmos-sdk/pull/14062) Remove rosetta from server start.
|
||||
* [13882] (https://github.com/cosmos/cosmos-sdk/pull/13882) Add tx `encode` and `decode` endpoints to amino tx service.
|
||||
> Note: These endpoints encodes and decodes only amino txs.
|
||||
@ -179,7 +180,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
|
||||
* [#13794](https://github.com/cosmos/cosmos-sdk/pull/13794) Most methods on `types/module.AppModule` have been moved to
|
||||
extension interfaces. `module.Manager.Modules` is now of type `map[string]interface{}` to support in parallel the new
|
||||
`cosmossdk.io/core/appmodule.AppModule` API.
|
||||
* (signing) [#13701](https://github.com/cosmos/cosmos-sdk/pull/) Add `context.Context` as an argument to SignModeHandler's `GetSignBytes` method and `x/auth/signing.VerifySignature`. You can pass `nil` for now, it will only be used once SIGN_MODE_TEXTUAL is live.
|
||||
* (signing) [#13701](https://github.com/cosmos/cosmos-sdk/pull/) Add `context.Context` as an argument `x/auth/signing.VerifySignature`.
|
||||
* (x/group) [#13876](https://github.com/cosmos/cosmos-sdk/pull/13876) Add `GetMinExecutionPeriod` method on DecisionPolicy interface.
|
||||
* (x/auth)[#13780](https://github.com/cosmos/cosmos-sdk/pull/13780) Querying with `id` (type of int64) in `AccountAddressByID` grpc query now throws error, use account-id(type of uint64) instead.
|
||||
* (snapshots) [14048](https://github.com/cosmos/cosmos-sdk/pull/14048) Move the Snapshot package to the store package. This is done in an effort group all storage related logic under one package.
|
||||
|
||||
@ -158,7 +158,7 @@ func SignWithPrivKey(
|
||||
var sigV2 signing.SignatureV2
|
||||
|
||||
// Generate the bytes to be signed.
|
||||
signBytes, err := txConfig.SignModeHandler().GetSignBytes(ctx, signMode, signerData, txBuilder.GetTx())
|
||||
signBytes, err := authsigning.GetSignBytesWithContext(txConfig.SignModeHandler(), ctx, signMode, signerData, txBuilder.GetTx())
|
||||
if err != nil {
|
||||
return sigV2, err
|
||||
}
|
||||
@ -300,7 +300,7 @@ func Sign(ctx context.Context, txf Factory, name string, txBuilder client.TxBuil
|
||||
}
|
||||
|
||||
// Generate the bytes to be signed.
|
||||
bytesToSign, err := txf.txConfig.SignModeHandler().GetSignBytes(ctx, signMode, signerData, txBuilder.GetTx())
|
||||
bytesToSign, err := authsigning.GetSignBytesWithContext(txf.txConfig.SignModeHandler(), ctx, signMode, signerData, txBuilder.GetTx())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -161,9 +161,6 @@ require (
|
||||
)
|
||||
|
||||
replace (
|
||||
// Temporary until we tag a new version
|
||||
cosmossdk.io/tools/rosetta => ../tools/rosetta
|
||||
|
||||
github.com/99designs/keyring => github.com/cosmos/keyring v1.2.0
|
||||
// Update to rosetta-sdk-go temporarly to have `check:spec` passing. See https://github.com/coinbase/rosetta-sdk-go/issues/449
|
||||
github.com/coinbase/rosetta-sdk-go => github.com/coinbase/rosetta-sdk-go v0.8.2-0.20221007214527-e03849ba430a
|
||||
|
||||
@ -56,6 +56,8 @@ cosmossdk.io/errors v1.0.0-beta.7 h1:gypHW76pTQGVnHKo6QBkb4yFOJjC+sUGRc5Al3Odj1w
|
||||
cosmossdk.io/errors v1.0.0-beta.7/go.mod h1:mz6FQMJRku4bY7aqS/Gwfcmr/ue91roMEKAmDUDpBfE=
|
||||
cosmossdk.io/math v1.0.0-beta.4 h1:JtKedVLGzA0vv84xjYmZ75RKG35Kf2WwcFu8IjRkIIw=
|
||||
cosmossdk.io/math v1.0.0-beta.4/go.mod h1:An0MllWJY6PxibUpnwGk8jOm+a/qIxlKmL5Zyp9NnaM=
|
||||
cosmossdk.io/tools/rosetta v0.1.0 h1:rJ0sp9bTuGzava+C2b0MFaci/zhINdxSOiJE1FC/UJw=
|
||||
cosmossdk.io/tools/rosetta v0.1.0/go.mod h1:9wDBVqKC7BDJjk+RWvoE4VXs3Ub/i5rLBrieKpoH+Zw=
|
||||
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
|
||||
filippo.io/edwards25519 v1.0.0-rc.1 h1:m0VOOB23frXZvAOK44usCgLWvtsxIoMCTBGJZlpmGfU=
|
||||
filippo.io/edwards25519 v1.0.0-rc.1/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns=
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
package sims
|
||||
|
||||
import (
|
||||
"context"
|
||||
"math/rand"
|
||||
"testing"
|
||||
"time"
|
||||
@ -62,8 +61,9 @@ func GenSignedMockTx(r *rand.Rand, txConfig client.TxConfig, msgs []sdk.Msg, fee
|
||||
Sequence: accSeqs[i],
|
||||
PubKey: p.PubKey(),
|
||||
}
|
||||
// When Textual is wired up, the context argument should be retrieved from the client context.
|
||||
signBytes, err := txConfig.SignModeHandler().GetSignBytes(context.TODO(), signMode, signerData, tx.GetTx())
|
||||
// When Textual is wired up, use GetSignBytesWithContext
|
||||
// ref: https://github.com/cosmos/cosmos-sdk/issues/13747
|
||||
signBytes, err := txConfig.SignModeHandler().GetSignBytes(signMode, signerData, tx.GetTx())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
@ -2,7 +2,6 @@ package rosetta
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"reflect"
|
||||
@ -115,7 +114,7 @@ func NewConverter(cdc *codec.ProtoCodec, ir codectypes.InterfaceRegistry, cfg sd
|
||||
txDecode: cfg.TxDecoder(),
|
||||
txEncode: cfg.TxEncoder(),
|
||||
bytesToSign: func(tx authsigning.Tx, signerData authsigning.SignerData) (b []byte, err error) {
|
||||
bytesToSign, err := cfg.SignModeHandler().GetSignBytes(context.TODO(), signing.SignMode_SIGN_MODE_LEGACY_AMINO_JSON, signerData, tx)
|
||||
bytesToSign, err := cfg.SignModeHandler().GetSignBytes(signing.SignMode_SIGN_MODE_LEGACY_AMINO_JSON, signerData, tx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@ -232,7 +232,7 @@ func genTxWithFeeGranter(gen client.TxConfig, msgs []sdk.Msg, feeAmt sdk.Coins,
|
||||
AccountNumber: accNums[i],
|
||||
Sequence: accSeqs[i],
|
||||
}
|
||||
signBytes, err := gen.SignModeHandler().GetSignBytes(nil, signMode, signerData, tx.GetTx())
|
||||
signBytes, err := gen.SignModeHandler().GetSignBytes(signMode, signerData, tx.GetTx())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
package legacytx
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
@ -33,7 +32,7 @@ func (stdTxSignModeHandler) Modes() []signingtypes.SignMode {
|
||||
}
|
||||
|
||||
// DefaultMode implements SignModeHandler.GetSignBytes
|
||||
func (stdTxSignModeHandler) GetSignBytes(_ context.Context, mode signingtypes.SignMode, data signing.SignerData, tx sdk.Tx) ([]byte, error) {
|
||||
func (stdTxSignModeHandler) GetSignBytes(mode signingtypes.SignMode, data signing.SignerData, tx sdk.Tx) ([]byte, error) {
|
||||
if mode != signingtypes.SignMode_SIGN_MODE_LEGACY_AMINO_JSON {
|
||||
return nil, fmt.Errorf("expected %s, got %s", signingtypes.SignMode_SIGN_MODE_LEGACY_AMINO_JSON, mode)
|
||||
}
|
||||
|
||||
@ -52,7 +52,7 @@ func TestLegacyAminoJSONHandler_GetSignBytes(t *testing.T) {
|
||||
Sequence: seqNum,
|
||||
PubKey: priv1.PubKey(),
|
||||
}
|
||||
signBz, err := handler.GetSignBytes(nil, signingtypes.SignMode_SIGN_MODE_LEGACY_AMINO_JSON, signingData, tx)
|
||||
signBz, err := handler.GetSignBytes(signingtypes.SignMode_SIGN_MODE_LEGACY_AMINO_JSON, signingData, tx)
|
||||
require.NoError(t, err)
|
||||
|
||||
expectedSignBz := StdSignBytes(chainId, accNum, seqNum, timeoutHeight, fee, msgs, memo, nil)
|
||||
@ -60,7 +60,7 @@ func TestLegacyAminoJSONHandler_GetSignBytes(t *testing.T) {
|
||||
require.Equal(t, expectedSignBz, signBz)
|
||||
|
||||
// expect error with wrong sign mode
|
||||
_, err = handler.GetSignBytes(nil, signingtypes.SignMode_SIGN_MODE_DIRECT, signingData, tx)
|
||||
_, err = handler.GetSignBytes(signingtypes.SignMode_SIGN_MODE_DIRECT, signingData, tx)
|
||||
require.Error(t, err)
|
||||
}
|
||||
|
||||
|
||||
@ -51,11 +51,28 @@ func (h SignModeHandlerMap) Modes() []signing.SignMode {
|
||||
return h.modes
|
||||
}
|
||||
|
||||
// DefaultMode implements SignModeHandler.GetSignBytes
|
||||
func (h SignModeHandlerMap) GetSignBytes(ctx context.Context, mode signing.SignMode, data SignerData, tx sdk.Tx) ([]byte, error) {
|
||||
// GetSignBytes implements SignModeHandler.GetSignBytes
|
||||
func (h SignModeHandlerMap) GetSignBytes(mode signing.SignMode, data SignerData, tx sdk.Tx) ([]byte, error) {
|
||||
handler, found := h.signModeHandlers[mode]
|
||||
if !found {
|
||||
return nil, fmt.Errorf("can't verify sign mode %s", mode.String())
|
||||
}
|
||||
return handler.GetSignBytes(ctx, mode, data, tx)
|
||||
return handler.GetSignBytes(mode, data, tx)
|
||||
}
|
||||
|
||||
// GetSignBytesWithContext implements SignModeHandler.GetSignBytesWithContext
|
||||
func (h SignModeHandlerMap) GetSignBytesWithContext(ctx context.Context, mode signing.SignMode, data SignerData, tx sdk.Tx) ([]byte, error) {
|
||||
handler, found := h.signModeHandlers[mode]
|
||||
if !found {
|
||||
return nil, fmt.Errorf("can't verify sign mode %s", mode.String())
|
||||
}
|
||||
|
||||
handlerWithContext, ok := handler.(SignModeHandlerWithContext)
|
||||
if ok {
|
||||
return handlerWithContext.GetSignBytesWithContext(ctx, mode, data, tx)
|
||||
}
|
||||
|
||||
// Default to stateless GetSignBytes if the underlying handler does not
|
||||
// implement WithContext.
|
||||
return handler.GetSignBytes(mode, data, tx)
|
||||
}
|
||||
|
||||
@ -66,16 +66,16 @@ func TestHandlerMap_GetSignBytes(t *testing.T) {
|
||||
Sequence: seqNum,
|
||||
PubKey: priv1.PubKey(),
|
||||
}
|
||||
signBz, err := handler.GetSignBytes(nil, signingtypes.SignMode_SIGN_MODE_LEGACY_AMINO_JSON, signingData, tx)
|
||||
signBz, err := handler.GetSignBytes(signingtypes.SignMode_SIGN_MODE_LEGACY_AMINO_JSON, signingData, tx)
|
||||
require.NoError(t, err)
|
||||
|
||||
expectedSignBz, err := aminoJSONHandler.GetSignBytes(nil, signingtypes.SignMode_SIGN_MODE_LEGACY_AMINO_JSON, signingData, tx)
|
||||
expectedSignBz, err := aminoJSONHandler.GetSignBytes(signingtypes.SignMode_SIGN_MODE_LEGACY_AMINO_JSON, signingData, tx)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Equal(t, expectedSignBz, signBz)
|
||||
|
||||
// expect error with wrong sign mode
|
||||
_, err = aminoJSONHandler.GetSignBytes(nil, signingtypes.SignMode_SIGN_MODE_DIRECT, signingData, tx)
|
||||
_, err = aminoJSONHandler.GetSignBytes(signingtypes.SignMode_SIGN_MODE_DIRECT, signingData, tx)
|
||||
require.Error(t, err)
|
||||
}
|
||||
|
||||
|
||||
@ -20,7 +20,21 @@ type SignModeHandler interface {
|
||||
|
||||
// GetSignBytes returns the sign bytes for the provided SignMode, SignerData and Tx,
|
||||
// or an error
|
||||
GetSignBytes(ctx context.Context, mode signing.SignMode, data SignerData, tx sdk.Tx) ([]byte, error)
|
||||
GetSignBytes(mode signing.SignMode, data SignerData, tx sdk.Tx) ([]byte, error)
|
||||
}
|
||||
|
||||
// SignModeHandlerWithContext is like SignModeHandler, with a new GetSignBytes
|
||||
// method which takes an additional context.Context argument, to be used to
|
||||
// access state. Consumers should preferably type-cast to this interface and
|
||||
// pass in the context.Context arg, and default to SignModeHandler otherwise.
|
||||
// This interface is created for backwards compatibility, and will be
|
||||
// deleted once SDK versions <v0.47 are not supported anymore.
|
||||
type SignModeHandlerWithContext interface {
|
||||
SignModeHandler
|
||||
|
||||
// GetSignBytes returns the sign bytes for the provided SignMode, SignerData and Tx,
|
||||
// or an error
|
||||
GetSignBytesWithContext(ctx context.Context, mode signing.SignMode, data SignerData, tx sdk.Tx) ([]byte, error)
|
||||
}
|
||||
|
||||
// SignerData is the specific information needed to sign a transaction that generally
|
||||
|
||||
@ -15,7 +15,7 @@ import (
|
||||
func VerifySignature(ctx context.Context, pubKey cryptotypes.PubKey, signerData SignerData, sigData signing.SignatureData, handler SignModeHandler, tx sdk.Tx) error {
|
||||
switch data := sigData.(type) {
|
||||
case *signing.SingleSignatureData:
|
||||
signBytes, err := handler.GetSignBytes(ctx, data.SignMode, signerData, tx)
|
||||
signBytes, err := GetSignBytesWithContext(handler, ctx, data.SignMode, signerData, tx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -30,7 +30,12 @@ func VerifySignature(ctx context.Context, pubKey cryptotypes.PubKey, signerData
|
||||
return fmt.Errorf("expected %T, got %T", (multisig.PubKey)(nil), pubKey)
|
||||
}
|
||||
err := multiPK.VerifyMultisignature(func(mode signing.SignMode) ([]byte, error) {
|
||||
return handler.GetSignBytes(ctx, mode, signerData, tx)
|
||||
handlerWithContext, ok := handler.(SignModeHandlerWithContext)
|
||||
if ok {
|
||||
return handlerWithContext.GetSignBytesWithContext(ctx, mode, signerData, tx)
|
||||
} else {
|
||||
return handler.GetSignBytes(mode, signerData, tx)
|
||||
}
|
||||
}, data)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -40,3 +45,16 @@ func VerifySignature(ctx context.Context, pubKey cryptotypes.PubKey, signerData
|
||||
return fmt.Errorf("unexpected SignatureData %T", sigData)
|
||||
}
|
||||
}
|
||||
|
||||
// GetSignBytesWithContext gets the sign bytes from the sign mode handler. It
|
||||
// checks if the sign mode handler supports SignModeHandlerWithContext, in
|
||||
// which case it passes the context.Context argument. Otherwise, it fallbacks
|
||||
// to GetSignBytes.
|
||||
func GetSignBytesWithContext(h SignModeHandler, ctx context.Context, mode signing.SignMode, data SignerData, tx sdk.Tx) ([]byte, error) {
|
||||
hWithCtx, ok := h.(SignModeHandlerWithContext)
|
||||
if ok {
|
||||
return hWithCtx.GetSignBytesWithContext(ctx, mode, data, tx)
|
||||
} else {
|
||||
return h.GetSignBytes(mode, data, tx)
|
||||
}
|
||||
}
|
||||
|
||||
@ -141,7 +141,7 @@ func TestBuilderWithAux(t *testing.T) {
|
||||
Sequence: 15,
|
||||
})
|
||||
signBz, err = txConfig.SignModeHandler().GetSignBytes(
|
||||
nil, signing.SignMode_SIGN_MODE_DIRECT,
|
||||
signing.SignMode_SIGN_MODE_DIRECT,
|
||||
authsigning.SignerData{
|
||||
Address: feepayerAddr.String(),
|
||||
ChainID: chainID,
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
package tx
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
signingtypes "github.com/cosmos/cosmos-sdk/types/tx/signing"
|
||||
@ -27,7 +26,7 @@ func (signModeDirectHandler) Modes() []signingtypes.SignMode {
|
||||
}
|
||||
|
||||
// GetSignBytes implements SignModeHandler.GetSignBytes
|
||||
func (signModeDirectHandler) GetSignBytes(_ context.Context, mode signingtypes.SignMode, data signing.SignerData, tx sdk.Tx) ([]byte, error) {
|
||||
func (signModeDirectHandler) GetSignBytes(mode signingtypes.SignMode, data signing.SignerData, tx sdk.Tx) ([]byte, error) {
|
||||
if mode != signingtypes.SignMode_SIGN_MODE_DIRECT {
|
||||
return nil, fmt.Errorf("expected %s, got %s", signingtypes.SignMode_SIGN_MODE_DIRECT, mode)
|
||||
}
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
package tx
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
|
||||
@ -29,7 +28,7 @@ func (signModeDirectAuxHandler) Modes() []signingtypes.SignMode {
|
||||
|
||||
// GetSignBytes implements SignModeHandler.GetSignBytes
|
||||
func (signModeDirectAuxHandler) GetSignBytes(
|
||||
_ context.Context, mode signingtypes.SignMode, data signing.SignerData, tx sdk.Tx,
|
||||
mode signingtypes.SignMode, data signing.SignerData, tx sdk.Tx,
|
||||
) ([]byte, error) {
|
||||
if mode != signingtypes.SignMode_SIGN_MODE_DIRECT_AUX {
|
||||
return nil, fmt.Errorf("expected %s, got %s", signingtypes.SignMode_SIGN_MODE_DIRECT_AUX, mode)
|
||||
|
||||
@ -80,11 +80,11 @@ func TestDirectAuxHandler(t *testing.T) {
|
||||
modeHandler := signModeDirectAuxHandler{}
|
||||
|
||||
t.Log("verify fee payer cannot use SIGN_MODE_DIRECT_AUX")
|
||||
_, err = modeHandler.GetSignBytes(nil, signingtypes.SignMode_SIGN_MODE_DIRECT_AUX, feePayerSigningData, txBuilder.GetTx())
|
||||
_, err = modeHandler.GetSignBytes(signingtypes.SignMode_SIGN_MODE_DIRECT_AUX, feePayerSigningData, txBuilder.GetTx())
|
||||
require.EqualError(t, err, fmt.Sprintf("fee payer %s cannot sign with %s: unauthorized", feePayerAddr.String(), signingtypes.SignMode_SIGN_MODE_DIRECT_AUX))
|
||||
|
||||
t.Log("verify GetSignBytes with generating sign bytes by marshaling signDocDirectAux")
|
||||
signBytes, err := modeHandler.GetSignBytes(nil, signingtypes.SignMode_SIGN_MODE_DIRECT_AUX, signingData, txBuilder.GetTx())
|
||||
signBytes, err := modeHandler.GetSignBytes(signingtypes.SignMode_SIGN_MODE_DIRECT_AUX, signingData, txBuilder.GetTx())
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, signBytes)
|
||||
|
||||
@ -121,7 +121,7 @@ func TestDirectAuxHandler(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
err = txBuilder.SetSignatures(sig)
|
||||
require.NoError(t, err)
|
||||
signBytes, err = modeHandler.GetSignBytes(nil, signingtypes.SignMode_SIGN_MODE_DIRECT_AUX, signingData, txBuilder.GetTx())
|
||||
signBytes, err = modeHandler.GetSignBytes(signingtypes.SignMode_SIGN_MODE_DIRECT_AUX, signingData, txBuilder.GetTx())
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, expectedSignBytes, signBytes)
|
||||
|
||||
@ -148,7 +148,7 @@ func TestDirectAuxModeHandler_nonDIRECT_MODE(t *testing.T) {
|
||||
t.Run(invalidMode.String(), func(t *testing.T) {
|
||||
var dh signModeDirectAuxHandler
|
||||
var signingData signing.SignerData
|
||||
_, err := dh.GetSignBytes(nil, invalidMode, signingData, nil)
|
||||
_, err := dh.GetSignBytes(invalidMode, signingData, nil)
|
||||
require.Error(t, err)
|
||||
wantErr := fmt.Errorf("expected %s, got %s", signingtypes.SignMode_SIGN_MODE_DIRECT_AUX, invalidMode)
|
||||
require.Equal(t, err, wantErr)
|
||||
@ -160,7 +160,7 @@ func TestDirectAuxModeHandler_nonProtoTx(t *testing.T) {
|
||||
var dh signModeDirectAuxHandler
|
||||
var signingData signing.SignerData
|
||||
tx := new(nonProtoTx)
|
||||
_, err := dh.GetSignBytes(nil, signingtypes.SignMode_SIGN_MODE_DIRECT_AUX, signingData, tx)
|
||||
_, err := dh.GetSignBytes(signingtypes.SignMode_SIGN_MODE_DIRECT_AUX, signingData, tx)
|
||||
require.Error(t, err)
|
||||
wantErr := fmt.Errorf("can only handle a protobuf Tx, got %T", tx)
|
||||
require.Equal(t, err, wantErr)
|
||||
|
||||
@ -75,7 +75,7 @@ func TestDirectModeHandler(t *testing.T) {
|
||||
PubKey: pubkey,
|
||||
}
|
||||
|
||||
signBytes, err := modeHandler.GetSignBytes(nil, signingtypes.SignMode_SIGN_MODE_DIRECT, signingData, txBuilder.GetTx())
|
||||
signBytes, err := modeHandler.GetSignBytes(signingtypes.SignMode_SIGN_MODE_DIRECT, signingData, txBuilder.GetTx())
|
||||
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, signBytes)
|
||||
@ -120,7 +120,7 @@ func TestDirectModeHandler(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
err = txBuilder.SetSignatures(sig)
|
||||
require.NoError(t, err)
|
||||
signBytes, err = modeHandler.GetSignBytes(nil, signingtypes.SignMode_SIGN_MODE_DIRECT, signingData, txBuilder.GetTx())
|
||||
signBytes, err = modeHandler.GetSignBytes(signingtypes.SignMode_SIGN_MODE_DIRECT, signingData, txBuilder.GetTx())
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, expectedSignBytes, signBytes)
|
||||
|
||||
@ -141,7 +141,7 @@ func TestDirectModeHandler_nonDIRECT_MODE(t *testing.T) {
|
||||
t.Run(invalidMode.String(), func(t *testing.T) {
|
||||
var dh signModeDirectHandler
|
||||
var signingData signing.SignerData
|
||||
_, err := dh.GetSignBytes(nil, invalidMode, signingData, nil)
|
||||
_, err := dh.GetSignBytes(invalidMode, signingData, nil)
|
||||
require.Error(t, err)
|
||||
wantErr := fmt.Errorf("expected %s, got %s", signingtypes.SignMode_SIGN_MODE_DIRECT, invalidMode)
|
||||
require.Equal(t, err, wantErr)
|
||||
@ -160,7 +160,7 @@ func TestDirectModeHandler_nonProtoTx(t *testing.T) {
|
||||
var dh signModeDirectHandler
|
||||
var signingData signing.SignerData
|
||||
tx := new(nonProtoTx)
|
||||
_, err := dh.GetSignBytes(nil, signingtypes.SignMode_SIGN_MODE_DIRECT, signingData, tx)
|
||||
_, err := dh.GetSignBytes(signingtypes.SignMode_SIGN_MODE_DIRECT, signingData, tx)
|
||||
require.Error(t, err)
|
||||
wantErr := fmt.Errorf("can only handle a protobuf Tx, got %T", tx)
|
||||
require.Equal(t, err, wantErr)
|
||||
|
||||
@ -128,7 +128,7 @@ func TestUnknownFields(t *testing.T) {
|
||||
decoder := DefaultTxDecoder(codec.NewProtoCodec(codectypes.NewInterfaceRegistry()))
|
||||
theTx, err := decoder(txBz)
|
||||
require.NoError(t, err)
|
||||
_, err = handler.GetSignBytes(nil, signingtypes.SignMode_SIGN_MODE_LEGACY_AMINO_JSON, signing.SignerData{}, theTx)
|
||||
_, err = handler.GetSignBytes(signingtypes.SignMode_SIGN_MODE_LEGACY_AMINO_JSON, signing.SignerData{}, theTx)
|
||||
require.EqualError(t, err, tt.shouldAminoErr)
|
||||
}
|
||||
})
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
package tx
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
@ -27,7 +26,7 @@ func (s signModeLegacyAminoJSONHandler) Modes() []signingtypes.SignMode {
|
||||
return []signingtypes.SignMode{signingtypes.SignMode_SIGN_MODE_LEGACY_AMINO_JSON}
|
||||
}
|
||||
|
||||
func (s signModeLegacyAminoJSONHandler) GetSignBytes(_ context.Context, mode signingtypes.SignMode, data signing.SignerData, tx sdk.Tx) ([]byte, error) {
|
||||
func (s signModeLegacyAminoJSONHandler) GetSignBytes(mode signingtypes.SignMode, data signing.SignerData, tx sdk.Tx) ([]byte, error) {
|
||||
if mode != signingtypes.SignMode_SIGN_MODE_LEGACY_AMINO_JSON {
|
||||
return nil, fmt.Errorf("expected %s, got %s", signingtypes.SignMode_SIGN_MODE_LEGACY_AMINO_JSON, mode)
|
||||
}
|
||||
|
||||
@ -97,7 +97,7 @@ func TestLegacyAminoJSONHandler_GetSignBytes(t *testing.T) {
|
||||
AccountNumber: accNum,
|
||||
Sequence: seqNum,
|
||||
}
|
||||
signBz, err := handler.GetSignBytes(nil, signingtypes.SignMode_SIGN_MODE_LEGACY_AMINO_JSON, signingData, tx)
|
||||
signBz, err := handler.GetSignBytes(signingtypes.SignMode_SIGN_MODE_LEGACY_AMINO_JSON, signingData, tx)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Equal(t, tc.expectedSignBz, signBz)
|
||||
@ -116,7 +116,7 @@ func TestLegacyAminoJSONHandler_GetSignBytes(t *testing.T) {
|
||||
}
|
||||
|
||||
// expect error with wrong sign mode
|
||||
_, err := handler.GetSignBytes(nil, signingtypes.SignMode_SIGN_MODE_DIRECT, signingData, tx)
|
||||
_, err := handler.GetSignBytes(signingtypes.SignMode_SIGN_MODE_DIRECT, signingData, tx)
|
||||
require.Error(t, err)
|
||||
|
||||
// expect error with extension options
|
||||
@ -126,7 +126,7 @@ func TestLegacyAminoJSONHandler_GetSignBytes(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
bldr.tx.Body.ExtensionOptions = []*cdctypes.Any{any}
|
||||
tx = bldr.GetTx()
|
||||
_, err = handler.GetSignBytes(nil, signingtypes.SignMode_SIGN_MODE_LEGACY_AMINO_JSON, signingData, tx)
|
||||
_, err = handler.GetSignBytes(signingtypes.SignMode_SIGN_MODE_LEGACY_AMINO_JSON, signingData, tx)
|
||||
require.Error(t, err)
|
||||
|
||||
// expect error with non-critical extension options
|
||||
@ -134,7 +134,7 @@ func TestLegacyAminoJSONHandler_GetSignBytes(t *testing.T) {
|
||||
buildTx(t, bldr)
|
||||
bldr.tx.Body.NonCriticalExtensionOptions = []*cdctypes.Any{any}
|
||||
tx = bldr.GetTx()
|
||||
_, err = handler.GetSignBytes(nil, signingtypes.SignMode_SIGN_MODE_LEGACY_AMINO_JSON, signingData, tx)
|
||||
_, err = handler.GetSignBytes(signingtypes.SignMode_SIGN_MODE_LEGACY_AMINO_JSON, signingData, tx)
|
||||
require.Error(t, err)
|
||||
}
|
||||
|
||||
|
||||
@ -2,7 +2,6 @@ package tx
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
||||
@ -135,7 +134,7 @@ func (s *TxConfigTestSuite) TestTxBuilderSetSignatures() {
|
||||
Sequence: seq1,
|
||||
PubKey: pubkey,
|
||||
}
|
||||
signBytes, err := signModeHandler.GetSignBytes(context.TODO(), signModeHandler.DefaultMode(), signerData, sigTx)
|
||||
signBytes, err := signModeHandler.GetSignBytes(signModeHandler.DefaultMode(), signerData, sigTx)
|
||||
s.Require().NoError(err)
|
||||
sigBz, err := privKey.Sign(signBytes)
|
||||
s.Require().NoError(err)
|
||||
@ -147,7 +146,7 @@ func (s *TxConfigTestSuite) TestTxBuilderSetSignatures() {
|
||||
Sequence: mseq,
|
||||
PubKey: multisigPk,
|
||||
}
|
||||
mSignBytes, err := signModeHandler.GetSignBytes(context.TODO(), signModeHandler.DefaultMode(), signerData, sigTx)
|
||||
mSignBytes, err := signModeHandler.GetSignBytes(signModeHandler.DefaultMode(), signerData, sigTx)
|
||||
s.Require().NoError(err)
|
||||
mSigBz1, err := privKey.Sign(mSignBytes)
|
||||
s.Require().NoError(err)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user