2019-02-11 09:02:47 -08:00
|
|
|
package keys
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/hex"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/tendermint/tendermint/crypto/secp256k1"
|
2019-03-01 13:29:33 -08:00
|
|
|
|
|
|
|
"github.com/cosmos/cosmos-sdk/crypto/keys/hd"
|
|
|
|
"github.com/cosmos/cosmos-sdk/types"
|
2020-01-09 06:04:28 -08:00
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
2019-02-11 09:02:47 -08:00
|
|
|
)
|
|
|
|
|
|
|
|
func Test_writeReadLedgerInfo(t *testing.T) {
|
|
|
|
var tmpKey secp256k1.PubKeySecp256k1
|
|
|
|
bz, _ := hex.DecodeString("035AD6810A47F073553FF30D2FCC7E0D3B1C0B74B61A1AAA2582344037151E143A")
|
|
|
|
copy(tmpKey[:], bz)
|
|
|
|
|
2020-01-14 07:40:10 -08:00
|
|
|
lInfo := newLedgerInfo("some_name", tmpKey, *hd.NewFundraiserParams(5, types.CoinType, 1), Secp256k1)
|
2019-02-11 09:02:47 -08:00
|
|
|
assert.Equal(t, TypeLedger, lInfo.GetType())
|
2019-02-25 03:34:39 -08:00
|
|
|
|
|
|
|
path, err := lInfo.GetPath()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, "44'/118'/5'/0/1", path.String())
|
2019-02-11 09:02:47 -08:00
|
|
|
assert.Equal(t,
|
|
|
|
"cosmospub1addwnpepqddddqg2glc8x4fl7vxjlnr7p5a3czm5kcdp4239sg6yqdc4rc2r5wmxv8p",
|
2020-01-09 06:04:28 -08:00
|
|
|
types.MustBech32ifyPubKey(sdk.Bech32PubKeyTypeAccPub, lInfo.GetPubKey()))
|
2019-02-11 09:02:47 -08:00
|
|
|
|
|
|
|
// Serialize and restore
|
2019-09-21 09:54:14 -07:00
|
|
|
serialized := marshalInfo(lInfo)
|
|
|
|
restoredInfo, err := unmarshalInfo(serialized)
|
2019-02-11 09:02:47 -08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NotNil(t, restoredInfo)
|
|
|
|
|
|
|
|
// Check both keys match
|
|
|
|
assert.Equal(t, lInfo.GetName(), restoredInfo.GetName())
|
|
|
|
assert.Equal(t, lInfo.GetType(), restoredInfo.GetType())
|
|
|
|
assert.Equal(t, lInfo.GetPubKey(), restoredInfo.GetPubKey())
|
|
|
|
|
2019-02-25 03:34:39 -08:00
|
|
|
restoredPath, err := restoredInfo.GetPath()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
assert.Equal(t, path, restoredPath)
|
2019-02-11 09:02:47 -08:00
|
|
|
}
|