@@ -99,7 +99,7 @@ func TestQueryConsumerChainOptedInValidators(t *testing.T) {
99
99
func TestQueryConsumerValidators (t * testing.T ) {
100
100
chainID := "chainID"
101
101
102
- pk , ctx , ctrl , _ := testkeeper .GetProviderKeeperAndCtx (t , testkeeper .NewInMemKeeperParams (t ))
102
+ pk , ctx , ctrl , mocks := testkeeper .GetProviderKeeperAndCtx (t , testkeeper .NewInMemKeeperParams (t ))
103
103
defer ctrl .Finish ()
104
104
105
105
req := types.QueryConsumerValidatorsRequest {
@@ -113,15 +113,19 @@ func TestQueryConsumerValidators(t *testing.T) {
113
113
providerAddr1 := types .NewProviderConsAddress ([]byte ("providerAddr1" ))
114
114
consumerKey1 := cryptotestutil .NewCryptoIdentityFromIntSeed (1 ).TMProtoCryptoPublicKey ()
115
115
consumerValidator1 := types.ConsensusValidator {ProviderConsAddr : providerAddr1 .ToSdkConsAddr (), Power : 1 , PublicKey : & consumerKey1 }
116
+ expectedCommissionRate1 := math .LegacyMustNewDecFromStr ("0.123" )
117
+ pk .SetConsumerCommissionRate (ctx , chainID , providerAddr1 , expectedCommissionRate1 )
116
118
117
119
providerAddr2 := types .NewProviderConsAddress ([]byte ("providerAddr2" ))
118
120
consumerKey2 := cryptotestutil .NewCryptoIdentityFromIntSeed (2 ).TMProtoCryptoPublicKey ()
119
121
consumerValidator2 := types.ConsensusValidator {ProviderConsAddr : providerAddr2 .ToSdkConsAddr (), Power : 2 , PublicKey : & consumerKey2 }
122
+ expectedCommissionRate2 := math .LegacyMustNewDecFromStr ("0.123" )
123
+ pk .SetConsumerCommissionRate (ctx , chainID , providerAddr2 , expectedCommissionRate2 )
120
124
121
125
expectedResponse := types.QueryConsumerValidatorsResponse {
122
126
Validators : []* types.QueryConsumerValidatorsValidator {
123
- {providerAddr1 .String (), & consumerKey1 , 1 },
124
- {providerAddr2 .String (), & consumerKey2 , 2 },
127
+ {ProviderAddress : providerAddr1 .String (), ConsumerKey : & consumerKey1 , Power : 1 , Rate : expectedCommissionRate1 },
128
+ {ProviderAddress : providerAddr2 .String (), ConsumerKey : & consumerKey2 , Power : 2 , Rate : expectedCommissionRate2 },
125
129
},
126
130
}
127
131
@@ -132,6 +136,17 @@ func TestQueryConsumerValidators(t *testing.T) {
132
136
res , err := pk .QueryConsumerValidators (ctx , & req )
133
137
require .NoError (t , err )
134
138
require .Equal (t , & expectedResponse , res )
139
+
140
+ // validator with no set consumer commission rate
141
+ pk .DeleteConsumerCommissionRate (ctx , chainID , providerAddr1 )
142
+ expectedCommissionRate := math .LegacyMustNewDecFromStr ("0.456" )
143
+ // because no consumer commission rate is set, the validator's set commission rate on the provider is used
144
+ val := stakingtypes.Validator {Commission : stakingtypes.Commission {CommissionRates : stakingtypes.CommissionRates {Rate : expectedCommissionRate }}}
145
+ mocks .MockStakingKeeper .EXPECT ().GetValidatorByConsAddr (
146
+ ctx , providerAddr1 .ToSdkConsAddr ()).Return (val , nil ).Times (1 )
147
+ res , _ = pk .QueryConsumerValidators (ctx , & req )
148
+ require .Equal (t , expectedCommissionRate , res .Validators [0 ].Rate )
149
+
135
150
}
136
151
137
152
func TestQueryConsumerChainsValidatorHasToValidate (t * testing.T ) {
0 commit comments