-
Notifications
You must be signed in to change notification settings - Fork 17
/
staking_test.go
84 lines (67 loc) · 2.26 KB
/
staking_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
//go:build bdd
package emoney_test
import (
nt "github.com/e-money/em-ledger/networktest"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/tidwall/sjson"
)
var _ = Describe("Staking", func() {
const (
QueryNgmRewards = "total.#(denom==\"ungm\")"
QueryJailedValidatorsCount = "validators.#(jailed==true)#"
)
Describe("Authority manages issuers", func() {
Context("", func() {
emcli := testnet.NewEmcli()
var (
Validator0Key = testnet.Keystore.Validators[0]
Validator2Key = testnet.Keystore.Validators[2]
)
It("creates a new testnet", func() {
awaitReady, err := testnet.RestartWithModifications(
// increase slash fraction so that amount is > 0
func(bz []byte) []byte {
bz, _ = sjson.SetBytes(bz, "app_state.slashing.params.slash_fraction_downtime", "0.100000000000000000")
return bz
})
Expect(err).ShouldNot(HaveOccurred())
Expect(awaitReady()).To(BeTrue())
})
It("kill validator 2 and get jailed", func() {
listener, err := nt.NewEventListener()
if err != nil {
panic(err)
}
slash, err := listener.AwaitSlash()
Expect(err).ToNot(HaveOccurred())
_, err = testnet.KillValidator(2)
Expect(err).ToNot(HaveOccurred())
Expect(slash()).ToNot(BeNil())
// wait 2 blocks
nt.IncChain(3)
rewardsJson, err := emcli.QueryRewards(Validator0Key.GetAddress())
Expect(err).ToNot(HaveOccurred())
Expect(rewardsJson.Get(QueryNgmRewards).Raw).ToNot(BeEmpty())
validators, err := emcli.QueryValidators()
Expect(err).ToNot(HaveOccurred())
validators = validators.Get(QueryJailedValidatorsCount)
Expect(validators.Array()).To(HaveLen(1))
})
It("validator unjails", func() {
validators, err := emcli.QueryValidators()
Expect(err).ToNot(HaveOccurred())
validators = validators.Get(QueryJailedValidatorsCount)
Expect(validators.Array()).To(HaveLen(1))
_, success, err := emcli.UnjailValidator(Validator2Key.GetAddress())
Expect(success).To(BeTrue())
Expect(err).ToNot(HaveOccurred())
nt.IncChain(1)
validators, err = emcli.QueryValidators()
Expect(err).ToNot(HaveOccurred())
validators = validators.Get(QueryJailedValidatorsCount)
Expect(validators.Array()).To(BeEmpty())
})
})
})
})