Skip to content

Commit

Permalink
fix: remaining APIs, tests and proto generation
Browse files Browse the repository at this point in the history
  • Loading branch information
emidev98 committed Mar 6, 2024
1 parent 3389e03 commit 1ec7992
Show file tree
Hide file tree
Showing 9 changed files with 1,438 additions and 515 deletions.
89 changes: 79 additions & 10 deletions docs/proto/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,14 @@
- [QueryAllianceDelegationResponse](#alliance.alliance.QueryAllianceDelegationResponse)
- [QueryAllianceDelegationRewardsRequest](#alliance.alliance.QueryAllianceDelegationRewardsRequest)
- [QueryAllianceDelegationRewardsResponse](#alliance.alliance.QueryAllianceDelegationRewardsResponse)
- [QueryAllianceRedelegationsByDelegatorRequest](#alliance.alliance.QueryAllianceRedelegationsByDelegatorRequest)
- [QueryAllianceRedelegationsByDelegatorResponse](#alliance.alliance.QueryAllianceRedelegationsByDelegatorResponse)
- [QueryAllianceRedelegationsRequest](#alliance.alliance.QueryAllianceRedelegationsRequest)
- [QueryAllianceRedelegationsResponse](#alliance.alliance.QueryAllianceRedelegationsResponse)
- [QueryAllianceRequest](#alliance.alliance.QueryAllianceRequest)
- [QueryAllianceResponse](#alliance.alliance.QueryAllianceResponse)
- [QueryAllianceUnbondingsByDelegatorRequest](#alliance.alliance.QueryAllianceUnbondingsByDelegatorRequest)
- [QueryAllianceUnbondingsByDelegatorResponse](#alliance.alliance.QueryAllianceUnbondingsByDelegatorResponse)
- [QueryAllianceUnbondingsByDenomAndDelegatorRequest](#alliance.alliance.QueryAllianceUnbondingsByDenomAndDelegatorRequest)
- [QueryAllianceUnbondingsByDenomAndDelegatorResponse](#alliance.alliance.QueryAllianceUnbondingsByDenomAndDelegatorResponse)
- [QueryAllianceUnbondingsRequest](#alliance.alliance.QueryAllianceUnbondingsRequest)
Expand Down Expand Up @@ -136,6 +140,7 @@
| ----- | ---- | ----- | ----------- |
| `denom` | [string](#string) | | |
| `index` | [string](#string) | | |
| `alliance` | [string](#string) | | |



Expand Down Expand Up @@ -678,6 +683,7 @@ UnbondingDelegation defines an unbonding object with relevant metadata.
| `completion_time` | [google.protobuf.Timestamp](#google.protobuf.Timestamp) | | completion_time is the unix time for unbonding completion. |
| `validator_address` | [string](#string) | | validator_address is the bech32-encoded address of the validator. |
| `amount` | [string](#string) | | amount defines the tokens to receive at completion. |
| `denom` | [string](#string) | | alliance denom of the unbonding delegation |



Expand Down Expand Up @@ -813,6 +819,38 @@ AllianceDelegation



<a name="alliance.alliance.QueryAllianceRedelegationsByDelegatorRequest"></a>

### QueryAllianceRedelegationsByDelegatorRequest



| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `delegator_addr` | [string](#string) | | |
| `pagination` | [cosmos.base.query.v1beta1.PageRequest](#cosmos.base.query.v1beta1.PageRequest) | | |






<a name="alliance.alliance.QueryAllianceRedelegationsByDelegatorResponse"></a>

### QueryAllianceRedelegationsByDelegatorResponse



| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `redelegations` | [RedelegationEntry](#alliance.alliance.RedelegationEntry) | repeated | |
| `pagination` | [cosmos.base.query.v1beta1.PageResponse](#cosmos.base.query.v1beta1.PageResponse) | | |






<a name="alliance.alliance.QueryAllianceRedelegationsRequest"></a>

### QueryAllianceRedelegationsRequest
Expand Down Expand Up @@ -876,6 +914,37 @@ Alliance



<a name="alliance.alliance.QueryAllianceUnbondingsByDelegatorRequest"></a>

### QueryAllianceUnbondingsByDelegatorRequest
AllianceDelegation


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `delegator_addr` | [string](#string) | | |
| `pagination` | [cosmos.base.query.v1beta1.PageRequest](#cosmos.base.query.v1beta1.PageRequest) | | |






<a name="alliance.alliance.QueryAllianceUnbondingsByDelegatorResponse"></a>

### QueryAllianceUnbondingsByDelegatorResponse



| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `unbondings` | [UnbondingDelegation](#alliance.alliance.UnbondingDelegation) | repeated | |






<a name="alliance.alliance.QueryAllianceUnbondingsByDenomAndDelegatorRequest"></a>

### QueryAllianceUnbondingsByDenomAndDelegatorRequest
Expand Down Expand Up @@ -1161,21 +1230,21 @@ Params

| Method Name | Request Type | Response Type | Description | HTTP Verb | Endpoint |
| ----------- | ------------ | ------------- | ------------| ------- | -------- |
| `Params` | [QueryParamsRequest](#alliance.alliance.QueryParamsRequest) | [QueryParamsResponse](#alliance.alliance.QueryParamsResponse) | | GET|/terra/alliances/params|
| `Alliances` | [QueryAlliancesRequest](#alliance.alliance.QueryAlliancesRequest) | [QueryAlliancesResponse](#alliance.alliance.QueryAlliancesResponse) | Query paginated alliances | GET|/terra/alliances|
| `IBCAlliance` | [QueryIBCAllianceRequest](#alliance.alliance.QueryIBCAllianceRequest) | [QueryAllianceResponse](#alliance.alliance.QueryAllianceResponse) | Query a specific alliance by ibc hash @deprecated: this endpoint will be replaced for by the encoded version of the denom e.g.: GET:/terra/alliances/ibc%2Falliance | GET|/terra/alliances/ibc/{hash}|
| `AllAlliancesDelegations` | [QueryAllAlliancesDelegationsRequest](#alliance.alliance.QueryAllAlliancesDelegationsRequest) | [QueryAlliancesDelegationsResponse](#alliance.alliance.QueryAlliancesDelegationsResponse) | Query all paginated alliance delegations | GET|/terra/alliances/delegations|
| `Params` | [QueryParamsRequest](#alliance.alliance.QueryParamsRequest) | [QueryParamsResponse](#alliance.alliance.QueryParamsResponse) | Query Alliance module parameters more info about the params https://docs.alliance.money/tech/parameters | GET|/terra/alliances/params|
| `Alliances` | [QueryAlliancesRequest](#alliance.alliance.QueryAlliancesRequest) | [QueryAlliancesResponse](#alliance.alliance.QueryAlliancesResponse) | Query all alliances with pagination | GET|/terra/alliances|
| `AllAlliancesDelegations` | [QueryAllAlliancesDelegationsRequest](#alliance.alliance.QueryAllAlliancesDelegationsRequest) | [QueryAlliancesDelegationsResponse](#alliance.alliance.QueryAlliancesDelegationsResponse) | Query all alliances delegations with pagination | GET|/terra/alliances/delegations|
| `AllianceValidator` | [QueryAllianceValidatorRequest](#alliance.alliance.QueryAllianceValidatorRequest) | [QueryAllianceValidatorResponse](#alliance.alliance.QueryAllianceValidatorResponse) | Query alliance validator | GET|/terra/alliances/validators/{validator_addr}|
| `AllAllianceValidators` | [QueryAllAllianceValidatorsRequest](#alliance.alliance.QueryAllAllianceValidatorsRequest) | [QueryAllianceValidatorsResponse](#alliance.alliance.QueryAllianceValidatorsResponse) | Query all paginated alliance validators | GET|/terra/alliances/validators|
| `AlliancesDelegation` | [QueryAlliancesDelegationsRequest](#alliance.alliance.QueryAlliancesDelegationsRequest) | [QueryAlliancesDelegationsResponse](#alliance.alliance.QueryAlliancesDelegationsResponse) | Query all paginated alliance delegations for a delegator addr | GET|/terra/alliances/delegations/{delegator_addr}|
| `AlliancesDelegationByValidator` | [QueryAlliancesDelegationByValidatorRequest](#alliance.alliance.QueryAlliancesDelegationByValidatorRequest) | [QueryAlliancesDelegationsResponse](#alliance.alliance.QueryAlliancesDelegationsResponse) | Query all paginated alliance delegations for a delegator addr and validator_addr | GET|/terra/alliances/delegations/{delegator_addr}/{validator_addr}|
| `AllianceDelegation` | [QueryAllianceDelegationRequest](#alliance.alliance.QueryAllianceDelegationRequest) | [QueryAllianceDelegationResponse](#alliance.alliance.QueryAllianceDelegationResponse) | Query a delegation to an alliance by delegator addr, validator_addr and denom | GET|/terra/alliances/delegations/{delegator_addr}/{validator_addr}/{denom}|
| `IBCAllianceDelegation` | [QueryIBCAllianceDelegationRequest](#alliance.alliance.QueryIBCAllianceDelegationRequest) | [QueryAllianceDelegationResponse](#alliance.alliance.QueryAllianceDelegationResponse) | Query a delegation to an alliance by delegator addr, validator_addr and denom @deprecated: this endpoint will be replaced for by the encoded version of the denom e.g.: GET:/terra/alliances/terradr1231/terravaloper41234/ibc%2Falliance | GET|/terra/alliances/delegations/{delegator_addr}/{validator_addr}/ibc/{hash}|
| `AllianceDelegationRewards` | [QueryAllianceDelegationRewardsRequest](#alliance.alliance.QueryAllianceDelegationRewardsRequest) | [QueryAllianceDelegationRewardsResponse](#alliance.alliance.QueryAllianceDelegationRewardsResponse) | Query for rewards by delegator addr, validator_addr and denom | GET|/terra/alliances/rewards/{delegator_addr}/{validator_addr}/{denom}|
| `AllianceDelegation` | [QueryAllianceDelegationRequest](#alliance.alliance.QueryAllianceDelegationRequest) | [QueryAllianceDelegationResponse](#alliance.alliance.QueryAllianceDelegationResponse) | Query a specific delegation by delegator addr, validator addr and denom | GET|/terra/alliances/delegations/{delegator_addr}/{validator_addr}/{denom}|
| `AllianceDelegationRewards` | [QueryAllianceDelegationRewardsRequest](#alliance.alliance.QueryAllianceDelegationRewardsRequest) | [QueryAllianceDelegationRewardsResponse](#alliance.alliance.QueryAllianceDelegationRewardsResponse) | Query a specific delegation rewards by delegator addr, validator addr and denom | GET|/terra/alliances/rewards/{delegator_addr}/{validator_addr}/{denom}|
| `IBCAllianceDelegationRewards` | [QueryIBCAllianceDelegationRewardsRequest](#alliance.alliance.QueryIBCAllianceDelegationRewardsRequest) | [QueryAllianceDelegationRewardsResponse](#alliance.alliance.QueryAllianceDelegationRewardsResponse) | Query for rewards by delegator addr, validator_addr and denom @deprecated: this endpoint will be replaced for by the encoded version of the denom e.g.: GET:/terra/alliances/terradr1231/terravaloper41234/ibc%2Falliance | GET|/terra/alliances/rewards/{delegator_addr}/{validator_addr}/ibc/{hash}|
| `AllianceUnbondingsByDenomAndDelegator` | [QueryAllianceUnbondingsByDenomAndDelegatorRequest](#alliance.alliance.QueryAllianceUnbondingsByDenomAndDelegatorRequest) | [QueryAllianceUnbondingsByDenomAndDelegatorResponse](#alliance.alliance.QueryAllianceUnbondingsByDenomAndDelegatorResponse) | Query for rewards by delegator addr, validator_addr and denom | GET|/terra/alliances/unbondings/{denom}/{delegator_addr}|
| `AllianceUnbondings` | [QueryAllianceUnbondingsRequest](#alliance.alliance.QueryAllianceUnbondingsRequest) | [QueryAllianceUnbondingsResponse](#alliance.alliance.QueryAllianceUnbondingsResponse) | Query for rewards by delegator addr, validator_addr and denom | GET|/terra/alliances/unbondings/{denom}/{delegator_addr}/{validator_addr}|
| `AllianceRedelegations` | [QueryAllianceRedelegationsRequest](#alliance.alliance.QueryAllianceRedelegationsRequest) | [QueryAllianceRedelegationsResponse](#alliance.alliance.QueryAllianceRedelegationsResponse) | Query redelegations by denom and delegator address | GET|/terra/alliances/redelegations/{denom}/{delegator_addr}|
| `AllianceUnbondingsByDelegator` | [QueryAllianceUnbondingsByDelegatorRequest](#alliance.alliance.QueryAllianceUnbondingsByDelegatorRequest) | [QueryAllianceUnbondingsByDelegatorResponse](#alliance.alliance.QueryAllianceUnbondingsByDelegatorResponse) | Query unbondings by delegator address | GET|/terra/alliances/unbondings/{delegator_addr}|
| `AllianceUnbondingsByDenomAndDelegator` | [QueryAllianceUnbondingsByDenomAndDelegatorRequest](#alliance.alliance.QueryAllianceUnbondingsByDenomAndDelegatorRequest) | [QueryAllianceUnbondingsByDenomAndDelegatorResponse](#alliance.alliance.QueryAllianceUnbondingsByDenomAndDelegatorResponse) | Query unbondings by denom, delegator addr | GET|/terra/alliances/unbondings/{denom}/{delegator_addr}|
| `AllianceUnbondings` | [QueryAllianceUnbondingsRequest](#alliance.alliance.QueryAllianceUnbondingsRequest) | [QueryAllianceUnbondingsResponse](#alliance.alliance.QueryAllianceUnbondingsResponse) | Query unbondings by denom, delegator addr, validator addr | GET|/terra/alliances/unbondings/{denom}/{delegator_addr}/{validator_addr}|
| `AllianceRedelegationsByDelegator` | [QueryAllianceRedelegationsByDelegatorRequest](#alliance.alliance.QueryAllianceRedelegationsByDelegatorRequest) | [QueryAllianceRedelegationsByDelegatorResponse](#alliance.alliance.QueryAllianceRedelegationsByDelegatorResponse) | Query paginated redelegations delegator addr | GET|/terra/alliances/redelegations/{delegator_addr}|
| `AllianceRedelegations` | [QueryAllianceRedelegationsRequest](#alliance.alliance.QueryAllianceRedelegationsRequest) | [QueryAllianceRedelegationsResponse](#alliance.alliance.QueryAllianceRedelegationsResponse) | Query paginated redelegations by denom and delegator addr | GET|/terra/alliances/redelegations/{denom}/{delegator_addr}|
| `Alliance` | [QueryAllianceRequest](#alliance.alliance.QueryAllianceRequest) | [QueryAllianceResponse](#alliance.alliance.QueryAllianceResponse) | Query a specific alliance by denom | GET|/terra/alliances/{denom}|

<!-- end services -->
Expand Down
2 changes: 0 additions & 2 deletions x/alliance/keeper/tests/delegation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,8 +412,6 @@ func TestSuccessfulRedelegation(t *testing.T) {
},
}, redelegationsRes)

unbondingPeriod, err := app.StakingKeeper.UnbondingTime(ctx)
require.NoError(t, err)
require.Equal(t, types.RedelegationEntry{
DelegatorAddress: delAddr1.String(),
SrcValidatorAddress: valAddr1.String(),
Expand Down
17 changes: 0 additions & 17 deletions x/alliance/keeper/tests/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,6 @@ func TestQueryAnUniqueIBCAlliance(t *testing.T) {
alliances, err := queryServer.Alliance(ctx, &types.QueryAllianceRequest{
Denom: "ibc%2Falliance2",
})
alliancesIbcEndpoint, err2 := queryServer.IBCAlliance(ctx, &types.QueryIBCAllianceRequest{ //nolint:staticcheck // SA1019: types.types.QueryIBCAllianceRequest is deprecated
Hash: "alliance2",
})

// THEN: VALIDATE THAT BOTH ALLIANCES HAVE THE CORRECT MODEL WHEN QUERYING
require.Nil(t, err)
Expand All @@ -178,20 +175,6 @@ func TestQueryAnUniqueIBCAlliance(t *testing.T) {
RewardChangeInterval: 0,
},
}, alliances)

require.Nil(t, err2)
require.Equal(t, &types.QueryAllianceResponse{
Alliance: &types.AllianceAsset{
Denom: "ibc/alliance2",
RewardWeight: sdk.NewDec(10),
RewardWeightRange: types.RewardWeightRange{Min: sdk.NewDec(2), Max: sdk.NewDec(12)},
TakeRate: sdk.MustNewDecFromStr("0.14159265359"),
TotalTokens: sdk.ZeroInt(),
TotalValidatorShares: sdk.NewDec(0),
RewardChangeRate: sdk.NewDec(0),
RewardChangeInterval: 0,
},
}, alliancesIbcEndpoint)
}

func TestQueryAllianceNotFound(t *testing.T) {
Expand Down
9 changes: 3 additions & 6 deletions x/alliance/keeper/tests/unbonding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,13 @@ func TestUnbondingMethods(t *testing.T) {
RewardWeightRange: types.RewardWeightRange{Min: math.LegacyNewDec(0), Max: math.LegacyNewDec(1)},
IsInitialized: true,
}
err := app.AllianceKeeper.SetAsset(ctx, allianceAsset)
require.NoError(t, err)
app.AllianceKeeper.SetAsset(ctx, allianceAsset)

// Query staking module unbonding time to assert later on
unbondingTime, err := app.StakingKeeper.UnbondingTime(ctx)
require.NoError(t, err)
unbondingTime := app.StakingKeeper.UnbondingTime(ctx)

// Get the native delegations to have a validator address where to delegate
delegations, err := app.StakingKeeper.GetAllDelegations(ctx)
require.NoError(t, err)
delegations := app.StakingKeeper.GetAllDelegations(ctx)
valAddr, err := sdk.ValAddressFromBech32(delegations[0].ValidatorAddress)
require.NoError(t, err)

Expand Down
7 changes: 3 additions & 4 deletions x/alliance/keeper/unbonding.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package keeper

import (
"bytes"
"context"

sdk "github.com/cosmos/cosmos-sdk/types"

Expand All @@ -19,11 +18,11 @@ func (k Keeper) GetUnbondings(
valAddr sdk.ValAddress,
) (unbondingDelegations []types.UnbondingDelegation, err error) {
// Get the store
store := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx))
store := ctx.KVStore(k.storeKey)
// create the iterator with the correct prefix
prefix := types.GetUndelegationsIndexOrderedByValidatorKey(valAddr)
// Get the iterator
iter := storetypes.KVStorePrefixIterator(store, prefix)
iter := sdk.KVStorePrefixIterator(store, prefix)
defer iter.Close()
suffix := types.GetPartialUnbondingKeySuffix(denom, delAddr)

Expand Down Expand Up @@ -114,7 +113,7 @@ func (k Keeper) CompleteUnbondings(ctx sdk.Context) error {

// This method retun all in-progress unbondings for a given delegator address
func (k Keeper) GetUnbondingsByDelegator(
ctx context.Context,
ctx sdk.Context,
delAddr sdk.AccAddress,
) (unbondingDelegations []types.UnbondingDelegation, err error) {
// Get and iterate over all alliances
Expand Down
4 changes: 2 additions & 2 deletions x/alliance/tests/e2e/delegate_undelegate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,14 +247,14 @@ func TestDelegatingASmallAmount(t *testing.T) {
unbondings, err := app.AllianceKeeper.GetUnbondingsByDenomAndDelegator(ctx, allianceAsset2, user1)
require.NoError(t, err)
require.Len(t, unbondings, 2)
require.Equal(t, val1.GetOperator(), unbondings[0].ValidatorAddress)
require.Equal(t, val1.GetOperator().String(), unbondings[0].ValidatorAddress)
require.Equal(t, math.NewInt(100), unbondings[0].Amount)

// Query the unbondings in progress
unbondings2, err := app.AllianceKeeper.GetUnbondings(ctx, allianceAsset2, user1, vals[0])
require.NoError(t, err)
require.Len(t, unbondings2, 2)
require.Equal(t, val1.GetOperator(), unbondings2[0].ValidatorAddress)
require.Equal(t, val1.GetOperator().String(), unbondings2[0].ValidatorAddress)
require.Equal(t, math.NewInt(100), unbondings2[0].Amount)
}

Expand Down
Loading

0 comments on commit 1ec7992

Please sign in to comment.