Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(x/accounts/default/lockup): Lockup account track undelegation when unbonding entry is mature #22254

Merged
merged 42 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
4fd342f
add und entry proto
sontrinh16 Oct 14, 2024
83d300d
add track ubd entries
sontrinh16 Oct 14, 2024
41a1808
Merge branch 'main' into son/lockup_unbond_sync
sontrinh16 Oct 14, 2024
a63f909
add track undelegations before check tokens sendable
sontrinh16 Oct 15, 2024
0544b0d
Merge branch 'son/lockup_unbond_sync' of https://github.com/cosmos/co…
sontrinh16 Oct 15, 2024
a37205e
minor
sontrinh16 Oct 15, 2024
e1e0ce2
fix tests
sontrinh16 Oct 15, 2024
b1135b6
fix tests
sontrinh16 Oct 15, 2024
716621a
Merge branch 'main' into son/lockup_unbond_sync
sontrinh16 Oct 16, 2024
7641b26
Merge branch 'main' into son/lockup_unbond_sync
sontrinh16 Oct 16, 2024
700ea01
manually track undelegation
sontrinh16 Oct 16, 2024
0c26ac3
Merge branch 'son/lockup_unbond_sync' of https://github.com/cosmos/co…
sontrinh16 Oct 16, 2024
2eaff98
Merge branch 'main' into son/lockup_unbond_sync
sontrinh16 Oct 16, 2024
8ff7f82
Merge branch 'main' into son/lockup_unbond_sync
sontrinh16 Oct 21, 2024
f157e17
Update x/accounts/proto/cosmos/accounts/defaults/lockup/lockup.proto
sontrinh16 Oct 23, 2024
de6f925
fix conflict
sontrinh16 Oct 28, 2024
075d9ee
Merge branch 'son/lockup_unbond_sync' of https://github.com/cosmos/co…
sontrinh16 Oct 28, 2024
9f25810
minor
sontrinh16 Oct 28, 2024
22d24c1
fix tests
sontrinh16 Oct 28, 2024
c990e46
minor
sontrinh16 Oct 28, 2024
8e9bde2
fix tests
sontrinh16 Oct 28, 2024
70e61c5
minor
sontrinh16 Oct 28, 2024
4158151
Merge branch 'main' into son/lockup_unbond_sync
sontrinh16 Oct 29, 2024
e0b096e
Merge branch 'main' into son/lockup_unbond_sync
sontrinh16 Oct 30, 2024
7e5d20e
Merge branch 'main' into son/lockup_unbond_sync
sontrinh16 Oct 31, 2024
2a8d551
Merge branch 'main' into son/lockup_unbond_sync
sontrinh16 Nov 5, 2024
4e83bc7
Merge branch 'main' into son/lockup_unbond_sync
sontrinh16 Nov 20, 2024
646c178
Merge branch 'son/lockup_unbond_sync' of https://github.com/cosmos/co…
sontrinh16 Nov 26, 2024
f9dcc39
remove ubd id
sontrinh16 Nov 28, 2024
f9d1bfb
fixing
sontrinh16 Dec 2, 2024
8e3be3d
fix tests
sontrinh16 Dec 2, 2024
7fb8c29
add remove matured entry
sontrinh16 Dec 2, 2024
ed0cbdb
Merge branch 'main' into son/lockup_unbond_sync
sontrinh16 Dec 2, 2024
1ed4b64
revert
sontrinh16 Dec 2, 2024
a7ee203
fix tests
sontrinh16 Dec 2, 2024
af32a94
more fixing
sontrinh16 Dec 2, 2024
54c8f5c
remove withdraw unlocked coins
sontrinh16 Dec 4, 2024
a4c8c3e
clean up
sontrinh16 Dec 4, 2024
292cf01
address comments
sontrinh16 Dec 9, 2024
ce829cf
minor
sontrinh16 Dec 9, 2024
be528f7
Merge branch 'main' into son/lockup_unbond_sync
sontrinh16 Dec 9, 2024
5f59218
resolve conflict
sontrinh16 Dec 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,370 changes: 1,323 additions & 47 deletions api/cosmos/accounts/defaults/lockup/v1/lockup.pulsar.go

Large diffs are not rendered by default.

