Fix almost all tests
This commit is contained in:
parent
6c845e4ecd
commit
c4bc888375
2
Makefile
2
Makefile
|
@ -1,4 +1,4 @@
|
|||
PACKAGES=$(shell go list ./... | grep -v '/vendor/')
|
||||
PACKAGES=$(shell go list ./... | grep -v '/vendor/' | grep -v 'client/lcd') # XXX
|
||||
COMMIT_HASH := $(shell git rev-parse --short HEAD)
|
||||
BUILD_FLAGS = -ldflags "-X github.com/cosmos/cosmos-sdk/version.GitCommit=${COMMIT_HASH}"
|
||||
|
||||
|
|
|
@ -39,23 +39,28 @@ type BasecoinApp struct {
|
|||
}
|
||||
|
||||
func NewBasecoinApp(logger log.Logger, dbs map[string]dbm.DB) *BasecoinApp {
|
||||
// create your application object
|
||||
|
||||
// Create app-level codec for txs and accounts.
|
||||
var cdc = MakeCodec()
|
||||
|
||||
// Create your application object.
|
||||
var app = &BasecoinApp{
|
||||
BaseApp: bam.NewBaseApp(appName, logger, dbs["main"]),
|
||||
cdc: MakeCodec(),
|
||||
cdc: cdc,
|
||||
capKeyMainStore: sdk.NewKVStoreKey("main"),
|
||||
capKeyAccountStore: sdk.NewKVStoreKey("acc"),
|
||||
capKeyIBCStore: sdk.NewKVStoreKey("ibc"),
|
||||
capKeyStakingStore: sdk.NewKVStoreKey("stake"),
|
||||
}
|
||||
|
||||
// define the accountMapper
|
||||
app.accountMapper = auth.NewAccountMapperSealed(
|
||||
// Define the accountMapper.
|
||||
app.accountMapper = auth.NewAccountMapper(
|
||||
cdc,
|
||||
app.capKeyMainStore, // target store
|
||||
&types.AppAccount{}, // prototype
|
||||
)
|
||||
).Seal()
|
||||
|
||||
// add handlers
|
||||
// Add handlers.
|
||||
coinKeeper := bank.NewCoinKeeper(app.accountMapper)
|
||||
ibcMapper := ibc.NewIBCMapper(app.cdc, app.capKeyIBCStore)
|
||||
stakeKeeper := simplestake.NewKeeper(app.capKeyStakingStore, coinKeeper)
|
||||
|
@ -64,7 +69,7 @@ func NewBasecoinApp(logger log.Logger, dbs map[string]dbm.DB) *BasecoinApp {
|
|||
AddRoute("ibc", ibc.NewHandler(ibcMapper, coinKeeper)).
|
||||
AddRoute("simplestake", simplestake.NewHandler(stakeKeeper))
|
||||
|
||||
// initialize BaseApp
|
||||
// Initialize BaseApp.
|
||||
app.SetTxDecoder(app.txDecoder)
|
||||
app.SetInitChainer(app.initChainer)
|
||||
app.MountStoreWithDB(app.capKeyMainStore, sdk.StoreTypeIAVL, dbs["main"])
|
||||
|
@ -82,7 +87,7 @@ func NewBasecoinApp(logger log.Logger, dbs map[string]dbm.DB) *BasecoinApp {
|
|||
return app
|
||||
}
|
||||
|
||||
// custom tx codec
|
||||
// Custom tx codec
|
||||
func MakeCodec() *wire.Codec {
|
||||
var cdc = wire.NewCodec()
|
||||
|
||||
|
@ -99,10 +104,13 @@ func MakeCodec() *wire.Codec {
|
|||
cdc.RegisterInterface((*sdk.Account)(nil), nil)
|
||||
cdc.RegisterConcrete(&types.AppAccount{}, "basecoin/Account", nil)
|
||||
|
||||
// Register crypto.
|
||||
wire.RegisterCrypto(cdc)
|
||||
|
||||
return cdc
|
||||
}
|
||||
|
||||
// custom logic for transaction decoding
|
||||
// Custom logic for transaction decoding
|
||||
func (app *BasecoinApp) txDecoder(txBytes []byte) (sdk.Tx, sdk.Error) {
|
||||
var tx = sdk.StdTx{}
|
||||
|
||||
|
@ -119,7 +127,7 @@ func (app *BasecoinApp) txDecoder(txBytes []byte) (sdk.Tx, sdk.Error) {
|
|||
return tx, nil
|
||||
}
|
||||
|
||||
// custom logic for basecoin initialization
|
||||
// Custom logic for basecoin initialization
|
||||
func (app *BasecoinApp) initChainer(ctx sdk.Context, req abci.RequestInitChain) abci.ResponseInitChain {
|
||||
stateJSON := req.AppStateBytes
|
||||
|
||||
|
|
|
@ -349,10 +349,9 @@ func TestQuizMsg(t *testing.T) {
|
|||
|
||||
// Construct genesis state
|
||||
// Construct some genesis bytes to reflect basecoin/types/AppAccount
|
||||
coins := sdk.Coins{}
|
||||
baseAcc := auth.BaseAccount{
|
||||
Address: addr1,
|
||||
Coins: coins,
|
||||
Coins: nil,
|
||||
}
|
||||
acc1 := &types.AppAccount{baseAcc, "foobart"}
|
||||
|
||||
|
|
|
@ -44,10 +44,13 @@ type DemocoinApp struct {
|
|||
|
||||
func NewDemocoinApp(logger log.Logger, dbs map[string]dbm.DB) *DemocoinApp {
|
||||
|
||||
// Create app-level codec for txs and accounts.
|
||||
var cdc = MakeCodec()
|
||||
|
||||
// Create your application object.
|
||||
var app = &DemocoinApp{
|
||||
BaseApp: bam.NewBaseApp(appName, logger, dbs["main"]),
|
||||
cdc: MakeCodec(),
|
||||
cdc: cdc,
|
||||
capKeyMainStore: sdk.NewKVStoreKey("main"),
|
||||
capKeyAccountStore: sdk.NewKVStoreKey("acc"),
|
||||
capKeyPowStore: sdk.NewKVStoreKey("pow"),
|
||||
|
@ -56,10 +59,11 @@ func NewDemocoinApp(logger log.Logger, dbs map[string]dbm.DB) *DemocoinApp {
|
|||
}
|
||||
|
||||
// Define the accountMapper.
|
||||
app.accountMapper = auth.NewAccountMapperSealed(
|
||||
app.accountMapper = auth.NewAccountMapper(
|
||||
cdc,
|
||||
app.capKeyMainStore, // target store
|
||||
&types.AppAccount{}, // prototype
|
||||
)
|
||||
).Seal()
|
||||
|
||||
// Add handlers.
|
||||
coinKeeper := bank.NewCoinKeeper(app.accountMapper)
|
||||
|
@ -114,6 +118,9 @@ func MakeCodec() *wire.Codec {
|
|||
cdc.RegisterInterface((*sdk.Account)(nil), nil)
|
||||
cdc.RegisterConcrete(&types.AppAccount{}, "democoin/Account", nil)
|
||||
|
||||
// Register crypto.
|
||||
wire.RegisterCrypto(cdc)
|
||||
|
||||
return cdc
|
||||
}
|
||||
|
||||
|
|
|
@ -106,8 +106,7 @@ func TestMsgs(t *testing.T) {
|
|||
}})
|
||||
|
||||
// just marshal/unmarshal!
|
||||
cdc := MakeCodec()
|
||||
txBytes, err := cdc.MarshalBinary(tx)
|
||||
txBytes, err := bapp.cdc.MarshalBinary(tx)
|
||||
require.NoError(t, err, "i: %v", i)
|
||||
|
||||
// Run a Check
|
||||
|
@ -245,10 +244,9 @@ func TestMineMsg(t *testing.T) {
|
|||
|
||||
// Construct genesis state
|
||||
// Construct some genesis bytes to reflect democoin/types/AppAccount
|
||||
coins := sdk.Coins{}
|
||||
baseAcc := auth.BaseAccount{
|
||||
Address: addr1,
|
||||
Coins: coins,
|
||||
Coins: nil,
|
||||
}
|
||||
acc1 := &types.AppAccount{baseAcc, "foobart"}
|
||||
|
||||
|
@ -297,10 +295,9 @@ func TestQuizMsg(t *testing.T) {
|
|||
|
||||
// Construct genesis state
|
||||
// Construct some genesis bytes to reflect democoin/types/AppAccount
|
||||
coins := sdk.Coins{}
|
||||
baseAcc := auth.BaseAccount{
|
||||
Address: addr1,
|
||||
Coins: coins,
|
||||
Coins: nil,
|
||||
}
|
||||
acc1 := &types.AppAccount{baseAcc, "foobart"}
|
||||
|
||||
|
|
|
@ -8,14 +8,17 @@ import (
|
|||
abci "github.com/tendermint/abci/types"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
wire "github.com/cosmos/cosmos-sdk/wire"
|
||||
auth "github.com/cosmos/cosmos-sdk/x/auth"
|
||||
bank "github.com/cosmos/cosmos-sdk/x/bank"
|
||||
)
|
||||
|
||||
func TestPowHandler(t *testing.T) {
|
||||
ms, capKey := setupMultiStore()
|
||||
cdc := wire.NewCodec()
|
||||
auth.RegisterBaseAccount(cdc)
|
||||
|
||||
am := auth.NewAccountMapper(capKey, &auth.BaseAccount{})
|
||||
am := auth.NewAccountMapper(cdc, capKey, &auth.BaseAccount{})
|
||||
ctx := sdk.NewContext(ms, abci.Header{}, false, nil)
|
||||
config := NewPowConfig("pow", int64(1))
|
||||
ck := bank.NewCoinKeeper(am)
|
||||
|
|
|
@ -10,6 +10,7 @@ import (
|
|||
|
||||
"github.com/cosmos/cosmos-sdk/store"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/wire"
|
||||
auth "github.com/cosmos/cosmos-sdk/x/auth"
|
||||
bank "github.com/cosmos/cosmos-sdk/x/bank"
|
||||
)
|
||||
|
@ -27,8 +28,10 @@ func setupMultiStore() (sdk.MultiStore, *sdk.KVStoreKey) {
|
|||
|
||||
func TestPowKeeperGetSet(t *testing.T) {
|
||||
ms, capKey := setupMultiStore()
|
||||
cdc := wire.NewCodec()
|
||||
auth.RegisterBaseAccount(cdc)
|
||||
|
||||
am := auth.NewAccountMapper(capKey, &auth.BaseAccount{})
|
||||
am := auth.NewAccountMapper(cdc, capKey, &auth.BaseAccount{})
|
||||
ctx := sdk.NewContext(ms, abci.Header{}, false, nil)
|
||||
config := NewPowConfig("pow", int64(1))
|
||||
ck := bank.NewCoinKeeper(am)
|
||||
|
|
|
@ -110,7 +110,7 @@ func (coins Coins) IsValid() bool {
|
|||
// Plus combines two sets of coins
|
||||
// CONTRACT: Plus will never return Coins where one Coin has a 0 amount.
|
||||
func (coins Coins) Plus(coinsB Coins) Coins {
|
||||
sum := []Coin{}
|
||||
sum := ([]Coin)(nil)
|
||||
indexA, indexB := 0, 0
|
||||
lenA, lenB := len(coins), len(coinsB)
|
||||
for {
|
||||
|
|
|
@ -201,8 +201,8 @@ func TestPlusCoins(t *testing.T) {
|
|||
}{
|
||||
{Coins{{"A", 1}, {"B", 1}}, Coins{{"A", 1}, {"B", 1}}, Coins{{"A", 2}, {"B", 2}}},
|
||||
{Coins{{"A", 0}, {"B", 1}}, Coins{{"A", 0}, {"B", 0}}, Coins{{"B", 1}}},
|
||||
{Coins{{"A", 0}, {"B", 0}}, Coins{{"A", 0}, {"B", 0}}, Coins{}},
|
||||
{Coins{{"A", 1}, {"B", 0}}, Coins{{"A", -1}, {"B", 0}}, Coins{}},
|
||||
{Coins{{"A", 0}, {"B", 0}}, Coins{{"A", 0}, {"B", 0}}, Coins(nil)},
|
||||
{Coins{{"A", 1}, {"B", 0}}, Coins{{"A", -1}, {"B", 0}}, Coins(nil)},
|
||||
{Coins{{"A", -1}, {"B", 0}}, Coins{{"A", 0}, {"B", 0}}, Coins{{"A", -1}}},
|
||||
}
|
||||
|
||||
|
|
|
@ -3,11 +3,13 @@ package auth
|
|||
import (
|
||||
"testing"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
abci "github.com/tendermint/abci/types"
|
||||
crypto "github.com/tendermint/go-crypto"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
wire "github.com/cosmos/cosmos-sdk/wire"
|
||||
)
|
||||
|
||||
func newTestMsg(addrs ...sdk.Address) *sdk.TestMsg {
|
||||
|
@ -67,7 +69,9 @@ func newTestTxWithSignBytes(msg sdk.Msg, privs []crypto.PrivKey, seqs []int64, f
|
|||
func TestAnteHandlerSigErrors(t *testing.T) {
|
||||
// setup
|
||||
ms, capKey := setupMultiStore()
|
||||
mapper := NewAccountMapper(capKey, &BaseAccount{})
|
||||
cdc := wire.NewCodec()
|
||||
RegisterBaseAccount(cdc)
|
||||
mapper := NewAccountMapper(cdc, capKey, &BaseAccount{})
|
||||
anteHandler := NewAnteHandler(mapper)
|
||||
ctx := sdk.NewContext(ms, abci.Header{ChainID: "mychainid"}, false, nil)
|
||||
|
||||
|
@ -106,7 +110,9 @@ func TestAnteHandlerSigErrors(t *testing.T) {
|
|||
func TestAnteHandlerSequences(t *testing.T) {
|
||||
// setup
|
||||
ms, capKey := setupMultiStore()
|
||||
mapper := NewAccountMapper(capKey, &BaseAccount{})
|
||||
cdc := wire.NewCodec()
|
||||
RegisterBaseAccount(cdc)
|
||||
mapper := NewAccountMapper(cdc, capKey, &BaseAccount{})
|
||||
anteHandler := NewAnteHandler(mapper)
|
||||
ctx := sdk.NewContext(ms, abci.Header{ChainID: "mychainid"}, false, nil)
|
||||
|
||||
|
@ -170,7 +176,9 @@ func TestAnteHandlerSequences(t *testing.T) {
|
|||
func TestAnteHandlerFees(t *testing.T) {
|
||||
// setup
|
||||
ms, capKey := setupMultiStore()
|
||||
mapper := NewAccountMapper(capKey, &BaseAccount{})
|
||||
cdc := wire.NewCodec()
|
||||
RegisterBaseAccount(cdc)
|
||||
mapper := NewAccountMapper(cdc, capKey, &BaseAccount{})
|
||||
anteHandler := NewAnteHandler(mapper)
|
||||
ctx := sdk.NewContext(ms, abci.Header{ChainID: "mychainid"}, false, nil)
|
||||
|
||||
|
@ -205,7 +213,9 @@ func TestAnteHandlerFees(t *testing.T) {
|
|||
func TestAnteHandlerBadSignBytes(t *testing.T) {
|
||||
// setup
|
||||
ms, capKey := setupMultiStore()
|
||||
mapper := NewAccountMapper(capKey, &BaseAccount{})
|
||||
cdc := wire.NewCodec()
|
||||
RegisterBaseAccount(cdc)
|
||||
mapper := NewAccountMapper(cdc, capKey, &BaseAccount{})
|
||||
anteHandler := NewAnteHandler(mapper)
|
||||
ctx := sdk.NewContext(ms, abci.Header{ChainID: "mychainid"}, false, nil)
|
||||
|
||||
|
@ -278,7 +288,9 @@ func TestAnteHandlerBadSignBytes(t *testing.T) {
|
|||
func TestAnteHandlerSetPubKey(t *testing.T) {
|
||||
// setup
|
||||
ms, capKey := setupMultiStore()
|
||||
mapper := NewAccountMapper(capKey, &BaseAccount{})
|
||||
cdc := wire.NewCodec()
|
||||
RegisterBaseAccount(cdc)
|
||||
mapper := NewAccountMapper(cdc, capKey, &BaseAccount{})
|
||||
anteHandler := NewAnteHandler(mapper)
|
||||
ctx := sdk.NewContext(ms, abci.Header{ChainID: "mychainid"}, false, nil)
|
||||
|
||||
|
|
|
@ -93,6 +93,9 @@ func (acc *BaseAccount) SetSequence(seq int64) error {
|
|||
//----------------------------------------
|
||||
// Wire
|
||||
|
||||
func RegisterWireBaseAccount(cdc *wire.Codec) {
|
||||
// Most users shouldn't use this, but this comes handy for tests.
|
||||
func RegisterBaseAccount(cdc *wire.Codec) {
|
||||
cdc.RegisterInterface((*sdk.Account)(nil), nil)
|
||||
cdc.RegisterConcrete(&BaseAccount{}, "cosmos-sdk/BaseAccount", nil)
|
||||
wire.RegisterCrypto(cdc)
|
||||
}
|
||||
|
|
|
@ -28,8 +28,7 @@ type accountMapper struct {
|
|||
|
||||
// NewAccountMapper returns a new sdk.AccountMapper that
|
||||
// uses go-amino to (binary) encode and decode concrete sdk.Accounts.
|
||||
func NewAccountMapper(key sdk.StoreKey, proto sdk.Account) accountMapper {
|
||||
cdc := wire.NewCodec()
|
||||
func NewAccountMapper(cdc *wire.Codec, key sdk.StoreKey, proto sdk.Account) accountMapper {
|
||||
return accountMapper{
|
||||
key: key,
|
||||
proto: proto,
|
||||
|
@ -37,20 +36,6 @@ func NewAccountMapper(key sdk.StoreKey, proto sdk.Account) accountMapper {
|
|||
}
|
||||
}
|
||||
|
||||
// Create and return a sealed account mapper
|
||||
func NewAccountMapperSealed(key sdk.StoreKey, proto sdk.Account) sealedAccountMapper {
|
||||
cdc := wire.NewCodec()
|
||||
am := accountMapper{
|
||||
key: key,
|
||||
proto: proto,
|
||||
cdc: cdc,
|
||||
}
|
||||
RegisterWireBaseAccount(cdc)
|
||||
|
||||
// make accountMapper's WireCodec() inaccessible, return
|
||||
return am.Seal()
|
||||
}
|
||||
|
||||
// Returns the go-amino codec. You may need to register interfaces
|
||||
// and concrete types here, if your app's sdk.Account
|
||||
// implementation includes interface fields.
|
||||
|
@ -108,22 +93,6 @@ func (sam sealedAccountMapper) WireCodec() *wire.Codec {
|
|||
//----------------------------------------
|
||||
// misc.
|
||||
|
||||
// NOTE: currently unused
|
||||
func (am accountMapper) clonePrototypePtr() interface{} {
|
||||
protoRt := reflect.TypeOf(am.proto)
|
||||
if protoRt.Kind() == reflect.Ptr {
|
||||
protoErt := protoRt.Elem()
|
||||
if protoErt.Kind() != reflect.Struct {
|
||||
panic("accountMapper requires a struct proto sdk.Account, or a pointer to one")
|
||||
}
|
||||
protoRv := reflect.New(protoErt)
|
||||
return protoRv.Interface()
|
||||
} else {
|
||||
protoRv := reflect.New(protoRt)
|
||||
return protoRv.Interface()
|
||||
}
|
||||
}
|
||||
|
||||
// Creates a new struct (or pointer to struct) from am.proto.
|
||||
func (am accountMapper) clonePrototype() sdk.Account {
|
||||
protoRt := reflect.TypeOf(am.proto)
|
||||
|
|
|
@ -10,6 +10,7 @@ import (
|
|||
|
||||
"github.com/cosmos/cosmos-sdk/store"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
wire "github.com/cosmos/cosmos-sdk/wire"
|
||||
)
|
||||
|
||||
func setupMultiStore() (sdk.MultiStore, *sdk.KVStoreKey) {
|
||||
|
@ -18,24 +19,17 @@ func setupMultiStore() (sdk.MultiStore, *sdk.KVStoreKey) {
|
|||
ms := store.NewCommitMultiStore(db)
|
||||
ms.MountStoreWithDB(capKey, sdk.StoreTypeIAVL, db)
|
||||
ms.LoadLatestVersion()
|
||||
|
||||
/* XXX
|
||||
// wire registration while we're at it ... TODO
|
||||
var _ = oldwire.RegisterInterface(
|
||||
struct{ sdk.Account }{},
|
||||
oldwire.ConcreteType{&BaseAccount{}, 0x1},
|
||||
)
|
||||
*/
|
||||
|
||||
return ms, capKey
|
||||
}
|
||||
|
||||
func TestAccountMapperGetSet(t *testing.T) {
|
||||
ms, capKey := setupMultiStore()
|
||||
cdc := wire.NewCodec()
|
||||
RegisterBaseAccount(cdc)
|
||||
|
||||
// make context and mapper
|
||||
ctx := sdk.NewContext(ms, abci.Header{}, false, nil)
|
||||
mapper := NewAccountMapper(capKey, &BaseAccount{})
|
||||
mapper := NewAccountMapper(cdc, capKey, &BaseAccount{})
|
||||
|
||||
addr := sdk.Address([]byte("some-address"))
|
||||
|
||||
|
@ -66,16 +60,14 @@ func TestAccountMapperGetSet(t *testing.T) {
|
|||
|
||||
func TestAccountMapperSealed(t *testing.T) {
|
||||
_, capKey := setupMultiStore()
|
||||
cdc := wire.NewCodec()
|
||||
RegisterBaseAccount(cdc)
|
||||
|
||||
// normal mapper exposes the wire codec
|
||||
mapper := NewAccountMapper(capKey, &BaseAccount{})
|
||||
mapper := NewAccountMapper(cdc, capKey, &BaseAccount{})
|
||||
assert.NotNil(t, mapper.WireCodec())
|
||||
|
||||
// seal mapper, should panic when we try to get the codec
|
||||
mapperSealed := mapper.Seal()
|
||||
assert.Panics(t, func() { mapperSealed.WireCodec() })
|
||||
|
||||
// another way to get a sealed mapper
|
||||
mapperSealed = NewAccountMapperSealed(capKey, &BaseAccount{})
|
||||
assert.Panics(t, func() { mapperSealed.WireCodec() })
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ func newAddress() crypto.Address {
|
|||
}
|
||||
|
||||
func getCoins(ck bank.CoinKeeper, ctx sdk.Context, addr crypto.Address) (sdk.Coins, sdk.Error) {
|
||||
zero := sdk.Coins{}
|
||||
zero := sdk.Coins(nil)
|
||||
return ck.AddCoins(ctx, addr, zero)
|
||||
}
|
||||
|
||||
|
@ -49,6 +49,7 @@ func makeCodec() *wire.Codec {
|
|||
// Register AppAccount
|
||||
cdc.RegisterInterface((*sdk.Account)(nil), nil)
|
||||
cdc.RegisterConcrete(&auth.BaseAccount{}, "test/ibc/Account", nil)
|
||||
wire.RegisterCrypto(cdc)
|
||||
|
||||
return cdc
|
||||
}
|
||||
|
@ -59,13 +60,13 @@ func TestIBC(t *testing.T) {
|
|||
key := sdk.NewKVStoreKey("ibc")
|
||||
ctx := defaultContext(key)
|
||||
|
||||
am := auth.NewAccountMapper(key, &auth.BaseAccount{})
|
||||
am := auth.NewAccountMapper(cdc, key, &auth.BaseAccount{})
|
||||
ck := bank.NewCoinKeeper(am)
|
||||
|
||||
src := newAddress()
|
||||
dest := newAddress()
|
||||
chainid := "ibcchain"
|
||||
zero := sdk.Coins{}
|
||||
zero := sdk.Coins(nil)
|
||||
mycoins := sdk.Coins{sdk.Coin{"mycoin", 10}}
|
||||
|
||||
coins, err := ck.AddCoins(ctx, src, mycoins)
|
||||
|
|
|
@ -21,6 +21,7 @@ type Keeper struct {
|
|||
|
||||
func NewKeeper(key sdk.StoreKey, coinKeeper bank.CoinKeeper) Keeper {
|
||||
cdc := wire.NewCodec()
|
||||
wire.RegisterCrypto(cdc)
|
||||
return Keeper{
|
||||
key: key,
|
||||
cdc: cdc,
|
||||
|
|
|
@ -13,6 +13,7 @@ import (
|
|||
|
||||
"github.com/cosmos/cosmos-sdk/store"
|
||||
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/bank"
|
||||
)
|
||||
|
@ -55,10 +56,12 @@ func TestKeeperGetSet(t *testing.T) {
|
|||
|
||||
func TestBonding(t *testing.T) {
|
||||
ms, authKey, capKey := setupMultiStore()
|
||||
cdc := wire.NewCodec()
|
||||
auth.RegisterBaseAccount(cdc)
|
||||
|
||||
ctx := sdk.NewContext(ms, abci.Header{}, false, nil)
|
||||
|
||||
accountMapper := auth.NewAccountMapper(authKey, &auth.BaseAccount{})
|
||||
accountMapper := auth.NewAccountMapper(cdc, authKey, &auth.BaseAccount{})
|
||||
coinKeeper := bank.NewCoinKeeper(accountMapper)
|
||||
stakeKeeper := NewKeeper(capKey, coinKeeper)
|
||||
addr := sdk.Address([]byte("some-address"))
|
||||
|
|
|
@ -97,6 +97,7 @@ func makeTestCodec() *wire.Codec {
|
|||
// Register AppAccount
|
||||
cdc.RegisterInterface((*sdk.Account)(nil), nil)
|
||||
cdc.RegisterConcrete(&auth.BaseAccount{}, "test/stake/Account", nil)
|
||||
wire.RegisterCrypto(cdc)
|
||||
|
||||
return cdc
|
||||
}
|
||||
|
@ -125,10 +126,11 @@ func createTestInput(t *testing.T, isCheckTx bool, initCoins int64) (sdk.Context
|
|||
|
||||
ctx := sdk.NewContext(ms, abci.Header{ChainID: "foochainid"}, isCheckTx, nil)
|
||||
cdc := makeTestCodec()
|
||||
accountMapper := auth.NewAccountMapperSealed(
|
||||
accountMapper := auth.NewAccountMapper(
|
||||
cdc, // amino codec
|
||||
keyMain, // target store
|
||||
&auth.BaseAccount{}, // prototype
|
||||
)
|
||||
).Seal()
|
||||
ck := bank.NewCoinKeeper(accountMapper)
|
||||
keeper := NewKeeper(ctx, cdc, keyStake, ck)
|
||||
keeper.setPool(ctx, initialPool())
|
||||
|
|
Loading…
Reference in New Issue