Skip to content

Commit

Permalink
small fixes (Stride-Labs#259)
Browse files Browse the repository at this point in the history
  • Loading branch information
asalzmann authored Sep 2, 2022
1 parent a5ba2a7 commit 48d9b6e
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 9 deletions.
2 changes: 1 addition & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ import (
const (
AccountAddressPrefix = "stride"
Name = "stride"
Version = "0.0.1"
Version = "1.0.0"
)

// this line is used by starport scaffolding # stargate/wasm/app/enabledProposals
Expand Down
2 changes: 1 addition & 1 deletion scripts-local/tests/osmo_tests.bats
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ setup() {
WAIT_FOR_BLOCK $STRIDE_LOGS 2
# wait four days (transfers, stake, move rewards, reinvest rewards)
epoch_duration=$($STRIDE_CMD q epochs epoch-infos | grep -Fiw -B 2 'stride_epoch' | head -n 1 | grep -o -E '[0-9]+')
sleep $(($epoch_duration * 4))
sleep $(($epoch_duration * 6))
# simple check that number of tokens staked increases
NEW_STAKED_BAL=$($OSMO_CMD q staking delegation $OSMO_DELEGATION_ICA_ADDR $OSMO_DELEGATE_VAL | GETSTAKE)
EXPECTED_STAKED_BAL=667
Expand Down
2 changes: 2 additions & 0 deletions x/stakeibc/keeper/msg_server_redeem_stake.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (

func (k msgServer) RedeemStake(goCtx context.Context, msg *types.MsgRedeemStake) (*types.MsgRedeemStakeResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)
k.Logger(ctx).Info(fmt.Sprintf("redeem stake: %s", msg.String()))

// get our addresses, make sure they're valid
sender, err := sdk.AccAddressFromBech32(msg.Creator)
Expand Down Expand Up @@ -149,5 +150,6 @@ func (k msgServer) RedeemStake(goCtx context.Context, msg *types.MsgRedeemStake)
}
k.RecordsKeeper.SetEpochUnbondingRecord(ctx, *updatedEpochUnbondingRecord)

k.Logger(ctx).Info(fmt.Sprintf("executed redeem stake: %s", msg.String()))
return &types.MsgRedeemStakeResponse{}, nil
}
6 changes: 5 additions & 1 deletion x/stakeibc/keeper/unbonding_records.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,11 @@ func (k Keeper) SweepAllUnbondedTokensForHostZone(ctx sdk.Context, hostZone type
k.Logger(ctx).Info(fmt.Sprintf("\tUnbonding time: %d blockTime %d, shouldProcess %v", hostZoneUnbonding.UnbondingTime, blockTime, shouldProcess))

// if the unbonding period has elapsed, then we can send the ICA call to sweep this hostZone's unbondings to the redemption account (in a batch)
if (hostZoneUnbonding.UnbondingTime < blockTime) && shouldProcess {
// verify
// 1. the unbonding time is set (g.t. 0)
// 2. the unbonding time is less than the current block time
// 3. the host zone is in the UNBONDED state, meaning it's ready to be transferred
if (hostZoneUnbonding.UnbondingTime > 0 && hostZoneUnbonding.UnbondingTime < blockTime) && shouldProcess {
// we have a match, so we can process this unbonding
logMsg := fmt.Sprintf("\t\tAdding %d to amt to batch transfer from delegation acct to rewards acct for host zone %s, epoch %v",
hostZoneUnbonding.NativeTokenAmount, hostZone.ChainId, epochUnbondingRecord.EpochNumber)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,13 @@ func (s *KeeperTestSuite) SetupSweepUnbondedTokens() SweepUnbondedTokensTestCase
HostZoneId: HostChainId,
NativeTokenAmount: 2_000_000,
Status: recordtypes.HostZoneUnbonding_UNBONDED,
UnbondingTime: unbondingTime,
},
{
HostZoneId: OsmoChainId,
NativeTokenAmount: 2_000_000,
Status: recordtypes.HostZoneUnbonding_UNBONDED,
UnbondingTime: unbondingTime,
},
},
},
Expand Down
8 changes: 4 additions & 4 deletions x/stakeibc/types/message_redeem_stake.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ func (msg *MsgRedeemStake) ValidateBasic() error {
if err != nil {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err)
}
// check valid receiver address
_, err = sdk.AccAddressFromBech32(msg.Receiver)
if err != nil {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid receiver address (%s)", err)
// validate host zone is not empty
// we check validity in the RedeemState function
if msg.Receiver == "" {
return sdkerrors.Wrapf(ErrRequiredFieldEmpty, "receiver cannot be empty")
}
// ensure amount is a nonzero positive integer
if msg.Amount <= 0 {
Expand Down
3 changes: 1 addition & 2 deletions x/stakeibc/types/message_redeem_stake_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,10 @@ func TestMsgRedeemStake_ValidateBasic(t *testing.T) {
name: "invalid receiver",
msg: MsgRedeemStake{
Creator: sample.AccAddress(),
Receiver: "invalid_address",
HostZone: "GAIA",
Amount: uint64(1),
},
err: sdkerrors.ErrInvalidAddress,
err: ErrRequiredFieldEmpty,
},
{
name: "amount max int",
Expand Down

0 comments on commit 48d9b6e

Please sign in to comment.