-
Notifications
You must be signed in to change notification settings - Fork 17
/
feegrant_test.go
115 lines (94 loc) · 3.71 KB
/
feegrant_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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
//go:build bdd
package emoney_test
import (
sdk "github.com/cosmos/cosmos-sdk/types"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/tidwall/gjson"
"strconv"
)
var _ = Describe("FeeGrant", func() {
var (
emcli = testnet.NewEmcli()
authority = testnet.Keystore.Authority
granter = testnet.Keystore.Key1
grantee = testnet.Keystore.Key2
reciever = testnet.Keystore.Key3
initialBalance = 0 // toBeOverridden
sendValue = 2500000
spendLimit = 1000000
feeAmount = 5000
totalGasSpent = 0
denom = "ungm"
)
Describe("Let's Test This FeeGrant Module", func() {
It("creates a new testnet", createNewTestnet)
It("Let's get the initial funds value", func() {
var err error
initialBalance, err = emcli.QueryBalanceDenom(granter.GetAddress(), denom)
Expect(err).ToNot(HaveOccurred())
})
It("Let's set gasprice and confirm", func() {
var prices, err = sdk.ParseDecCoins("0.00005" + denom)
Expect(err).ToNot(HaveOccurred())
_, success, err := emcli.AuthoritySetMinGasPrices(authority, prices.String())
Expect(success).To(BeTrue())
Expect(err).ToNot(HaveOccurred())
_, err = emcli.QueryMinGasPrices()
Expect(err).ShouldNot(HaveOccurred())
})
It("Let's check some initial balances", func() {
var granterBalance, err = emcli.QueryBalanceDenom(granter.GetAddress(), denom)
Expect(err).ShouldNot(HaveOccurred())
Expect(granterBalance).To(Equal(initialBalance))
var granteeBalance, err2 = emcli.QueryBalanceDenom(grantee.GetAddress(), denom)
Expect(err2).ShouldNot(HaveOccurred())
Expect(granteeBalance).To(Equal(initialBalance))
})
It("Let's make a grant", func() {
_, _, err := emcli.FeegrantGrant(granter, grantee, strconv.Itoa(spendLimit)+denom, strconv.Itoa(feeAmount)+denom)
totalGasSpent += feeAmount
Expect(err).ShouldNot(HaveOccurred())
})
It("Let's check that the grant is there", func() {
var msg, err = emcli.FeegrantQuery(grantee)
Expect(err).ShouldNot(HaveOccurred())
ir := gjson.ParseBytes(msg)
Expect(len(ir.Get("allowances").Array())).To(Equal(1))
})
It("Let's check some balances", func() {
var granterBalance, err = emcli.QueryBalanceDenom(granter.GetAddress(), denom)
Expect(err).ShouldNot(HaveOccurred())
Expect(granterBalance).To(Equal(initialBalance - feeAmount))
granteeBalance, err := emcli.QueryBalanceDenom(grantee.GetAddress(), denom)
Expect(err).ShouldNot(HaveOccurred())
Expect(granteeBalance).To(Equal(initialBalance))
})
It("Let grantee send message and let granter pay fee", func() {
var msg, err = emcli.SendGrantfee(grantee, reciever, granter, strconv.Itoa(sendValue)+denom, strconv.Itoa(feeAmount)+denom)
totalGasSpent += feeAmount
ir := gjson.ParseBytes([]byte(msg))
code := ir.Get("code").Int()
Expect(int(code)).To(Equal(0))
Expect(err).ShouldNot(HaveOccurred())
})
It("Let's check some balances after send", func() {
var granteeBalance, err = emcli.QueryBalanceDenom(grantee.GetAddress(), denom)
Expect(err).ShouldNot(HaveOccurred())
Expect(granteeBalance).To(Equal(initialBalance - sendValue))
granterBalance, err := emcli.QueryBalanceDenom(granter.GetAddress(), denom)
Expect(err).ShouldNot(HaveOccurred())
Expect(granterBalance).To(Equal(initialBalance - totalGasSpent))
})
It("Let's revoke that grant", func() {
var _, _, err = emcli.FeegrantRevoke(granter, grantee, strconv.Itoa(feeAmount)+denom)
Expect(err).ShouldNot(HaveOccurred())
})
It("Let's check that the grant is gone", func() {
var msg, err = emcli.FeegrantQuery(grantee)
Expect(err).ShouldNot(HaveOccurred())
ir := gjson.ParseBytes(msg)
Expect(len(ir.Get("allowances").Array())).To(Equal(0))
})
})
})