Skip to content

Commit

Permalink
Revert "chg: bump deps and skip some tests due to tendermint upgrade"
Browse files Browse the repository at this point in the history
This reverts commit 3f80723.
  • Loading branch information
marcello33 committed Oct 2, 2024
1 parent e0cd9bc commit 023c861
Show file tree
Hide file tree
Showing 13 changed files with 305 additions and 3,638 deletions.
7 changes: 1 addition & 6 deletions client/keys/add_ledger_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build ledger || test_ledger_mock
// +build ledger test_ledger_mock
//+build ledger test_ledger_mock

package keys

Expand All @@ -18,8 +17,6 @@ import (
)

func Test_runAddCmdLedgerWithCustomCoinType(t *testing.T) {
t.Skip("not relevant for this project")

config := sdk.GetConfig()

bech32PrefixAccAddr := "terra"
Expand Down Expand Up @@ -74,8 +71,6 @@ func Test_runAddCmdLedgerWithCustomCoinType(t *testing.T) {
}

func Test_runAddCmdLedger(t *testing.T) {
t.Skip("not relevant for this project")

cmd := addKeyCommand()
assert.NotNil(t, cmd)

Expand Down
2 changes: 0 additions & 2 deletions client/keys/show_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ import (
)

func Test_multiSigKey_Properties(t *testing.T) {
t.Skip("not relevant for this project")

tmpKey1 := secp256k1.GenPrivKeySecp256k1([]byte("mySecret"))
pk := multisig.NewPubKeyMultisigThreshold(1, []crypto.PubKey{tmpKey1.PubKey()})
tmp := keys.NewMultiInfo("myMultisig", pk)
Expand Down
5 changes: 1 addition & 4 deletions crypto/encode_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package crypto

import (
"os"
"testing"

"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -47,7 +48,6 @@ func checkAminoJSON(t *testing.T, src interface{}, dst interface{}, isNil bool)
}

// nolint: vet
/* not relevant for this project
func ExamplePrintRegisteredTypes() {
cdc.PrintTypes(os.Stdout)
// Output: | Type | Name | Prefix | Length | Notes |
Expand All @@ -59,10 +59,8 @@ func ExamplePrintRegisteredTypes() {
//| PrivKeyEd25519 | tendermint/PrivKeyEd25519 | 0xA3288910 | 0x40 | |
//| PrivKeySecp256k1 | tendermint/PrivKeySecp256k1 | 0xE1B0F79B | 0x20 | |
}
*/

func TestKeyEncodings(t *testing.T) {
t.Skip("not relevant for this project")
cases := []struct {
privKey tcrypto.PrivKey
privSize, pubSize int // binary sizes with the amino overhead
Expand Down Expand Up @@ -106,7 +104,6 @@ func TestKeyEncodings(t *testing.T) {
}

func TestNilEncodings(t *testing.T) {
t.Skip("not relevant for this project")

// Check nil Signature.
var a, b []byte
Expand Down
2 changes: 0 additions & 2 deletions crypto/keys/hd/fundraiser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ func initFundraiserTestVectors(t *testing.T) []addrData {
}

func TestFundraiserCompatibility(t *testing.T) {
t.Skip("not relevant for this project")

hdToAddrTable := initFundraiserTestVectors(t)

for i, d := range hdToAddrTable {
Expand Down
3 changes: 1 addition & 2 deletions crypto/keys/keybase_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ func TestCreateLedgerUnsupportedAlgo(t *testing.T) {
}

func TestCreateLedger(t *testing.T) {
t.Skip("not relevant for this project")

kb := NewInMemory()

// test_cover and test_unit will result in different answers
Expand Down Expand Up @@ -276,6 +274,7 @@ func TestExportImport(t *testing.T) {
require.Equal(t, john, john2)
}

//
func TestExportImportPubKey(t *testing.T) {
// make the storage with reasonable defaults
cstore := NewInMemory()
Expand Down
2 changes: 0 additions & 2 deletions crypto/keys/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import (
)

func Test_writeReadLedgerInfo(t *testing.T) {
t.Skip("not relevant for this project")

var tmpKey secp256k1.PubKeySecp256k1
bz, _ := hex.DecodeString("035AD6810A47F073553FF30D2FCC7E0D3B1C0B74B61A1AAA2582344037151E143A")
copy(tmpKey[:], bz)
Expand Down
162 changes: 93 additions & 69 deletions crypto/ledger_mock.go
Original file line number Diff line number Diff line change
@@ -1,94 +1,118 @@
// Code generated by MockGen. DO NOT EDIT.
// Source: crypto/ledger_secp256k1.go
//go:build ledger && test_ledger_mock
// +build ledger,test_ledger_mock

// Package crypto is a generated GoMock package.
package crypto

import (
reflect "reflect"
"fmt"

gomock "github.com/golang/mock/gomock"
"github.com/btcsuite/btcd/btcec/v2"
"github.com/pkg/errors"

secp256k1 "github.com/tendermint/btcd/btcec"
"github.com/tendermint/tendermint/crypto"
tmsecp256k1 "github.com/tendermint/tendermint/crypto/secp256k1"

bip39 "github.com/cosmos/go-bip39"

"github.com/cosmos/cosmos-sdk/crypto/keys/hd"
"github.com/cosmos/cosmos-sdk/tests"
sdk "github.com/cosmos/cosmos-sdk/types"
)

// MockLedgerSECP256K1 is a mock of LedgerSECP256K1 interface.
type MockLedgerSECP256K1 struct {
ctrl *gomock.Controller
recorder *MockLedgerSECP256K1MockRecorder
// If ledger support (build tag) has been enabled, which implies a CGO dependency,
// set the discoverLedger function which is responsible for loading the Ledger
// device at runtime or returning an error.
func init() {
discoverLedger = func() (LedgerSECP256K1, error) {
return LedgerSECP256K1Mock{}, nil
}
}

// MockLedgerSECP256K1MockRecorder is the mock recorder for MockLedgerSECP256K1.
type MockLedgerSECP256K1MockRecorder struct {
mock *MockLedgerSECP256K1
type LedgerSECP256K1Mock struct {
}

// NewMockLedgerSECP256K1 creates a new mock instance.
func NewMockLedgerSECP256K1(ctrl *gomock.Controller) *MockLedgerSECP256K1 {
mock := &MockLedgerSECP256K1{ctrl: ctrl}
mock.recorder = &MockLedgerSECP256K1MockRecorder{mock}
return mock
func (mock LedgerSECP256K1Mock) Close() error {
return nil
}

// EXPECT returns an object that allows the caller to indicate expected use.
func (m *MockLedgerSECP256K1) EXPECT() *MockLedgerSECP256K1MockRecorder {
return m.recorder
}
// GetPublicKeySECP256K1 mocks a ledger device
// as per the original API, it returns an uncompressed key
func (mock LedgerSECP256K1Mock) GetPublicKeySECP256K1(derivationPath []uint32) ([]byte, error) {
if derivationPath[0] != 44 {
return nil, errors.New("Invalid derivation path")
}

// Close mocks base method.
func (m *MockLedgerSECP256K1) Close() error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Close")
ret0, _ := ret[0].(error)
return ret0
}
if derivationPath[1] != sdk.GetConfig().GetCoinType() {
return nil, errors.New("Invalid derivation path")
}

// Close indicates an expected call of Close.
func (mr *MockLedgerSECP256K1MockRecorder) Close() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Close", reflect.TypeOf((*MockLedgerSECP256K1)(nil).Close))
}
seed, err := bip39.NewSeedWithErrorChecking(tests.TestMnemonic, "")
if err != nil {
return nil, err
}

// GetAddressPubKeySECP256K1 mocks base method.
func (m *MockLedgerSECP256K1) GetAddressPubKeySECP256K1(arg0 []uint32, arg1 string) ([]byte, string, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetAddressPubKeySECP256K1", arg0, arg1)
ret0, _ := ret[0].([]byte)
ret1, _ := ret[1].(string)
ret2, _ := ret[2].(error)
return ret0, ret1, ret2
}
path := hd.NewParams(derivationPath[0], derivationPath[1], derivationPath[2], derivationPath[3] != 0, derivationPath[4])
masterPriv, ch := hd.ComputeMastersFromSeed(seed)
derivedPriv, err := hd.DerivePrivateKeyForPath(masterPriv, ch, path.String())
if err != nil {
return nil, err
}

// GetAddressPubKeySECP256K1 indicates an expected call of GetAddressPubKeySECP256K1.
func (mr *MockLedgerSECP256K1MockRecorder) GetAddressPubKeySECP256K1(arg0, arg1 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAddressPubKeySECP256K1", reflect.TypeOf((*MockLedgerSECP256K1)(nil).GetAddressPubKeySECP256K1), arg0, arg1)
}
_, pubkeyObject := secp256k1.PrivKeyFromBytes(secp256k1.S256(), derivedPriv[:])

// GetPublicKeySECP256K1 mocks base method.
func (m *MockLedgerSECP256K1) GetPublicKeySECP256K1(arg0 []uint32) ([]byte, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetPublicKeySECP256K1", arg0)
ret0, _ := ret[0].([]byte)
ret1, _ := ret[1].(error)
return ret0, ret1
return pubkeyObject.SerializeUncompressed(), nil
}

// GetPublicKeySECP256K1 indicates an expected call of GetPublicKeySECP256K1.
func (mr *MockLedgerSECP256K1MockRecorder) GetPublicKeySECP256K1(arg0 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetPublicKeySECP256K1", reflect.TypeOf((*MockLedgerSECP256K1)(nil).GetPublicKeySECP256K1), arg0)
// GetAddressPubKeySECP256K1 mocks a ledger device
// as per the original API, it returns a compressed key and a bech32 address
func (mock LedgerSECP256K1Mock) GetAddressPubKeySECP256K1(derivationPath []uint32, hrp string) ([]byte, string, error) {
pk, err := mock.GetPublicKeySECP256K1(derivationPath)
if err != nil {
return nil, "", err
}

// re-serialize in the 33-byte compressed format
cmp, err := btcec.ParsePubKey(pk[:], btcec.S256())
if err != nil {
return nil, "", fmt.Errorf("error parsing public key: %v", err)
}

var compressedPublicKey tmsecp256k1.PubKeySecp256k1
copy(compressedPublicKey[:], cmp.SerializeCompressed())

// Generate the bech32 addr using existing tmcrypto/etc.
addr := sdk.AccAddress(compressedPublicKey.Address()).String()
return pk, addr, err
}

// SignSECP256K1 mocks base method.
func (m *MockLedgerSECP256K1) SignSECP256K1(arg0 []uint32, arg1 []byte) ([]byte, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "SignSECP256K1", arg0, arg1)
ret0, _ := ret[0].([]byte)
ret1, _ := ret[1].(error)
return ret0, ret1
func (mock LedgerSECP256K1Mock) SignSECP256K1(derivationPath []uint32, message []byte) ([]byte, error) {
path := hd.NewParams(derivationPath[0], derivationPath[1], derivationPath[2], derivationPath[3] != 0, derivationPath[4])
seed, err := bip39.NewSeedWithErrorChecking(tests.TestMnemonic, "")
if err != nil {
return nil, err
}

masterPriv, ch := hd.ComputeMastersFromSeed(seed)
derivedPriv, err := hd.DerivePrivateKeyForPath(masterPriv, ch, path.String())
if err != nil {
return nil, err
}

priv, _ := secp256k1.PrivKeyFromBytes(secp256k1.S256(), derivedPriv[:])

sig, err := priv.Sign(crypto.Sha256(message))
if err != nil {
return nil, err
}

// Need to return DER as the ledger does
sig2 := btcec.Signature{R: sig.R, S: sig.S}
return sig2.Serialize(), nil
}

// SignSECP256K1 indicates an expected call of SignSECP256K1.
func (mr *MockLedgerSECP256K1MockRecorder) SignSECP256K1(arg0, arg1 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SignSECP256K1", reflect.TypeOf((*MockLedgerSECP256K1)(nil).SignSECP256K1), arg0, arg1)
// ShowAddressSECP256K1 shows the address for the corresponding bip32 derivation path
func (mock LedgerSECP256K1Mock) ShowAddressSECP256K1(bip32Path []uint32, hrp string) error {
fmt.Printf("Request to show address for %v at %v", hrp, bip32Path)
return nil
}
11 changes: 0 additions & 11 deletions crypto/ledger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ func TestLedgerErrorHandling(t *testing.T) {
}

func TestPublicKeyUnsafe(t *testing.T) {
t.Skip("not relevant for this project")

path := *hd.NewFundraiserParams(0, sdk.CoinType, 0)
priv, err := NewPrivKeyLedgerSecp256k1Unsafe(path)
require.Nil(t, err, "%s", err)
Expand All @@ -45,8 +43,6 @@ func TestPublicKeyUnsafe(t *testing.T) {
}

func TestPublicKeyUnsafeHDPath(t *testing.T) {
t.Skip("not relevant for this project")

expectedAnswers := []string{
"cosmospub1addwnpepqd87l8xhcnrrtzxnkql7k55ph8fr9jarf4hn6udwukfprlalu8lgw0urza0",
"cosmospub1addwnpepqfsdqjr68h7wjg5wacksmqaypasnra232fkgu5sxdlnlu8j22ztxvlqvd65",
Expand Down Expand Up @@ -102,7 +98,6 @@ func TestPublicKeyUnsafeHDPath(t *testing.T) {
}

func TestPublicKeySafe(t *testing.T) {
t.Skip("not relevant for this project")
path := *hd.NewFundraiserParams(0, sdk.CoinType, 0)
priv, addr, err := NewPrivKeyLedgerSecp256k1(path, "cosmos")

Expand All @@ -126,8 +121,6 @@ func TestPublicKeySafe(t *testing.T) {
}

func TestPublicKeyHDPath(t *testing.T) {
t.Skip("not relevant for this project")

expectedPubKeys := []string{
"cosmospub1addwnpepqd87l8xhcnrrtzxnkql7k55ph8fr9jarf4hn6udwukfprlalu8lgw0urza0",
"cosmospub1addwnpepqfsdqjr68h7wjg5wacksmqaypasnra232fkgu5sxdlnlu8j22ztxvlqvd65",
Expand Down Expand Up @@ -211,8 +204,6 @@ func getFakeTx(accountNumber uint32) []byte {
}

func TestSignaturesHD(t *testing.T) {
t.Skip("not relevant for this project")

for account := uint32(0); account < 100; account += 30 {
msg := getFakeTx(account)

Expand All @@ -232,8 +223,6 @@ func TestSignaturesHD(t *testing.T) {
}

func TestRealLedgerSecp256k1(t *testing.T) {
t.Skip("not relevant for this project")

msg := getFakeTx(50)
path := *hd.NewFundraiserParams(0, sdk.CoinType, 0)
priv, err := NewPrivKeyLedgerSecp256k1Unsafe(path)
Expand Down
Loading

0 comments on commit 023c861

Please sign in to comment.