/
common.go
528 lines (466 loc) · 18.3 KB
/
common.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
package util
import (
"bytes"
"testing"
"time"
cosmosmath "cosmossdk.io/math"
"github.com/celestiaorg/celestia-app/app"
"github.com/celestiaorg/celestia-app/x/qgb"
"github.com/celestiaorg/celestia-app/x/qgb/keeper"
qgbtypes "github.com/celestiaorg/celestia-app/x/qgb/types"
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
ccodec "github.com/cosmos/cosmos-sdk/crypto/codec"
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
ccrypto "github.com/cosmos/cosmos-sdk/crypto/types"
"github.com/cosmos/cosmos-sdk/std"
"github.com/cosmos/cosmos-sdk/store"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth"
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/cosmos/cosmos-sdk/x/bank"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
"github.com/cosmos/cosmos-sdk/x/distribution"
distrkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper"
distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
"github.com/cosmos/cosmos-sdk/x/params"
paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper"
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
slashingkeeper "github.com/cosmos/cosmos-sdk/x/slashing/keeper"
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
"github.com/cosmos/cosmos-sdk/x/staking"
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
gethcommon "github.com/ethereum/go-ethereum/common"
"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/libs/log"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
tmversion "github.com/tendermint/tendermint/proto/tendermint/version"
dbm "github.com/tendermint/tm-db"
)
var (
// ModuleBasics is a mock module basic manager for testing
ModuleBasics = app.ModuleBasics
// TestingStakeParams is a set of staking params for testing
TestingStakeParams = stakingtypes.Params{
UnbondingTime: 100,
MaxValidators: 10,
MaxEntries: 10,
HistoricalEntries: 10000,
BondDenom: "stake",
MinCommissionRate: sdk.NewDecWithPrec(0, 0),
}
// ConsPrivKeys generate ed25519 ConsPrivKeys to be used for validator operator keys
ConsPrivKeys = []ccrypto.PrivKey{
ed25519.GenPrivKey(),
ed25519.GenPrivKey(),
ed25519.GenPrivKey(),
ed25519.GenPrivKey(),
ed25519.GenPrivKey(),
}
// ConsPubKeys holds the consensus public keys to be used for validator operator keys
ConsPubKeys = []ccrypto.PubKey{
ConsPrivKeys[0].PubKey(),
ConsPrivKeys[1].PubKey(),
ConsPrivKeys[2].PubKey(),
ConsPrivKeys[3].PubKey(),
ConsPrivKeys[4].PubKey(),
}
// AccPrivKeys generate secp256k1 pubkeys to be used for account pub keys
AccPrivKeys = []ccrypto.PrivKey{
secp256k1.GenPrivKey(),
secp256k1.GenPrivKey(),
secp256k1.GenPrivKey(),
secp256k1.GenPrivKey(),
secp256k1.GenPrivKey(),
}
// AccPubKeys holds the pub keys for the account keys
AccPubKeys = []ccrypto.PubKey{
AccPrivKeys[0].PubKey(),
AccPrivKeys[1].PubKey(),
AccPrivKeys[2].PubKey(),
AccPrivKeys[3].PubKey(),
AccPrivKeys[4].PubKey(),
}
// AccAddrs holds the sdk.AccAddresses
AccAddrs = []sdk.AccAddress{
sdk.AccAddress(AccPubKeys[0].Address()),
sdk.AccAddress(AccPubKeys[1].Address()),
sdk.AccAddress(AccPubKeys[2].Address()),
sdk.AccAddress(AccPubKeys[3].Address()),
sdk.AccAddress(AccPubKeys[4].Address()),
}
// ValAddrs holds the sdk.ValAddresses
ValAddrs = []sdk.ValAddress{
sdk.ValAddress(AccPubKeys[0].Address()),
sdk.ValAddress(AccPubKeys[1].Address()),
sdk.ValAddress(AccPubKeys[2].Address()),
sdk.ValAddress(AccPubKeys[3].Address()),
sdk.ValAddress(AccPubKeys[4].Address()),
}
// EVMAddrs holds etheruem addresses
EVMAddrs = initEVMAddrs(100)
// InitTokens holds the number of tokens to initialize an account with
InitTokens = sdk.TokensFromConsensusPower(110, sdk.DefaultPowerReduction)
// InitCoins holds the number of coins to initialize an account with
InitCoins = sdk.NewCoins(sdk.NewCoin(TestingStakeParams.BondDenom, InitTokens))
// StakingAmount holds the staking power to start a validator with
StakingAmount = sdk.TokensFromConsensusPower(10, sdk.DefaultPowerReduction)
)
func initEVMAddrs(count int) []gethcommon.Address {
addresses := make([]gethcommon.Address, count)
for i := 0; i < count; i++ {
evmAddr := gethcommon.BytesToAddress(bytes.Repeat([]byte{byte(i + 1)}, gethcommon.AddressLength))
addresses[i] = evmAddr
}
return addresses
}
// TestInput stores the various keepers required to test the QGB
type TestInput struct {
QgbKeeper keeper.Keeper
AccountKeeper authkeeper.AccountKeeper
StakingKeeper stakingkeeper.Keeper
SlashingKeeper slashingkeeper.Keeper
DistKeeper distrkeeper.Keeper
BankKeeper bankkeeper.BaseKeeper
Context sdk.Context
Marshaler codec.Codec
LegacyAmino *codec.LegacyAmino
}
// CreateTestEnvWithoutQGBKeysInit creates the keeper testing environment for the QGB
func CreateTestEnvWithoutQGBKeysInit(t *testing.T) TestInput {
t.Helper()
// Initialize store keys
qgbKey := sdk.NewKVStoreKey(qgbtypes.StoreKey)
keyAcc := sdk.NewKVStoreKey(authtypes.StoreKey)
keyStaking := sdk.NewKVStoreKey(stakingtypes.StoreKey)
keyBank := sdk.NewKVStoreKey(banktypes.StoreKey)
keyDistro := sdk.NewKVStoreKey(distrtypes.StoreKey)
keyParams := sdk.NewKVStoreKey(paramstypes.StoreKey)
tkeyParams := sdk.NewTransientStoreKey(paramstypes.TStoreKey)
keySlashing := sdk.NewKVStoreKey(slashingtypes.StoreKey)
// Initialize memory database and mount stores on it
db := dbm.NewMemDB()
ms := store.NewCommitMultiStore(db)
ms.MountStoreWithDB(qgbKey, storetypes.StoreTypeIAVL, db)
ms.MountStoreWithDB(keyAcc, storetypes.StoreTypeIAVL, db)
ms.MountStoreWithDB(keyParams, storetypes.StoreTypeIAVL, db)
ms.MountStoreWithDB(keyStaking, storetypes.StoreTypeIAVL, db)
ms.MountStoreWithDB(keyBank, storetypes.StoreTypeIAVL, db)
ms.MountStoreWithDB(keyDistro, storetypes.StoreTypeIAVL, db)
ms.MountStoreWithDB(tkeyParams, storetypes.StoreTypeTransient, db)
ms.MountStoreWithDB(keySlashing, storetypes.StoreTypeIAVL, db)
err := ms.LoadLatestVersion()
require.Nil(t, err)
// Create sdk.Context
ctx := sdk.NewContext(ms, tmproto.Header{
Version: tmversion.Consensus{
Block: 0,
App: 0,
},
ChainID: "",
Height: 1234567,
Time: time.Date(2020, time.April, 22, 12, 0, 0, 0, time.UTC),
LastBlockId: tmproto.BlockID{
Hash: []byte{},
PartSetHeader: tmproto.PartSetHeader{
Total: 0,
Hash: []byte{},
},
},
LastCommitHash: []byte{},
DataHash: []byte{},
ValidatorsHash: []byte{},
NextValidatorsHash: []byte{},
ConsensusHash: []byte{},
AppHash: []byte{},
LastResultsHash: []byte{},
EvidenceHash: []byte{},
ProposerAddress: []byte{},
}, false, log.TestingLogger())
cdc := MakeTestCodec()
marshaler := MakeTestMarshaler()
paramsKeeper := paramskeeper.NewKeeper(marshaler, cdc, keyParams, tkeyParams)
paramsKeeper.Subspace(authtypes.ModuleName)
paramsKeeper.Subspace(banktypes.ModuleName)
paramsKeeper.Subspace(stakingtypes.ModuleName)
paramsKeeper.Subspace(distrtypes.ModuleName)
paramsKeeper.Subspace(qgbtypes.DefaultParamspace)
paramsKeeper.Subspace(slashingtypes.ModuleName)
// this is also used to initialize module accounts for all the map keys
maccPerms := map[string][]string{
authtypes.FeeCollectorName: nil,
distrtypes.ModuleName: nil,
stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking},
stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking},
qgbtypes.ModuleName: {authtypes.Minter, authtypes.Burner},
}
accountKeeper := authkeeper.NewAccountKeeper(
marshaler,
keyAcc, // target store
getSubspace(paramsKeeper, authtypes.ModuleName),
authtypes.ProtoBaseAccount, // prototype
maccPerms,
app.Bech32PrefixAccAddr,
)
blockedAddr := make(map[string]bool, len(maccPerms))
for acc := range maccPerms {
blockedAddr[authtypes.NewModuleAddress(acc).String()] = true
}
bankKeeper := bankkeeper.NewBaseKeeper(
marshaler,
keyBank,
accountKeeper,
getSubspace(paramsKeeper, banktypes.ModuleName),
blockedAddr,
)
bankKeeper.SetParams(
ctx,
banktypes.Params{
SendEnabled: []*banktypes.SendEnabled{},
DefaultSendEnabled: true,
},
)
stakingKeeper := stakingkeeper.NewKeeper(marshaler, keyStaking, accountKeeper, bankKeeper, getSubspace(paramsKeeper, stakingtypes.ModuleName))
stakingKeeper.SetParams(ctx, TestingStakeParams)
distKeeper := distrkeeper.NewKeeper(marshaler, keyDistro, getSubspace(paramsKeeper, distrtypes.ModuleName), accountKeeper, bankKeeper, stakingKeeper, authtypes.FeeCollectorName)
distKeeper.SetParams(ctx, distrtypes.DefaultParams())
// set genesis items required for distribution
distKeeper.SetFeePool(ctx, distrtypes.InitialFeePool())
// total supply to track this
totalSupply := sdk.NewCoins(sdk.NewInt64Coin("stake", 100000000))
// set up initial accounts
for name, perms := range maccPerms {
mod := authtypes.NewEmptyModuleAccount(name, perms...)
if name == stakingtypes.NotBondedPoolName {
err = bankKeeper.MintCoins(ctx, qgbtypes.ModuleName, totalSupply)
require.NoError(t, err)
err = bankKeeper.SendCoinsFromModuleToModule(ctx, qgbtypes.ModuleName, mod.Name, totalSupply)
require.NoError(t, err)
} else if name == distrtypes.ModuleName {
// some big pot to pay out
amt := sdk.NewCoins(sdk.NewInt64Coin("stake", 500000))
err = bankKeeper.MintCoins(ctx, qgbtypes.ModuleName, amt)
require.NoError(t, err)
err = bankKeeper.SendCoinsFromModuleToModule(ctx, qgbtypes.ModuleName, mod.Name, amt)
require.NoError(t, err)
}
accountKeeper.SetModuleAccount(ctx, mod)
}
stakeAddr := authtypes.NewModuleAddress(stakingtypes.BondedPoolName)
moduleAcct := accountKeeper.GetAccount(ctx, stakeAddr)
require.NotNil(t, moduleAcct)
slashingKeeper := slashingkeeper.NewKeeper(
marshaler,
keySlashing,
&stakingKeeper,
getSubspace(paramsKeeper, slashingtypes.ModuleName).WithKeyTable(slashingtypes.ParamKeyTable()),
)
k := keeper.NewKeeper(marshaler, qgbKey, getSubspace(paramsKeeper, qgbtypes.DefaultParamspace), &stakingKeeper)
testQGBParams := qgbtypes.DefaultGenesis().Params
k.SetParams(ctx, *testQGBParams)
stakingKeeper = *stakingKeeper.SetHooks(
stakingtypes.NewMultiStakingHooks(
distKeeper.Hooks(),
slashingKeeper.Hooks(),
k.Hooks(),
),
)
return TestInput{
QgbKeeper: *k,
AccountKeeper: accountKeeper,
BankKeeper: bankKeeper,
StakingKeeper: stakingKeeper,
SlashingKeeper: slashingKeeper,
DistKeeper: distKeeper,
Context: ctx,
Marshaler: marshaler,
LegacyAmino: cdc,
}
}
// CreateTestEnv creates the keeper testing environment for QGB
func CreateTestEnv(t *testing.T) TestInput {
input := CreateTestEnvWithoutQGBKeysInit(t)
input.QgbKeeper.SetLatestAttestationNonce(input.Context, qgb.InitialLatestAttestationNonce)
input.QgbKeeper.SetEarliestAvailableAttestationNonce(input.Context, qgb.InitialEarliestAvailableAttestationNonce)
return input
}
// MakeTestCodec creates a legacy amino codec for testing
func MakeTestCodec() *codec.LegacyAmino {
cdc := codec.NewLegacyAmino()
auth.AppModuleBasic{}.RegisterLegacyAminoCodec(cdc)
bank.AppModuleBasic{}.RegisterLegacyAminoCodec(cdc)
staking.AppModuleBasic{}.RegisterLegacyAminoCodec(cdc)
distribution.AppModuleBasic{}.RegisterLegacyAminoCodec(cdc)
sdk.RegisterLegacyAminoCodec(cdc)
ccodec.RegisterCrypto(cdc)
params.AppModuleBasic{}.RegisterLegacyAminoCodec(cdc)
qgbtypes.RegisterLegacyAminoCodec(cdc)
return cdc
}
// getSubspace returns a param subspace for a given module name.
func getSubspace(k paramskeeper.Keeper, moduleName string) paramstypes.Subspace {
subspace, _ := k.GetSubspace(moduleName)
return subspace
}
// MakeTestMarshaler creates a proto codec for use in testing
func MakeTestMarshaler() codec.Codec {
interfaceRegistry := codectypes.NewInterfaceRegistry()
std.RegisterInterfaces(interfaceRegistry)
ModuleBasics.RegisterInterfaces(interfaceRegistry)
qgbtypes.RegisterInterfaces(interfaceRegistry)
return codec.NewProtoCodec(interfaceRegistry)
}
// SetupFiveValChain does all the initialization for a 5 Validator chain using the keys here
func SetupFiveValChain(t *testing.T) (TestInput, sdk.Context) {
t.Helper()
input := CreateTestEnv(t)
// Set the params for our modules
input.StakingKeeper.SetParams(input.Context, TestingStakeParams)
// Initialize each of the validators
for i := range []int{0, 1, 2, 3, 4} {
CreateValidator(t, input, AccAddrs[i], AccPubKeys[i], uint64(i), ValAddrs[i], ConsPubKeys[i], StakingAmount)
RegisterEVMAddress(t, input, ValAddrs[i], EVMAddrs[i])
}
// Run the staking endblocker to ensure valset is correct in state
staking.EndBlocker(input.Context, input.StakingKeeper)
// Return the test input
return input, input.Context
}
func CreateValidator(
t *testing.T,
input TestInput,
accAddr sdk.AccAddress,
accPubKey ccrypto.PubKey,
accountNumber uint64,
valAddr sdk.ValAddress,
consPubKey ccrypto.PubKey,
stakingAmount cosmosmath.Int,
) {
// Initialize the account for the key
acc := input.AccountKeeper.NewAccount(
input.Context,
authtypes.NewBaseAccount(accAddr, accPubKey, accountNumber, 0),
)
// Set the balance for the account
require.NoError(t, input.BankKeeper.MintCoins(input.Context, qgbtypes.ModuleName, InitCoins))
err := input.BankKeeper.SendCoinsFromModuleToAccount(input.Context, qgbtypes.ModuleName, acc.GetAddress(), InitCoins)
require.NoError(t, err)
// Set the account in state
input.AccountKeeper.SetAccount(input.Context, acc)
// Create a validator for that account using some tokens in the account
// and the staking handler
msgServer := stakingkeeper.NewMsgServerImpl(input.StakingKeeper)
_, err = msgServer.CreateValidator(input.Context, NewTestMsgCreateValidator(valAddr, consPubKey, stakingAmount))
require.NoError(t, err)
}
func RegisterEVMAddress(
t *testing.T,
input TestInput,
valAddr sdk.ValAddress,
evmAddr gethcommon.Address,
) {
qgbMsgServer := keeper.NewMsgServerImpl(input.QgbKeeper)
registerMsg := qgbtypes.NewMsgRegisterEVMAddress(valAddr, evmAddr)
_, err := qgbMsgServer.RegisterEVMAddress(input.Context, registerMsg)
require.NoError(t, err)
}
func NewTestMsgCreateValidator(
address sdk.ValAddress,
pubKey ccrypto.PubKey,
amt cosmosmath.Int,
) *stakingtypes.MsgCreateValidator {
commission := stakingtypes.NewCommissionRates(sdk.ZeroDec(), sdk.ZeroDec(), sdk.ZeroDec())
out, err := stakingtypes.NewMsgCreateValidator(
address, pubKey, sdk.NewCoin("stake", amt),
stakingtypes.Description{
Moniker: "",
Identity: "",
Website: "",
SecurityContact: "",
Details: "",
}, commission, sdk.OneInt(),
)
if err != nil {
panic(err)
}
return out
}
// SetupTestChain sets up a test environment with the provided validator voting weights
func SetupTestChain(t *testing.T, weights []uint64) (TestInput, sdk.Context) {
t.Helper()
input := CreateTestEnv(t)
// Set the params for our modules
TestingStakeParams.MaxValidators = 100
input.StakingKeeper.SetParams(input.Context, TestingStakeParams)
// Initialize each of the validators
stakingMsgServer := stakingkeeper.NewMsgServerImpl(input.StakingKeeper)
qgbMsgServer := keeper.NewMsgServerImpl(input.QgbKeeper)
for i, weight := range weights {
consPrivKey := ed25519.GenPrivKey()
consPubKey := consPrivKey.PubKey()
valPrivKey := secp256k1.GenPrivKey()
valPubKey := valPrivKey.PubKey()
valAddr := sdk.ValAddress(valPubKey.Address())
accAddr := sdk.AccAddress(valPubKey.Address())
// Initialize the account for the key
acc := input.AccountKeeper.NewAccount(
input.Context,
authtypes.NewBaseAccount(accAddr, valPubKey, uint64(i), 0),
)
// Set the balance for the account
weightCoins := sdk.NewCoins(sdk.NewInt64Coin(TestingStakeParams.BondDenom, int64(weight)))
require.NoError(t, input.BankKeeper.MintCoins(input.Context, qgbtypes.ModuleName, weightCoins))
require.NoError(t, input.BankKeeper.SendCoinsFromModuleToAccount(input.Context, qgbtypes.ModuleName, accAddr, weightCoins))
// Set the account in state
input.AccountKeeper.SetAccount(input.Context, acc)
// Create a validator for that account using some of the tokens in the account
// and the staking handler
_, err := stakingMsgServer.CreateValidator(
input.Context,
NewTestMsgCreateValidator(valAddr, consPubKey, sdk.NewIntFromUint64(weight)),
)
require.NoError(t, err)
registerMsg := qgbtypes.NewMsgRegisterEVMAddress(valAddr, EVMAddrs[i])
_, err = qgbMsgServer.RegisterEVMAddress(input.Context, registerMsg)
require.NoError(t, err)
// Run the staking endblocker to ensure valset is correct in state
staking.EndBlocker(input.Context, input.StakingKeeper)
}
// some inputs can cause the validator creation not to work, this checks that
// everything was successful
validators := input.StakingKeeper.GetBondedValidatorsByPower(input.Context)
require.Equal(t, len(weights), len(validators))
// Return the test input
return input, input.Context
}
func NewTestMsgUnDelegateValidator(address sdk.ValAddress, amt cosmosmath.Int) *stakingtypes.MsgUndelegate {
msg := stakingtypes.NewMsgUndelegate(sdk.AccAddress(address), address, sdk.NewCoin("stake", amt))
return msg
}
// ExecuteQGBHeights executes the end exclusive range of heights specified by beginHeight and endHeight
// along with the QGB abci.EndBlocker on each one of them.
// Returns the updated context with block height advanced to endHeight.
func ExecuteQGBHeights(ctx sdk.Context, qgbKeeper keeper.Keeper, beginHeight int64, endHeight int64) sdk.Context {
for i := beginHeight; i < endHeight; i++ {
ctx = ctx.WithBlockHeight(i)
qgb.EndBlocker(ctx, qgbKeeper)
}
return ctx
}
// ExecuteQGBHeightsWithTime executes the end exclusive range of heights specified by beginHeight and endHeight
// along with the QGB abci.EndBlocker on each one of them.
// Uses the interval to calculate the block header time.
func ExecuteQGBHeightsWithTime(ctx sdk.Context, qgbKeeper keeper.Keeper, beginHeight int64, endHeight int64, blockInterval time.Duration) sdk.Context {
blockTime := ctx.BlockTime()
for i := beginHeight; i < endHeight; i++ {
ctx = ctx.WithBlockHeight(i).WithBlockTime(blockTime)
qgb.EndBlocker(ctx, qgbKeeper)
blockTime = blockTime.Add(blockInterval)
}
return ctx
}