Skip to content

Commit

Permalink
works
Browse files Browse the repository at this point in the history
  • Loading branch information
sunnya97 committed May 24, 2018
1 parent 33492cc commit 5d7c3af
Show file tree
Hide file tree
Showing 29 changed files with 197 additions and 247 deletions.
47 changes: 1 addition & 46 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 8 additions & 7 deletions baseapp/baseapp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ import (
"github.com/stretchr/testify/require"

abci "github.com/tendermint/abci/types"
"github.com/tendermint/go-crypto"
crypto "github.com/tendermint/go-crypto"
cmn "github.com/tendermint/tmlibs/common"
dbm "github.com/tendermint/tmlibs/db"
"github.com/tendermint/tmlibs/log"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/wire"
"github.com/cosmos/cosmos-sdk/x/auth"
)

func defaultLogger() log.Logger {
Expand Down Expand Up @@ -446,12 +447,12 @@ type testUpdatePowerTx struct {

const msgType = "testUpdatePowerTx"

func (tx testUpdatePowerTx) Type() string { return msgType }
func (tx testUpdatePowerTx) GetMsg() sdk.Msg { return tx }
func (tx testUpdatePowerTx) GetSignBytes() []byte { return nil }
func (tx testUpdatePowerTx) ValidateBasic() sdk.Error { return nil }
func (tx testUpdatePowerTx) GetSigners() []sdk.Address { return nil }
func (tx testUpdatePowerTx) GetSignatures() []sdk.StdSignature { return nil }
func (tx testUpdatePowerTx) Type() string { return msgType }
func (tx testUpdatePowerTx) GetMsg() sdk.Msg { return tx }
func (tx testUpdatePowerTx) GetSignBytes() []byte { return nil }
func (tx testUpdatePowerTx) ValidateBasic() sdk.Error { return nil }
func (tx testUpdatePowerTx) GetSigners() []sdk.Address { return nil }
func (tx testUpdatePowerTx) GetSignatures() []auth.StdSignature { return nil }

func TestValidatorChange(t *testing.T) {

Expand Down
5 changes: 3 additions & 2 deletions client/lcd/lcd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
btypes "github.com/cosmos/cosmos-sdk/examples/basecoin/types"
tests "github.com/cosmos/cosmos-sdk/tests"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth"
)

var (
Expand Down Expand Up @@ -436,11 +437,11 @@ func request(t *testing.T, port, method, path string, payload []byte) (*http.Res
return res, string(output)
}

func getAccount(t *testing.T, sendAddr string) sdk.Account {
func getAccount(t *testing.T, sendAddr string) auth.Account {
// get the account to get the sequence
res, body := request(t, port, "GET", "/accounts/"+sendAddr, nil)
require.Equal(t, http.StatusOK, res.StatusCode, body)
var acc sdk.Account
var acc auth.Account
err := cdc.UnmarshalJSON([]byte(body), &acc)
require.Nil(t, err)
return acc
Expand Down
7 changes: 3 additions & 4 deletions cmd/gaia/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"github.com/cosmos/cosmos-sdk/wire"
"github.com/cosmos/cosmos-sdk/x/auth"
"github.com/cosmos/cosmos-sdk/x/bank"
"github.com/cosmos/cosmos-sdk/x/baseaccount"
"github.com/cosmos/cosmos-sdk/x/ibc"
"github.com/cosmos/cosmos-sdk/x/stake"
)
Expand Down Expand Up @@ -63,8 +62,8 @@ func NewGaiaApp(logger log.Logger, db dbm.DB) *GaiaApp {
// define the accountMapper
app.accountMapper = auth.NewAccountMapper(
app.cdc,
app.keyAccount, // target store
&baseaccount.BaseAccount{}, // prototype
app.keyAccount, // target store
&auth.BaseAccount{}, // prototype
)

// add handlers
Expand Down Expand Up @@ -97,7 +96,7 @@ func MakeCodec() *wire.Codec {
ibc.RegisterWire(cdc)
bank.RegisterWire(cdc)
stake.RegisterWire(cdc)
baseaccount.RegisterWire(cdc)
auth.RegisterWire(cdc)
sdk.RegisterWire(cdc)
wire.RegisterCrypto(cdc)
return cdc
Expand Down
12 changes: 6 additions & 6 deletions cmd/gaia/app/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ var (
coins = sdk.Coins{{"foocoin", 10}}
halfCoins = sdk.Coins{{"foocoin", 5}}
manyCoins = sdk.Coins{{"foocoin", 1}, {"barcoin", 1}}
fee = sdk.StdFee{
fee = auth.StdFee{
sdk.Coins{{"foocoin", 0}},
100000,
}
Expand Down Expand Up @@ -463,17 +463,17 @@ func CheckBalance(t *testing.T, gapp *GaiaApp, addr sdk.Address, balExpected str
assert.Equal(t, balExpected, fmt.Sprintf("%v", res2.GetCoins()))
}

func genTx(msg sdk.Msg, seq []int64, priv ...crypto.PrivKeyEd25519) sdk.StdTx {
sigs := make([]sdk.StdSignature, len(priv))
func genTx(msg sdk.Msg, seq []int64, priv ...crypto.PrivKeyEd25519) auth.StdTx {
sigs := make([]auth.StdSignature, len(priv))
for i, p := range priv {
sigs[i] = sdk.StdSignature{
sigs[i] = auth.StdSignature{
PubKey: p.PubKey(),
Signature: p.Sign(sdk.StdSignBytes(chainID, seq, fee, msg)),
Signature: p.Sign(auth.StdSignBytes(chainID, seq, fee, msg)),
Sequence: seq[i],
}
}

return sdk.NewStdTx(msg, fee, sigs)
return auth.NewStdTx(msg, fee, sigs)

}

Expand Down
9 changes: 4 additions & 5 deletions cmd/gaia/app/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/wire"
"github.com/cosmos/cosmos-sdk/x/auth"
"github.com/cosmos/cosmos-sdk/x/baseaccount"
"github.com/cosmos/cosmos-sdk/x/stake"
)

Expand All @@ -29,7 +28,7 @@ type GenesisAccount struct {
Coins sdk.Coins `json:"coins"`
}

func NewGenesisAccount(acc *baseaccount.BaseAccount) GenesisAccount {
func NewGenesisAccount(acc *auth.BaseAccount) GenesisAccount {
return GenesisAccount{
Address: acc.Address,
Coins: acc.Coins,
Expand All @@ -44,8 +43,8 @@ func NewGenesisAccountI(acc auth.Account) GenesisAccount {
}

// convert GenesisAccount to auth.BaseAccount
func (ga *GenesisAccount) ToAccount() (acc *baseaccount.BaseAccount) {
return &baseaccount.BaseAccount{
func (ga *GenesisAccount) ToAccount() (acc *auth.BaseAccount) {
return &auth.BaseAccount{
Address: ga.Address,
Coins: ga.Coins.Sort(),
}
Expand Down Expand Up @@ -149,7 +148,7 @@ func GaiaAppGenState(cdc *wire.Codec, appGenTxs []json.RawMessage) (appState jso
}

// create the genesis account, give'm few steaks and a buncha token with there name
accAuth := baseaccount.NewBaseAccountWithAddress(genTx.Address)
accAuth := auth.NewBaseAccountWithAddress(genTx.Address)
accAuth.Coins = sdk.Coins{
{genTx.Name + "Token", 1000},
{"steak", freeFermionsAcc},
Expand Down
10 changes: 5 additions & 5 deletions examples/basecoin/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type BasecoinApp struct {
keyStake *sdk.KVStoreKey

// Manage getting and setting accounts
accountMapper sdk.AccountMapper
accountMapper auth.AccountMapper
coinKeeper bank.Keeper
ibcMapper ibc.Mapper
stakeKeeper stake.Keeper
Expand Down Expand Up @@ -70,15 +70,15 @@ func NewBasecoinApp(logger log.Logger, db dbm.DB) *BasecoinApp {

// register message routes
app.Router().
AddRoute("auth", auth.NewHandler(app.accountMapper.(auth.AccountMapper))).
AddRoute("auth", auth.NewHandler(app.accountMapper)).
AddRoute("bank", bank.NewHandler(app.coinKeeper)).
AddRoute("ibc", ibc.NewHandler(app.ibcMapper, app.coinKeeper)).
AddRoute("stake", stake.NewHandler(app.stakeKeeper))

// Initialize BaseApp.
app.SetInitChainer(app.initChainer)
app.MountStoresIAVL(app.keyMain, app.keyAccount, app.keyIBC, app.keyStake)
app.SetAnteHandler(auth.NewAnteHandler(app.accountMapper, auth.BurnFeeHandler))
app.SetAnteHandler(auth.NewAnteHandler(app.accountMapper))
err := app.LoadLatestVersion(app.keyMain)
if err != nil {
cmn.Exit(err.Error())
Expand All @@ -96,7 +96,7 @@ func MakeCodec() *wire.Codec {
ibc.RegisterWire(cdc)

// register custom AppAccount
cdc.RegisterInterface((*sdk.Account)(nil), nil)
cdc.RegisterInterface((*auth.Account)(nil), nil)
cdc.RegisterConcrete(&types.AppAccount{}, "basecoin/Account", nil)
return cdc
}
Expand Down Expand Up @@ -129,7 +129,7 @@ func (app *BasecoinApp) ExportAppStateJSON() (appState json.RawMessage, err erro

// iterate to get the accounts
accounts := []*types.GenesisAccount{}
appendAccount := func(acc sdk.Account) (stop bool) {
appendAccount := func(acc auth.Account) (stop bool) {
account := &types.GenesisAccount{
Address: acc.GetAddress(),
Coins: acc.GetCoins(),
Expand Down
12 changes: 6 additions & 6 deletions examples/basecoin/app/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ var (
coins = sdk.Coins{{"foocoin", 10}}
halfCoins = sdk.Coins{{"foocoin", 5}}
manyCoins = sdk.Coins{{"foocoin", 1}, {"barcoin", 1}}
fee = sdk.StdFee{
fee = auth.StdFee{
sdk.Coins{{"foocoin", 0}},
100000,
}
Expand Down Expand Up @@ -471,17 +471,17 @@ func TestIBCMsgs(t *testing.T) {
SignCheckDeliver(t, bapp, receiveMsg, []int64{3}, false, priv1)
}

func genTx(msg sdk.Msg, seq []int64, priv ...crypto.PrivKeyEd25519) sdk.StdTx {
sigs := make([]sdk.StdSignature, len(priv))
func genTx(msg sdk.Msg, seq []int64, priv ...crypto.PrivKeyEd25519) auth.StdTx {
sigs := make([]auth.StdSignature, len(priv))
for i, p := range priv {
sigs[i] = sdk.StdSignature{
sigs[i] = auth.StdSignature{
PubKey: p.PubKey(),
Signature: p.Sign(sdk.StdSignBytes(chainID, seq, fee, msg)),
Signature: p.Sign(auth.StdSignBytes(chainID, seq, fee, msg)),
Sequence: seq[i],
}
}

return sdk.NewStdTx(msg, fee, sigs)
return auth.NewStdTx(msg, fee, sigs)

}

Expand Down
6 changes: 3 additions & 3 deletions examples/basecoin/types/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/cosmos/cosmos-sdk/x/auth"
)

var _ sdk.Account = (*AppAccount)(nil)
var _ auth.Account = (*AppAccount)(nil)

// Custom extensions for this application. This is just an example of
// extending auth.BaseAccount with custom fields.
Expand All @@ -23,8 +23,8 @@ func (acc AppAccount) GetName() string { return acc.Name }
func (acc *AppAccount) SetName(name string) { acc.Name = name }

// Get the AccountDecoder function for the custom AppAccount
func GetAccountDecoder(cdc *wire.Codec) sdk.AccountDecoder {
return func(accBytes []byte) (res sdk.Account, err error) {
func GetAccountDecoder(cdc *wire.Codec) auth.AccountDecoder {
return func(accBytes []byte) (res auth.Account, err error) {
if len(accBytes) == 0 {
return nil, sdk.ErrTxDecode("accBytes are empty")
}
Expand Down
8 changes: 4 additions & 4 deletions examples/democoin/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ type DemocoinApp struct {
stakeKeeper simplestake.Keeper

// Manage getting and setting accounts
accountMapper sdk.AccountMapper
accountMapper auth.AccountMapper
}

func NewDemocoinApp(logger log.Logger, db dbm.DB) *DemocoinApp {
Expand Down Expand Up @@ -89,7 +89,7 @@ func NewDemocoinApp(logger log.Logger, db dbm.DB) *DemocoinApp {
// Initialize BaseApp.
app.SetInitChainer(app.initChainerFn(app.coolKeeper, app.powKeeper))
app.MountStoresIAVL(app.capKeyMainStore, app.capKeyAccountStore, app.capKeyPowStore, app.capKeyIBCStore, app.capKeyStakingStore)
app.SetAnteHandler(auth.NewAnteHandler(app.accountMapper, auth.BurnFeeHandler))
app.SetAnteHandler(auth.NewAnteHandler(app.accountMapper))
err := app.LoadLatestVersion(app.capKeyMainStore)
if err != nil {
cmn.Exit(err.Error())
Expand All @@ -109,7 +109,7 @@ func MakeCodec() *wire.Codec {
simplestake.RegisterWire(cdc)

// Register AppAccount
cdc.RegisterInterface((*sdk.Account)(nil), nil)
cdc.RegisterInterface((*auth.Account)(nil), nil)
cdc.RegisterConcrete(&types.AppAccount{}, "democoin/Account", nil)
return cdc
}
Expand Down Expand Up @@ -158,7 +158,7 @@ func (app *DemocoinApp) ExportAppStateJSON() (appState json.RawMessage, err erro

// iterate to get the accounts
accounts := []*types.GenesisAccount{}
appendAccount := func(acc sdk.Account) (stop bool) {
appendAccount := func(acc auth.Account) (stop bool) {
account := &types.GenesisAccount{
Address: acc.GetAddress(),
Coins: acc.GetCoins(),
Expand Down
16 changes: 8 additions & 8 deletions examples/democoin/app/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ var (
addr1 = priv1.PubKey().Address()
addr2 = crypto.GenPrivKeyEd25519().PubKey().Address()
coins = sdk.Coins{{"foocoin", 10}}
fee = sdk.StdFee{
fee = auth.StdFee{
sdk.Coins{{"foocoin", 0}},
1000000,
}
Expand Down Expand Up @@ -93,8 +93,8 @@ func TestMsgs(t *testing.T) {

sequences := []int64{0}
for i, m := range msgs {
sig := priv1.Sign(sdk.StdSignBytes(chainID, sequences, fee, m.msg))
tx := sdk.NewStdTx(m.msg, fee, []sdk.StdSignature{{
sig := priv1.Sign(auth.StdSignBytes(chainID, sequences, fee, m.msg))
tx := auth.NewStdTx(m.msg, fee, []auth.StdSignature{{
PubKey: priv1.PubKey(),
Signature: sig,
}})
Expand Down Expand Up @@ -194,8 +194,8 @@ func TestMsgSendWithAccounts(t *testing.T) {

// Sign the tx
sequences := []int64{0}
sig := priv1.Sign(sdk.StdSignBytes(chainID, sequences, fee, sendMsg))
tx := sdk.NewStdTx(sendMsg, fee, []sdk.StdSignature{{
sig := priv1.Sign(auth.StdSignBytes(chainID, sequences, fee, sendMsg))
tx := auth.NewStdTx(sendMsg, fee, []auth.StdSignature{{
PubKey: priv1.PubKey(),
Signature: sig,
}})
Expand Down Expand Up @@ -227,7 +227,7 @@ func TestMsgSendWithAccounts(t *testing.T) {

// resigning the tx with the bumped sequence should work
sequences = []int64{1}
sig = priv1.Sign(sdk.StdSignBytes(chainID, sequences, fee, tx.Msg))
sig = priv1.Sign(auth.StdSignBytes(chainID, sequences, fee, tx.Msg))
tx.Signatures[0].Signature = sig
res = bapp.Deliver(tx)
assert.Equal(t, sdk.ABCICodeOK, res.Code, res.Log)
Expand Down Expand Up @@ -394,9 +394,9 @@ func TestHandler(t *testing.T) {
func SignCheckDeliver(t *testing.T, bapp *DemocoinApp, msg sdk.Msg, seq int64, expPass bool) {

// Sign the tx
tx := sdk.NewStdTx(msg, fee, []sdk.StdSignature{{
tx := auth.NewStdTx(msg, fee, []auth.StdSignature{{
PubKey: priv1.PubKey(),
Signature: priv1.Sign(sdk.StdSignBytes(chainID, []int64{seq}, fee, msg)),
Signature: priv1.Sign(auth.StdSignBytes(chainID, []int64{seq}, fee, msg)),
Sequence: seq,
}})

Expand Down
Loading

0 comments on commit 5d7c3af

Please sign in to comment.