-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.go
52 lines (43 loc) · 1.82 KB
/
utils.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
package ibctesting
import (
"testing"
"github.com/stretchr/testify/require"
abci "github.com/tendermint/tendermint/abci/types"
tmtypes "github.com/tendermint/tendermint/types"
sdkstaking "github.com/cosmos/cosmos-sdk/x/staking/types"
stakingtypes "github.com/nephirim/fanfury-sdk/v2/x/lsnative/staking/types"
)
// ApplyValSetChanges takes in tmtypes.ValidatorSet and []abci.ValidatorUpdate and will return a new tmtypes.ValidatorSet which has the
// provided validator updates applied to the provided validator set.
func ApplyValSetChanges(t *testing.T, valSet *tmtypes.ValidatorSet, valUpdates []abci.ValidatorUpdate) *tmtypes.ValidatorSet {
updates, err := tmtypes.PB2TM.ValidatorUpdates(valUpdates)
require.NoError(t, err)
// must copy since validator set will mutate with UpdateWithChangeSet
newVals := valSet.Copy()
err = newVals.UpdateWithChangeSet(updates)
require.NoError(t, err)
return newVals
}
// SdkValidatorsToValidators converts sdk types into our custom staking types.
func SdkValidatorsToValidators(sdkVals sdkstaking.Validators) stakingtypes.Validators {
vals := make([]stakingtypes.Validator, 0, len(sdkVals))
for _, val := range sdkVals {
vals = append(vals, stakingtypes.Validator(stakingtypes.Validator{
OperatorAddress: val.OperatorAddress,
ConsensusPubkey: val.ConsensusPubkey,
Jailed: val.Jailed,
Status: val.Status,
Tokens: val.Tokens,
DelegatorShares: val.DelegatorShares,
Description: stakingtypes.Description(val.Description),
UnbondingHeight: val.UnbondingHeight,
UnbondingTime: val.UnbondingTime,
Commission: stakingtypes.Commission{
CommissionRates: stakingtypes.CommissionRates(val.Commission.CommissionRates),
UpdateTime: val.Commission.UpdateTime,
},
MinSelfDelegation: val.MinSelfDelegation,
}))
}
return vals
}