Add back cool module tests to democoin
This commit is contained in:
parent
f1af53fe30
commit
c8bba0545b
|
@ -18,6 +18,8 @@ import (
|
||||||
"github.com/cosmos/cosmos-sdk/x/simplestake"
|
"github.com/cosmos/cosmos-sdk/x/simplestake"
|
||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/examples/democoin/types"
|
"github.com/cosmos/cosmos-sdk/examples/democoin/types"
|
||||||
|
"github.com/cosmos/cosmos-sdk/examples/democoin/x/cool"
|
||||||
|
"github.com/cosmos/cosmos-sdk/examples/democoin/x/sketchy"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -58,10 +60,13 @@ func NewDemocoinApp(logger log.Logger, dbs map[string]dbm.DB) *DemocoinApp {
|
||||||
|
|
||||||
// add handlers
|
// add handlers
|
||||||
coinKeeper := bank.NewCoinKeeper(app.accountMapper)
|
coinKeeper := bank.NewCoinKeeper(app.accountMapper)
|
||||||
|
coolKeeper := cool.NewKeeper(app.capKeyMainStore, coinKeeper)
|
||||||
ibcMapper := ibc.NewIBCMapper(app.cdc, app.capKeyIBCStore)
|
ibcMapper := ibc.NewIBCMapper(app.cdc, app.capKeyIBCStore)
|
||||||
stakeKeeper := simplestake.NewKeeper(app.capKeyStakingStore, coinKeeper)
|
stakeKeeper := simplestake.NewKeeper(app.capKeyStakingStore, coinKeeper)
|
||||||
app.Router().
|
app.Router().
|
||||||
AddRoute("bank", bank.NewHandler(coinKeeper), nil).
|
AddRoute("bank", bank.NewHandler(coinKeeper), nil).
|
||||||
|
AddRoute("cool", cool.NewHandler(coolKeeper), coolKeeper.InitGenesis).
|
||||||
|
AddRoute("sketchy", sketchy.NewHandler(), nil).
|
||||||
AddRoute("ibc", ibc.NewHandler(ibcMapper, coinKeeper), nil).
|
AddRoute("ibc", ibc.NewHandler(ibcMapper, coinKeeper), nil).
|
||||||
AddRoute("simplestake", simplestake.NewHandler(stakeKeeper), nil)
|
AddRoute("simplestake", simplestake.NewHandler(stakeKeeper), nil)
|
||||||
|
|
||||||
|
@ -98,6 +103,8 @@ func MakeCodec() *wire.Codec {
|
||||||
struct{ sdk.Msg }{},
|
struct{ sdk.Msg }{},
|
||||||
oldwire.ConcreteType{bank.SendMsg{}, msgTypeSend},
|
oldwire.ConcreteType{bank.SendMsg{}, msgTypeSend},
|
||||||
oldwire.ConcreteType{bank.IssueMsg{}, msgTypeIssue},
|
oldwire.ConcreteType{bank.IssueMsg{}, msgTypeIssue},
|
||||||
|
oldwire.ConcreteType{cool.QuizMsg{}, msgTypeQuiz},
|
||||||
|
oldwire.ConcreteType{cool.SetTrendMsg{}, msgTypeSetTrend},
|
||||||
oldwire.ConcreteType{ibc.IBCTransferMsg{}, msgTypeIBCTransferMsg},
|
oldwire.ConcreteType{ibc.IBCTransferMsg{}, msgTypeIBCTransferMsg},
|
||||||
oldwire.ConcreteType{ibc.IBCReceiveMsg{}, msgTypeIBCReceiveMsg},
|
oldwire.ConcreteType{ibc.IBCReceiveMsg{}, msgTypeIBCReceiveMsg},
|
||||||
oldwire.ConcreteType{simplestake.BondMsg{}, msgTypeBondMsg},
|
oldwire.ConcreteType{simplestake.BondMsg{}, msgTypeBondMsg},
|
||||||
|
|
|
@ -10,6 +10,7 @@ import (
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/examples/democoin/types"
|
"github.com/cosmos/cosmos-sdk/examples/democoin/types"
|
||||||
|
"github.com/cosmos/cosmos-sdk/examples/democoin/x/cool"
|
||||||
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/auth"
|
||||||
"github.com/cosmos/cosmos-sdk/x/bank"
|
"github.com/cosmos/cosmos-sdk/x/bank"
|
||||||
|
@ -38,6 +39,31 @@ var (
|
||||||
Inputs: []bank.Input{bank.NewInput(addr1, coins)},
|
Inputs: []bank.Input{bank.NewInput(addr1, coins)},
|
||||||
Outputs: []bank.Output{bank.NewOutput(addr2, coins)},
|
Outputs: []bank.Output{bank.NewOutput(addr2, coins)},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
quizMsg1 = cool.QuizMsg{
|
||||||
|
Sender: addr1,
|
||||||
|
CoolAnswer: "icecold",
|
||||||
|
}
|
||||||
|
|
||||||
|
quizMsg2 = cool.QuizMsg{
|
||||||
|
Sender: addr1,
|
||||||
|
CoolAnswer: "badvibesonly",
|
||||||
|
}
|
||||||
|
|
||||||
|
setTrendMsg1 = cool.SetTrendMsg{
|
||||||
|
Sender: addr1,
|
||||||
|
Cool: "icecold",
|
||||||
|
}
|
||||||
|
|
||||||
|
setTrendMsg2 = cool.SetTrendMsg{
|
||||||
|
Sender: addr1,
|
||||||
|
Cool: "badvibesonly",
|
||||||
|
}
|
||||||
|
|
||||||
|
setTrendMsg3 = cool.SetTrendMsg{
|
||||||
|
Sender: addr1,
|
||||||
|
Cool: "warmandkind",
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
func loggerAndDBs() (log.Logger, map[string]dbm.DB) {
|
func loggerAndDBs() (log.Logger, map[string]dbm.DB) {
|
||||||
|
@ -65,6 +91,8 @@ func TestMsgs(t *testing.T) {
|
||||||
msg sdk.Msg
|
msg sdk.Msg
|
||||||
}{
|
}{
|
||||||
{sendMsg},
|
{sendMsg},
|
||||||
|
{quizMsg1},
|
||||||
|
{setTrendMsg1},
|
||||||
}
|
}
|
||||||
|
|
||||||
sequences := []int64{0}
|
sequences := []int64{0}
|
||||||
|
@ -112,6 +140,9 @@ func TestGenesis(t *testing.T) {
|
||||||
"accounts": []*types.GenesisAccount{
|
"accounts": []*types.GenesisAccount{
|
||||||
types.NewGenesisAccount(acc),
|
types.NewGenesisAccount(acc),
|
||||||
},
|
},
|
||||||
|
"cool": map[string]string{
|
||||||
|
"trend": "ice-cold",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
stateBytes, err := json.MarshalIndent(genesisState, "", "\t")
|
stateBytes, err := json.MarshalIndent(genesisState, "", "\t")
|
||||||
|
|
||||||
|
@ -149,6 +180,9 @@ func TestSendMsgWithAccounts(t *testing.T) {
|
||||||
"accounts": []*types.GenesisAccount{
|
"accounts": []*types.GenesisAccount{
|
||||||
types.NewGenesisAccount(acc1),
|
types.NewGenesisAccount(acc1),
|
||||||
},
|
},
|
||||||
|
"cool": map[string]string{
|
||||||
|
"trend": "ice-cold",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
stateBytes, err := json.MarshalIndent(genesisState, "", "\t")
|
stateBytes, err := json.MarshalIndent(genesisState, "", "\t")
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
|
@ -221,6 +255,9 @@ func TestQuizMsg(t *testing.T) {
|
||||||
"accounts": []*types.GenesisAccount{
|
"accounts": []*types.GenesisAccount{
|
||||||
types.NewGenesisAccount(acc1),
|
types.NewGenesisAccount(acc1),
|
||||||
},
|
},
|
||||||
|
"cool": map[string]string{
|
||||||
|
"trend": "ice-cold",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
stateBytes, err := json.MarshalIndent(genesisState, "", "\t")
|
stateBytes, err := json.MarshalIndent(genesisState, "", "\t")
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
|
@ -235,6 +272,21 @@ func TestQuizMsg(t *testing.T) {
|
||||||
res1 := bapp.accountMapper.GetAccount(ctxCheck, addr1)
|
res1 := bapp.accountMapper.GetAccount(ctxCheck, addr1)
|
||||||
assert.Equal(t, acc1, res1)
|
assert.Equal(t, acc1, res1)
|
||||||
|
|
||||||
|
// Set the trend, submit a really cool quiz and check for reward
|
||||||
|
SignCheckDeliver(t, bapp, setTrendMsg1, 0, true)
|
||||||
|
SignCheckDeliver(t, bapp, quizMsg1, 1, true)
|
||||||
|
CheckBalance(t, bapp, "69icecold")
|
||||||
|
SignCheckDeliver(t, bapp, quizMsg2, 2, false) // result without reward
|
||||||
|
CheckBalance(t, bapp, "69icecold")
|
||||||
|
SignCheckDeliver(t, bapp, quizMsg1, 3, true)
|
||||||
|
CheckBalance(t, bapp, "138icecold")
|
||||||
|
SignCheckDeliver(t, bapp, setTrendMsg2, 4, true) // reset the trend
|
||||||
|
SignCheckDeliver(t, bapp, quizMsg1, 5, false) // the same answer will nolonger do!
|
||||||
|
CheckBalance(t, bapp, "138icecold")
|
||||||
|
SignCheckDeliver(t, bapp, quizMsg2, 6, true) // earlier answer now relavent again
|
||||||
|
CheckBalance(t, bapp, "69badvibesonly,138icecold")
|
||||||
|
SignCheckDeliver(t, bapp, setTrendMsg3, 7, false) // expect to fail to set the trend to something which is not cool
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestHandler(t *testing.T) {
|
func TestHandler(t *testing.T) {
|
||||||
|
@ -253,6 +305,9 @@ func TestHandler(t *testing.T) {
|
||||||
"accounts": []*types.GenesisAccount{
|
"accounts": []*types.GenesisAccount{
|
||||||
types.NewGenesisAccount(acc1),
|
types.NewGenesisAccount(acc1),
|
||||||
},
|
},
|
||||||
|
"cool": map[string]string{
|
||||||
|
"trend": "ice-cold",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
stateBytes, err := json.MarshalIndent(genesisState, "", "\t")
|
stateBytes, err := json.MarshalIndent(genesisState, "", "\t")
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
|
|
Loading…
Reference in New Issue