2018-06-07 17:20:35 -07:00
|
|
|
package ibc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2018-06-21 09:55:08 -07:00
|
|
|
"github.com/stretchr/testify/require"
|
2018-06-07 17:20:35 -07:00
|
|
|
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
"github.com/cosmos/cosmos-sdk/x/auth"
|
|
|
|
"github.com/cosmos/cosmos-sdk/x/bank"
|
2018-07-03 21:21:36 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/mock"
|
2018-06-07 17:20:35 -07:00
|
|
|
|
2018-06-28 17:54:47 -07:00
|
|
|
abci "github.com/tendermint/tendermint/abci/types"
|
2018-07-25 13:43:37 -07:00
|
|
|
"github.com/tendermint/tendermint/crypto/ed25519"
|
2018-06-07 17:20:35 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
// initialize the mock application for this module
|
|
|
|
func getMockApp(t *testing.T) *mock.App {
|
|
|
|
mapp := mock.NewApp()
|
|
|
|
|
|
|
|
RegisterWire(mapp.Cdc)
|
|
|
|
keyIBC := sdk.NewKVStoreKey("ibc")
|
|
|
|
ibcMapper := NewMapper(mapp.Cdc, keyIBC, mapp.RegisterCodespace(DefaultCodespace))
|
|
|
|
coinKeeper := bank.NewKeeper(mapp.AccountMapper)
|
|
|
|
mapp.Router().AddRoute("ibc", NewHandler(ibcMapper, coinKeeper))
|
|
|
|
|
2018-06-21 09:55:08 -07:00
|
|
|
require.NoError(t, mapp.CompleteSetup([]*sdk.KVStoreKey{keyIBC}))
|
2018-06-07 17:20:35 -07:00
|
|
|
return mapp
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestIBCMsgs(t *testing.T) {
|
2018-06-07 20:55:14 -07:00
|
|
|
mapp := getMockApp(t)
|
2018-06-07 17:20:35 -07:00
|
|
|
|
|
|
|
sourceChain := "source-chain"
|
|
|
|
destChain := "dest-chain"
|
|
|
|
|
2018-07-25 13:43:37 -07:00
|
|
|
priv1 := ed25519.GenPrivKey()
|
2018-07-06 00:06:53 -07:00
|
|
|
addr1 := sdk.AccAddress(priv1.PubKey().Address())
|
2018-07-30 17:09:50 -07:00
|
|
|
coins := sdk.Coins{sdk.NewInt64Coin("foocoin", 10)}
|
2018-06-07 17:20:35 -07:00
|
|
|
var emptyCoins sdk.Coins
|
|
|
|
|
|
|
|
acc := &auth.BaseAccount{
|
|
|
|
Address: addr1,
|
|
|
|
Coins: coins,
|
|
|
|
}
|
|
|
|
accs := []auth.Account{acc}
|
|
|
|
|
2018-06-07 20:55:14 -07:00
|
|
|
mock.SetGenesis(mapp, accs)
|
2018-06-07 17:20:35 -07:00
|
|
|
|
|
|
|
// A checkTx context (true)
|
2018-06-07 20:55:14 -07:00
|
|
|
ctxCheck := mapp.BaseApp.NewContext(true, abci.Header{})
|
|
|
|
res1 := mapp.AccountMapper.GetAccount(ctxCheck, addr1)
|
2018-06-29 18:10:15 -07:00
|
|
|
require.Equal(t, acc, res1)
|
2018-06-07 17:20:35 -07:00
|
|
|
|
|
|
|
packet := IBCPacket{
|
|
|
|
SrcAddr: addr1,
|
|
|
|
DestAddr: addr1,
|
|
|
|
Coins: coins,
|
|
|
|
SrcChain: sourceChain,
|
|
|
|
DestChain: destChain,
|
|
|
|
}
|
|
|
|
|
|
|
|
transferMsg := IBCTransferMsg{
|
|
|
|
IBCPacket: packet,
|
|
|
|
}
|
|
|
|
|
|
|
|
receiveMsg := IBCReceiveMsg{
|
|
|
|
IBCPacket: packet,
|
|
|
|
Relayer: addr1,
|
|
|
|
Sequence: 0,
|
|
|
|
}
|
|
|
|
|
2018-06-21 15:05:25 -07:00
|
|
|
mock.SignCheckDeliver(t, mapp.BaseApp, []sdk.Msg{transferMsg}, []int64{0}, []int64{0}, true, priv1)
|
2018-06-07 20:55:14 -07:00
|
|
|
mock.CheckBalance(t, mapp, addr1, emptyCoins)
|
2018-06-21 15:05:25 -07:00
|
|
|
mock.SignCheckDeliver(t, mapp.BaseApp, []sdk.Msg{transferMsg}, []int64{0}, []int64{1}, false, priv1)
|
|
|
|
mock.SignCheckDeliver(t, mapp.BaseApp, []sdk.Msg{receiveMsg}, []int64{0}, []int64{2}, true, priv1)
|
2018-06-07 20:55:14 -07:00
|
|
|
mock.CheckBalance(t, mapp, addr1, coins)
|
2018-06-21 15:05:25 -07:00
|
|
|
mock.SignCheckDeliver(t, mapp.BaseApp, []sdk.Msg{receiveMsg}, []int64{0}, []int64{2}, false, priv1)
|
2018-06-07 17:20:35 -07:00
|
|
|
}
|