forked from cosmos/cosmos-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
keeper_test.go
90 lines (68 loc) · 2.3 KB
/
keeper_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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package auth
import (
"testing"
"github.com/stretchr/testify/require"
sdk "github.com/cosmos/cosmos-sdk/types"
)
func TestAccountMapperGetSet(t *testing.T) {
input := setupTestInput()
addr := sdk.AccAddress([]byte("some-address"))
// no account before its created
acc := input.ak.GetAccount(input.ctx, addr)
require.Nil(t, acc)
// create account and check default values
acc = input.ak.NewAccountWithAddress(input.ctx, addr)
require.NotNil(t, acc)
require.Equal(t, addr, acc.GetAddress())
require.EqualValues(t, nil, acc.GetPubKey())
require.EqualValues(t, 0, acc.GetSequence())
// NewAccount doesn't call Set, so it's still nil
require.Nil(t, input.ak.GetAccount(input.ctx, addr))
// set some values on the account and save it
newSequence := uint64(20)
acc.SetSequence(newSequence)
input.ak.SetAccount(input.ctx, acc)
// check the new values
acc = input.ak.GetAccount(input.ctx, addr)
require.NotNil(t, acc)
require.Equal(t, newSequence, acc.GetSequence())
}
func TestAccountMapperRemoveAccount(t *testing.T) {
input := setupTestInput()
addr1 := sdk.AccAddress([]byte("addr1"))
addr2 := sdk.AccAddress([]byte("addr2"))
// create accounts
acc1 := input.ak.NewAccountWithAddress(input.ctx, addr1)
acc2 := input.ak.NewAccountWithAddress(input.ctx, addr2)
accSeq1 := uint64(20)
accSeq2 := uint64(40)
acc1.SetSequence(accSeq1)
acc2.SetSequence(accSeq2)
input.ak.SetAccount(input.ctx, acc1)
input.ak.SetAccount(input.ctx, acc2)
acc1 = input.ak.GetAccount(input.ctx, addr1)
require.NotNil(t, acc1)
require.Equal(t, accSeq1, acc1.GetSequence())
// remove one account
input.ak.RemoveAccount(input.ctx, acc1)
acc1 = input.ak.GetAccount(input.ctx, addr1)
require.Nil(t, acc1)
acc2 = input.ak.GetAccount(input.ctx, addr2)
require.NotNil(t, acc2)
require.Equal(t, accSeq2, acc2.GetSequence())
}
func TestSetParams(t *testing.T) {
input := setupTestInput()
params := DefaultParams()
input.ak.SetParams(input.ctx, params)
newParams := Params{}
input.ak.paramSubspace.Get(input.ctx, KeyTxSigLimit, &newParams.TxSigLimit)
require.Equal(t, newParams.TxSigLimit, DefaultTxSigLimit)
}
func TestGetParams(t *testing.T) {
input := setupTestInput()
params := DefaultParams()
input.ak.SetParams(input.ctx, params)
newParams := input.ak.GetParams(input.ctx)
require.Equal(t, params, newParams)
}