<!-- The default pull request template is for types feat, fix, or refactor. For other templates, add one of the following parameters to the url: - template=docs.md - template=other.md --> ## Description Revert #10268 As part of the TX working group, we decided not to introduce a new sign mode for tipper signing. The tipper will use amino-json to sign via ledger (see #10346). Also, add `signing.SignerData#Address` (will be used in subsequent PR #10346) <!-- Add a description of the changes that this PR introduces and the files that are the most critical to review. --> --- ### Author Checklist *All items are required. Please add a note to the item if the item is not applicable and please add links to any relevant follow up issues.* I have... - [ ] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] added `!` to the type prefix if API or client breaking change - [ ] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting)) - [ ] provided a link to the relevant issue or specification - [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules) - [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing) - [ ] added a changelog entry to `CHANGELOG.md` - [ ] included comments for [documenting Go code](https://blog.golang.org/godoc) - [ ] updated the relevant documentation or specification - [ ] reviewed "Files changed" and left comments if necessary - [ ] confirmed all CI checks have passed ### Reviewers Checklist *All items are required. Please add a note if the item is not applicable and please add your handle next to the items reviewed if you only reviewed selected items.* I have... - [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] confirmed `!` in the type prefix if API or client breaking change - [ ] confirmed all author checklist items have been addressed - [ ] reviewed state machine logic - [ ] reviewed API design and naming - [ ] reviewed documentation is accurate - [ ] reviewed tests and test coverage - [ ] manually tested (if applicable)
93 lines
2.4 KiB
Go
93 lines
2.4 KiB
Go
package signing_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
signingtypes "github.com/cosmos/cosmos-sdk/types/tx/signing"
|
|
"github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx"
|
|
"github.com/cosmos/cosmos-sdk/x/auth/signing"
|
|
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
|
|
)
|
|
|
|
func MakeTestHandlerMap() signing.SignModeHandler {
|
|
return signing.NewSignModeHandlerMap(
|
|
signingtypes.SignMode_SIGN_MODE_LEGACY_AMINO_JSON,
|
|
[]signing.SignModeHandler{
|
|
legacytx.NewStdTxSignModeHandler(),
|
|
},
|
|
)
|
|
}
|
|
|
|
func TestHandlerMap_GetSignBytes(t *testing.T) {
|
|
priv1 := secp256k1.GenPrivKey()
|
|
addr1 := sdk.AccAddress(priv1.PubKey().Address())
|
|
priv2 := secp256k1.GenPrivKey()
|
|
addr2 := sdk.AccAddress(priv2.PubKey().Address())
|
|
|
|
coins := sdk.Coins{sdk.NewInt64Coin("foocoin", 10)}
|
|
|
|
fee := legacytx.StdFee{
|
|
Amount: coins,
|
|
Gas: 10000,
|
|
}
|
|
memo := "foo"
|
|
msgs := []sdk.Msg{
|
|
&banktypes.MsgSend{
|
|
FromAddress: addr1.String(),
|
|
ToAddress: addr2.String(),
|
|
Amount: coins,
|
|
},
|
|
}
|
|
|
|
tx := legacytx.StdTx{
|
|
Msgs: msgs,
|
|
Fee: fee,
|
|
Signatures: nil,
|
|
Memo: memo,
|
|
}
|
|
|
|
var (
|
|
chainId = "test-chain"
|
|
accNum uint64 = 7
|
|
seqNum uint64 = 7
|
|
)
|
|
|
|
handler := MakeTestHandlerMap()
|
|
aminoJSONHandler := legacytx.NewStdTxSignModeHandler()
|
|
|
|
signingData := signing.SignerData{
|
|
Address: addr1.String(),
|
|
ChainID: chainId,
|
|
AccountNumber: accNum,
|
|
Sequence: seqNum,
|
|
SignerIndex: 0,
|
|
}
|
|
signBz, err := handler.GetSignBytes(signingtypes.SignMode_SIGN_MODE_LEGACY_AMINO_JSON, signingData, tx)
|
|
require.NoError(t, err)
|
|
|
|
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(signingtypes.SignMode_SIGN_MODE_DIRECT, signingData, tx)
|
|
require.Error(t, err)
|
|
}
|
|
|
|
func TestHandlerMap_DefaultMode(t *testing.T) {
|
|
handler := MakeTestHandlerMap()
|
|
require.Equal(t, signingtypes.SignMode_SIGN_MODE_LEGACY_AMINO_JSON, handler.DefaultMode())
|
|
}
|
|
|
|
func TestHandlerMap_Modes(t *testing.T) {
|
|
handler := MakeTestHandlerMap()
|
|
modes := handler.Modes()
|
|
require.Contains(t, modes, signingtypes.SignMode_SIGN_MODE_LEGACY_AMINO_JSON)
|
|
require.Len(t, modes, 1)
|
|
}
|