2019-08-19 06:29:17 -07:00
package keeper_test
2018-04-09 15:10:58 -07:00
import (
"testing"
2019-01-14 08:11:24 -08:00
"time"
2018-04-09 15:10:58 -07:00
2020-01-30 13:31:16 -08:00
"github.com/stretchr/testify/suite"
2019-01-02 13:19:48 -08:00
abci "github.com/tendermint/tendermint/abci/types"
2020-01-16 13:46:51 -08:00
tmkv "github.com/tendermint/tendermint/libs/kv"
2019-01-14 08:11:24 -08:00
tmtime "github.com/tendermint/tendermint/types/time"
2019-01-02 13:19:48 -08:00
2019-08-19 06:29:17 -07:00
"github.com/cosmos/cosmos-sdk/simapp"
2018-04-09 15:10:58 -07:00
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth"
2019-10-10 08:53:30 -07:00
"github.com/cosmos/cosmos-sdk/x/auth/vesting"
2020-02-20 06:24:26 -08:00
"github.com/cosmos/cosmos-sdk/x/bank/types"
2018-04-09 15:10:58 -07:00
)
2020-01-30 13:31:16 -08:00
const (
fooDenom = "foo"
barDenom = "bar"
)
2018-04-09 15:10:58 -07:00
2020-01-30 13:31:16 -08:00
func newFooCoin ( amt int64 ) sdk . Coin {
return sdk . NewInt64Coin ( fooDenom , amt )
}
2018-04-09 15:10:58 -07:00
2020-01-30 13:31:16 -08:00
func newBarCoin ( amt int64 ) sdk . Coin {
return sdk . NewInt64Coin ( barDenom , amt )
}
2018-04-09 15:10:58 -07:00
2020-01-30 13:31:16 -08:00
type IntegrationTestSuite struct {
suite . Suite
2018-04-09 15:10:58 -07:00
2020-01-30 13:31:16 -08:00
app * simapp . SimApp
ctx sdk . Context
}
2018-04-09 15:10:58 -07:00
2020-01-30 13:31:16 -08:00
func ( suite * IntegrationTestSuite ) SetupTest ( ) {
app := simapp . Setup ( false )
ctx := app . BaseApp . NewContext ( false , abci . Header { } )
2018-04-09 15:10:58 -07:00
2020-01-30 13:31:16 -08:00
app . AccountKeeper . SetParams ( ctx , auth . DefaultParams ( ) )
app . BankKeeper . SetSendEnabled ( ctx , true )
2018-04-09 15:10:58 -07:00
2020-01-30 13:31:16 -08:00
suite . app = app
suite . ctx = ctx
}
2018-04-09 15:10:58 -07:00
2020-02-04 18:33:02 -08:00
func ( suite * IntegrationTestSuite ) TestSendCoinsNewAccount ( ) {
app , ctx := suite . app , suite . ctx
balances := sdk . NewCoins ( newFooCoin ( 100 ) , newBarCoin ( 50 ) )
addr1 := sdk . AccAddress ( [ ] byte ( "addr1" ) )
acc1 := app . AccountKeeper . NewAccountWithAddress ( ctx , addr1 )
app . AccountKeeper . SetAccount ( ctx , acc1 )
suite . Require ( ) . NoError ( app . BankKeeper . SetBalances ( ctx , addr1 , balances ) )
acc1Balances := app . BankKeeper . GetAllBalances ( ctx , addr1 )
suite . Require ( ) . Equal ( balances , acc1Balances )
addr2 := sdk . AccAddress ( [ ] byte ( "addr2" ) )
suite . Require ( ) . Nil ( app . AccountKeeper . GetAccount ( ctx , addr2 ) )
suite . Require ( ) . Empty ( app . BankKeeper . GetAllBalances ( ctx , addr2 ) )
sendAmt := sdk . NewCoins ( newFooCoin ( 50 ) , newBarCoin ( 25 ) )
suite . Require ( ) . NoError ( app . BankKeeper . SendCoins ( ctx , addr1 , addr2 , sendAmt ) )
acc2Balances := app . BankKeeper . GetAllBalances ( ctx , addr2 )
suite . Require ( ) . Equal ( sendAmt , acc2Balances )
suite . Require ( ) . NotNil ( app . AccountKeeper . GetAccount ( ctx , addr2 ) )
}
2020-01-30 13:31:16 -08:00
func ( suite * IntegrationTestSuite ) TestInputOutputCoins ( ) {
app , ctx := suite . app , suite . ctx
balances := sdk . NewCoins ( newFooCoin ( 90 ) , newBarCoin ( 30 ) )
2018-04-09 15:10:58 -07:00
2020-01-30 13:31:16 -08:00
addr1 := sdk . AccAddress ( [ ] byte ( "addr1" ) )
acc1 := app . AccountKeeper . NewAccountWithAddress ( ctx , addr1 )
app . AccountKeeper . SetAccount ( ctx , acc1 )
2018-04-09 15:10:58 -07:00
2020-01-30 13:31:16 -08:00
addr2 := sdk . AccAddress ( [ ] byte ( "addr2" ) )
acc2 := app . AccountKeeper . NewAccountWithAddress ( ctx , addr2 )
app . AccountKeeper . SetAccount ( ctx , acc2 )
2018-04-09 15:10:58 -07:00
2020-01-30 13:31:16 -08:00
addr3 := sdk . AccAddress ( [ ] byte ( "addr3" ) )
acc3 := app . AccountKeeper . NewAccountWithAddress ( ctx , addr3 )
app . AccountKeeper . SetAccount ( ctx , acc3 )
2018-04-09 15:10:58 -07:00
2019-06-05 16:26:17 -07:00
inputs := [ ] types . Input {
2020-01-30 13:31:16 -08:00
{ Address : addr1 , Coins : sdk . NewCoins ( newFooCoin ( 30 ) , newBarCoin ( 10 ) ) } ,
{ Address : addr1 , Coins : sdk . NewCoins ( newFooCoin ( 30 ) , newBarCoin ( 10 ) ) } ,
2018-04-09 15:10:58 -07:00
}
2019-06-05 16:26:17 -07:00
outputs := [ ] types . Output {
2020-01-30 13:31:16 -08:00
{ Address : addr2 , Coins : sdk . NewCoins ( newFooCoin ( 30 ) , newBarCoin ( 10 ) ) } ,
{ Address : addr3 , Coins : sdk . NewCoins ( newFooCoin ( 30 ) , newBarCoin ( 10 ) ) } ,
2018-04-09 15:10:58 -07:00
}
2020-01-30 13:31:16 -08:00
suite . Require ( ) . Error ( app . BankKeeper . InputOutputCoins ( ctx , inputs , [ ] types . Output { } ) )
suite . Require ( ) . Error ( app . BankKeeper . InputOutputCoins ( ctx , inputs , outputs ) )
suite . Require ( ) . NoError ( app . BankKeeper . SetBalances ( ctx , addr1 , balances ) )
insufficientInputs := [ ] types . Input {
{ Address : addr1 , Coins : sdk . NewCoins ( newFooCoin ( 300 ) , newBarCoin ( 100 ) ) } ,
{ Address : addr1 , Coins : sdk . NewCoins ( newFooCoin ( 300 ) , newBarCoin ( 100 ) ) } ,
2019-08-19 06:29:17 -07:00
}
2020-01-30 13:31:16 -08:00
insufficientOutputs := [ ] types . Output {
{ Address : addr2 , Coins : sdk . NewCoins ( newFooCoin ( 300 ) , newBarCoin ( 100 ) ) } ,
{ Address : addr3 , Coins : sdk . NewCoins ( newFooCoin ( 300 ) , newBarCoin ( 100 ) ) } ,
}
suite . Require ( ) . Error ( app . BankKeeper . InputOutputCoins ( ctx , insufficientInputs , insufficientOutputs ) )
suite . Require ( ) . NoError ( app . BankKeeper . InputOutputCoins ( ctx , inputs , outputs ) )
acc1Balances := app . BankKeeper . GetAllBalances ( ctx , addr1 )
expected := sdk . NewCoins ( newFooCoin ( 30 ) , newBarCoin ( 10 ) )
suite . Require ( ) . Equal ( expected , acc1Balances )
acc2Balances := app . BankKeeper . GetAllBalances ( ctx , addr2 )
suite . Require ( ) . Equal ( expected , acc2Balances )
acc3Balances := app . BankKeeper . GetAllBalances ( ctx , addr3 )
suite . Require ( ) . Equal ( expected , acc3Balances )
2018-04-09 15:10:58 -07:00
}
2020-01-30 13:31:16 -08:00
func ( suite * IntegrationTestSuite ) TestSendCoins ( ) {
app , ctx := suite . app , suite . ctx
balances := sdk . NewCoins ( newFooCoin ( 100 ) , newBarCoin ( 50 ) )
2019-07-31 08:39:02 -07:00
2020-01-30 13:31:16 -08:00
addr1 := sdk . AccAddress ( [ ] byte ( "addr1" ) )
acc1 := app . AccountKeeper . NewAccountWithAddress ( ctx , addr1 )
app . AccountKeeper . SetAccount ( ctx , acc1 )
2019-07-31 08:39:02 -07:00
2020-01-30 13:31:16 -08:00
addr2 := sdk . AccAddress ( [ ] byte ( "addr2" ) )
acc2 := app . AccountKeeper . NewAccountWithAddress ( ctx , addr2 )
app . AccountKeeper . SetAccount ( ctx , acc2 )
suite . Require ( ) . NoError ( app . BankKeeper . SetBalances ( ctx , addr2 , balances ) )
2018-04-09 15:10:58 -07:00
2020-01-30 13:31:16 -08:00
sendAmt := sdk . NewCoins ( newFooCoin ( 50 ) , newBarCoin ( 25 ) )
suite . Require ( ) . Error ( app . BankKeeper . SendCoins ( ctx , addr1 , addr2 , sendAmt ) )
suite . Require ( ) . NoError ( app . BankKeeper . SetBalances ( ctx , addr1 , balances ) )
suite . Require ( ) . NoError ( app . BankKeeper . SendCoins ( ctx , addr1 , addr2 , sendAmt ) )
acc1Balances := app . BankKeeper . GetAllBalances ( ctx , addr1 )
expected := sdk . NewCoins ( newFooCoin ( 50 ) , newBarCoin ( 25 ) )
suite . Require ( ) . Equal ( expected , acc1Balances )
acc2Balances := app . BankKeeper . GetAllBalances ( ctx , addr2 )
expected = sdk . NewCoins ( newFooCoin ( 150 ) , newBarCoin ( 75 ) )
suite . Require ( ) . Equal ( expected , acc2Balances )
}
func ( suite * IntegrationTestSuite ) TestValidateBalance ( ) {
app , ctx := suite . app , suite . ctx
now := tmtime . Now ( )
ctx = ctx . WithBlockHeader ( abci . Header { Time : now } )
endTime := now . Add ( 24 * time . Hour )
addr1 := sdk . AccAddress ( [ ] byte ( "addr1" ) )
2018-07-06 00:06:53 -07:00
addr2 := sdk . AccAddress ( [ ] byte ( "addr2" ) )
2018-04-09 15:10:58 -07:00
2020-01-30 13:31:16 -08:00
suite . Require ( ) . Error ( app . BankKeeper . ValidateBalance ( ctx , addr1 ) )
acc := app . AccountKeeper . NewAccountWithAddress ( ctx , addr1 )
2019-08-19 06:29:17 -07:00
app . AccountKeeper . SetAccount ( ctx , acc )
2020-01-30 13:31:16 -08:00
balances := sdk . NewCoins ( newFooCoin ( 100 ) )
suite . Require ( ) . NoError ( app . BankKeeper . SetBalances ( ctx , addr1 , balances ) )
suite . Require ( ) . NoError ( app . BankKeeper . ValidateBalance ( ctx , addr1 ) )
bacc := auth . NewBaseAccountWithAddress ( addr2 )
2020-02-18 04:50:13 -08:00
vacc := vesting . NewContinuousVestingAccount ( bacc , balances . Add ( balances ... ) , now . Unix ( ) , endTime . Unix ( ) )
2020-01-30 13:31:16 -08:00
app . AccountKeeper . SetAccount ( ctx , vacc )
suite . Require ( ) . NoError ( app . BankKeeper . SetBalances ( ctx , addr2 , balances ) )
suite . Require ( ) . Error ( app . BankKeeper . ValidateBalance ( ctx , addr2 ) )
2018-04-09 15:10:58 -07:00
}
2020-01-30 13:31:16 -08:00
func ( suite * IntegrationTestSuite ) TestBalance ( ) {
app , ctx := suite . app , suite . ctx
addr := sdk . AccAddress ( [ ] byte ( "addr1" ) )
2019-08-27 06:17:31 -07:00
2020-01-30 13:31:16 -08:00
acc := app . AccountKeeper . NewAccountWithAddress ( ctx , addr )
app . AccountKeeper . SetAccount ( ctx , acc )
suite . Require ( ) . Equal ( sdk . NewCoin ( fooDenom , sdk . ZeroInt ( ) ) , app . BankKeeper . GetBalance ( ctx , addr , fooDenom ) )
balances := sdk . NewCoins ( newFooCoin ( 100 ) )
suite . Require ( ) . NoError ( app . BankKeeper . SetBalances ( ctx , addr , balances ) )
suite . Require ( ) . Equal ( balances . AmountOf ( fooDenom ) , app . BankKeeper . GetBalance ( ctx , addr , fooDenom ) . Amount )
suite . Require ( ) . Equal ( balances , app . BankKeeper . GetAllBalances ( ctx , addr ) )
newFooBalance := newFooCoin ( 99 )
suite . Require ( ) . NoError ( app . BankKeeper . SetBalance ( ctx , addr , newFooBalance ) )
suite . Require ( ) . Equal ( newFooBalance , app . BankKeeper . GetBalance ( ctx , addr , fooDenom ) )
balances = sdk . NewCoins ( newBarCoin ( 500 ) )
suite . Require ( ) . NoError ( app . BankKeeper . SetBalances ( ctx , addr , balances ) )
suite . Require ( ) . Equal ( sdk . NewCoin ( fooDenom , sdk . ZeroInt ( ) ) , app . BankKeeper . GetBalance ( ctx , addr , fooDenom ) )
suite . Require ( ) . Equal ( balances . AmountOf ( barDenom ) , app . BankKeeper . GetBalance ( ctx , addr , barDenom ) . Amount )
suite . Require ( ) . Equal ( balances , app . BankKeeper . GetAllBalances ( ctx , addr ) )
2019-08-27 06:17:31 -07:00
2020-01-30 13:31:16 -08:00
invalidBalance := sdk . Coin { Denom : "fooDenom" , Amount : sdk . NewInt ( - 50 ) }
suite . Require ( ) . Error ( app . BankKeeper . SetBalance ( ctx , addr , invalidBalance ) )
}
func ( suite * IntegrationTestSuite ) TestSendEnabled ( ) {
app , ctx := suite . app , suite . ctx
enabled := false
app . BankKeeper . SetSendEnabled ( ctx , enabled )
suite . Require ( ) . Equal ( enabled , app . BankKeeper . GetSendEnabled ( ctx ) )
}
func ( suite * IntegrationTestSuite ) TestHasBalance ( ) {
app , ctx := suite . app , suite . ctx
addr := sdk . AccAddress ( [ ] byte ( "addr1" ) )
acc := app . AccountKeeper . NewAccountWithAddress ( ctx , addr )
app . AccountKeeper . SetAccount ( ctx , acc )
balances := sdk . NewCoins ( newFooCoin ( 100 ) )
suite . Require ( ) . False ( app . BankKeeper . HasBalance ( ctx , addr , newFooCoin ( 99 ) ) )
app . BankKeeper . SetBalances ( ctx , addr , balances )
suite . Require ( ) . False ( app . BankKeeper . HasBalance ( ctx , addr , newFooCoin ( 101 ) ) )
suite . Require ( ) . True ( app . BankKeeper . HasBalance ( ctx , addr , newFooCoin ( 100 ) ) )
suite . Require ( ) . True ( app . BankKeeper . HasBalance ( ctx , addr , newFooCoin ( 1 ) ) )
}
func ( suite * IntegrationTestSuite ) TestMsgSendEvents ( ) {
app , ctx := suite . app , suite . ctx
2019-08-27 06:17:31 -07:00
addr := sdk . AccAddress ( [ ] byte ( "addr1" ) )
addr2 := sdk . AccAddress ( [ ] byte ( "addr2" ) )
acc := app . AccountKeeper . NewAccountWithAddress ( ctx , addr )
app . AccountKeeper . SetAccount ( ctx , acc )
2020-01-30 13:31:16 -08:00
newCoins := sdk . NewCoins ( sdk . NewInt64Coin ( fooDenom , 50 ) )
suite . Require ( ) . Error ( app . BankKeeper . SendCoins ( ctx , addr , addr2 , newCoins ) )
2019-08-27 06:17:31 -07:00
events := ctx . EventManager ( ) . Events ( )
2020-01-30 13:31:16 -08:00
suite . Require ( ) . Equal ( 2 , len ( events ) )
2019-08-27 06:17:31 -07:00
event1 := sdk . Event {
Type : types . EventTypeTransfer ,
2020-01-16 13:46:51 -08:00
Attributes : [ ] tmkv . Pair { } ,
2019-08-27 06:17:31 -07:00
}
event1 . Attributes = append (
event1 . Attributes ,
2020-01-30 13:31:16 -08:00
tmkv . Pair { Key : [ ] byte ( types . AttributeKeyRecipient ) , Value : [ ] byte ( addr2 . String ( ) ) } ,
)
2019-08-27 06:17:31 -07:00
event1 . Attributes = append (
event1 . Attributes ,
2020-01-30 13:31:16 -08:00
tmkv . Pair { Key : [ ] byte ( sdk . AttributeKeyAmount ) , Value : [ ] byte ( newCoins . String ( ) ) } ,
)
2019-08-27 06:17:31 -07:00
event2 := sdk . Event {
Type : sdk . EventTypeMessage ,
2020-01-16 13:46:51 -08:00
Attributes : [ ] tmkv . Pair { } ,
2019-08-27 06:17:31 -07:00
}
event2 . Attributes = append (
event2 . Attributes ,
2020-01-30 13:31:16 -08:00
tmkv . Pair { Key : [ ] byte ( types . AttributeKeySender ) , Value : [ ] byte ( addr . String ( ) ) } ,
)
suite . Require ( ) . Equal ( event1 , events [ 0 ] )
suite . Require ( ) . Equal ( event2 , events [ 1 ] )
app . BankKeeper . SetBalances ( ctx , addr , sdk . NewCoins ( sdk . NewInt64Coin ( fooDenom , 50 ) ) )
newCoins = sdk . NewCoins ( sdk . NewInt64Coin ( fooDenom , 50 ) )
suite . Require ( ) . NoError ( app . BankKeeper . SendCoins ( ctx , addr , addr2 , newCoins ) )
2019-08-27 06:17:31 -07:00
events = ctx . EventManager ( ) . Events ( )
2020-01-30 13:31:16 -08:00
suite . Require ( ) . Equal ( 4 , len ( events ) )
suite . Require ( ) . Equal ( event1 , events [ 2 ] )
suite . Require ( ) . Equal ( event2 , events [ 3 ] )
2019-08-27 06:17:31 -07:00
}
2020-01-30 13:31:16 -08:00
func ( suite * IntegrationTestSuite ) TestMsgMultiSendEvents ( ) {
app , ctx := suite . app , suite . ctx
2020-01-27 06:46:55 -08:00
app . BankKeeper . SetSendEnabled ( ctx , true )
addr := sdk . AccAddress ( [ ] byte ( "addr1" ) )
addr2 := sdk . AccAddress ( [ ] byte ( "addr2" ) )
addr3 := sdk . AccAddress ( [ ] byte ( "addr3" ) )
addr4 := sdk . AccAddress ( [ ] byte ( "addr4" ) )
acc := app . AccountKeeper . NewAccountWithAddress ( ctx , addr )
acc2 := app . AccountKeeper . NewAccountWithAddress ( ctx , addr2 )
app . AccountKeeper . SetAccount ( ctx , acc )
app . AccountKeeper . SetAccount ( ctx , acc2 )
2020-01-30 13:31:16 -08:00
newCoins := sdk . NewCoins ( sdk . NewInt64Coin ( fooDenom , 50 ) )
newCoins2 := sdk . NewCoins ( sdk . NewInt64Coin ( barDenom , 100 ) )
2020-01-27 06:46:55 -08:00
inputs := [ ] types . Input {
{ Address : addr , Coins : newCoins } ,
{ Address : addr2 , Coins : newCoins2 } ,
}
outputs := [ ] types . Output {
{ Address : addr3 , Coins : newCoins } ,
{ Address : addr4 , Coins : newCoins2 } ,
}
2020-01-30 13:31:16 -08:00
suite . Require ( ) . Error ( app . BankKeeper . InputOutputCoins ( ctx , inputs , outputs ) )
2020-01-27 06:46:55 -08:00
events := ctx . EventManager ( ) . Events ( )
2020-01-30 13:31:16 -08:00
suite . Require ( ) . Equal ( 0 , len ( events ) )
2020-01-27 06:46:55 -08:00
// Set addr's coins but not addr2's coins
2020-01-30 13:31:16 -08:00
app . BankKeeper . SetBalances ( ctx , addr , sdk . NewCoins ( sdk . NewInt64Coin ( fooDenom , 50 ) ) )
suite . Require ( ) . Error ( app . BankKeeper . InputOutputCoins ( ctx , inputs , outputs ) )
2020-01-27 06:46:55 -08:00
events = ctx . EventManager ( ) . Events ( )
2020-01-30 13:31:16 -08:00
suite . Require ( ) . Equal ( 1 , len ( events ) )
2020-01-27 06:46:55 -08:00
event1 := sdk . Event {
Type : sdk . EventTypeMessage ,
Attributes : [ ] tmkv . Pair { } ,
}
event1 . Attributes = append (
event1 . Attributes ,
2020-01-30 13:31:16 -08:00
tmkv . Pair { Key : [ ] byte ( types . AttributeKeySender ) , Value : [ ] byte ( addr . String ( ) ) } ,
)
suite . Require ( ) . Equal ( event1 , events [ 0 ] )
2020-01-27 06:46:55 -08:00
// Set addr's coins and addr2's coins
2020-01-30 13:31:16 -08:00
app . BankKeeper . SetBalances ( ctx , addr , sdk . NewCoins ( sdk . NewInt64Coin ( fooDenom , 50 ) ) )
newCoins = sdk . NewCoins ( sdk . NewInt64Coin ( fooDenom , 50 ) )
app . BankKeeper . SetBalances ( ctx , addr2 , sdk . NewCoins ( sdk . NewInt64Coin ( barDenom , 100 ) ) )
newCoins2 = sdk . NewCoins ( sdk . NewInt64Coin ( barDenom , 100 ) )
suite . Require ( ) . NoError ( app . BankKeeper . InputOutputCoins ( ctx , inputs , outputs ) )
2020-01-27 06:46:55 -08:00
events = ctx . EventManager ( ) . Events ( )
2020-01-30 13:31:16 -08:00
suite . Require ( ) . Equal ( 5 , len ( events ) )
2020-01-27 06:46:55 -08:00
event2 := sdk . Event {
Type : sdk . EventTypeMessage ,
Attributes : [ ] tmkv . Pair { } ,
}
event2 . Attributes = append (
event2 . Attributes ,
2020-01-30 13:31:16 -08:00
tmkv . Pair { Key : [ ] byte ( types . AttributeKeySender ) , Value : [ ] byte ( addr2 . String ( ) ) } ,
)
2020-01-27 06:46:55 -08:00
event3 := sdk . Event {
Type : types . EventTypeTransfer ,
Attributes : [ ] tmkv . Pair { } ,
}
event3 . Attributes = append (
event3 . Attributes ,
2020-01-30 13:31:16 -08:00
tmkv . Pair { Key : [ ] byte ( types . AttributeKeyRecipient ) , Value : [ ] byte ( addr3 . String ( ) ) } ,
)
2020-01-27 06:46:55 -08:00
event3 . Attributes = append (
event3 . Attributes ,
tmkv . Pair { Key : [ ] byte ( sdk . AttributeKeyAmount ) , Value : [ ] byte ( newCoins . String ( ) ) } )
event4 := sdk . Event {
Type : types . EventTypeTransfer ,
Attributes : [ ] tmkv . Pair { } ,
}
event4 . Attributes = append (
event4 . Attributes ,
2020-01-30 13:31:16 -08:00
tmkv . Pair { Key : [ ] byte ( types . AttributeKeyRecipient ) , Value : [ ] byte ( addr4 . String ( ) ) } ,
)
2020-01-27 06:46:55 -08:00
event4 . Attributes = append (
event4 . Attributes ,
2020-01-30 13:31:16 -08:00
tmkv . Pair { Key : [ ] byte ( sdk . AttributeKeyAmount ) , Value : [ ] byte ( newCoins2 . String ( ) ) } ,
)
suite . Require ( ) . Equal ( event1 , events [ 1 ] )
suite . Require ( ) . Equal ( event2 , events [ 2 ] )
suite . Require ( ) . Equal ( event3 , events [ 3 ] )
suite . Require ( ) . Equal ( event4 , events [ 4 ] )
2020-01-27 06:46:55 -08:00
}
2020-01-30 13:31:16 -08:00
func ( suite * IntegrationTestSuite ) TestSpendableCoins ( ) {
app , ctx := suite . app , suite . ctx
now := tmtime . Now ( )
ctx = ctx . WithBlockHeader ( abci . Header { Time : now } )
endTime := now . Add ( 24 * time . Hour )
2019-08-19 06:29:17 -07:00
2020-01-30 13:31:16 -08:00
origCoins := sdk . NewCoins ( sdk . NewInt64Coin ( "stake" , 100 ) )
delCoins := sdk . NewCoins ( sdk . NewInt64Coin ( "stake" , 50 ) )
2018-04-09 15:10:58 -07:00
2020-01-30 13:31:16 -08:00
addr1 := sdk . AccAddress ( [ ] byte ( "addr1" ) )
addr2 := sdk . AccAddress ( [ ] byte ( "addr2" ) )
addrModule := sdk . AccAddress ( [ ] byte ( "moduleAcc" ) )
macc := app . AccountKeeper . NewAccountWithAddress ( ctx , addrModule )
bacc := auth . NewBaseAccountWithAddress ( addr1 )
2020-02-18 04:50:13 -08:00
vacc := vesting . NewContinuousVestingAccount ( bacc , origCoins , ctx . BlockHeader ( ) . Time . Unix ( ) , endTime . Unix ( ) )
2020-01-30 13:31:16 -08:00
acc := app . AccountKeeper . NewAccountWithAddress ( ctx , addr2 )
2018-04-09 15:10:58 -07:00
2020-01-30 13:31:16 -08:00
app . AccountKeeper . SetAccount ( ctx , macc )
app . AccountKeeper . SetAccount ( ctx , vacc )
2019-08-19 06:29:17 -07:00
app . AccountKeeper . SetAccount ( ctx , acc )
2020-01-30 13:31:16 -08:00
suite . Require ( ) . NoError ( app . BankKeeper . SetBalances ( ctx , addr1 , origCoins ) )
suite . Require ( ) . NoError ( app . BankKeeper . SetBalances ( ctx , addr2 , origCoins ) )
2018-04-09 15:10:58 -07:00
2020-01-30 13:31:16 -08:00
suite . Require ( ) . Equal ( origCoins , app . BankKeeper . SpendableCoins ( ctx , addr2 ) )
2018-04-09 15:10:58 -07:00
2020-01-30 13:31:16 -08:00
ctx = ctx . WithBlockTime ( now . Add ( 12 * time . Hour ) )
suite . Require ( ) . NoError ( app . BankKeeper . DelegateCoins ( ctx , addr2 , addrModule , delCoins ) )
suite . Require ( ) . Equal ( origCoins . Sub ( delCoins ) , app . BankKeeper . SpendableCoins ( ctx , addr1 ) )
2018-04-09 15:10:58 -07:00
}
2019-01-14 08:11:24 -08:00
2020-01-30 13:31:16 -08:00
func ( suite * IntegrationTestSuite ) TestVestingAccountSend ( ) {
app , ctx := suite . app , suite . ctx
2019-01-14 08:11:24 -08:00
now := tmtime . Now ( )
2019-08-19 06:29:17 -07:00
ctx = ctx . WithBlockHeader ( abci . Header { Time : now } )
2019-01-14 08:11:24 -08:00
endTime := now . Add ( 24 * time . Hour )
2019-03-14 07:32:46 -07:00
origCoins := sdk . NewCoins ( sdk . NewInt64Coin ( "stake" , 100 ) )
sendCoins := sdk . NewCoins ( sdk . NewInt64Coin ( "stake" , 50 ) )
2019-01-14 08:11:24 -08:00
addr1 := sdk . AccAddress ( [ ] byte ( "addr1" ) )
addr2 := sdk . AccAddress ( [ ] byte ( "addr2" ) )
2020-01-30 13:31:16 -08:00
2019-01-17 08:15:13 -08:00
bacc := auth . NewBaseAccountWithAddress ( addr1 )
2020-02-18 04:50:13 -08:00
vacc := vesting . NewContinuousVestingAccount ( bacc , origCoins , now . Unix ( ) , endTime . Unix ( ) )
2020-01-30 13:31:16 -08:00
2019-08-19 06:29:17 -07:00
app . AccountKeeper . SetAccount ( ctx , vacc )
2020-01-30 13:31:16 -08:00
suite . Require ( ) . NoError ( app . BankKeeper . SetBalances ( ctx , addr1 , origCoins ) )
2019-01-14 08:11:24 -08:00
// require that no coins be sendable at the beginning of the vesting schedule
2020-01-30 13:31:16 -08:00
suite . Require ( ) . Error ( app . BankKeeper . SendCoins ( ctx , addr1 , addr2 , sendCoins ) )
2019-01-14 08:11:24 -08:00
// receive some coins
2020-01-30 13:31:16 -08:00
suite . Require ( ) . NoError ( app . BankKeeper . SetBalances ( ctx , addr1 , origCoins . Add ( sendCoins ... ) ) )
2019-01-14 08:11:24 -08:00
// require that all vested coins are spendable plus any received
ctx = ctx . WithBlockTime ( now . Add ( 12 * time . Hour ) )
2020-01-30 13:31:16 -08:00
suite . Require ( ) . NoError ( app . BankKeeper . SendCoins ( ctx , addr1 , addr2 , sendCoins ) )
suite . Require ( ) . Equal ( origCoins , app . BankKeeper . GetAllBalances ( ctx , addr1 ) )
2019-10-10 08:53:30 -07:00
}
2020-01-30 13:31:16 -08:00
func ( suite * IntegrationTestSuite ) TestPeriodicVestingAccountSend ( ) {
app , ctx := suite . app , suite . ctx
2019-10-10 08:53:30 -07:00
now := tmtime . Now ( )
ctx = ctx . WithBlockHeader ( abci . Header { Time : now } )
origCoins := sdk . NewCoins ( sdk . NewInt64Coin ( "stake" , 100 ) )
sendCoins := sdk . NewCoins ( sdk . NewInt64Coin ( "stake" , 50 ) )
addr1 := sdk . AccAddress ( [ ] byte ( "addr1" ) )
addr2 := sdk . AccAddress ( [ ] byte ( "addr2" ) )
periods := vesting . Periods {
vesting . Period { Length : int64 ( 12 * 60 * 60 ) , Amount : sdk . Coins { sdk . NewInt64Coin ( "stake" , 50 ) } } ,
vesting . Period { Length : int64 ( 6 * 60 * 60 ) , Amount : sdk . Coins { sdk . NewInt64Coin ( "stake" , 25 ) } } ,
vesting . Period { Length : int64 ( 6 * 60 * 60 ) , Amount : sdk . Coins { sdk . NewInt64Coin ( "stake" , 25 ) } } ,
}
2020-01-30 13:31:16 -08:00
bacc := auth . NewBaseAccountWithAddress ( addr1 )
2020-02-18 04:50:13 -08:00
vacc := vesting . NewPeriodicVestingAccount ( bacc , origCoins , ctx . BlockHeader ( ) . Time . Unix ( ) , periods )
2020-01-30 13:31:16 -08:00
2019-10-10 08:53:30 -07:00
app . AccountKeeper . SetAccount ( ctx , vacc )
2020-01-30 13:31:16 -08:00
suite . Require ( ) . NoError ( app . BankKeeper . SetBalances ( ctx , addr1 , origCoins ) )
2019-10-10 08:53:30 -07:00
// require that no coins be sendable at the beginning of the vesting schedule
2020-01-30 13:31:16 -08:00
suite . Require ( ) . Error ( app . BankKeeper . SendCoins ( ctx , addr1 , addr2 , sendCoins ) )
2019-10-10 08:53:30 -07:00
// receive some coins
2020-01-30 13:31:16 -08:00
suite . Require ( ) . NoError ( app . BankKeeper . SetBalances ( ctx , addr1 , origCoins . Add ( sendCoins ... ) ) )
2019-10-10 08:53:30 -07:00
// require that all vested coins are spendable plus any received
ctx = ctx . WithBlockTime ( now . Add ( 12 * time . Hour ) )
2020-01-30 13:31:16 -08:00
suite . Require ( ) . NoError ( app . BankKeeper . SendCoins ( ctx , addr1 , addr2 , sendCoins ) )
suite . Require ( ) . Equal ( origCoins , app . BankKeeper . GetAllBalances ( ctx , addr1 ) )
2019-01-14 08:11:24 -08:00
}
2020-01-30 13:31:16 -08:00
func ( suite * IntegrationTestSuite ) TestVestingAccountReceive ( ) {
app , ctx := suite . app , suite . ctx
2019-01-14 08:11:24 -08:00
now := tmtime . Now ( )
2019-08-19 06:29:17 -07:00
ctx = ctx . WithBlockHeader ( abci . Header { Time : now } )
2019-01-14 08:11:24 -08:00
endTime := now . Add ( 24 * time . Hour )
2019-03-14 07:32:46 -07:00
origCoins := sdk . NewCoins ( sdk . NewInt64Coin ( "stake" , 100 ) )
sendCoins := sdk . NewCoins ( sdk . NewInt64Coin ( "stake" , 50 ) )
2019-01-14 08:11:24 -08:00
addr1 := sdk . AccAddress ( [ ] byte ( "addr1" ) )
addr2 := sdk . AccAddress ( [ ] byte ( "addr2" ) )
2019-01-17 08:15:13 -08:00
bacc := auth . NewBaseAccountWithAddress ( addr1 )
2020-02-18 04:50:13 -08:00
vacc := vesting . NewContinuousVestingAccount ( bacc , origCoins , ctx . BlockHeader ( ) . Time . Unix ( ) , endTime . Unix ( ) )
2019-10-10 08:53:30 -07:00
acc := app . AccountKeeper . NewAccountWithAddress ( ctx , addr2 )
2020-01-30 13:31:16 -08:00
2019-10-10 08:53:30 -07:00
app . AccountKeeper . SetAccount ( ctx , vacc )
app . AccountKeeper . SetAccount ( ctx , acc )
2020-01-30 13:31:16 -08:00
suite . Require ( ) . NoError ( app . BankKeeper . SetBalances ( ctx , addr1 , origCoins ) )
suite . Require ( ) . NoError ( app . BankKeeper . SetBalances ( ctx , addr2 , origCoins ) )
2019-10-10 08:53:30 -07:00
// send some coins to the vesting account
2020-01-30 13:31:16 -08:00
suite . Require ( ) . NoError ( app . BankKeeper . SendCoins ( ctx , addr2 , addr1 , sendCoins ) )
2019-10-10 08:53:30 -07:00
// require the coins are spendable
vacc = app . AccountKeeper . GetAccount ( ctx , addr1 ) . ( * vesting . ContinuousVestingAccount )
2020-01-30 13:31:16 -08:00
balances := app . BankKeeper . GetAllBalances ( ctx , addr1 )
suite . Require ( ) . Equal ( origCoins . Add ( sendCoins ... ) , balances )
suite . Require ( ) . Equal ( balances . Sub ( vacc . LockedCoins ( now ) ) , sendCoins )
2019-10-10 08:53:30 -07:00
// require coins are spendable plus any that have vested
2020-01-30 13:31:16 -08:00
suite . Require ( ) . Equal ( balances . Sub ( vacc . LockedCoins ( now . Add ( 12 * time . Hour ) ) ) , origCoins )
2019-10-10 08:53:30 -07:00
}
2020-01-30 13:31:16 -08:00
func ( suite * IntegrationTestSuite ) TestPeriodicVestingAccountReceive ( ) {
app , ctx := suite . app , suite . ctx
2019-10-10 08:53:30 -07:00
now := tmtime . Now ( )
ctx = ctx . WithBlockHeader ( abci . Header { Time : now } )
origCoins := sdk . NewCoins ( sdk . NewInt64Coin ( "stake" , 100 ) )
sendCoins := sdk . NewCoins ( sdk . NewInt64Coin ( "stake" , 50 ) )
addr1 := sdk . AccAddress ( [ ] byte ( "addr1" ) )
addr2 := sdk . AccAddress ( [ ] byte ( "addr2" ) )
bacc := auth . NewBaseAccountWithAddress ( addr1 )
periods := vesting . Periods {
vesting . Period { Length : int64 ( 12 * 60 * 60 ) , Amount : sdk . Coins { sdk . NewInt64Coin ( "stake" , 50 ) } } ,
vesting . Period { Length : int64 ( 6 * 60 * 60 ) , Amount : sdk . Coins { sdk . NewInt64Coin ( "stake" , 25 ) } } ,
vesting . Period { Length : int64 ( 6 * 60 * 60 ) , Amount : sdk . Coins { sdk . NewInt64Coin ( "stake" , 25 ) } } ,
}
2020-01-30 13:31:16 -08:00
2020-02-18 04:50:13 -08:00
vacc := vesting . NewPeriodicVestingAccount ( bacc , origCoins , ctx . BlockHeader ( ) . Time . Unix ( ) , periods )
2019-08-19 06:29:17 -07:00
acc := app . AccountKeeper . NewAccountWithAddress ( ctx , addr2 )
2020-01-30 13:31:16 -08:00
2019-08-19 06:29:17 -07:00
app . AccountKeeper . SetAccount ( ctx , vacc )
app . AccountKeeper . SetAccount ( ctx , acc )
2020-01-30 13:31:16 -08:00
suite . Require ( ) . NoError ( app . BankKeeper . SetBalances ( ctx , addr1 , origCoins ) )
suite . Require ( ) . NoError ( app . BankKeeper . SetBalances ( ctx , addr2 , origCoins ) )
2019-01-14 08:11:24 -08:00
// send some coins to the vesting account
2020-01-30 13:31:16 -08:00
suite . Require ( ) . NoError ( app . BankKeeper . SendCoins ( ctx , addr2 , addr1 , sendCoins ) )
2019-01-14 08:11:24 -08:00
// require the coins are spendable
2019-10-10 08:53:30 -07:00
vacc = app . AccountKeeper . GetAccount ( ctx , addr1 ) . ( * vesting . PeriodicVestingAccount )
2020-01-30 13:31:16 -08:00
balances := app . BankKeeper . GetAllBalances ( ctx , addr1 )
suite . Require ( ) . Equal ( origCoins . Add ( sendCoins ... ) , balances )
suite . Require ( ) . Equal ( balances . Sub ( vacc . LockedCoins ( now ) ) , sendCoins )
2019-01-14 08:11:24 -08:00
// require coins are spendable plus any that have vested
2020-01-30 13:31:16 -08:00
suite . Require ( ) . Equal ( balances . Sub ( vacc . LockedCoins ( now . Add ( 12 * time . Hour ) ) ) , origCoins )
2019-01-14 08:11:24 -08:00
}
2020-01-30 13:31:16 -08:00
func ( suite * IntegrationTestSuite ) TestDelegateCoins ( ) {
app , ctx := suite . app , suite . ctx
2019-01-14 08:11:24 -08:00
now := tmtime . Now ( )
2019-08-19 06:29:17 -07:00
ctx = ctx . WithBlockHeader ( abci . Header { Time : now } )
2019-01-14 08:11:24 -08:00
endTime := now . Add ( 24 * time . Hour )
2019-03-14 07:32:46 -07:00
origCoins := sdk . NewCoins ( sdk . NewInt64Coin ( "stake" , 100 ) )
delCoins := sdk . NewCoins ( sdk . NewInt64Coin ( "stake" , 50 ) )
2019-01-14 08:11:24 -08:00
addr1 := sdk . AccAddress ( [ ] byte ( "addr1" ) )
addr2 := sdk . AccAddress ( [ ] byte ( "addr2" ) )
2019-06-28 13:11:27 -07:00
addrModule := sdk . AccAddress ( [ ] byte ( "moduleAcc" ) )
2019-01-14 08:11:24 -08:00
2020-01-30 13:31:16 -08:00
macc := app . AccountKeeper . NewAccountWithAddress ( ctx , addrModule ) // we don't need to define an actual module account bc we just need the address for testing
acc := app . AccountKeeper . NewAccountWithAddress ( ctx , addr2 )
2019-01-17 08:15:13 -08:00
bacc := auth . NewBaseAccountWithAddress ( addr1 )
2020-02-18 04:50:13 -08:00
vacc := vesting . NewContinuousVestingAccount ( bacc , origCoins , ctx . BlockHeader ( ) . Time . Unix ( ) , endTime . Unix ( ) )
2020-01-30 13:31:16 -08:00
app . AccountKeeper . SetAccount ( ctx , vacc )
app . AccountKeeper . SetAccount ( ctx , acc )
app . AccountKeeper . SetAccount ( ctx , macc )
suite . Require ( ) . NoError ( app . BankKeeper . SetBalances ( ctx , addr1 , origCoins ) )
suite . Require ( ) . NoError ( app . BankKeeper . SetBalances ( ctx , addr2 , origCoins ) )
2019-01-14 08:11:24 -08:00
ctx = ctx . WithBlockTime ( now . Add ( 12 * time . Hour ) )
// require the ability for a non-vesting account to delegate
2020-01-30 13:31:16 -08:00
suite . Require ( ) . NoError ( app . BankKeeper . DelegateCoins ( ctx , addr2 , addrModule , delCoins ) )
suite . Require ( ) . Equal ( origCoins . Sub ( delCoins ) , app . BankKeeper . GetAllBalances ( ctx , addr2 ) )
suite . Require ( ) . Equal ( delCoins , app . BankKeeper . GetAllBalances ( ctx , addrModule ) )
2019-01-14 08:11:24 -08:00
// require the ability for a vesting account to delegate
2020-01-30 13:31:16 -08:00
suite . Require ( ) . NoError ( app . BankKeeper . DelegateCoins ( ctx , addr1 , addrModule , delCoins ) )
suite . Require ( ) . Equal ( delCoins , app . BankKeeper . GetAllBalances ( ctx , addr1 ) )
}
func ( suite * IntegrationTestSuite ) TestDelegateCoins_Invalid ( ) {
app , ctx := suite . app , suite . ctx
origCoins := sdk . NewCoins ( newFooCoin ( 100 ) )
delCoins := sdk . NewCoins ( newFooCoin ( 50 ) )
addr1 := sdk . AccAddress ( [ ] byte ( "addr1" ) )
addrModule := sdk . AccAddress ( [ ] byte ( "moduleAcc" ) )
macc := app . AccountKeeper . NewAccountWithAddress ( ctx , addrModule ) // we don't need to define an actual module account bc we just need the address for testing
acc := app . AccountKeeper . NewAccountWithAddress ( ctx , addr1 )
suite . Require ( ) . Error ( app . BankKeeper . DelegateCoins ( ctx , addr1 , addrModule , delCoins ) )
invalidCoins := sdk . Coins { sdk . Coin { Denom : "fooDenom" , Amount : sdk . NewInt ( - 50 ) } }
suite . Require ( ) . Error ( app . BankKeeper . DelegateCoins ( ctx , addr1 , addrModule , invalidCoins ) )
app . AccountKeeper . SetAccount ( ctx , macc )
suite . Require ( ) . NoError ( app . BankKeeper . SetBalances ( ctx , addr1 , origCoins ) )
suite . Require ( ) . Error ( app . BankKeeper . DelegateCoins ( ctx , addr1 , addrModule , delCoins ) )
app . AccountKeeper . SetAccount ( ctx , acc )
suite . Require ( ) . Error ( app . BankKeeper . DelegateCoins ( ctx , addr1 , addrModule , origCoins . Add ( origCoins ... ) ) )
2019-01-14 08:11:24 -08:00
}
2020-01-30 13:31:16 -08:00
func ( suite * IntegrationTestSuite ) TestUndelegateCoins ( ) {
app , ctx := suite . app , suite . ctx
2019-01-14 08:11:24 -08:00
now := tmtime . Now ( )
2019-08-19 06:29:17 -07:00
ctx = ctx . WithBlockHeader ( abci . Header { Time : now } )
2019-01-14 08:11:24 -08:00
endTime := now . Add ( 24 * time . Hour )
2019-03-14 07:32:46 -07:00
origCoins := sdk . NewCoins ( sdk . NewInt64Coin ( "stake" , 100 ) )
delCoins := sdk . NewCoins ( sdk . NewInt64Coin ( "stake" , 50 ) )
2019-01-14 08:11:24 -08:00
addr1 := sdk . AccAddress ( [ ] byte ( "addr1" ) )
addr2 := sdk . AccAddress ( [ ] byte ( "addr2" ) )
2019-06-28 13:11:27 -07:00
addrModule := sdk . AccAddress ( [ ] byte ( "moduleAcc" ) )
2019-01-14 08:11:24 -08:00
2019-01-17 08:15:13 -08:00
bacc := auth . NewBaseAccountWithAddress ( addr1 )
2020-01-30 13:31:16 -08:00
macc := app . AccountKeeper . NewAccountWithAddress ( ctx , addrModule ) // we don't need to define an actual module account bc we just need the address for testing
2020-02-18 04:50:13 -08:00
vacc := vesting . NewContinuousVestingAccount ( bacc , origCoins , ctx . BlockHeader ( ) . Time . Unix ( ) , endTime . Unix ( ) )
2020-01-30 13:31:16 -08:00
acc := app . AccountKeeper . NewAccountWithAddress ( ctx , addr2 )
app . AccountKeeper . SetAccount ( ctx , vacc )
app . AccountKeeper . SetAccount ( ctx , acc )
app . AccountKeeper . SetAccount ( ctx , macc )
suite . Require ( ) . NoError ( app . BankKeeper . SetBalances ( ctx , addr1 , origCoins ) )
suite . Require ( ) . NoError ( app . BankKeeper . SetBalances ( ctx , addr2 , origCoins ) )
2019-01-14 08:11:24 -08:00
ctx = ctx . WithBlockTime ( now . Add ( 12 * time . Hour ) )
// require the ability for a non-vesting account to delegate
2019-08-19 06:29:17 -07:00
err := app . BankKeeper . DelegateCoins ( ctx , addr2 , addrModule , delCoins )
2020-01-30 13:31:16 -08:00
suite . Require ( ) . NoError ( err )
2019-01-14 08:11:24 -08:00
2020-01-30 13:31:16 -08:00
suite . Require ( ) . Equal ( origCoins . Sub ( delCoins ) , app . BankKeeper . GetAllBalances ( ctx , addr2 ) )
suite . Require ( ) . Equal ( delCoins , app . BankKeeper . GetAllBalances ( ctx , addrModule ) )
2019-06-28 13:11:27 -07:00
2019-01-14 08:11:24 -08:00
// require the ability for a non-vesting account to undelegate
2020-01-30 13:31:16 -08:00
suite . Require ( ) . NoError ( app . BankKeeper . UndelegateCoins ( ctx , addrModule , addr2 , delCoins ) )
2019-01-14 08:11:24 -08:00
2020-01-30 13:31:16 -08:00
suite . Require ( ) . Equal ( origCoins , app . BankKeeper . GetAllBalances ( ctx , addr2 ) )
suite . Require ( ) . True ( app . BankKeeper . GetAllBalances ( ctx , addrModule ) . Empty ( ) )
2019-01-14 08:11:24 -08:00
// require the ability for a vesting account to delegate
2020-01-30 13:31:16 -08:00
suite . Require ( ) . NoError ( app . BankKeeper . DelegateCoins ( ctx , addr1 , addrModule , delCoins ) )
2019-01-14 08:11:24 -08:00
2020-01-30 13:31:16 -08:00
suite . Require ( ) . Equal ( origCoins . Sub ( delCoins ) , app . BankKeeper . GetAllBalances ( ctx , addr1 ) )
suite . Require ( ) . Equal ( delCoins , app . BankKeeper . GetAllBalances ( ctx , addrModule ) )
2019-06-28 13:11:27 -07:00
2019-01-14 08:11:24 -08:00
// require the ability for a vesting account to undelegate
2020-01-30 13:31:16 -08:00
suite . Require ( ) . NoError ( app . BankKeeper . UndelegateCoins ( ctx , addrModule , addr1 , delCoins ) )
suite . Require ( ) . Equal ( origCoins , app . BankKeeper . GetAllBalances ( ctx , addr1 ) )
suite . Require ( ) . True ( app . BankKeeper . GetAllBalances ( ctx , addrModule ) . Empty ( ) )
}
func ( suite * IntegrationTestSuite ) TestUndelegateCoins_Invalid ( ) {
app , ctx := suite . app , suite . ctx
origCoins := sdk . NewCoins ( newFooCoin ( 100 ) )
delCoins := sdk . NewCoins ( newFooCoin ( 50 ) )
addr1 := sdk . AccAddress ( [ ] byte ( "addr1" ) )
addrModule := sdk . AccAddress ( [ ] byte ( "moduleAcc" ) )
macc := app . AccountKeeper . NewAccountWithAddress ( ctx , addrModule ) // we don't need to define an actual module account bc we just need the address for testing
acc := app . AccountKeeper . NewAccountWithAddress ( ctx , addr1 )
suite . Require ( ) . Error ( app . BankKeeper . UndelegateCoins ( ctx , addrModule , addr1 , delCoins ) )
app . AccountKeeper . SetAccount ( ctx , macc )
suite . Require ( ) . NoError ( app . BankKeeper . SetBalances ( ctx , addr1 , origCoins ) )
suite . Require ( ) . Error ( app . BankKeeper . UndelegateCoins ( ctx , addrModule , addr1 , delCoins ) )
app . AccountKeeper . SetAccount ( ctx , acc )
suite . Require ( ) . Error ( app . BankKeeper . UndelegateCoins ( ctx , addrModule , addr1 , delCoins ) )
}
2019-01-14 08:11:24 -08:00
2020-01-30 13:31:16 -08:00
func TestKeeperTestSuite ( t * testing . T ) {
suite . Run ( t , new ( IntegrationTestSuite ) )
2019-01-14 08:11:24 -08:00
}