forked from strangelove-ventures/poa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
conversions_test.go
100 lines (87 loc) · 2.63 KB
/
conversions_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
96
97
98
99
100
package poa_test
import (
"testing"
time "time"
"github.com/stretchr/testify/suite"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
"cosmossdk.io/math"
"github.com/strangelove-ventures/poa"
)
type ConversionTestSuite struct {
suite.Suite
}
func TestConversionSuite(t *testing.T) {
suite.Run(t, new(ConversionTestSuite))
}
func (suite *ConversionTestSuite) TestPOAStakingConversions() {
// description
description := poa.NewDescription("moniker", "identity", "website", "securityContact", "details")
expectedDesc := poa.Description{
Moniker: "moniker",
Identity: "identity",
Website: "website",
SecurityContact: "securityContact",
Details: "details",
}
suite.Require().Equal(expectedDesc, description)
// commissions
commissions := poa.NewCommissionRates(
math.LegacyMustNewDecFromStr("0.1"),
math.LegacyMustNewDecFromStr("0.2"),
math.LegacyMustNewDecFromStr("0.3"),
)
expectedComm := poa.CommissionRates{
Rate: math.LegacyMustNewDecFromStr("0.1"),
MaxRate: math.LegacyMustNewDecFromStr("0.2"),
MaxChangeRate: math.LegacyMustNewDecFromStr("0.3"),
}
suite.Require().Equal(expectedComm, commissions)
// poa -> staking
poaVal := poa.Validator{
OperatorAddress: "operatorAddress",
ConsensusPubkey: nil,
Jailed: false,
Status: poa.Bonded,
Tokens: math.NewInt(1000000),
DelegatorShares: math.LegacyMustNewDecFromStr("1000000"),
Description: description,
UnbondingHeight: 1,
UnbondingTime: time.Time{},
Commission: poa.Commission{
CommissionRates: commissions,
},
MinSelfDelegation: math.OneInt(),
UnbondingOnHoldRefCount: 1,
UnbondingIds: []uint64{1},
}
stakingVal := poa.ConvertPOAToStaking(poaVal)
expectedStakingVal := stakingtypes.Validator{
OperatorAddress: "operatorAddress",
ConsensusPubkey: nil,
Jailed: false,
Status: stakingtypes.Bonded,
Tokens: math.NewInt(1000000),
DelegatorShares: math.LegacyMustNewDecFromStr("1000000"),
Description: stakingtypes.NewDescription(
"moniker",
"identity",
"website",
"securityContact",
"details",
),
UnbondingHeight: 1,
UnbondingTime: time.Time{},
Commission: stakingtypes.NewCommission(
math.LegacyMustNewDecFromStr("0.1"),
math.LegacyMustNewDecFromStr("0.2"),
math.LegacyMustNewDecFromStr("0.3"),
),
MinSelfDelegation: math.OneInt(),
UnbondingOnHoldRefCount: 1,
UnbondingIds: []uint64{1},
}
suite.Require().Equal(expectedStakingVal, stakingVal)
// staking -> poa
newPoaVal := poa.ConvertStakingToPOA(stakingVal)
suite.Require().Equal(poaVal, newPoaVal)
}