-
Notifications
You must be signed in to change notification settings - Fork 828
/
Copy pathupgrade_test.go
88 lines (74 loc) · 3.06 KB
/
upgrade_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
package app_test
import (
"testing"
"time"
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/upgrade/types"
"github.com/sei-protocol/sei-chain/app"
"github.com/stretchr/testify/require"
abci "github.com/tendermint/tendermint/abci/types"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
)
func TestUpgradesListIsSorted(t *testing.T) {
tm := time.Now().UTC()
valPub := secp256k1.GenPrivKey().PubKey()
testWrapper := app.NewTestWrapper(t, tm, valPub, false)
testWrapper.App.RegisterUpgradeHandlers()
}
// Test community tax param is set to 0 as part of upgrade 1.2.3beta
func TestDistributionCommunityTaxParamMigration(t *testing.T) {
tm := time.Now().UTC()
valPub := secp256k1.GenPrivKey().PubKey()
testWrapper := app.NewTestWrapper(t, tm, valPub, false)
testWrapper.App.RegisterUpgradeHandlers()
params := testWrapper.App.DistrKeeper.GetParams(testWrapper.Ctx)
testWrapper.Require().Equal(params.CommunityTax, sdk.NewDec(0))
}
func TestSkipOptimisticProcessingOnUpgrade(t *testing.T) {
t.Parallel()
t.Run("Test optimistic processing is skipped on upgrade", func(t *testing.T) {
tm := time.Now().UTC()
valPub := secp256k1.GenPrivKey().PubKey()
testWrapper := app.NewTestWrapper(t, tm, valPub, false)
// No optimistic processing with upgrade scheduled
testCtx := testWrapper.App.BaseApp.NewContext(false, tmproto.Header{Height: 3, ChainID: "sei-test", Time: tm})
testWrapper.App.UpgradeKeeper.ScheduleUpgrade(testWrapper.Ctx, types.Plan{
Name: "test-plan",
Height: testCtx.BlockHeight(),
})
plan, found := testWrapper.App.UpgradeKeeper.GetUpgradePlan(testCtx)
require.True(t, found)
require.True(t, plan.ShouldExecute(testCtx))
res, _ := testWrapper.App.ProcessProposalHandler(testCtx, &abci.RequestProcessProposal{
Height: 1,
})
require.Equal(t, res.Status, abci.ResponseProcessProposal_ACCEPT)
require.True(t, testWrapper.App.GetOptimisticProcessingInfo().Aborted)
})
t.Run("Test optimistic processing if no upgrade", func(t *testing.T) {
tm := time.Now().UTC()
valPub := secp256k1.GenPrivKey().PubKey()
testWrapper := app.NewTestWrapper(t, tm, valPub, false)
testCtx := testWrapper.App.BaseApp.NewContext(false, tmproto.Header{Height: 3, ChainID: "sei-test", Time: tm})
testWrapper.App.UpgradeKeeper.ScheduleUpgrade(testWrapper.Ctx, types.Plan{
Name: "test-plan",
Height: testCtx.BlockHeight() + 1,
})
plan, found := testWrapper.App.UpgradeKeeper.GetUpgradePlan(testCtx)
require.True(t, found)
require.False(t, plan.ShouldExecute(testCtx))
go func() {
testWrapper.App.ProcessProposalHandler(testCtx, &abci.RequestProcessProposal{Height: 1})
}()
require.Eventually(t, func() bool {
if testWrapper.App.GetOptimisticProcessingInfo() == nil {
return false
}
<-testWrapper.App.GetOptimisticProcessingInfo().Completion
return true
}, 5*time.Second, time.Millisecond*100)
// require.Equal(t, res.Status, abci.ResponseProcessProposal_ACCEPT)
require.False(t, testWrapper.App.GetOptimisticProcessingInfo().Aborted)
})
}