1,233 changes: 1,133 additions & 100 deletions api/cosmos/accounts/defaults/lockup/v1/query.pulsar.go

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func (s *IntegrationTestSuite) TestContinuousLockingAccount() {
ctx := sdk.NewContext(app.CommitMultiStore(), false, app.Logger()).WithHeaderInfo(header.Info{
Time: currentTime,
})
s.setupStakingParams(ctx, app)
ownerAddrStr, err := app.AuthKeeper.AddressCodec().BytesToString(accOwner)
require.NoError(t, err)
s.fundAccount(app, ctx, accOwner, sdk.Coins{sdk.NewCoin("stake", math.NewInt(1000000))})
Expand Down Expand Up @@ -163,17 +164,22 @@ func (s *IntegrationTestSuite) TestContinuousLockingAccount() {
require.NoError(t, err)
require.Equal(t, len(ubd.Entries), 1)

// check if tracking is updated accordingly
lockupAccountInfoResponse := s.queryLockupAccInfo(ctx, app, accountAddr)
delLocking := lockupAccountInfoResponse.DelegatedLocking
require.True(t, delLocking.AmountOf("stake").Equal(math.ZeroInt()))
// check if an entry is added
unbondingEntriesResponse := s.queryUnbondingEntries(ctx, app, accountAddr, val.OperatorAddress)
entries := unbondingEntriesResponse.UnbondingEntries
require.True(t, entries[0].Amount.Amount.Equal(math.NewInt(100)))
require.True(t, entries[0].ValidatorAddress == val.OperatorAddress)
})

// Update context time to end time
ctx = ctx.WithHeaderInfo(header.Info{
Time: currentTime.Add(time.Minute),
})

// trigger endblock for staking to handle matured unbonding delegation
_, err = app.StakingKeeper.EndBlocker(ctx)
require.NoError(t, err)

