-
Notifications
You must be signed in to change notification settings - Fork 10
/
test_fixtures.go
85 lines (77 loc) · 2.24 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
74
75
76
77
78
79
80
81
82
83
84
85
package types
import (
"testing"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/address"
"github.com/tendermint/tendermint/libs/rand"
)
func PromoteProposalFixture(mutators ...func(*PromoteToPrivilegedContractProposal)) *PromoteToPrivilegedContractProposal {
const anyAddress = "cosmos1qyqszqgpqyqszqgpqyqszqgpqyqszqgpjnp7du"
p := &PromoteToPrivilegedContractProposal{
Title: "Foo",
Description: "Bar",
Contract: anyAddress,
}
for _, m := range mutators {
m(p)
}
return p
}
func DemoteProposalFixture(mutators ...func(proposal *DemotePrivilegedContractProposal)) *DemotePrivilegedContractProposal {
const anyAddress = "cosmos1qyqszqgpqyqszqgpqyqszqgpqyqszqgpjnp7du"
p := &DemotePrivilegedContractProposal{
Title: "Foo",
Description: "Bar",
Contract: anyAddress,
}
for _, m := range mutators {
m(p)
}
return p
}
func GenesisStateFixture(t *testing.T, mutators ...func(*GenesisState)) GenesisState {
t.Helper()
anyContractAddr := RandomBech32Address(t)
genesisState := GenesisState{
Wasm: wasmtypes.GenesisFixture(func(state *wasmtypes.GenesisState) {
state.Codes[1] = wasmtypes.CodeFixture(func(code *wasmtypes.Code) {
code.CodeID = 2
code.Pinned = true
})
state.Contracts[1] = wasmtypes.ContractFixture(func(contract *wasmtypes.Contract) {
contract.ContractAddress = anyContractAddr
contract.ContractInfo.CodeID = 2
})
state.Sequences = []wasmtypes.Sequence{
{IDKey: wasmtypes.KeyLastCodeID, Value: 10},
{IDKey: wasmtypes.KeyLastInstanceID, Value: 11},
}
state.GenMsgs = nil
}),
PrivilegedContractAddresses: []string{anyContractAddr},
}
for _, m := range mutators {
m(&genesisState)
}
return genesisState
}
func TgradeContractDetailsFixture(t *testing.T, mutators ...func(d *TgradeContractDetails)) TgradeContractDetails {
t.Helper()
d := TgradeContractDetails{
RegisteredPrivileges: []RegisteredPrivilege{{
Position: 1,
PrivilegeType: "begin_blocker",
}},
}
for _, m := range mutators {
m(&d)
}
return d
}
func RandomAddress(_ *testing.T) sdk.AccAddress {
return rand.Bytes(address.Len)
}
func RandomBech32Address(t *testing.T) string {
return RandomAddress(t).String()
}