Drop on-disk keybase in favor of keyring (#164)

* Port to new keyring

* modify add-genesis-account to use keyring

* Adapt lcd tests to use keyring

* Attempt to fix localnet ci job

* Revert "Attempt to fix localnet ci job"

This reverts commit c299dd9ffb2a77a1f3b9b33bb71ef104261ed1fc.

* Try pass env var to docker container

* localnet does need COSMOS_SDK_TEST_KEYRING to function properly

* Revert tiny change

* Simplify tests

* Refresh against sdk's respective branch latest commit

* Refresh against sdk branch's latest commit

* Attempt to reduce diff size

* Refresh against latest commit

* Update against latest commit

* Refresh against sdk's latest master

* Avoid create temporary keybase

* Revert "Avoid create temporary keybase"

This reverts commit c3f6d77f373370fea521edabe60c532c676cd9a6.

* Update docs

* Remove unnecessary arguments

* Remove unnecessary arguments

* Code cleanup

* Refresh sdk module, add upgrade module

* Refresh deps

* Fix merge

* Cleanup, AddrSeed does not need Password anymore
This commit is contained in:
Alessio Treglia
2019-11-18 11:34:26 +00:00
committed by Federico Kunze
parent 967fc43f1a
commit 71f3b4f0fc
14 changed files with 191 additions and 220 deletions

View File

@@ -6,14 +6,12 @@ import (
"fmt"
"io/ioutil"
"net/http"
"regexp"
"strings"
"testing"
"github.com/cosmos/cosmos-sdk/client"
clientkeys "github.com/cosmos/cosmos-sdk/client/keys"
"github.com/cosmos/cosmos-sdk/client/rpc"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/crypto/keys"
crkeys "github.com/cosmos/cosmos-sdk/crypto/keys"
sdk "github.com/cosmos/cosmos-sdk/types"
@@ -213,61 +211,6 @@ func doKeysPost(t *testing.T, port, name, password, mnemonic string, account int
return resp
}
// GET /keys/seed Create a new seed to create a new account defaultValidFor
func getKeysSeed(t *testing.T, port string) string {
res, body := Request(t, port, "GET", "/keys/seed", nil)
require.Equal(t, http.StatusOK, res.StatusCode, body)
reg := regexp.MustCompile(`([a-z]+ ){12}`)
match := reg.MatchString(body)
require.True(t, match, "Returned seed has wrong format", body)
return body
}
// POST /keys/{name}/recove Recover a account from a seed
func doRecoverKey(t *testing.T, port, recoverName, recoverPassword, mnemonic string, account uint32, index uint32) {
pk := clientkeys.NewRecoverKey(recoverPassword, mnemonic, int(account), int(index))
req, err := cdc.MarshalJSON(pk)
require.NoError(t, err)
res, body := Request(t, port, "POST", fmt.Sprintf("/keys/%s/recover", recoverName), req)
require.Equal(t, http.StatusOK, res.StatusCode, body)
var resp keys.KeyOutput
err = codec.Cdc.UnmarshalJSON([]byte(body), &resp)
require.Nil(t, err, body)
addr1Bech32 := resp.Address
_, err = sdk.AccAddressFromBech32(addr1Bech32)
require.NoError(t, err, "Failed to return a correct bech32 address")
}
// GET /keys/{name} Get a certain locally stored account
func getKey(t *testing.T, port, name string) keys.KeyOutput {
res, body := Request(t, port, "GET", fmt.Sprintf("/keys/%s", name), nil)
require.Equal(t, http.StatusOK, res.StatusCode, body)
var resp keys.KeyOutput
err := cdc.UnmarshalJSON([]byte(body), &resp)
require.Nil(t, err)
return resp
}
// PUT /keys/{name} Update the password for this account in the KMS
func updateKey(t *testing.T, port, name, oldPassword, newPassword string, fail bool) {
kr := clientkeys.NewUpdateKeyReq(oldPassword, newPassword)
req, err := cdc.MarshalJSON(kr)
require.NoError(t, err)
keyEndpoint := fmt.Sprintf("/keys/%s", name)
res, body := Request(t, port, "PUT", keyEndpoint, req)
if fail {
require.Equal(t, http.StatusUnauthorized, res.StatusCode, body)
return
}
require.Equal(t, http.StatusOK, res.StatusCode, body)
}
// GET /auth/accounts/{address} Get the account information on blockchain
func getAccount(t *testing.T, port string, addr sdk.AccAddress) (acc authexported.Account) {
res, body := Request(t, port, "GET", fmt.Sprintf("/auth/accounts/%s", addr.String()), nil)
@@ -294,12 +237,11 @@ func doBroadcast(t *testing.T, port string, tx auth.StdTx) (*http.Response, stri
// doTransfer performs a balance transfer with auto gas calculation. It also signs
// the tx and broadcasts it.
func doTransfer(
t *testing.T, port, seed, name, memo, pwd string, addr sdk.AccAddress, fees sdk.Coins,
t *testing.T, port, name, memo string, addr sdk.AccAddress, fees sdk.Coins,
kb crkeys.Keybase,
) (sdk.AccAddress, sdk.TxResponse) {
resp, body, recvAddr := doTransferWithGas(
t, port, seed, name, memo, pwd, addr, "", 1.0, false, true, fees,
)
resp, body, recvAddr := doTransferWithGas(t, port, name, memo, addr, "", 1.0, false, true, fees, kb)
require.Equal(t, http.StatusOK, resp.StatusCode, body)
var txResp sdk.TxResponse
@@ -314,14 +256,15 @@ func doTransfer(
// signed and broadcasted. The sending account's number and sequence are
// determined prior to generating the tx.
func doTransferWithGas(
t *testing.T, port, seed, name, memo, pwd string, addr sdk.AccAddress,
t *testing.T, port, name, memo string, addr sdk.AccAddress,
gas string, gasAdjustment float64, simulate, broadcast bool, fees sdk.Coins,
kb crkeys.Keybase,
) (resp *http.Response, body string, receiveAddr sdk.AccAddress) {
// create receive address
kb := crkeys.NewInMemory()
kb2 := crkeys.NewInMemory()
receiveInfo, _, err := kb.CreateMnemonic(
receiveInfo, _, err := kb2.CreateMnemonic(
"receive_address", crkeys.English, client.DefaultKeyPass, crkeys.SigningAlgo("secp256k1"),
)
require.Nil(t, err)
@@ -352,7 +295,7 @@ func doTransferWithGas(
}
// sign and broadcast
resp, body = signAndBroadcastGenTx(t, port, name, pwd, body, acc, gasAdjustment, simulate)
resp, body = signAndBroadcastGenTx(t, port, name, body, acc, gasAdjustment, simulate, kb)
return resp, body, receiveAddr
}
@@ -360,15 +303,16 @@ func doTransferWithGas(
// automatically determines the account's number and sequence when generating the
// tx.
func doTransferWithGasAccAuto(
t *testing.T, port, seed, name, memo, pwd string, addr sdk.AccAddress,
t *testing.T, port, name, memo string, addr sdk.AccAddress,
gas string, gasAdjustment float64, simulate, broadcast bool, fees sdk.Coins,
kb crkeys.Keybase,
) (resp *http.Response, body string, receiveAddr sdk.AccAddress) {
// create receive address
kb := crkeys.NewInMemory()
kb2 := crkeys.NewInMemory()
acc := getAccount(t, port, addr)
receiveInfo, _, err := kb.CreateMnemonic(
receiveInfo, _, err := kb2.CreateMnemonic(
"receive_address", crkeys.English, client.DefaultKeyPass, crkeys.SigningAlgo("secp256k1"),
)
require.Nil(t, err)
@@ -395,14 +339,15 @@ func doTransferWithGasAccAuto(
}
// sign and broadcast
resp, body = signAndBroadcastGenTx(t, port, name, pwd, body, acc, gasAdjustment, simulate)
resp, body = signAndBroadcastGenTx(t, port, name, body, acc, gasAdjustment, simulate, kb)
return resp, body, receiveAddr
}
// signAndBroadcastGenTx accepts a successfully generated unsigned tx, signs it,
// and broadcasts it.
func signAndBroadcastGenTx(
t *testing.T, port, name, pwd, genTx string, acc authexported.Account, gasAdjustment float64, simulate bool,
t *testing.T, port, name, genTx string, acc authexported.Account,
gasAdjustment float64, simulate bool, kb crkeys.Keybase,
) (resp *http.Response, body string) {
chainID := viper.GetString(client.FlagChainID)
@@ -422,9 +367,9 @@ func signAndBroadcastGenTx(
tx.Memo,
tx.Fee.Amount,
nil,
)
).WithKeybase(kb)
signedTx, err := txbldr.SignStdTx(name, pwd, tx, false)
signedTx, err := txbldr.SignStdTx(name, client.DefaultKeyPass, tx, false)
require.NoError(t, err)
return doBroadcast(t, port, signedTx)
@@ -436,8 +381,9 @@ func signAndBroadcastGenTx(
// POST /staking/delegators/{delegatorAddr}/delegations Submit delegation
func doDelegate(
t *testing.T, port, name, pwd string, delAddr sdk.AccAddress,
t *testing.T, port, name string, delAddr sdk.AccAddress,
valAddr sdk.ValAddress, amount sdk.Int, fees sdk.Coins,
kb crkeys.Keybase,
) sdk.TxResponse {
acc := getAccount(t, port, delAddr)
@@ -461,7 +407,7 @@ func doDelegate(
require.Equal(t, http.StatusOK, resp.StatusCode, body)
// sign and broadcast
resp, body = signAndBroadcastGenTx(t, port, name, pwd, body, acc, client.DefaultGasAdjustment, false)
resp, body = signAndBroadcastGenTx(t, port, name, body, acc, client.DefaultGasAdjustment, false, kb)
require.Equal(t, http.StatusOK, resp.StatusCode, body)
var txResp sdk.TxResponse
@@ -473,8 +419,9 @@ func doDelegate(
// POST /staking/delegators/{delegatorAddr}/delegations Submit delegation
func doUndelegate(
t *testing.T, port, name, pwd string, delAddr sdk.AccAddress,
t *testing.T, port, name string, delAddr sdk.AccAddress,
valAddr sdk.ValAddress, amount sdk.Int, fees sdk.Coins,
kb crkeys.Keybase,
) sdk.TxResponse {
acc := getAccount(t, port, delAddr)
@@ -497,7 +444,7 @@ func doUndelegate(
resp, body := Request(t, port, "POST", fmt.Sprintf("/staking/delegators/%s/unbonding_delegations", delAddr), req)
require.Equal(t, http.StatusOK, resp.StatusCode, body)
resp, body = signAndBroadcastGenTx(t, port, name, pwd, body, acc, client.DefaultGasAdjustment, false)
resp, body = signAndBroadcastGenTx(t, port, name, body, acc, client.DefaultGasAdjustment, false, kb)
require.Equal(t, http.StatusOK, resp.StatusCode, body)
var txResp sdk.TxResponse
@@ -509,8 +456,9 @@ func doUndelegate(
// POST /staking/delegators/{delegatorAddr}/delegations Submit delegation
func doBeginRedelegation(
t *testing.T, port, name, pwd string, delAddr sdk.AccAddress, valSrcAddr,
t *testing.T, port, name string, delAddr sdk.AccAddress, valSrcAddr,
valDstAddr sdk.ValAddress, amount sdk.Int, fees sdk.Coins,
kb crkeys.Keybase,
) sdk.TxResponse {
acc := getAccount(t, port, delAddr)
@@ -534,7 +482,7 @@ func doBeginRedelegation(
resp, body := Request(t, port, "POST", fmt.Sprintf("/staking/delegators/%s/redelegations", delAddr), req)
require.Equal(t, http.StatusOK, resp.StatusCode, body)
resp, body = signAndBroadcastGenTx(t, port, name, pwd, body, acc, client.DefaultGasAdjustment, false)
resp, body = signAndBroadcastGenTx(t, port, name, body, acc, client.DefaultGasAdjustment, false, kb)
require.Equal(t, http.StatusOK, resp.StatusCode, body)
var txResp sdk.TxResponse
@@ -722,8 +670,9 @@ func getValidatorUnbondingDelegations(t *testing.T, port string, validatorAddr s
// ----------------------------------------------------------------------
// POST /gov/proposals Submit a proposal
func doSubmitProposal(
t *testing.T, port, seed, name, pwd string, proposerAddr sdk.AccAddress,
t *testing.T, port, name string, proposerAddr sdk.AccAddress,
amount sdk.Int, fees sdk.Coins,
kb crkeys.Keybase,
) sdk.TxResponse {
acc := getAccount(t, port, proposerAddr)
@@ -749,7 +698,7 @@ func doSubmitProposal(
resp, body := Request(t, port, "POST", "/gov/proposals", req)
require.Equal(t, http.StatusOK, resp.StatusCode, body)
resp, body = signAndBroadcastGenTx(t, port, name, pwd, body, acc, client.DefaultGasAdjustment, false)
resp, body = signAndBroadcastGenTx(t, port, name, body, acc, client.DefaultGasAdjustment, false, kb)
require.Equal(t, http.StatusOK, resp.StatusCode, body)
var txResp sdk.TxResponse
@@ -760,8 +709,9 @@ func doSubmitProposal(
}
func doSubmitParamChangeProposal(
t *testing.T, port, seed, name, pwd string, proposerAddr sdk.AccAddress,
t *testing.T, port, name string, proposerAddr sdk.AccAddress,
amount sdk.Int, fees sdk.Coins,
kb crkeys.Keybase,
) sdk.TxResponse {
acc := getAccount(t, port, proposerAddr)
@@ -788,7 +738,7 @@ func doSubmitParamChangeProposal(
resp, body := Request(t, port, "POST", "/gov/proposals/param_change", req)
require.Equal(t, http.StatusOK, resp.StatusCode, body)
resp, body = signAndBroadcastGenTx(t, port, name, pwd, body, acc, client.DefaultGasAdjustment, false)
resp, body = signAndBroadcastGenTx(t, port, name, body, acc, client.DefaultGasAdjustment, false, kb)
require.Equal(t, http.StatusOK, resp.StatusCode, body)
var txResp sdk.TxResponse
@@ -799,8 +749,9 @@ func doSubmitParamChangeProposal(
}
func doSubmitCommunityPoolSpendProposal(
t *testing.T, port, seed, name, pwd string, proposerAddr sdk.AccAddress,
t *testing.T, port, name string, proposerAddr sdk.AccAddress,
amount sdk.Int, fees sdk.Coins,
kb crkeys.Keybase,
) sdk.TxResponse {
acc := getAccount(t, port, proposerAddr)
@@ -826,7 +777,7 @@ func doSubmitCommunityPoolSpendProposal(
resp, body := Request(t, port, "POST", "/gov/proposals/community_pool_spend", req)
require.Equal(t, http.StatusOK, resp.StatusCode, body)
resp, body = signAndBroadcastGenTx(t, port, name, pwd, body, acc, client.DefaultGasAdjustment, false)
resp, body = signAndBroadcastGenTx(t, port, name, body, acc, client.DefaultGasAdjustment, false, kb)
require.Equal(t, http.StatusOK, resp.StatusCode, body)
var txResp sdk.TxResponse
@@ -893,8 +844,9 @@ func getProposalsFilterStatus(t *testing.T, port string, status gov.ProposalStat
// POST /gov/proposals/{proposalId}/deposits Deposit tokens to a proposal
func doDeposit(
t *testing.T, port, seed, name, pwd string, proposerAddr sdk.AccAddress,
t *testing.T, port, name string, proposerAddr sdk.AccAddress,
proposalID uint64, amount sdk.Int, fees sdk.Coins,
kb crkeys.Keybase,
) sdk.TxResponse {
acc := getAccount(t, port, proposerAddr)
@@ -916,7 +868,7 @@ func doDeposit(
resp, body := Request(t, port, "POST", fmt.Sprintf("/gov/proposals/%d/deposits", proposalID), req)
require.Equal(t, http.StatusOK, resp.StatusCode, body)
resp, body = signAndBroadcastGenTx(t, port, name, pwd, body, acc, client.DefaultGasAdjustment, false)
resp, body = signAndBroadcastGenTx(t, port, name, body, acc, client.DefaultGasAdjustment, false, kb)
require.Equal(t, http.StatusOK, resp.StatusCode, body)
var txResp sdk.TxResponse
@@ -950,8 +902,9 @@ func getTally(t *testing.T, port string, proposalID uint64) gov.TallyResult {
// POST /gov/proposals/{proposalId}/votes Vote a proposal
func doVote(
t *testing.T, port, seed, name, pwd string, proposerAddr sdk.AccAddress,
t *testing.T, port, name string, proposerAddr sdk.AccAddress,
proposalID uint64, option string, fees sdk.Coins,
kb crkeys.Keybase,
) sdk.TxResponse {
// get the account to get the sequence
@@ -974,7 +927,7 @@ func doVote(
resp, body := Request(t, port, "POST", fmt.Sprintf("/gov/proposals/%d/votes", proposalID), req)
require.Equal(t, http.StatusOK, resp.StatusCode, body)
resp, body = signAndBroadcastGenTx(t, port, name, pwd, body, acc, client.DefaultGasAdjustment, false)
resp, body = signAndBroadcastGenTx(t, port, name, body, acc, client.DefaultGasAdjustment, false, kb)
require.Equal(t, http.StatusOK, resp.StatusCode, body)
var txResp sdk.TxResponse
@@ -1109,7 +1062,7 @@ func getSigningInfoList(t *testing.T, port string) []slashing.ValidatorSigningIn
// TODO: Test this functionality, it is not currently in any of the tests
// POST /slashing/validators/{validatorAddr}/unjail Unjail a jailed validator
func doUnjail(
t *testing.T, port, seed, name, pwd string, valAddr sdk.ValAddress, fees sdk.Coins,
t *testing.T, port, name string, valAddr sdk.ValAddress, fees sdk.Coins,
) sdk.TxResponse {
acc := getAccount(t, port, sdk.AccAddress(valAddr.Bytes()))
@@ -1126,7 +1079,7 @@ func doUnjail(
resp, body := Request(t, port, "POST", fmt.Sprintf("/slashing/validators/%s/unjail", valAddr.String()), req)
require.Equal(t, http.StatusOK, resp.StatusCode, body)
resp, body = signAndBroadcastGenTx(t, port, name, pwd, body, acc, client.DefaultGasAdjustment, false)
resp, body = signAndBroadcastGenTx(t, port, name, body, acc, client.DefaultGasAdjustment, false, nil)
require.Equal(t, http.StatusOK, resp.StatusCode, body)
var txResp sdk.TxResponse
@@ -1140,7 +1093,7 @@ func doUnjail(
// POST /distribution/delegators/{delgatorAddr}/rewards Withdraw delegator rewards
func doWithdrawDelegatorAllRewards(
t *testing.T, port, seed, name, pwd string, delegatorAddr sdk.AccAddress, fees sdk.Coins,
t *testing.T, port, name string, delegatorAddr sdk.AccAddress, fees sdk.Coins,
) sdk.TxResponse {
// get the account to get the sequence
acc := getAccount(t, port, delegatorAddr)
@@ -1159,7 +1112,7 @@ func doWithdrawDelegatorAllRewards(
resp, body := Request(t, port, "POST", fmt.Sprintf("/distribution/delegators/%s/rewards", delegatorAddr), req)
require.Equal(t, http.StatusOK, resp.StatusCode, body)
resp, body = signAndBroadcastGenTx(t, port, name, pwd, body, acc, client.DefaultGasAdjustment, false)
resp, body = signAndBroadcastGenTx(t, port, name, body, acc, client.DefaultGasAdjustment, false, nil)
require.Equal(t, http.StatusOK, resp.StatusCode, body)
var txResp sdk.TxResponse