// test if tracking delegate work perfectly
t.Run("ok - execute delegate message", func(t *testing.T) {
msg := &types.MsgDelegate{
Expand All @@ -196,8 +202,14 @@ func (s *IntegrationTestSuite) TestContinuousLockingAccount() {
// check if tracking is updated accordingly
lockupAccountInfoResponse := s.queryLockupAccInfo(ctx, app, accountAddr)
delLocking := lockupAccountInfoResponse.DelegatedLocking
// should be update as ubd entry is matured
require.True(t, delLocking.AmountOf("stake").Equal(math.ZeroInt()))
delFree := lockupAccountInfoResponse.DelegatedFree
require.True(t, delFree.AmountOf("stake").Equal(math.NewInt(100)))

// check if the entry is removed
unbondingEntriesResponse := s.queryUnbondingEntries(ctx, app, accountAddr, val.OperatorAddress)
entries := unbondingEntriesResponse.UnbondingEntries
require.Len(t, entries, 0)
})
}
29 changes: 23 additions & 6 deletions tests/integration/accounts/lockup/delayed_lockup_test_suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func (s *IntegrationTestSuite) TestDelayedLockingAccount() {
ctx := sdk.NewContext(app.CommitMultiStore(), false, app.Logger()).WithHeaderInfo(header.Info{
Time: currentTime,
})
s.setupStakingParams(ctx, app)
ownerAddrStr, err := app.AuthKeeper.AddressCodec().BytesToString(accOwner)
require.NoError(t, err)
s.fundAccount(app, ctx, accOwner, sdk.Coins{sdk.NewCoin("stake", math.NewInt(1000000))})
Expand Down Expand Up @@ -125,18 +126,24 @@ func (s *IntegrationTestSuite) TestDelayedLockingAccount() {
require.NoError(t, err)
require.Equal(t, len(ubd.Entries), 1)

// check if tracking is updated accordingly
lockupAccountInfoResponse := s.queryLockupAccInfo(ctx, app, accountAddr)
delLocking := lockupAccountInfoResponse.DelegatedLocking
require.True(t, delLocking.AmountOf("stake").Equal(math.ZeroInt()))
// check if an entry is added
unbondingEntriesResponse := s.queryUnbondingEntries(ctx, app, accountAddr, val.OperatorAddress)
entries := unbondingEntriesResponse.UnbondingEntries
require.True(t, entries[0].Amount.Amount.Equal(math.NewInt(100)))
require.True(t, entries[0].ValidatorAddress == val.OperatorAddress)
})

// Update context time
// After endtime fund should be unlock
// And unbond time elapsed
ctx = ctx.WithHeaderInfo(header.Info{
Time: currentTime.Add(time.Second * 61),
})

// trigger endblock for staking to handle matured unbonding delegation
_, err = app.StakingKeeper.EndBlocker(ctx)
require.NoError(t, err)

// Check if token is sendable after unlock
t.Run("ok - execute send message", func(t *testing.T) {
msg := &types.MsgSend{
Expand All @@ -149,6 +156,16 @@ func (s *IntegrationTestSuite) TestDelayedLockingAccount() {

balance := app.BankKeeper.GetBalance(ctx, randAcc, "stake")
require.True(t, balance.Amount.Equal(math.NewInt(100)))

// check if tracking ubd entry is updated accordingly
lockupAccountInfoResponse := s.queryLockupAccInfo(ctx, app, accountAddr)
delLocking := lockupAccountInfoResponse.DelegatedLocking
require.True(t, delLocking.AmountOf("stake").Equal(math.ZeroInt()))

// check if the entry is removed
unbondingEntriesResponse := s.queryUnbondingEntries(ctx, app, accountAddr, val.OperatorAddress)
entries := unbondingEntriesResponse.UnbondingEntries
require.Len(t, entries, 0)
})
// Test to withdraw all the remain funds to an account of choice
t.Run("ok - execute withdraw message", func(t *testing.T) {
Expand All @@ -165,8 +182,8 @@ func (s *IntegrationTestSuite) TestDelayedLockingAccount() {
require.NoError(t, err)

// withdrawable amount should be
// 1000stake - 100stake( above sent amt ) - 100stake(above delegate amt) = 800stake
// 1000stake - 100stake( above sent amt ) = 800stake
balance := app.BankKeeper.GetBalance(ctx, withdrawAcc, "stake")
require.True(t, balance.Amount.Equal(math.NewInt(800)))
require.True(t, balance.Amount.Equal(math.NewInt(900)))
})
}
22 changes: 18 additions & 4 deletions tests/integration/accounts/lockup/periodic_lockup_test_suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func (s *IntegrationTestSuite) TestPeriodicLockingAccount() {
ctx := sdk.NewContext(app.CommitMultiStore(), false, app.Logger()).WithHeaderInfo(header.Info{
Time: currentTime,
})
s.setupStakingParams(ctx, app)
ownerAddrStr, err := app.AuthKeeper.AddressCodec().BytesToString(accOwner)
require.NoError(t, err)
s.fundAccount(app, ctx, accOwner, sdk.Coins{sdk.NewCoin("stake", math.NewInt(1000000))})
Expand Down Expand Up @@ -185,10 +186,11 @@ func (s *IntegrationTestSuite) TestPeriodicLockingAccount() {
require.NoError(t, err)
require.Equal(t, len(ubd.Entries), 1)

// check if tracking is updated accordingly
lockupAccountInfoResponse := s.queryLockupAccInfo(ctx, app, accountAddr)
delLocking := lockupAccountInfoResponse.DelegatedLocking
require.True(t, delLocking.AmountOf("stake").Equal(math.ZeroInt()))
// check if an entry is added
unbondingEntriesResponse := s.queryUnbondingEntries(ctx, app, accountAddr, val.OperatorAddress)
entries := unbondingEntriesResponse.UnbondingEntries
require.True(t, entries[0].Amount.Amount.Equal(math.NewInt(100)))
require.True(t, entries[0].ValidatorAddress == val.OperatorAddress)
})

// Update context time
Expand All @@ -197,6 +199,10 @@ func (s *IntegrationTestSuite) TestPeriodicLockingAccount() {
Time: currentTime.Add(time.Minute * 3),
})

// trigger endblock for staking to handle matured unbonding delegation
_, err = app.StakingKeeper.EndBlocker(ctx)
require.NoError(t, err)

t.Run("ok - execute delegate message", func(t *testing.T) {
msg := &types.MsgDelegate{
Sender: ownerAddrStr,
Expand All @@ -217,7 +223,15 @@ func (s *IntegrationTestSuite) TestPeriodicLockingAccount() {

// check if tracking is updated accordingly
lockupAccountInfoResponse := s.queryLockupAccInfo(ctx, app, accountAddr)
// check if matured ubd entry cleared
delLocking := lockupAccountInfoResponse.DelegatedLocking
require.True(t, delLocking.AmountOf("stake").Equal(math.ZeroInt()))
delFree := lockupAccountInfoResponse.DelegatedFree
require.True(t, delFree.AmountOf("stake").Equal(math.NewInt(100)))

// check if the entry is removed
unbondingEntriesResponse := s.queryUnbondingEntries(ctx, app, accountAddr, val.OperatorAddress)
entries := unbondingEntriesResponse.UnbondingEntries
require.Len(t, entries, 0)
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func (s *IntegrationTestSuite) TestPermanentLockingAccount() {
ctx := sdk.NewContext(app.CommitMultiStore(), false, app.Logger()).WithHeaderInfo(header.Info{
Time: currentTime,
})
s.setupStakingParams(ctx, app)
ownerAddrStr, err := app.AuthKeeper.AddressCodec().BytesToString(accOwner)
require.NoError(t, err)
s.fundAccount(app, ctx, accOwner, sdk.Coins{sdk.NewCoin("stake", math.NewInt(1000000))})
Expand Down Expand Up @@ -109,10 +110,11 @@ func (s *IntegrationTestSuite) TestPermanentLockingAccount() {
require.NoError(t, err)
require.Equal(t, len(ubd.Entries), 1)

// check if tracking is updated accordingly
lockupAccountInfoResponse := s.queryLockupAccInfo(ctx, app, accountAddr)
delLocking := lockupAccountInfoResponse.DelegatedLocking
require.True(t, delLocking.AmountOf("stake").Equal(math.ZeroInt()))
// check if an entry is added
unbondingEntriesResponse := s.queryUnbondingEntries(ctx, app, accountAddr, val.OperatorAddress)
entries := unbondingEntriesResponse.UnbondingEntries
require.True(t, entries[0].Amount.Amount.Equal(math.NewInt(100)))
require.True(t, entries[0].ValidatorAddress == val.OperatorAddress)
})

s.fundAccount(app, ctx, accountAddr, sdk.Coins{sdk.NewCoin("stake", math.NewInt(1000))})
Expand All @@ -129,4 +131,43 @@ func (s *IntegrationTestSuite) TestPermanentLockingAccount() {
balance := app.BankKeeper.GetBalance(ctx, randAcc, "stake")
require.True(t, balance.Amount.Equal(math.NewInt(100)))
})

// Update context time
ctx = ctx.WithHeaderInfo(header.Info{
Time: currentTime.Add(time.Second * 11),
})

// trigger endblock for staking to handle matured unbonding delegation
_, err = app.StakingKeeper.EndBlocker(ctx)
require.NoError(t, err)

t.Run("ok - execute delegate message", func(t *testing.T) {
msg := &types.MsgDelegate{
Sender: ownerAddrStr,
ValidatorAddress: val.OperatorAddress,
Amount: sdk.NewCoin("stake", math.NewInt(10)),
}
err = s.executeTx(ctx, msg, app, accountAddr, accOwner)
require.NoError(t, err)

valbz, err := app.StakingKeeper.ValidatorAddressCodec().StringToBytes(val.OperatorAddress)
require.NoError(t, err)

del, err := app.StakingKeeper.Delegations.Get(
ctx, collections.Join(sdk.AccAddress(accountAddr), sdk.ValAddress(valbz)),
)
require.NoError(t, err)
require.NotNil(t, del)

// check if tracking is updated accordingly
lockupAccountInfoResponse := s.queryLockupAccInfo(ctx, app, accountAddr)
delLocking := lockupAccountInfoResponse.DelegatedLocking
// matured ubd entry should be cleared so del locking should only be 10
require.True(t, delLocking.AmountOf("stake").Equal(math.NewInt(10)))

// check if the entry is removed
unbondingEntriesResponse := s.queryUnbondingEntries(ctx, app, accountAddr, val.OperatorAddress)
entries := unbondingEntriesResponse.UnbondingEntries
require.Len(t, entries, 0)
})
}
25 changes: 25 additions & 0 deletions tests/integration/accounts/lockup/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package lockup

import (
"testing"
"time"

"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
Expand Down Expand Up @@ -70,3 +71,27 @@ func (s *IntegrationTestSuite) queryLockupAccInfo(ctx sdk.Context, app *simapp.S

return lockupAccountInfoResponse
}

func (s *IntegrationTestSuite) queryUnbondingEntries(ctx sdk.Context, app *simapp.SimApp, accAddr []byte, valAddr string) *types.QueryUnbondingEntriesResponse {
req := &types.QueryUnbondingEntriesRequest{
ValidatorAddress: valAddr,
}
resp, err := s.queryAcc(ctx, req, app, accAddr)
require.NoError(s.T(), err)
require.NotNil(s.T(), resp)

unbondingEntriesResponse, ok := resp.(*types.QueryUnbondingEntriesResponse)
require.True(s.T(), ok)

return unbondingEntriesResponse
}

func (s *IntegrationTestSuite) setupStakingParams(ctx sdk.Context, app *simapp.SimApp) {
params, err := app.StakingKeeper.Params.Get(ctx)
require.NoError(s.T(), err)

// update unbonding time
params.UnbondingTime = time.Duration(time.Second * 10)
err = app.StakingKeeper.Params.Set(ctx, params)
require.NoError(s.T(), err)
}
1 change: 1 addition & 0 deletions x/accounts/defaults/lockup/continuous_locking_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,4 +200,5 @@ func (cva ContinuousLockingAccount) RegisterExecuteHandlers(builder *accountstd.

func (cva ContinuousLockingAccount) RegisterQueryHandlers(builder *accountstd.QueryBuilder) {
accountstd.RegisterQueryHandler(builder, cva.QueryLockupAccountInfo)
cva.BaseLockup.RegisterQueryHandlers(builder)
}
43 changes: 8 additions & 35 deletions x/accounts/defaults/lockup/continuous_locking_account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,48 +102,21 @@ func TestContinousAccountUndelegate(t *testing.T) {
})
require.NoError(t, err)

delLocking, err = acc.DelegatedLocking.Get(ctx, "test")
require.NoError(t, err)
require.True(t, delLocking.Equal(math.ZeroInt()))

startTime, err := acc.StartTime.Get(sdkCtx)
require.NoError(t, err)

// Update context time to unlocked half of the original locking amount
sdkCtx = sdkCtx.WithHeaderInfo(header.Info{
Time: startTime.Add(time.Minute * 1),
})

_, err = acc.Delegate(sdkCtx, &lockuptypes.MsgDelegate{
Sender: "owner",
ValidatorAddress: "val_address",
Amount: sdk.NewCoin("test", math.NewInt(6)),
})
entries, err := acc.UnbondEntries.Get(sdkCtx, "val_address")
require.NoError(t, err)
require.Len(t, entries.Entries, 1)
require.True(t, entries.Entries[0].Amount.Amount.Equal(math.NewInt(1)))
require.True(t, entries.Entries[0].ValidatorAddress == "val_address")

delLocking, err = acc.DelegatedLocking.Get(ctx, "test")
require.NoError(t, err)
require.True(t, delLocking.Equal(math.NewInt(5)))

delFree, err := acc.DelegatedFree.Get(ctx, "test")
err = acc.CheckUbdEntriesMature(sdkCtx)
require.NoError(t, err)
require.True(t, delFree.Equal(math.NewInt(1)))

// Undelegate
_, err = acc.Undelegate(sdkCtx, &lockuptypes.MsgUndelegate{
Sender: "owner",
ValidatorAddress: "val_address",
Amount: sdk.NewCoin("test", math.NewInt(4)),
})
require.NoError(t, err)
_, err = acc.UnbondEntries.Get(sdkCtx, "val_address")
require.Error(t, err)

delLocking, err = acc.DelegatedLocking.Get(ctx, "test")
require.NoError(t, err)
require.True(t, delLocking.Equal(math.NewInt(2)))

delFree, err = acc.DelegatedFree.Get(ctx, "test")
require.NoError(t, err)
require.True(t, delFree.Equal(math.ZeroInt()))
require.True(t, delLocking.Equal(math.ZeroInt()))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Add timeline validation for undelegation process

The test should verify the intermediate state where funds are still locked during the unbonding period. Add assertions to check:

  1. Delegated locking amount before unbonding maturity
  2. Delegated locking amount after advancing context time to maturity

Example:

// Check intermediate state
delLocking, err = acc.DelegatedLocking.Get(ctx, "test")
require.NoError(t, err)
require.True(t, delLocking.Equal(math.NewInt(1))) // Should still be locked

// Advance time to maturity
sdkCtx = sdkCtx.WithHeaderInfo(header.Info{
    Time: ubdEntry.CompletionTime,
})

// Update undelegation entry after maturity
_, err = acc.UpdateUndelegationEntry(sdkCtx, &lockuptypes.MsgUpdateUndelegationEntry{
    Sender: "owner",
    Id:     ubdSeq - 1,
})
require.NoError(t, err)

// Now verify zero locking amount
delLocking, err = acc.DelegatedLocking.Get(ctx, "test")
require.NoError(t, err)
require.True(t, delLocking.Equal(math.ZeroInt()))

}

func TestContinousAccountSendCoins(t *testing.T) {
Expand Down
1 change: 1 addition & 0 deletions x/accounts/defaults/lockup/delayed_locking_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,5 @@ func (dva DelayedLockingAccount) RegisterExecuteHandlers(builder *accountstd.Exe

func (dva DelayedLockingAccount) RegisterQueryHandlers(builder *accountstd.QueryBuilder) {
accountstd.RegisterQueryHandler(builder, dva.QueryVestingAccountInfo)
dva.BaseLockup.RegisterQueryHandlers(builder)
}
37 changes: 7 additions & 30 deletions x/accounts/defaults/lockup/delayed_locking_account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,44 +101,21 @@ func TestDelayedAccountUndelegate(t *testing.T) {
})
require.NoError(t, err)

delLocking, err = acc.DelegatedLocking.Get(ctx, "test")
entries, err := acc.UnbondEntries.Get(sdkCtx, "val_address")
require.NoError(t, err)
require.True(t, delLocking.Equal(math.ZeroInt()))
require.Len(t, entries.Entries, 1)
require.True(t, entries.Entries[0].Amount.Amount.Equal(math.NewInt(1)))
require.True(t, entries.Entries[0].ValidatorAddress == "val_address")

endTime, err := acc.EndTime.Get(sdkCtx)
err = acc.CheckUbdEntriesMature(sdkCtx)
require.NoError(t, err)

// Update context time to unlocked all the original locking amount
sdkCtx = sdkCtx.WithHeaderInfo(header.Info{
Time: endTime.Add(time.Second),
})

_, err = acc.Delegate(sdkCtx, &lockuptypes.MsgDelegate{
Sender: "owner",
ValidatorAddress: "val_address",
Amount: sdk.NewCoin("test", math.NewInt(6)),
})
require.NoError(t, err)
_, err = acc.UnbondEntries.Get(sdkCtx, "val_address")
require.Error(t, err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add timeline validation for unbonding process.

The test should verify the intermediate state during the unbonding period.

Add assertions to check:

  1. State before maturity
  2. State after advancing context time
 err = acc.CheckUbdEntriesMature(sdkCtx)
 require.NoError(t, err)
+
+// Verify intermediate state
+delLocking, err = acc.DelegatedLocking.Get(ctx, "test")
+require.NoError(t, err)
+require.True(t, delLocking.Equal(math.NewInt(1))) // Should still be locked
+
+// Advance time to maturity
+sdkCtx = sdkCtx.WithHeaderInfo(header.Info{
+    Time: entries.Entries[0].CompletionTime,
+})
+
+err = acc.CheckUbdEntriesMature(sdkCtx)
+require.NoError(t, err)

Committable suggestion skipped: line range outside the PR's diff.


delLocking, err = acc.DelegatedLocking.Get(ctx, "test")
require.NoError(t, err)
require.True(t, delLocking.Equal(math.ZeroInt()))

delFree, err := acc.DelegatedFree.Get(ctx, "test")
require.NoError(t, err)
require.True(t, delFree.Equal(math.NewInt(6)))

// Undelegate
_, err = acc.Undelegate(sdkCtx, &lockuptypes.MsgUndelegate{
Sender: "owner",
ValidatorAddress: "val_address",
Amount: sdk.NewCoin("test", math.NewInt(4)),
})
require.NoError(t, err)

delFree, err = acc.DelegatedFree.Get(ctx, "test")
require.NoError(t, err)
require.True(t, delFree.Equal(math.NewInt(2)))
}

func TestDelayedAccountSendCoins(t *testing.T) {
Expand Down
Loading
Loading