Merge PR #1575: ready-for-review: sdk.AccAddress natively bech32
This commit is contained in:
@@ -109,7 +109,7 @@ func (ctx CoreContext) queryStore(key cmn.HexBytes, storeName, endPath string) (
|
||||
}
|
||||
|
||||
// Get the from address from the name flag
|
||||
func (ctx CoreContext) GetFromAddress() (from sdk.Address, err error) {
|
||||
func (ctx CoreContext) GetFromAddress() (from sdk.AccAddress, err error) {
|
||||
|
||||
keybase, err := keys.GetKeyBase()
|
||||
if err != nil {
|
||||
@@ -126,7 +126,7 @@ func (ctx CoreContext) GetFromAddress() (from sdk.Address, err error) {
|
||||
return nil, errors.Errorf("no key for: %s", name)
|
||||
}
|
||||
|
||||
return info.GetPubKey().Address(), nil
|
||||
return sdk.AccAddress(info.GetPubKey().Address()), nil
|
||||
}
|
||||
|
||||
// sign and build the transaction from the msg
|
||||
|
||||
+2
-2
@@ -221,14 +221,14 @@ func AddNewKeyRequestHandler(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
keyOutput.Seed = mnemonic
|
||||
|
||||
output, err := json.MarshalIndent(keyOutput, "", " ")
|
||||
bz, err := json.Marshal(keyOutput)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
w.Write([]byte(err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
w.Write(output)
|
||||
w.Write(bz)
|
||||
}
|
||||
|
||||
// function to just a new seed to display in the UI before actually persisting it in the keybase
|
||||
|
||||
+7
-10
@@ -48,11 +48,11 @@ func SetKeyBase(kb keys.Keybase) {
|
||||
|
||||
// used for outputting keys.Info over REST
|
||||
type KeyOutput struct {
|
||||
Name string `json:"name"`
|
||||
Type string `json:"type"`
|
||||
Address string `json:"address"`
|
||||
PubKey string `json:"pub_key"`
|
||||
Seed string `json:"seed,omitempty"`
|
||||
Name string `json:"name"`
|
||||
Type string `json:"type"`
|
||||
Address sdk.AccAddress `json:"address"`
|
||||
PubKey string `json:"pub_key"`
|
||||
Seed string `json:"seed,omitempty"`
|
||||
}
|
||||
|
||||
// create a list of KeyOutput in bech32 format
|
||||
@@ -70,10 +70,7 @@ func Bech32KeysOutput(infos []keys.Info) ([]KeyOutput, error) {
|
||||
|
||||
// create a KeyOutput in bech32 format
|
||||
func Bech32KeyOutput(info keys.Info) (KeyOutput, error) {
|
||||
bechAccount, err := sdk.Bech32ifyAcc(sdk.Address(info.GetPubKey().Address().Bytes()))
|
||||
if err != nil {
|
||||
return KeyOutput{}, err
|
||||
}
|
||||
account := sdk.AccAddress(info.GetPubKey().Address().Bytes())
|
||||
bechPubKey, err := sdk.Bech32ifyAccPub(info.GetPubKey())
|
||||
if err != nil {
|
||||
return KeyOutput{}, err
|
||||
@@ -81,7 +78,7 @@ func Bech32KeyOutput(info keys.Info) (KeyOutput, error) {
|
||||
return KeyOutput{
|
||||
Name: info.GetName(),
|
||||
Type: info.GetType(),
|
||||
Address: bechAccount,
|
||||
Address: account,
|
||||
PubKey: bechPubKey,
|
||||
}, nil
|
||||
}
|
||||
|
||||
+62
-96
@@ -36,7 +36,7 @@ func init() {
|
||||
func TestKeys(t *testing.T) {
|
||||
name, password := "test", "1234567890"
|
||||
addr, seed := CreateAddr(t, "test", password, GetKB(t))
|
||||
cleanup, _, port := InitializeTestLCD(t, 1, []sdk.Address{addr})
|
||||
cleanup, _, port := InitializeTestLCD(t, 1, []sdk.AccAddress{addr})
|
||||
defer cleanup()
|
||||
|
||||
// get seed
|
||||
@@ -60,8 +60,8 @@ func TestKeys(t *testing.T) {
|
||||
err = wire.Cdc.UnmarshalJSON([]byte(body), &resp)
|
||||
require.Nil(t, err, body)
|
||||
|
||||
addr2Bech32 := resp.Address
|
||||
_, err = sdk.GetAccAddressBech32(addr2Bech32)
|
||||
addr2Bech32 := resp.Address.String()
|
||||
_, err = sdk.AccAddressFromBech32(addr2Bech32)
|
||||
require.NoError(t, err, "Failed to return a correct bech32 address")
|
||||
|
||||
// existing keys
|
||||
@@ -71,12 +71,12 @@ func TestKeys(t *testing.T) {
|
||||
err = cdc.UnmarshalJSON([]byte(body), &m)
|
||||
require.Nil(t, err)
|
||||
|
||||
addrBech32 := sdk.MustBech32ifyAcc(addr)
|
||||
addrBech32 := addr.String()
|
||||
|
||||
require.Equal(t, name, m[0].Name, "Did not serve keys name correctly")
|
||||
require.Equal(t, addrBech32, m[0].Address, "Did not serve keys Address correctly")
|
||||
require.Equal(t, addrBech32, m[0].Address.String(), "Did not serve keys Address correctly")
|
||||
require.Equal(t, newName, m[1].Name, "Did not serve keys name correctly")
|
||||
require.Equal(t, addr2Bech32, m[1].Address, "Did not serve keys Address correctly")
|
||||
require.Equal(t, addr2Bech32, m[1].Address.String(), "Did not serve keys Address correctly")
|
||||
|
||||
// select key
|
||||
keyEndpoint := fmt.Sprintf("/keys/%s", newName)
|
||||
@@ -87,7 +87,7 @@ func TestKeys(t *testing.T) {
|
||||
require.Nil(t, err)
|
||||
|
||||
require.Equal(t, newName, m2.Name, "Did not serve keys name correctly")
|
||||
require.Equal(t, addr2Bech32, m2.Address, "Did not serve keys Address correctly")
|
||||
require.Equal(t, addr2Bech32, m2.Address.String(), "Did not serve keys Address correctly")
|
||||
|
||||
// update key
|
||||
jsonStr = []byte(fmt.Sprintf(`{
|
||||
@@ -109,7 +109,7 @@ func TestKeys(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestVersion(t *testing.T) {
|
||||
cleanup, _, port := InitializeTestLCD(t, 1, []sdk.Address{})
|
||||
cleanup, _, port := InitializeTestLCD(t, 1, []sdk.AccAddress{})
|
||||
defer cleanup()
|
||||
|
||||
// node info
|
||||
@@ -132,7 +132,7 @@ func TestVersion(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestNodeStatus(t *testing.T) {
|
||||
cleanup, _, port := InitializeTestLCD(t, 1, []sdk.Address{})
|
||||
cleanup, _, port := InitializeTestLCD(t, 1, []sdk.AccAddress{})
|
||||
defer cleanup()
|
||||
|
||||
// node info
|
||||
@@ -154,7 +154,7 @@ func TestNodeStatus(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestBlock(t *testing.T) {
|
||||
cleanup, _, port := InitializeTestLCD(t, 1, []sdk.Address{})
|
||||
cleanup, _, port := InitializeTestLCD(t, 1, []sdk.AccAddress{})
|
||||
defer cleanup()
|
||||
|
||||
var resultBlock ctypes.ResultBlock
|
||||
@@ -184,7 +184,7 @@ func TestBlock(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestValidators(t *testing.T) {
|
||||
cleanup, _, port := InitializeTestLCD(t, 1, []sdk.Address{})
|
||||
cleanup, _, port := InitializeTestLCD(t, 1, []sdk.AccAddress{})
|
||||
defer cleanup()
|
||||
|
||||
var resultVals rpc.ResultValidatorsOutput
|
||||
@@ -197,7 +197,7 @@ func TestValidators(t *testing.T) {
|
||||
|
||||
require.NotEqual(t, rpc.ResultValidatorsOutput{}, resultVals)
|
||||
|
||||
require.Contains(t, resultVals.Validators[0].Address, "cosmosvaladdr")
|
||||
require.Contains(t, resultVals.Validators[0].Address.String(), "cosmosvaladdr")
|
||||
require.Contains(t, resultVals.Validators[0].PubKey, "cosmosvalpub")
|
||||
|
||||
// --
|
||||
@@ -219,15 +219,15 @@ func TestValidators(t *testing.T) {
|
||||
func TestCoinSend(t *testing.T) {
|
||||
name, password := "test", "1234567890"
|
||||
addr, seed := CreateAddr(t, "test", password, GetKB(t))
|
||||
cleanup, _, port := InitializeTestLCD(t, 1, []sdk.Address{addr})
|
||||
cleanup, _, port := InitializeTestLCD(t, 1, []sdk.AccAddress{addr})
|
||||
defer cleanup()
|
||||
|
||||
bz, err := hex.DecodeString("8FA6AB57AD6870F6B5B2E57735F38F2F30E73CB6")
|
||||
require.NoError(t, err)
|
||||
someFakeAddr := sdk.MustBech32ifyAcc(bz)
|
||||
someFakeAddr := sdk.AccAddress(bz)
|
||||
|
||||
// query empty
|
||||
res, body := Request(t, port, "GET", "/accounts/"+someFakeAddr, nil)
|
||||
res, body := Request(t, port, "GET", fmt.Sprintf("/accounts/%s", someFakeAddr), nil)
|
||||
require.Equal(t, http.StatusNoContent, res.StatusCode, body)
|
||||
|
||||
acc := getAccount(t, port, addr)
|
||||
@@ -261,7 +261,7 @@ func TestCoinSend(t *testing.T) {
|
||||
func TestIBCTransfer(t *testing.T) {
|
||||
name, password := "test", "1234567890"
|
||||
addr, seed := CreateAddr(t, "test", password, GetKB(t))
|
||||
cleanup, _, port := InitializeTestLCD(t, 1, []sdk.Address{addr})
|
||||
cleanup, _, port := InitializeTestLCD(t, 1, []sdk.AccAddress{addr})
|
||||
defer cleanup()
|
||||
|
||||
acc := getAccount(t, port, addr)
|
||||
@@ -290,7 +290,7 @@ func TestIBCTransfer(t *testing.T) {
|
||||
func TestTxs(t *testing.T) {
|
||||
name, password := "test", "1234567890"
|
||||
addr, seed := CreateAddr(t, "test", password, GetKB(t))
|
||||
cleanup, _, port := InitializeTestLCD(t, 1, []sdk.Address{addr})
|
||||
cleanup, _, port := InitializeTestLCD(t, 1, []sdk.AccAddress{addr})
|
||||
defer cleanup()
|
||||
|
||||
// query wrong
|
||||
@@ -334,8 +334,7 @@ func TestTxs(t *testing.T) {
|
||||
|
||||
// query sender
|
||||
// also tests url decoding
|
||||
addrBech := sdk.MustBech32ifyAcc(addr)
|
||||
res, body = Request(t, port, "GET", "/txs?tag=sender_bech32=%27"+addrBech+"%27", nil)
|
||||
res, body = Request(t, port, "GET", fmt.Sprintf("/txs?tag=sender_bech32=%%27%s%%27", addr), nil)
|
||||
require.Equal(t, http.StatusOK, res.StatusCode, body)
|
||||
|
||||
err = cdc.UnmarshalJSON([]byte(body), &indexedTxs)
|
||||
@@ -344,8 +343,7 @@ func TestTxs(t *testing.T) {
|
||||
require.Equal(t, resultTx.Height, indexedTxs[0].Height)
|
||||
|
||||
// query recipient
|
||||
receiveAddrBech := sdk.MustBech32ifyAcc(receiveAddr)
|
||||
res, body = Request(t, port, "GET", fmt.Sprintf("/txs?tag=recipient_bech32='%s'", receiveAddrBech), nil)
|
||||
res, body = Request(t, port, "GET", fmt.Sprintf("/txs?tag=recipient_bech32='%s'", receiveAddr), nil)
|
||||
require.Equal(t, http.StatusOK, res.StatusCode, body)
|
||||
|
||||
err = cdc.UnmarshalJSON([]byte(body), &indexedTxs)
|
||||
@@ -355,7 +353,7 @@ func TestTxs(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestValidatorsQuery(t *testing.T) {
|
||||
cleanup, pks, port := InitializeTestLCD(t, 2, []sdk.Address{})
|
||||
cleanup, pks, port := InitializeTestLCD(t, 2, []sdk.AccAddress{})
|
||||
defer cleanup()
|
||||
require.Equal(t, 2, len(pks))
|
||||
|
||||
@@ -379,10 +377,10 @@ func TestValidatorsQuery(t *testing.T) {
|
||||
func TestBonding(t *testing.T) {
|
||||
name, password, denom := "test", "1234567890", "steak"
|
||||
addr, seed := CreateAddr(t, "test", password, GetKB(t))
|
||||
cleanup, pks, port := InitializeTestLCD(t, 1, []sdk.Address{addr})
|
||||
cleanup, pks, port := InitializeTestLCD(t, 1, []sdk.AccAddress{addr})
|
||||
defer cleanup()
|
||||
|
||||
validator1Owner := pks[0].Address()
|
||||
validator1Owner := sdk.AccAddress(pks[0].Address())
|
||||
|
||||
// create bond TX
|
||||
resultTx := doDelegate(t, port, seed, name, password, addr, validator1Owner)
|
||||
@@ -429,7 +427,7 @@ func TestBonding(t *testing.T) {
|
||||
func TestSubmitProposal(t *testing.T) {
|
||||
name, password := "test", "1234567890"
|
||||
addr, seed := CreateAddr(t, "test", password, GetKB(t))
|
||||
cleanup, _, port := InitializeTestLCD(t, 1, []sdk.Address{addr})
|
||||
cleanup, _, port := InitializeTestLCD(t, 1, []sdk.AccAddress{addr})
|
||||
defer cleanup()
|
||||
|
||||
// create SubmitProposal TX
|
||||
@@ -451,7 +449,7 @@ func TestSubmitProposal(t *testing.T) {
|
||||
func TestDeposit(t *testing.T) {
|
||||
name, password := "test", "1234567890"
|
||||
addr, seed := CreateAddr(t, "test", password, GetKB(t))
|
||||
cleanup, _, port := InitializeTestLCD(t, 1, []sdk.Address{addr})
|
||||
cleanup, _, port := InitializeTestLCD(t, 1, []sdk.AccAddress{addr})
|
||||
defer cleanup()
|
||||
|
||||
// create SubmitProposal TX
|
||||
@@ -485,7 +483,7 @@ func TestDeposit(t *testing.T) {
|
||||
func TestVote(t *testing.T) {
|
||||
name, password := "test", "1234567890"
|
||||
addr, seed := CreateAddr(t, "test", password, GetKB(t))
|
||||
cleanup, _, port := InitializeTestLCD(t, 1, []sdk.Address{addr})
|
||||
cleanup, _, port := InitializeTestLCD(t, 1, []sdk.AccAddress{addr})
|
||||
defer cleanup()
|
||||
|
||||
// create SubmitProposal TX
|
||||
@@ -523,13 +521,13 @@ func TestVote(t *testing.T) {
|
||||
func TestUnrevoke(t *testing.T) {
|
||||
_, password := "test", "1234567890"
|
||||
addr, _ := CreateAddr(t, "test", password, GetKB(t))
|
||||
cleanup, pks, port := InitializeTestLCD(t, 1, []sdk.Address{addr})
|
||||
cleanup, pks, port := InitializeTestLCD(t, 1, []sdk.AccAddress{addr})
|
||||
defer cleanup()
|
||||
|
||||
// XXX: any less than this and it fails
|
||||
tests.WaitForHeight(3, port)
|
||||
|
||||
signingInfo := getSigningInfo(t, port, pks[0].Address())
|
||||
signingInfo := getSigningInfo(t, port, sdk.ValAddress(pks[0].Address()))
|
||||
tests.WaitForHeight(4, port)
|
||||
require.Equal(t, true, signingInfo.IndexOffset > 0)
|
||||
require.Equal(t, int64(0), signingInfo.JailedUntil)
|
||||
@@ -541,7 +539,7 @@ func TestProposalsQuery(t *testing.T) {
|
||||
name2, password2 := "test2", "1234567890"
|
||||
addr, seed := CreateAddr(t, "test", password1, GetKB(t))
|
||||
addr2, seed2 := CreateAddr(t, "test2", password2, GetKB(t))
|
||||
cleanup, _, port := InitializeTestLCD(t, 1, []sdk.Address{addr, addr2})
|
||||
cleanup, _, port := InitializeTestLCD(t, 1, []sdk.AccAddress{addr, addr2})
|
||||
defer cleanup()
|
||||
|
||||
// Addr1 proposes (and deposits) proposals #1 and #2
|
||||
@@ -607,9 +605,8 @@ func TestProposalsQuery(t *testing.T) {
|
||||
|
||||
//_____________________________________________________________________________
|
||||
// get the account to get the sequence
|
||||
func getAccount(t *testing.T, port string, addr sdk.Address) auth.Account {
|
||||
addrBech32 := sdk.MustBech32ifyAcc(addr)
|
||||
res, body := Request(t, port, "GET", "/accounts/"+addrBech32, nil)
|
||||
func getAccount(t *testing.T, port string, addr sdk.AccAddress) auth.Account {
|
||||
res, body := Request(t, port, "GET", fmt.Sprintf("/accounts/%s", addr), nil)
|
||||
require.Equal(t, http.StatusOK, res.StatusCode, body)
|
||||
var acc auth.Account
|
||||
err := cdc.UnmarshalJSON([]byte(body), &acc)
|
||||
@@ -617,14 +614,13 @@ func getAccount(t *testing.T, port string, addr sdk.Address) auth.Account {
|
||||
return acc
|
||||
}
|
||||
|
||||
func doSend(t *testing.T, port, seed, name, password string, addr sdk.Address) (receiveAddr sdk.Address, resultTx ctypes.ResultBroadcastTxCommit) {
|
||||
func doSend(t *testing.T, port, seed, name, password string, addr sdk.AccAddress) (receiveAddr sdk.AccAddress, resultTx ctypes.ResultBroadcastTxCommit) {
|
||||
|
||||
// create receive address
|
||||
kb := client.MockKeyBase()
|
||||
receiveInfo, _, err := kb.CreateMnemonic("receive_address", cryptoKeys.English, "1234567890", cryptoKeys.SigningAlgo("secp256k1"))
|
||||
require.Nil(t, err)
|
||||
receiveAddr = receiveInfo.GetPubKey().Address()
|
||||
receiveAddrBech := sdk.MustBech32ifyAcc(receiveAddr)
|
||||
receiveAddr = sdk.AccAddress(receiveInfo.GetPubKey().Address())
|
||||
|
||||
acc := getAccount(t, port, addr)
|
||||
accnum := acc.GetAccountNumber()
|
||||
@@ -646,7 +642,7 @@ func doSend(t *testing.T, port, seed, name, password string, addr sdk.Address) (
|
||||
"amount":[%s],
|
||||
"chain_id":"%s"
|
||||
}`, name, password, accnum, sequence, coinbz, chainID))
|
||||
res, body := Request(t, port, "POST", "/accounts/"+receiveAddrBech+"/send", jsonStr)
|
||||
res, body := Request(t, port, "POST", fmt.Sprintf("/accounts/%s/send", receiveAddr), jsonStr)
|
||||
require.Equal(t, http.StatusOK, res.StatusCode, body)
|
||||
|
||||
err = cdc.UnmarshalJSON([]byte(body), &resultTx)
|
||||
@@ -655,13 +651,12 @@ func doSend(t *testing.T, port, seed, name, password string, addr sdk.Address) (
|
||||
return receiveAddr, resultTx
|
||||
}
|
||||
|
||||
func doIBCTransfer(t *testing.T, port, seed, name, password string, addr sdk.Address) (resultTx ctypes.ResultBroadcastTxCommit) {
|
||||
func doIBCTransfer(t *testing.T, port, seed, name, password string, addr sdk.AccAddress) (resultTx ctypes.ResultBroadcastTxCommit) {
|
||||
// create receive address
|
||||
kb := client.MockKeyBase()
|
||||
receiveInfo, _, err := kb.CreateMnemonic("receive_address", cryptoKeys.English, "1234567890", cryptoKeys.SigningAlgo("secp256k1"))
|
||||
require.Nil(t, err)
|
||||
receiveAddr := receiveInfo.GetPubKey().Address()
|
||||
receiveAddrBech := sdk.MustBech32ifyAcc(receiveAddr)
|
||||
receiveAddr := sdk.AccAddress(receiveInfo.GetPubKey().Address())
|
||||
|
||||
chainID := viper.GetString(client.FlagChainID)
|
||||
|
||||
@@ -685,7 +680,7 @@ func doIBCTransfer(t *testing.T, port, seed, name, password string, addr sdk.Add
|
||||
}
|
||||
]
|
||||
}`, name, password, accnum, sequence, chainID, "steak"))
|
||||
res, body := Request(t, port, "POST", "/ibc/testchain/"+receiveAddrBech+"/send", jsonStr)
|
||||
res, body := Request(t, port, "POST", fmt.Sprintf("/ibc/testchain/%s/send", receiveAddr), jsonStr)
|
||||
require.Equal(t, http.StatusOK, res.StatusCode, body)
|
||||
|
||||
err = cdc.UnmarshalJSON([]byte(body), &resultTx)
|
||||
@@ -694,9 +689,8 @@ func doIBCTransfer(t *testing.T, port, seed, name, password string, addr sdk.Add
|
||||
return resultTx
|
||||
}
|
||||
|
||||
func getSigningInfo(t *testing.T, port string, validatorAddr sdk.Address) slashing.ValidatorSigningInfo {
|
||||
validatorAddrBech := sdk.MustBech32ifyVal(validatorAddr)
|
||||
res, body := Request(t, port, "GET", "/slashing/signing_info/"+validatorAddrBech, nil)
|
||||
func getSigningInfo(t *testing.T, port string, validatorAddr sdk.ValAddress) slashing.ValidatorSigningInfo {
|
||||
res, body := Request(t, port, "GET", fmt.Sprintf("/slashing/signing_info/%s", validatorAddr), nil)
|
||||
require.Equal(t, http.StatusOK, res.StatusCode, body)
|
||||
var signingInfo slashing.ValidatorSigningInfo
|
||||
err := cdc.UnmarshalJSON([]byte(body), &signingInfo)
|
||||
@@ -704,13 +698,10 @@ func getSigningInfo(t *testing.T, port string, validatorAddr sdk.Address) slashi
|
||||
return signingInfo
|
||||
}
|
||||
|
||||
func getDelegation(t *testing.T, port string, delegatorAddr, validatorAddr sdk.Address) stake.Delegation {
|
||||
|
||||
delegatorAddrBech := sdk.MustBech32ifyAcc(delegatorAddr)
|
||||
validatorAddrBech := sdk.MustBech32ifyVal(validatorAddr)
|
||||
func getDelegation(t *testing.T, port string, delegatorAddr, validatorAddr sdk.AccAddress) stake.Delegation {
|
||||
|
||||
// get the account to get the sequence
|
||||
res, body := Request(t, port, "GET", "/stake/"+delegatorAddrBech+"/delegation/"+validatorAddrBech, nil)
|
||||
res, body := Request(t, port, "GET", fmt.Sprintf("/stake/%s/delegation/%s", delegatorAddr, validatorAddr), nil)
|
||||
require.Equal(t, http.StatusOK, res.StatusCode, body)
|
||||
var bond stake.Delegation
|
||||
err := cdc.UnmarshalJSON([]byte(body), &bond)
|
||||
@@ -718,15 +709,12 @@ func getDelegation(t *testing.T, port string, delegatorAddr, validatorAddr sdk.A
|
||||
return bond
|
||||
}
|
||||
|
||||
func doDelegate(t *testing.T, port, seed, name, password string, delegatorAddr, validatorAddr sdk.Address) (resultTx ctypes.ResultBroadcastTxCommit) {
|
||||
func doDelegate(t *testing.T, port, seed, name, password string, delegatorAddr, validatorAddr sdk.AccAddress) (resultTx ctypes.ResultBroadcastTxCommit) {
|
||||
// get the account to get the sequence
|
||||
acc := getAccount(t, port, delegatorAddr)
|
||||
accnum := acc.GetAccountNumber()
|
||||
sequence := acc.GetSequence()
|
||||
|
||||
delegatorAddrBech := sdk.MustBech32ifyAcc(delegatorAddr)
|
||||
validatorAddrBech := sdk.MustBech32ifyVal(validatorAddr)
|
||||
|
||||
chainID := viper.GetString(client.FlagChainID)
|
||||
|
||||
// send
|
||||
@@ -748,7 +736,7 @@ func doDelegate(t *testing.T, port, seed, name, password string, delegatorAddr,
|
||||
"complete_unbondings": [],
|
||||
"begin_redelegates": [],
|
||||
"complete_redelegates": []
|
||||
}`, name, password, accnum, sequence, chainID, delegatorAddrBech, validatorAddrBech, "steak"))
|
||||
}`, name, password, accnum, sequence, chainID, delegatorAddr, validatorAddr, "steak"))
|
||||
res, body := Request(t, port, "POST", "/stake/delegations", jsonStr)
|
||||
require.Equal(t, http.StatusOK, res.StatusCode, body)
|
||||
|
||||
@@ -760,16 +748,13 @@ func doDelegate(t *testing.T, port, seed, name, password string, delegatorAddr,
|
||||
}
|
||||
|
||||
func doBeginUnbonding(t *testing.T, port, seed, name, password string,
|
||||
delegatorAddr, validatorAddr sdk.Address) (resultTx ctypes.ResultBroadcastTxCommit) {
|
||||
delegatorAddr, validatorAddr sdk.AccAddress) (resultTx ctypes.ResultBroadcastTxCommit) {
|
||||
|
||||
// get the account to get the sequence
|
||||
acc := getAccount(t, port, delegatorAddr)
|
||||
accnum := acc.GetAccountNumber()
|
||||
sequence := acc.GetSequence()
|
||||
|
||||
delegatorAddrBech := sdk.MustBech32ifyAcc(delegatorAddr)
|
||||
validatorAddrBech := sdk.MustBech32ifyVal(validatorAddr)
|
||||
|
||||
chainID := viper.GetString(client.FlagChainID)
|
||||
|
||||
// send
|
||||
@@ -791,7 +776,7 @@ func doBeginUnbonding(t *testing.T, port, seed, name, password string,
|
||||
"complete_unbondings": [],
|
||||
"begin_redelegates": [],
|
||||
"complete_redelegates": []
|
||||
}`, name, password, accnum, sequence, chainID, delegatorAddrBech, validatorAddrBech))
|
||||
}`, name, password, accnum, sequence, chainID, delegatorAddr, validatorAddr))
|
||||
res, body := Request(t, port, "POST", "/stake/delegations", jsonStr)
|
||||
require.Equal(t, http.StatusOK, res.StatusCode, body)
|
||||
|
||||
@@ -803,17 +788,13 @@ func doBeginUnbonding(t *testing.T, port, seed, name, password string,
|
||||
}
|
||||
|
||||
func doBeginRedelegation(t *testing.T, port, seed, name, password string,
|
||||
delegatorAddr, validatorSrcAddr, validatorDstAddr sdk.Address) (resultTx ctypes.ResultBroadcastTxCommit) {
|
||||
delegatorAddr, validatorSrcAddr, validatorDstAddr sdk.AccAddress) (resultTx ctypes.ResultBroadcastTxCommit) {
|
||||
|
||||
// get the account to get the sequence
|
||||
acc := getAccount(t, port, delegatorAddr)
|
||||
accnum := acc.GetAccountNumber()
|
||||
sequence := acc.GetSequence()
|
||||
|
||||
delegatorAddrBech := sdk.MustBech32ifyAcc(delegatorAddr)
|
||||
validatorSrcAddrBech := sdk.MustBech32ifyVal(validatorSrcAddr)
|
||||
validatorDstAddrBech := sdk.MustBech32ifyVal(validatorDstAddr)
|
||||
|
||||
chainID := viper.GetString(client.FlagChainID)
|
||||
|
||||
// send
|
||||
@@ -836,7 +817,7 @@ func doBeginRedelegation(t *testing.T, port, seed, name, password string,
|
||||
}
|
||||
],
|
||||
"complete_redelegates": []
|
||||
}`, name, password, accnum, sequence, chainID, delegatorAddrBech, validatorSrcAddrBech, validatorDstAddrBech))
|
||||
}`, name, password, accnum, sequence, chainID, delegatorAddr, validatorSrcAddr, validatorDstAddr))
|
||||
res, body := Request(t, port, "POST", "/stake/delegations", jsonStr)
|
||||
require.Equal(t, http.StatusOK, res.StatusCode, body)
|
||||
|
||||
@@ -866,9 +847,8 @@ func getProposal(t *testing.T, port string, proposalID int64) gov.ProposalRest {
|
||||
return proposal
|
||||
}
|
||||
|
||||
func getDeposit(t *testing.T, port string, proposalID int64, depositerAddr sdk.Address) gov.DepositRest {
|
||||
bechDepositerAddr := sdk.MustBech32ifyAcc(depositerAddr)
|
||||
res, body := Request(t, port, "GET", fmt.Sprintf("/gov/proposals/%d/deposits/%s", proposalID, bechDepositerAddr), nil)
|
||||
func getDeposit(t *testing.T, port string, proposalID int64, depositerAddr sdk.AccAddress) gov.DepositRest {
|
||||
res, body := Request(t, port, "GET", fmt.Sprintf("/gov/proposals/%d/deposits/%s", proposalID, depositerAddr), nil)
|
||||
require.Equal(t, http.StatusOK, res.StatusCode, body)
|
||||
var deposit gov.DepositRest
|
||||
err := cdc.UnmarshalJSON([]byte(body), &deposit)
|
||||
@@ -876,9 +856,8 @@ func getDeposit(t *testing.T, port string, proposalID int64, depositerAddr sdk.A
|
||||
return deposit
|
||||
}
|
||||
|
||||
func getVote(t *testing.T, port string, proposalID int64, voterAddr sdk.Address) gov.VoteRest {
|
||||
bechVoterAddr := sdk.MustBech32ifyAcc(voterAddr)
|
||||
res, body := Request(t, port, "GET", fmt.Sprintf("/gov/proposals/%d/votes/%s", proposalID, bechVoterAddr), nil)
|
||||
func getVote(t *testing.T, port string, proposalID int64, voterAddr sdk.AccAddress) gov.VoteRest {
|
||||
res, body := Request(t, port, "GET", fmt.Sprintf("/gov/proposals/%d/votes/%s", proposalID, voterAddr), nil)
|
||||
require.Equal(t, http.StatusOK, res.StatusCode, body)
|
||||
var vote gov.VoteRest
|
||||
err := cdc.UnmarshalJSON([]byte(body), &vote)
|
||||
@@ -896,10 +875,8 @@ func getProposalsAll(t *testing.T, port string) []gov.ProposalRest {
|
||||
return proposals
|
||||
}
|
||||
|
||||
func getProposalsFilterDepositer(t *testing.T, port string, depositerAddr sdk.Address) []gov.ProposalRest {
|
||||
bechDepositerAddr := sdk.MustBech32ifyAcc(depositerAddr)
|
||||
|
||||
res, body := Request(t, port, "GET", fmt.Sprintf("/gov/proposals?depositer=%s", bechDepositerAddr), nil)
|
||||
func getProposalsFilterDepositer(t *testing.T, port string, depositerAddr sdk.AccAddress) []gov.ProposalRest {
|
||||
res, body := Request(t, port, "GET", fmt.Sprintf("/gov/proposals?depositer=%s", depositerAddr), nil)
|
||||
require.Equal(t, http.StatusOK, res.StatusCode, body)
|
||||
|
||||
var proposals []gov.ProposalRest
|
||||
@@ -908,10 +885,8 @@ func getProposalsFilterDepositer(t *testing.T, port string, depositerAddr sdk.Ad
|
||||
return proposals
|
||||
}
|
||||
|
||||
func getProposalsFilterVoter(t *testing.T, port string, voterAddr sdk.Address) []gov.ProposalRest {
|
||||
bechVoterAddr := sdk.MustBech32ifyAcc(voterAddr)
|
||||
|
||||
res, body := Request(t, port, "GET", fmt.Sprintf("/gov/proposals?voter=%s", bechVoterAddr), nil)
|
||||
func getProposalsFilterVoter(t *testing.T, port string, voterAddr sdk.AccAddress) []gov.ProposalRest {
|
||||
res, body := Request(t, port, "GET", fmt.Sprintf("/gov/proposals?voter=%s", voterAddr), nil)
|
||||
require.Equal(t, http.StatusOK, res.StatusCode, body)
|
||||
|
||||
var proposals []gov.ProposalRest
|
||||
@@ -920,11 +895,8 @@ func getProposalsFilterVoter(t *testing.T, port string, voterAddr sdk.Address) [
|
||||
return proposals
|
||||
}
|
||||
|
||||
func getProposalsFilterVoterDepositer(t *testing.T, port string, voterAddr sdk.Address, depositerAddr sdk.Address) []gov.ProposalRest {
|
||||
bechVoterAddr := sdk.MustBech32ifyAcc(voterAddr)
|
||||
bechDepositerAddr := sdk.MustBech32ifyAcc(depositerAddr)
|
||||
|
||||
res, body := Request(t, port, "GET", fmt.Sprintf("/gov/proposals?depositer=%s&voter=%s", bechDepositerAddr, bechVoterAddr), nil)
|
||||
func getProposalsFilterVoterDepositer(t *testing.T, port string, voterAddr, depositerAddr sdk.AccAddress) []gov.ProposalRest {
|
||||
res, body := Request(t, port, "GET", fmt.Sprintf("/gov/proposals?depositer=%s&voter=%s", depositerAddr, voterAddr), nil)
|
||||
require.Equal(t, http.StatusOK, res.StatusCode, body)
|
||||
|
||||
var proposals []gov.ProposalRest
|
||||
@@ -933,7 +905,7 @@ func getProposalsFilterVoterDepositer(t *testing.T, port string, voterAddr sdk.A
|
||||
return proposals
|
||||
}
|
||||
|
||||
func doSubmitProposal(t *testing.T, port, seed, name, password string, proposerAddr sdk.Address) (resultTx ctypes.ResultBroadcastTxCommit) {
|
||||
func doSubmitProposal(t *testing.T, port, seed, name, password string, proposerAddr sdk.AccAddress) (resultTx ctypes.ResultBroadcastTxCommit) {
|
||||
// get the account to get the sequence
|
||||
acc := getAccount(t, port, proposerAddr)
|
||||
accnum := acc.GetAccountNumber()
|
||||
@@ -941,8 +913,6 @@ func doSubmitProposal(t *testing.T, port, seed, name, password string, proposerA
|
||||
|
||||
chainID := viper.GetString(client.FlagChainID)
|
||||
|
||||
bechProposerAddr := sdk.MustBech32ifyAcc(proposerAddr)
|
||||
|
||||
// submitproposal
|
||||
jsonStr := []byte(fmt.Sprintf(`{
|
||||
"title": "Test",
|
||||
@@ -958,7 +928,7 @@ func doSubmitProposal(t *testing.T, port, seed, name, password string, proposerA
|
||||
"sequence":"%d",
|
||||
"gas":"100000"
|
||||
}
|
||||
}`, bechProposerAddr, name, password, chainID, accnum, sequence))
|
||||
}`, proposerAddr, name, password, chainID, accnum, sequence))
|
||||
res, body := Request(t, port, "POST", "/gov/proposals", jsonStr)
|
||||
require.Equal(t, http.StatusOK, res.StatusCode, body)
|
||||
|
||||
@@ -969,7 +939,7 @@ func doSubmitProposal(t *testing.T, port, seed, name, password string, proposerA
|
||||
return results
|
||||
}
|
||||
|
||||
func doDeposit(t *testing.T, port, seed, name, password string, proposerAddr sdk.Address, proposalID int64) (resultTx ctypes.ResultBroadcastTxCommit) {
|
||||
func doDeposit(t *testing.T, port, seed, name, password string, proposerAddr sdk.AccAddress, proposalID int64) (resultTx ctypes.ResultBroadcastTxCommit) {
|
||||
// get the account to get the sequence
|
||||
acc := getAccount(t, port, proposerAddr)
|
||||
accnum := acc.GetAccountNumber()
|
||||
@@ -977,8 +947,6 @@ func doDeposit(t *testing.T, port, seed, name, password string, proposerAddr sdk
|
||||
|
||||
chainID := viper.GetString(client.FlagChainID)
|
||||
|
||||
bechProposerAddr := sdk.MustBech32ifyAcc(proposerAddr)
|
||||
|
||||
// deposit on proposal
|
||||
jsonStr := []byte(fmt.Sprintf(`{
|
||||
"depositer": "%s",
|
||||
@@ -991,7 +959,7 @@ func doDeposit(t *testing.T, port, seed, name, password string, proposerAddr sdk
|
||||
"sequence": "%d",
|
||||
"gas":"100000"
|
||||
}
|
||||
}`, bechProposerAddr, name, password, chainID, accnum, sequence))
|
||||
}`, proposerAddr, name, password, chainID, accnum, sequence))
|
||||
res, body := Request(t, port, "POST", fmt.Sprintf("/gov/proposals/%d/deposits", proposalID), jsonStr)
|
||||
require.Equal(t, http.StatusOK, res.StatusCode, body)
|
||||
|
||||
@@ -1002,7 +970,7 @@ func doDeposit(t *testing.T, port, seed, name, password string, proposerAddr sdk
|
||||
return results
|
||||
}
|
||||
|
||||
func doVote(t *testing.T, port, seed, name, password string, proposerAddr sdk.Address, proposalID int64) (resultTx ctypes.ResultBroadcastTxCommit) {
|
||||
func doVote(t *testing.T, port, seed, name, password string, proposerAddr sdk.AccAddress, proposalID int64) (resultTx ctypes.ResultBroadcastTxCommit) {
|
||||
// get the account to get the sequence
|
||||
acc := getAccount(t, port, proposerAddr)
|
||||
accnum := acc.GetAccountNumber()
|
||||
@@ -1010,8 +978,6 @@ func doVote(t *testing.T, port, seed, name, password string, proposerAddr sdk.Ad
|
||||
|
||||
chainID := viper.GetString(client.FlagChainID)
|
||||
|
||||
bechProposerAddr := sdk.MustBech32ifyAcc(proposerAddr)
|
||||
|
||||
// vote on proposal
|
||||
jsonStr := []byte(fmt.Sprintf(`{
|
||||
"voter": "%s",
|
||||
@@ -1024,7 +990,7 @@ func doVote(t *testing.T, port, seed, name, password string, proposerAddr sdk.Ad
|
||||
"sequence": "%d",
|
||||
"gas":"100000"
|
||||
}
|
||||
}`, bechProposerAddr, name, password, chainID, accnum, sequence))
|
||||
}`, proposerAddr, name, password, chainID, accnum, sequence))
|
||||
res, body := Request(t, port, "POST", fmt.Sprintf("/gov/proposals/%d/votes", proposalID), jsonStr)
|
||||
fmt.Println(res)
|
||||
require.Equal(t, http.StatusOK, res.StatusCode, body)
|
||||
|
||||
@@ -80,19 +80,19 @@ func GetKB(t *testing.T) crkeys.Keybase {
|
||||
}
|
||||
|
||||
// add an address to the store return name and password
|
||||
func CreateAddr(t *testing.T, name, password string, kb crkeys.Keybase) (addr sdk.Address, seed string) {
|
||||
func CreateAddr(t *testing.T, name, password string, kb crkeys.Keybase) (addr sdk.AccAddress, seed string) {
|
||||
var info crkeys.Info
|
||||
var err error
|
||||
info, seed, err = kb.CreateMnemonic(name, crkeys.English, password, crkeys.Secp256k1)
|
||||
require.NoError(t, err)
|
||||
addr = info.GetPubKey().Address()
|
||||
addr = sdk.AccAddress(info.GetPubKey().Address())
|
||||
return
|
||||
}
|
||||
|
||||
// strt TM and the LCD in process, listening on their respective sockets
|
||||
// nValidators = number of validators
|
||||
// initAddrs = accounts to initialize with some steaks
|
||||
func InitializeTestLCD(t *testing.T, nValidators int, initAddrs []sdk.Address) (cleanup func(), validatorsPKs []crypto.PubKey, port string) {
|
||||
func InitializeTestLCD(t *testing.T, nValidators int, initAddrs []sdk.AccAddress) (cleanup func(), validatorsPKs []crypto.PubKey, port string) {
|
||||
|
||||
config := GetConfig()
|
||||
config.Consensus.TimeoutCommit = 100
|
||||
@@ -132,7 +132,7 @@ func InitializeTestLCD(t *testing.T, nValidators int, initAddrs []sdk.Address) (
|
||||
for _, gdValidator := range genDoc.Validators {
|
||||
pk := gdValidator.PubKey
|
||||
validatorsPKs = append(validatorsPKs, pk) // append keys for output
|
||||
appGenTx, _, _, err := gapp.GaiaAppGenTxNF(cdc, pk, sdk.MustBech32ifyAcc(pk.Address()), "test_val1")
|
||||
appGenTx, _, _, err := gapp.GaiaAppGenTxNF(cdc, pk, sdk.AccAddress(pk.Address()), "test_val1")
|
||||
require.NoError(t, err)
|
||||
appGenTxs = append(appGenTxs, appGenTx)
|
||||
}
|
||||
|
||||
@@ -32,10 +32,10 @@ func ValidatorCommand() *cobra.Command {
|
||||
|
||||
// Validator output in bech32 format
|
||||
type ValidatorOutput struct {
|
||||
Address string `json:"address"` // in bech32
|
||||
PubKey string `json:"pub_key"` // in bech32
|
||||
Accum int64 `json:"accum"`
|
||||
VotingPower int64 `json:"voting_power"`
|
||||
Address sdk.ValAddress `json:"address"` // in bech32
|
||||
PubKey string `json:"pub_key"` // in bech32
|
||||
Accum int64 `json:"accum"`
|
||||
VotingPower int64 `json:"voting_power"`
|
||||
}
|
||||
|
||||
// Validators at a certain height output in bech32 format
|
||||
@@ -45,17 +45,13 @@ type ResultValidatorsOutput struct {
|
||||
}
|
||||
|
||||
func bech32ValidatorOutput(validator *tmtypes.Validator) (ValidatorOutput, error) {
|
||||
bechAddress, err := sdk.Bech32ifyVal(validator.Address)
|
||||
if err != nil {
|
||||
return ValidatorOutput{}, err
|
||||
}
|
||||
bechValPubkey, err := sdk.Bech32ifyValPub(validator.PubKey)
|
||||
if err != nil {
|
||||
return ValidatorOutput{}, err
|
||||
}
|
||||
|
||||
return ValidatorOutput{
|
||||
Address: bechAddress,
|
||||
Address: sdk.ValAddress(validator.Address),
|
||||
PubKey: bechValPubkey,
|
||||
Accum: validator.Accum,
|
||||
VotingPower: validator.VotingPower,
|
||||
|
||||
+1
-1
@@ -124,7 +124,7 @@ func SearchTxRequestHandlerFn(ctx context.CoreContext, cdc *wire.Codec) http.Han
|
||||
return
|
||||
}
|
||||
|
||||
tag = strings.TrimRight(key, "_bech32") + "='" + sdk.Address(bz).String() + "'"
|
||||
tag = strings.TrimRight(key, "_bech32") + "='" + sdk.AccAddress(bz).String() + "'"
|
||||
}
|
||||
|
||||
txs, err := searchTxs(ctx, cdc, []string{tag})
|
||||
|
||||
Reference in New Issue
Block a user