forked from noble-assets/noble
-
Notifications
You must be signed in to change notification settings - Fork 1
/
globalfee_test.go
141 lines (112 loc) · 4.39 KB
/
globalfee_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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
package interchaintest_test
import (
"context"
"fmt"
"testing"
"github.com/cosmos/cosmos-sdk/x/params/types/proposal"
"github.com/noble-assets/noble/v7/cmd"
"github.com/strangelove-ventures/interchaintest/v4"
"github.com/strangelove-ventures/interchaintest/v4/chain/cosmos"
"github.com/strangelove-ventures/interchaintest/v4/testreporter"
proposaltypes "github.com/strangelove-ventures/paramauthority/x/params/types/proposal"
"github.com/stretchr/testify/require"
"go.uber.org/zap/zaptest"
)
// run `make local-image`to rebuild updated binary before running test
func TestGlobalFee(t *testing.T) {
if testing.Short() {
t.Skip()
}
t.Parallel()
ctx := context.Background()
rep := testreporter.NewNopReporter()
eRep := rep.RelayerExecReporter(t)
client, network := interchaintest.DockerSetup(t)
var gw genesisWrapper
cf := interchaintest.NewBuiltinChainFactory(zaptest.NewLogger(t), []*interchaintest.ChainSpec{
nobleChainSpec(ctx, &gw, "noble-1", 2, 0, false, true, false, true),
})
chains, err := cf.Chains(t.Name())
require.NoError(t, err)
gw.chain = chains[0].(*cosmos.CosmosChain)
noble := gw.chain
ic := interchaintest.NewInterchain().
AddChain(noble)
require.NoError(t, ic.Build(ctx, eRep, interchaintest.InterchainBuildOptions{
TestName: t.Name(),
Client: client,
NetworkID: network,
SkipPathCreation: false,
}))
t.Cleanup(func() {
_ = ic.Close()
})
chainCfg := noble.Config()
cmd.SetPrefixes(chainCfg.Bech32Prefix)
nobleValidator := noble.Validators[0]
sendAmount100 := fmt.Sprintf("100%s", chainCfg.Denom)
minGasPriceAmount := "0.00001"
minGasPrice := minGasPriceAmount + chainCfg.Denom
zeroGasPrice := "0.0" + chainCfg.Denom
// send tx with zero fees with the default MinimumGasPricesParam of 0 (null) - tx should succeed
_, err = nobleValidator.ExecTx(ctx, gw.extraWallets.User2.KeyName(), "bank", "send", gw.extraWallets.User2.KeyName(), gw.extraWallets.Alice.FormattedAddress(), sendAmount100, "--gas-prices", zeroGasPrice)
require.NoError(t, err, "failed sending transaction")
msgUpdateParams := proposaltypes.MsgUpdateParams{
ChangeProposal: proposal.NewParameterChangeProposal(
"Global Fees Param Change",
"Update global fees",
[]proposal.ParamChange{
{
Subspace: "globalfee",
Key: "MinimumGasPricesParam",
Value: fmt.Sprintf(`[{"denom":"%s", "amount":"%s"}]`, chainCfg.Denom, minGasPriceAmount),
},
}),
Authority: gw.paramAuthority.FormattedAddress(),
}
broadcaster := cosmos.NewBroadcaster(t, noble)
wallet := cosmos.NewWallet(
gw.paramAuthority.KeyName(),
gw.paramAuthority.Address(),
gw.paramAuthority.Mnemonic(),
chainCfg,
)
tx, err := cosmos.BroadcastTx(
ctx,
broadcaster,
wallet,
&msgUpdateParams,
)
require.NoError(t, err, "failed to broadcast tx")
require.Equal(t, uint32(0), tx.Code, "tx proposal failed")
// send tx with zero fees while the default MinimumGasPricesParam requires fees - tx should fail
_, err = nobleValidator.ExecTx(ctx, gw.extraWallets.User2.KeyName(),
"bank", "send",
gw.extraWallets.User2.FormattedAddress(), gw.extraWallets.Alice.FormattedAddress(), sendAmount100,
"--gas-prices", zeroGasPrice,
"-b", "block",
)
require.Error(t, err, "tx should not have succeeded with zero fees")
// send tx with the gas price set by MinimumGasPricesParam - tx should succeed
_, err = nobleValidator.ExecTx(ctx, gw.extraWallets.User2.KeyName(),
"bank", "send",
gw.extraWallets.User2.FormattedAddress(), gw.extraWallets.Alice.FormattedAddress(), sendAmount100,
"--gas-prices", minGasPrice,
"-b", "block",
)
require.NoError(t, err, "tx should have succeeded")
// send tx with zero fees while the default MinimumGasPricesParam requires fees, but update owner msg is in the bypass min fee msgs list - tx should succeed
_, err = nobleValidator.ExecTx(ctx, gw.tfRoles.Owner.KeyName(),
"tokenfactory", "update-owner", gw.tfRoles.Owner2.FormattedAddress(),
"--gas-prices", zeroGasPrice,
"-b", "block",
)
require.NoError(t, err, "failed to execute update owner tx with zero fees")
// send tx with zero fees while the default MinimumGasPricesParam requires fees, but accept owner msg is in the bypass min fee msgs list - tx should succeed
_, err = nobleValidator.ExecTx(ctx, gw.tfRoles.Owner2.KeyName(),
"tokenfactory", "accept-owner",
"--gas-prices", zeroGasPrice,
"-b", "block",
)
require.NoError(t, err, "failed to execute tx to accept ownership with zero fees")
}