-
Notifications
You must be signed in to change notification settings - Fork 60
/
genesis_test.go
95 lines (76 loc) · 3.21 KB
/
genesis_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
package participationrewards_test
import (
"encoding/json"
"fmt"
"testing"
"time"
"github.com/stretchr/testify/require"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
sdk "github.com/cosmos/cosmos-sdk/types"
simapp "github.com/quicksilver-zone/quicksilver/app"
"github.com/quicksilver-zone/quicksilver/x/participationrewards"
"github.com/quicksilver-zone/quicksilver/x/participationrewards/types"
)
func TestParticipationRewardsExportGenesis(t *testing.T) {
app := simapp.Setup(t, false)
ctx := app.BaseApp.NewContext(false, tmproto.Header{})
chainStartTime := ctx.BlockTime()
pool := types.OsmosisPoolProtocolData{
PoolID: 1,
PoolName: "atom/osmo",
LastUpdated: chainStartTime,
}
bz, err := json.Marshal(pool)
if err != nil {
t.Fatalf("unable to marshal protocol data: %v", err)
}
protocolData := types.NewProtocolData(types.ProtocolDataType_name[int32(types.ProtocolDataTypeOsmosisPool)], bz)
app.ParticipationRewardsKeeper.SetProtocolData(ctx, []byte(fmt.Sprintf("%d", pool.PoolID)), protocolData)
genesis := participationrewards.ExportGenesis(ctx, app.ParticipationRewardsKeeper)
// 0,0,0,4 (binary encoded types.ProtocolDataTypeOsmosisPool)
// 49 (ASCII value of '1')
require.Equal(t, string([]byte{0, 0, 0, 0, 0, 0, 0, 4, 49}), genesis.ProtocolData[0].Key)
require.Equal(t, types.ProtocolDataType_name[int32(types.ProtocolDataTypeOsmosisPool)], genesis.ProtocolData[0].ProtocolData.Type)
}
func TestParticipationRewardsInitGenesis(t *testing.T) {
// setup params
app := simapp.Setup(t, false)
ctx := app.BaseApp.NewContext(false, tmproto.Header{})
now := time.Now()
ctx = ctx.WithBlockHeight(1)
ctx = ctx.WithBlockTime(now)
validOsmosisData := `{
"poolid": 1,
"poolname": "atom/osmo",
"pooltype": "balancer",
"denoms": {
"ibc/00000000000000000000000000000000": {"denom": "ustake", "chainid": "testzone-1"}
}
}`
kpd := &types.KeyedProtocolData{
Key: "6",
ProtocolData: &types.ProtocolData{
Type: types.ProtocolDataType_name[int32(types.ProtocolDataTypeOsmosisPool)],
Data: []byte(validOsmosisData),
},
}
// test genesisState validation
genesisState := types.GenesisState{
Params: types.Params{
DistributionProportions: types.DistributionProportions{
ValidatorSelectionAllocation: sdk.NewDecWithPrec(5, 1),
HoldingsAllocation: sdk.NewDecWithPrec(5, 1),
LockupAllocation: sdk.ZeroDec(),
},
},
ProtocolData: []*types.KeyedProtocolData{kpd},
}
require.NoError(t, genesisState.Validate(), "genesis validation failed")
participationrewards.InitGenesis(ctx, app.ParticipationRewardsKeeper, genesisState)
require.Equal(t, app.ParticipationRewardsKeeper.GetParams(ctx).DistributionProportions.ValidatorSelectionAllocation, sdk.NewDecWithPrec(5, 1))
require.Equal(t, app.ParticipationRewardsKeeper.GetParams(ctx).DistributionProportions.HoldingsAllocation, sdk.NewDecWithPrec(5, 1))
require.Equal(t, app.ParticipationRewardsKeeper.GetParams(ctx).DistributionProportions.LockupAllocation, sdk.ZeroDec())
pd, found := app.ParticipationRewardsKeeper.GetProtocolData(ctx, types.ProtocolDataTypeOsmosisPool, "6")
require.True(t, found)
require.Equal(t, types.ProtocolDataType_name[int32(types.ProtocolDataTypeOsmosisPool)], pd.Type)
}