gaia new error codetype
This commit is contained in:
parent
c80b9674cd
commit
2994af56c9
|
@ -37,6 +37,9 @@ type GaiaApp struct {
|
|||
coinKeeper bank.CoinKeeper
|
||||
ibcMapper ibc.IBCMapper
|
||||
stakeKeeper stake.Keeper
|
||||
|
||||
// Handle fees
|
||||
feeHandler sdk.FeeHandler
|
||||
}
|
||||
|
||||
func NewGaiaApp(logger log.Logger, db dbm.DB) *GaiaApp {
|
||||
|
@ -59,19 +62,23 @@ func NewGaiaApp(logger log.Logger, db dbm.DB) *GaiaApp {
|
|||
|
||||
// add handlers
|
||||
app.coinKeeper = bank.NewCoinKeeper(app.accountMapper)
|
||||
app.ibcMapper = ibc.NewIBCMapper(app.cdc, app.capKeyIBCStore)
|
||||
app.stakeKeeper = stake.NewKeeper(app.cdc, app.capKeyStakeStore, app.coinKeeper)
|
||||
app.ibcMapper = ibc.NewIBCMapper(app.cdc, app.capKeyIBCStore, app.RegisterCodespace(ibc.DefaultCodespace))
|
||||
app.stakeKeeper = stake.NewKeeper(app.cdc, app.capKeyStakeStore, app.coinKeeper, app.RegisterCodespace(stake.DefaultCodespace))
|
||||
|
||||
app.Router().
|
||||
AddRoute("bank", bank.NewHandler(app.coinKeeper)).
|
||||
AddRoute("ibc", ibc.NewHandler(app.ibcMapper, app.coinKeeper)).
|
||||
AddRoute("stake", stake.NewHandler(app.stakeKeeper))
|
||||
|
||||
// Define the feeHandler.
|
||||
app.feeHandler = auth.BurnFeeHandler
|
||||
|
||||
// initialize BaseApp
|
||||
app.SetTxDecoder(app.txDecoder)
|
||||
app.SetInitChainer(app.initChainer)
|
||||
app.SetEndBlocker(stake.NewEndBlocker(app.stakeKeeper))
|
||||
app.MountStoresIAVL(app.capKeyMainStore, app.capKeyAccountStore, app.capKeyIBCStore, app.capKeyStakeStore)
|
||||
app.SetAnteHandler(auth.NewAnteHandler(app.accountMapper))
|
||||
app.SetAnteHandler(auth.NewAnteHandler(app.accountMapper, app.feeHandler))
|
||||
err := app.LoadLatestVersion(app.capKeyMainStore)
|
||||
if err != nil {
|
||||
cmn.Exit(err.Error())
|
||||
|
@ -113,7 +120,7 @@ func (app *GaiaApp) txDecoder(txBytes []byte) (sdk.Tx, sdk.Error) {
|
|||
// are registered by MakeTxCodec
|
||||
err := app.cdc.UnmarshalBinary(txBytes, &tx)
|
||||
if err != nil {
|
||||
return nil, sdk.ErrTxDecode("").TraceCause(err, "")
|
||||
return nil, sdk.ErrTxDecode("").Trace(err.Error())
|
||||
}
|
||||
return tx, nil
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ import (
|
|||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/examples/basecoin/types"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth"
|
||||
"github.com/cosmos/cosmos-sdk/x/bank"
|
||||
|
@ -138,48 +139,27 @@ func TestMsgs(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestSortGenesis(t *testing.T) {
|
||||
logger, dbs := loggerAndDB()
|
||||
gapp := NewGaiaApp(logger, dbs)
|
||||
func setGenesisAccounts(gapp *GaiaApp, accs ...auth.BaseAccount) error {
|
||||
genaccs := make([]*types.GenesisAccount, len(accs))
|
||||
for i, acc := range accs {
|
||||
genaccs[i] = types.NewGenesisAccount(&types.AppAccount{acc, accName})
|
||||
}
|
||||
|
||||
// Note the order: the coins are unsorted!
|
||||
coinDenom1, coinDenom2 := "foocoin", "barcoin"
|
||||
genesisState := types.GenesisState{
|
||||
Accounts: genaccs,
|
||||
}
|
||||
|
||||
str := `{
|
||||
"accounts": [{
|
||||
"address": "%s",
|
||||
"coins": [
|
||||
{
|
||||
"denom": "%s",
|
||||
"amount": 10
|
||||
},
|
||||
{
|
||||
"denom": "%s",
|
||||
"amount": 20
|
||||
}
|
||||
]
|
||||
}]
|
||||
}`
|
||||
genState := fmt.Sprintf(str, addr1.String(), coinDenom1, coinDenom2)
|
||||
stateBytes, err := json.MarshalIndent(genesisState, "", "\t")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Initialize the chain
|
||||
vals := []abci.Validator{}
|
||||
gapp.InitChain(abci.RequestInitChain{vals, []byte(genState)})
|
||||
gapp.InitChain(abci.RequestInitChain{vals, stateBytes})
|
||||
gapp.Commit()
|
||||
|
||||
// Unsorted coins means invalid
|
||||
err := sendMsg5.ValidateBasic()
|
||||
require.Equal(t, sdk.CodeInvalidCoins, err.ABCICode(), err.ABCILog())
|
||||
|
||||
// Sort coins, should be valid
|
||||
sendMsg5.Inputs[0].Coins.Sort()
|
||||
sendMsg5.Outputs[0].Coins.Sort()
|
||||
err = sendMsg5.ValidateBasic()
|
||||
require.Nil(t, err)
|
||||
|
||||
// Ensure we can send
|
||||
require.Nil(t, setGenesis(gapp)) // initialize the pool
|
||||
SignCheckDeliver(t, gapp, sendMsg5, []int64{0}, true, priv1)
|
||||
return nil
|
||||
}
|
||||
|
||||
func TestGenesis(t *testing.T) {
|
||||
|
@ -247,7 +227,7 @@ func TestSendMsgWithAccounts(t *testing.T) {
|
|||
tx.Signatures[0].Sequence = 1
|
||||
res := gapp.Deliver(tx)
|
||||
|
||||
assert.Equal(t, sdk.CodeUnauthorized, res.Code, res.Log)
|
||||
assert.Equal(t, sdk.ToABCICode(sdk.CodespaceRoot, sdk.CodeUnauthorized), res.Code, res.Log)
|
||||
|
||||
// resigning the tx with the bumped sequence should work
|
||||
SignCheckDeliver(t, gapp, sendMsg1, []int64{1}, true, priv1)
|
||||
|
@ -498,18 +478,18 @@ func SignCheckDeliver(t *testing.T, gapp *GaiaApp, msg sdk.Msg, seq []int64, exp
|
|||
// Run a Check
|
||||
res := gapp.Check(tx)
|
||||
if expPass {
|
||||
require.Equal(t, sdk.CodeOK, res.Code, res.Log)
|
||||
require.Equal(t, sdk.ABCICodeOK, res.Code, res.Log)
|
||||
} else {
|
||||
require.NotEqual(t, sdk.CodeOK, res.Code, res.Log)
|
||||
require.NotEqual(t, sdk.ABCICodeOK, res.Code, res.Log)
|
||||
}
|
||||
|
||||
// Simulate a Block
|
||||
gapp.BeginBlock(abci.RequestBeginBlock{})
|
||||
res = gapp.Deliver(tx)
|
||||
if expPass {
|
||||
require.Equal(t, sdk.CodeOK, res.Code, res.Log)
|
||||
require.Equal(t, sdk.ABCICodeOK, res.Code, res.Log)
|
||||
} else {
|
||||
require.NotEqual(t, sdk.CodeOK, res.Code, res.Log)
|
||||
require.NotEqual(t, sdk.ABCICodeOK, res.Code, res.Log)
|
||||
}
|
||||
gapp.EndBlock(abci.RequestEndBlock{})
|
||||
|
||||
|
@ -530,9 +510,9 @@ func SignDeliver(t *testing.T, gapp *GaiaApp, msg sdk.Msg, seq []int64, expPass
|
|||
gapp.BeginBlock(abci.RequestBeginBlock{})
|
||||
res := gapp.Deliver(tx)
|
||||
if expPass {
|
||||
require.Equal(t, sdk.CodeOK, res.Code, res.Log)
|
||||
require.Equal(t, sdk.ABCICodeOK, res.Code, res.Log)
|
||||
} else {
|
||||
require.NotEqual(t, sdk.CodeOK, res.Code, res.Log)
|
||||
require.NotEqual(t, sdk.ABCICodeOK, res.Code, res.Log)
|
||||
}
|
||||
gapp.EndBlock(abci.RequestEndBlock{})
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ type Keeper struct {
|
|||
codespace sdk.CodespaceType
|
||||
}
|
||||
|
||||
func NewKeeper(ctx sdk.Context, cdc *wire.Codec, key sdk.StoreKey, ck bank.CoinKeeper, codespace sdk.CodespaceType) Keeper {
|
||||
func NewKeeper(cdc *wire.Codec, key sdk.StoreKey, ck bank.CoinKeeper, codespace sdk.CodespaceType) Keeper {
|
||||
keeper := Keeper{
|
||||
storeKey: key,
|
||||
cdc: cdc,
|
||||
|
|
|
@ -140,7 +140,7 @@ func createTestInput(t *testing.T, isCheckTx bool, initCoins int64) (sdk.Context
|
|||
&auth.BaseAccount{}, // prototype
|
||||
).Seal()
|
||||
ck := bank.NewCoinKeeper(accountMapper)
|
||||
keeper := NewKeeper(ctx, cdc, keyStake, ck, DefaultCodespace)
|
||||
keeper := NewKeeper(cdc, keyStake, ck, DefaultCodespace)
|
||||
keeper.setPool(ctx, initialPool())
|
||||
keeper.setParams(ctx, defaultParams())
|
||||
|
||||
|
|
Loading…
Reference in New Issue