-
Notifications
You must be signed in to change notification settings - Fork 10
/
test_fixtures.go
73 lines (63 loc) · 1.87 KB
/
test_fixtures.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
package types
import (
"fmt"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
sdk "github.com/cosmos/cosmos-sdk/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
)
func MsgCreateValidatorFixture(mutators ...func(m *MsgCreateValidator)) *MsgCreateValidator {
pk1 := ed25519.GenPrivKey().PubKey()
desc := stakingtypes.NewDescription("testname", "", "", "", "")
r, err := NewMsgCreateValidator(sdk.AccAddress(pk1.Address()), pk1, sdk.NewInt64Coin(DefaultBondDenom, 50), desc)
if err != nil {
panic(err)
}
for _, m := range mutators {
m(r)
}
return r
}
func MsgUpdateValidatorFixture(mutators ...func(m *MsgUpdateValidator)) *MsgUpdateValidator {
desc := stakingtypes.NewDescription("other-name", "foo", "http://example.com", "bar", "my details")
r := NewMsgUpdateValidator(RandomAccAddress(), desc)
for _, m := range mutators {
m(r)
}
return r
}
func GenesisStateFixture(mutators ...func(m *GenesisState)) GenesisState {
r := DefaultGenesisState()
r.Engagement = []TG4Member{{
Address: RandomAccAddress().String(),
Weight: 10,
}}
for _, m := range mutators {
m(&r)
}
return r
}
func ValidatorFixture(mutators ...func(m *stakingtypes.Validator)) stakingtypes.Validator {
pkAny, err := codectypes.NewAnyWithValue(ed25519.GenPrivKey().PubKey())
if err != nil {
panic(fmt.Sprintf("failed to encode any type: %s", err.Error()))
}
desc := stakingtypes.Description{
Moniker: "myMoniker",
Identity: "myIdentity",
Website: "https://example.com",
SecurityContact: "myContact",
Details: "myDetails",
}
r := stakingtypes.Validator{
OperatorAddress: RandomAccAddress().String(),
ConsensusPubkey: pkAny,
Description: desc,
DelegatorShares: sdk.OneDec(),
Status: stakingtypes.Bonded,
}
for _, m := range mutators {
m(&r)
}
return r
}