-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathhandler_test.go
71 lines (55 loc) · 1.85 KB
/
handler_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package poa
import (
"testing"
"github.com/allinbits/modules/x/poa/keeper"
"github.com/allinbits/modules/x/poa/msg"
"github.com/allinbits/modules/x/poa/types"
sdk "github.com/cosmos/cosmos-sdk/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/stretchr/testify/require"
)
func TestHandleCreateValidatorPOA(t *testing.T) {
ctx, k := keeper.MakeTestCtxAndKeeper(t)
name := "name"
valPubKey := keeper.MakeTestPubKey(keeper.SamplePubKey)
valAddr := sdk.ValAddress(valPubKey.Address().Bytes())
accAddr := sdk.AccAddress(valPubKey.Address().Bytes())
msg := msg.NewMsgCreateValidatorPOA(
name,
valAddr,
valPubKey,
stakingtypes.Description{"nil", "nil", "nil", "nil", "nil"},
accAddr,
)
res, err := handleMsgCreateValidatorPOA(ctx, msg, k)
// Validate msg was handled correctly but checking the size of the store
allVals := k.GetAllValidators(ctx)
require.Equal(t, 1, len(allVals))
// No errors and res is populates
require.NoError(t, err)
require.NotNil(t, res)
}
func TestHandleVoteValidatorPOA(t *testing.T) {
ctx, k := keeper.MakeTestCtxAndKeeper(t)
name := "name"
valPubKey := keeper.MakeTestPubKey(keeper.SamplePubKey)
valAddr := sdk.ValAddress(valPubKey.Address().Bytes())
accAddr := sdk.AccAddress(valPubKey.Address().Bytes())
validator := types.NewValidator(
name,
valAddr,
valPubKey,
stakingtypes.Description{"nil", "nil", "nil", "nil", "nil"},
)
k.SetValidator(ctx, name, validator)
k.CalculateValidatorVotes(ctx)
k.ApplyAndReturnValidatorSetUpdates(ctx)
msg := msg.NewMsgVoteValidator("name", valAddr, true, accAddr)
res, err := handleMsgVoteValidator(ctx, msg, k)
// Validate msg was handled correctly but checking the size of the store
allVotes := k.GetAllVotes(ctx)
require.Equal(t, 1, len(allVotes))
// No errors and res is populated
require.NoError(t, err)
require.NotNil(t, res)
}