-
Notifications
You must be signed in to change notification settings - Fork 30
/
test_helper.go
44 lines (36 loc) 路 1.35 KB
/
test_helper.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
package e2e
import (
"testing"
"time"
"cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
teststaking "github.com/cosmos/cosmos-sdk/x/staking/testutil"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
test_helpers "github.com/terra-money/alliance/app"
)
func setupApp(t *testing.T, numValidators int, numDelegators int, initBalance sdk.Coins) (app *test_helpers.App, ctx sdk.Context, valAddrs []sdk.ValAddress, delAddrs []sdk.AccAddress) {
app = test_helpers.Setup(t)
ctx = app.BaseApp.NewContext(false)
startTime := time.Now()
ctx = ctx.WithBlockTime(startTime)
// Accounts
valAccAddrs := test_helpers.AddTestAddrsIncremental(app, ctx, numValidators, sdk.NewCoins())
pks := test_helpers.CreateTestPubKeys(numValidators)
for i := 0; i < numValidators; i++ {
valAddr := sdk.ValAddress(valAccAddrs[i])
valAddrs = append(valAddrs, valAddr)
_val := teststaking.NewValidator(t, valAddr, pks[i])
_val.Commission = stakingtypes.Commission{
CommissionRates: stakingtypes.CommissionRates{
Rate: math.LegacyNewDec(0),
MaxRate: math.LegacyNewDec(0),
MaxChangeRate: math.LegacyNewDec(0),
},
UpdateTime: time.Now(),
}
_val.Status = stakingtypes.Bonded
test_helpers.RegisterNewValidator(t, app, ctx, _val)
}
delAddrs = test_helpers.AddTestAddrsIncremental(app, ctx, numDelegators, initBalance)
return
}