0g-chain/internal/x/paychan/endblocker_test.go

58 lines
1.9 KiB
Go
Raw Normal View History

2018-08-29 03:45:26 +00:00
package paychan
import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/assert"
"testing"
)
func TestEndBlocker(t *testing.T) {
// SETUP
accountSeeds := []string{"senderSeed", "receiverSeed"}
ctx, _, channelKeeper, addrs, _, _, _ := createMockApp(accountSeeds)
2018-08-29 03:45:26 +00:00
sender := addrs[0]
receiver := addrs[1]
coins := sdk.Coins{sdk.NewCoin("KVA", 10)}
// create new channel
channelID := ChannelID(0) // should be 0 as first channel
channel := Channel{
ID: channelID,
Participants: [2]sdk.AccAddress{sender, receiver},
Coins: coins,
}
channelKeeper.setChannel(ctx, channel)
// create closing update and submittedUpdate
payout := Payout{sdk.Coins{sdk.NewCoin("KVA", 3)}, sdk.Coins{sdk.NewCoin("KVA", 7)}}
2018-08-29 03:45:26 +00:00
update := Update{
ChannelID: channelID,
Payout: payout,
//Sigs: [1]crypto.Signature{},
2018-08-29 03:45:26 +00:00
}
sUpdate := SubmittedUpdate{
Update: update,
ExecutionTime: 0, // current blocktime
}
// Set empty submittedUpdatesQueue TODO work out proper genesis initialisation
channelKeeper.setSubmittedUpdatesQueue(ctx, SubmittedUpdatesQueue{})
// flag channel for closure
channelKeeper.addToSubmittedUpdatesQueue(ctx, sUpdate)
// ACTION
EndBlocker(ctx, channelKeeper)
// CHECK RESULTS
// ideally just check if keeper.channelClose was called, but can't
// writing endBlocker to accept an interface of which keeper is implementation would make this possible
// check channel is gone
_, found := channelKeeper.getChannel(ctx, channelID)
assert.False(t, found)
// check queue is empty, NOTE: due to encoding, an empty queue (underneath just an int slice) will be decoded as nil slice rather than an empty slice
2018-09-01 23:29:51 +00:00
suq := channelKeeper.getSubmittedUpdatesQueue(ctx)
2018-08-29 03:45:26 +00:00
assert.Equal(t, SubmittedUpdatesQueue(nil), suq)
// check submittedUpdate is gone
_, found = channelKeeper.getSubmittedUpdate(ctx, channelID)
assert.False(t, found)
}