Merge PR #1340: Reverted ChangePubKey
* removed msgChangePubKey * changelog * removed setPubKey
This commit is contained in:
parent
17e5a48b65
commit
c3c570898d
|
@ -9,6 +9,8 @@ BREAKING CHANGES
|
||||||
* AltBytes renamed to Memo, now a string, max 100 characters, costs a bit of gas
|
* AltBytes renamed to Memo, now a string, max 100 characters, costs a bit of gas
|
||||||
* Transactions now take a list of Messages
|
* Transactions now take a list of Messages
|
||||||
* Signers of a transaction now only sign over their account and sequence number
|
* Signers of a transaction now only sign over their account and sequence number
|
||||||
|
* Removed MsgChangePubKey from auth
|
||||||
|
* Removed setPubKey from account mapper
|
||||||
|
|
||||||
FEATURES
|
FEATURES
|
||||||
* [gaiacli] You can now attach a simple text-only memo to any transaction, with the `--memo` flag
|
* [gaiacli] You can now attach a simple text-only memo to any transaction, with the `--memo` flag
|
||||||
|
|
|
@ -77,7 +77,6 @@ func NewBasecoinApp(logger log.Logger, db dbm.DB) *BasecoinApp {
|
||||||
|
|
||||||
// register message routes
|
// register message routes
|
||||||
app.Router().
|
app.Router().
|
||||||
AddRoute("auth", auth.NewHandler(app.accountMapper)).
|
|
||||||
AddRoute("bank", bank.NewHandler(app.coinKeeper)).
|
AddRoute("bank", bank.NewHandler(app.coinKeeper)).
|
||||||
AddRoute("ibc", ibc.NewHandler(app.ibcMapper, app.coinKeeper)).
|
AddRoute("ibc", ibc.NewHandler(app.ibcMapper, app.coinKeeper)).
|
||||||
AddRoute("stake", stake.NewHandler(app.stakeKeeper))
|
AddRoute("stake", stake.NewHandler(app.stakeKeeper))
|
||||||
|
|
|
@ -1,34 +0,0 @@
|
||||||
package auth
|
|
||||||
|
|
||||||
import (
|
|
||||||
"reflect"
|
|
||||||
|
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
||||||
)
|
|
||||||
|
|
||||||
// NewHandler returns a handler for "baseaccount" type messages.
|
|
||||||
func NewHandler(am AccountMapper) sdk.Handler {
|
|
||||||
return func(ctx sdk.Context, msg sdk.Msg) sdk.Result {
|
|
||||||
switch msg := msg.(type) {
|
|
||||||
case MsgChangeKey:
|
|
||||||
return handleMsgChangeKey(ctx, am, msg)
|
|
||||||
default:
|
|
||||||
errMsg := "Unrecognized baseaccount Msg type: " + reflect.TypeOf(msg).Name()
|
|
||||||
return sdk.ErrUnknownRequest(errMsg).Result()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Handle MsgChangeKey
|
|
||||||
// Should be very expensive, because once this happens, an account is un-prunable
|
|
||||||
func handleMsgChangeKey(ctx sdk.Context, am AccountMapper, msg MsgChangeKey) sdk.Result {
|
|
||||||
|
|
||||||
err := am.SetPubKey(ctx, msg.Address, msg.NewPubKey)
|
|
||||||
if err != nil {
|
|
||||||
return err.Result()
|
|
||||||
}
|
|
||||||
|
|
||||||
return sdk.Result{
|
|
||||||
Tags: sdk.NewTags("action", []byte("changePubkey"), "address", msg.Address.Bytes(), "pubkey", msg.NewPubKey.Bytes()),
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -100,17 +100,6 @@ func (am AccountMapper) GetPubKey(ctx sdk.Context, addr sdk.Address) (crypto.Pub
|
||||||
return acc.GetPubKey(), nil
|
return acc.GetPubKey(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sets the PubKey of the account at address
|
|
||||||
func (am AccountMapper) SetPubKey(ctx sdk.Context, addr sdk.Address, newPubKey crypto.PubKey) sdk.Error {
|
|
||||||
acc := am.GetAccount(ctx, addr)
|
|
||||||
if acc == nil {
|
|
||||||
return sdk.ErrUnknownAddress(addr.String())
|
|
||||||
}
|
|
||||||
acc.SetPubKey(newPubKey)
|
|
||||||
am.SetAccount(ctx, acc)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns the Sequence of the account at address
|
// Returns the Sequence of the account at address
|
||||||
func (am AccountMapper) GetSequence(ctx sdk.Context, addr sdk.Address) (int64, sdk.Error) {
|
func (am AccountMapper) GetSequence(ctx sdk.Context, addr sdk.Address) (int64, sdk.Error) {
|
||||||
acc := am.GetAccount(ctx, addr)
|
acc := am.GetAccount(ctx, addr)
|
||||||
|
|
|
@ -3,14 +3,11 @@ package mock
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
"github.com/cosmos/cosmos-sdk/x/auth"
|
|
||||||
"github.com/cosmos/cosmos-sdk/x/bank"
|
"github.com/cosmos/cosmos-sdk/x/bank"
|
||||||
|
|
||||||
abci "github.com/tendermint/abci/types"
|
|
||||||
crypto "github.com/tendermint/go-crypto"
|
crypto "github.com/tendermint/go-crypto"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -35,64 +32,7 @@ func getMockApp(t *testing.T) *App {
|
||||||
|
|
||||||
coinKeeper := bank.NewKeeper(mapp.AccountMapper)
|
coinKeeper := bank.NewKeeper(mapp.AccountMapper)
|
||||||
mapp.Router().AddRoute("bank", bank.NewHandler(coinKeeper))
|
mapp.Router().AddRoute("bank", bank.NewHandler(coinKeeper))
|
||||||
mapp.Router().AddRoute("auth", auth.NewHandler(mapp.AccountMapper))
|
|
||||||
|
|
||||||
require.NoError(t, mapp.CompleteSetup([]*sdk.KVStoreKey{}))
|
require.NoError(t, mapp.CompleteSetup([]*sdk.KVStoreKey{}))
|
||||||
return mapp
|
return mapp
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMsgChangePubKey(t *testing.T) {
|
|
||||||
mapp := getMockApp(t)
|
|
||||||
|
|
||||||
// Construct some genesis bytes to reflect basecoin/types/AppAccount
|
|
||||||
// Give 77 foocoin to the first key
|
|
||||||
coins := sdk.Coins{sdk.NewCoin("foocoin", 77)}
|
|
||||||
acc1 := &auth.BaseAccount{
|
|
||||||
Address: addr1,
|
|
||||||
Coins: coins,
|
|
||||||
}
|
|
||||||
accs := []auth.Account{acc1}
|
|
||||||
|
|
||||||
// Construct genesis state
|
|
||||||
SetGenesis(mapp, accs)
|
|
||||||
|
|
||||||
// A checkTx context (true)
|
|
||||||
ctxCheck := mapp.BaseApp.NewContext(true, abci.Header{})
|
|
||||||
res1 := mapp.AccountMapper.GetAccount(ctxCheck, addr1)
|
|
||||||
assert.Equal(t, acc1, res1.(*auth.BaseAccount))
|
|
||||||
|
|
||||||
// Run a CheckDeliver
|
|
||||||
SignCheckDeliver(t, mapp.BaseApp, []sdk.Msg{sendMsg1}, []int64{0}, []int64{0}, true, priv1)
|
|
||||||
|
|
||||||
// Check balances
|
|
||||||
CheckBalance(t, mapp, addr1, sdk.Coins{sdk.NewCoin("foocoin", 67)})
|
|
||||||
CheckBalance(t, mapp, addr2, sdk.Coins{sdk.NewCoin("foocoin", 10)})
|
|
||||||
|
|
||||||
changePubKeyMsg := auth.MsgChangeKey{
|
|
||||||
Address: addr1,
|
|
||||||
NewPubKey: priv2.PubKey(),
|
|
||||||
}
|
|
||||||
|
|
||||||
mapp.BeginBlock(abci.RequestBeginBlock{})
|
|
||||||
ctxDeliver := mapp.BaseApp.NewContext(false, abci.Header{})
|
|
||||||
acc2 := mapp.AccountMapper.GetAccount(ctxDeliver, addr1)
|
|
||||||
|
|
||||||
// send a MsgChangePubKey
|
|
||||||
SignCheckDeliver(t, mapp.BaseApp, []sdk.Msg{changePubKeyMsg}, []int64{0}, []int64{1}, true, priv1)
|
|
||||||
acc2 = mapp.AccountMapper.GetAccount(ctxDeliver, addr1)
|
|
||||||
|
|
||||||
assert.True(t, priv2.PubKey().Equals(acc2.GetPubKey()))
|
|
||||||
|
|
||||||
// signing a SendMsg with the old privKey should be an auth error
|
|
||||||
mapp.BeginBlock(abci.RequestBeginBlock{})
|
|
||||||
tx := GenTx([]sdk.Msg{sendMsg1}, []int64{0}, []int64{2}, priv1)
|
|
||||||
res := mapp.Deliver(tx)
|
|
||||||
assert.Equal(t, sdk.ToABCICode(sdk.CodespaceRoot, sdk.CodeUnauthorized), res.Code, res.Log)
|
|
||||||
|
|
||||||
// resigning the tx with the new correct priv key should work
|
|
||||||
SignCheckDeliver(t, mapp.BaseApp, []sdk.Msg{sendMsg1}, []int64{0}, []int64{2}, true, priv2)
|
|
||||||
|
|
||||||
// Check balances
|
|
||||||
CheckBalance(t, mapp, addr1, sdk.Coins{sdk.NewCoin("foocoin", 57)})
|
|
||||||
CheckBalance(t, mapp, addr2, sdk.Coins{sdk.NewCoin("foocoin", 20)})
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,41 +0,0 @@
|
||||||
package auth
|
|
||||||
|
|
||||||
import (
|
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
||||||
crypto "github.com/tendermint/go-crypto"
|
|
||||||
)
|
|
||||||
|
|
||||||
// MsgChangeKey - high level transaction of the auth module
|
|
||||||
type MsgChangeKey struct {
|
|
||||||
Address sdk.Address `json:"address"`
|
|
||||||
NewPubKey crypto.PubKey `json:"public_key"`
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ sdk.Msg = MsgChangeKey{}
|
|
||||||
|
|
||||||
// NewMsgChangeKey - msg to claim an account and set the PubKey
|
|
||||||
func NewMsgChangeKey(addr sdk.Address, pubkey crypto.PubKey) MsgChangeKey {
|
|
||||||
return MsgChangeKey{Address: addr, NewPubKey: pubkey}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Implements Msg.
|
|
||||||
func (msg MsgChangeKey) Type() string { return "auth" }
|
|
||||||
|
|
||||||
// Implements Msg.
|
|
||||||
func (msg MsgChangeKey) ValidateBasic() sdk.Error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Implements Msg.
|
|
||||||
func (msg MsgChangeKey) GetSignBytes() []byte {
|
|
||||||
b, err := msgCdc.MarshalJSON(msg) // XXX: ensure some canonical form
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
return b
|
|
||||||
}
|
|
||||||
|
|
||||||
// Implements Msg.
|
|
||||||
func (msg MsgChangeKey) GetSigners() []sdk.Address {
|
|
||||||
return []sdk.Address{msg.Address}
|
|
||||||
}
|
|
|
@ -1,47 +0,0 @@
|
||||||
package auth
|
|
||||||
|
|
||||||
import (
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
crypto "github.com/tendermint/go-crypto"
|
|
||||||
|
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestNewMsgChangeKey(t *testing.T) {}
|
|
||||||
|
|
||||||
func TestMsgChangeKeyType(t *testing.T) {
|
|
||||||
addr1 := sdk.Address([]byte("input"))
|
|
||||||
newPubKey := crypto.GenPrivKeyEd25519().PubKey()
|
|
||||||
|
|
||||||
var msg = MsgChangeKey{
|
|
||||||
Address: addr1,
|
|
||||||
NewPubKey: newPubKey,
|
|
||||||
}
|
|
||||||
|
|
||||||
assert.Equal(t, msg.Type(), "auth")
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestMsgChangeKeyValidation(t *testing.T) {
|
|
||||||
|
|
||||||
addr1 := sdk.Address([]byte("input"))
|
|
||||||
|
|
||||||
// emptyPubKey := crypto.PubKeyEd25519{}
|
|
||||||
// var msg = MsgChangeKey{
|
|
||||||
// Address: addr1,
|
|
||||||
// NewPubKey: emptyPubKey,
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // fmt.Println(msg.NewPubKey.Empty())
|
|
||||||
// fmt.Println(msg.NewPubKey.Bytes())
|
|
||||||
|
|
||||||
// assert.NotNil(t, msg.ValidateBasic())
|
|
||||||
|
|
||||||
newPubKey := crypto.GenPrivKeyEd25519().PubKey()
|
|
||||||
msg := MsgChangeKey{
|
|
||||||
Address: addr1,
|
|
||||||
NewPubKey: newPubKey,
|
|
||||||
}
|
|
||||||
assert.Nil(t, msg.ValidateBasic())
|
|
||||||
}
|
|
|
@ -8,7 +8,6 @@ import (
|
||||||
func RegisterWire(cdc *wire.Codec) {
|
func RegisterWire(cdc *wire.Codec) {
|
||||||
cdc.RegisterInterface((*Account)(nil), nil)
|
cdc.RegisterInterface((*Account)(nil), nil)
|
||||||
cdc.RegisterConcrete(&BaseAccount{}, "auth/Account", nil)
|
cdc.RegisterConcrete(&BaseAccount{}, "auth/Account", nil)
|
||||||
cdc.RegisterConcrete(MsgChangeKey{}, "auth/ChangeKey", nil)
|
|
||||||
cdc.RegisterConcrete(StdTx{}, "auth/StdTx", nil)
|
cdc.RegisterConcrete(StdTx{}, "auth/StdTx", nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue