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

Add test for the fork #133

Merged
merged 10 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
46 changes: 21 additions & 25 deletions app/fork_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package app

import (
"fmt"
"testing"
"time"

Expand All @@ -13,12 +12,10 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
)

var oneEnternityLater = time.Date(9999, 9, 9, 9, 9, 9, 9, time.UTC)

func TestFork(t *testing.T) {
realio := Setup(false, nil)

ctx := realio.BaseApp.NewContext(false, tmproto.Header{Height: int64(ForkHeight)})
ctx := realio.BaseApp.NewContext(false, tmproto.Header{Height: ForkHeight})
stakingKeeper := realio.StakingKeeper

timeKey := time.Date(2024, 4, 1, 1, 1, 1, 1, time.UTC)
Expand All @@ -27,7 +24,7 @@ func TestFork(t *testing.T) {
DelegatorAddress: "test_del_1",
ValidatorAddress: "test_val_1",
Entries: []stakingtypes.UnbondingDelegationEntry{
stakingtypes.NewUnbondingDelegationEntry(int64(ForkHeight), timeKey, math.OneInt()),
stakingtypes.NewUnbondingDelegationEntry(ForkHeight, timeKey, math.OneInt()),
},
}

Expand All @@ -39,7 +36,7 @@ func TestFork(t *testing.T) {
ValidatorSrcAddress: "test_val_1",
ValidatorDstAddress: "test_val_2",
Entries: []stakingtypes.RedelegationEntry{
stakingtypes.NewRedelegationEntry(int64(ForkHeight), timeKey, math.OneInt(), sdk.OneDec()),
stakingtypes.NewRedelegationEntry(ForkHeight, timeKey, math.OneInt(), sdk.OneDec()),
},
}
stakingKeeper.InsertRedelegationQueue(ctx, duplicativeRedelegation, timeKey)
Expand All @@ -48,7 +45,7 @@ func TestFork(t *testing.T) {

duplicativeVal := stakingtypes.Validator{
OperatorAddress: "test_op",
UnbondingHeight: int64(ForkHeight),
UnbondingHeight: ForkHeight,
UnbondingTime: timeKey,
}

Expand All @@ -74,9 +71,8 @@ func TestFork(t *testing.T) {
require.Equal(t, triplets[0].ValidatorDstAddress, duplicativeRedelegation.ValidatorDstAddress)
require.Equal(t, triplets[0].ValidatorSrcAddress, duplicativeRedelegation.ValidatorSrcAddress)

vals := stakingKeeper.GetUnbondingValidators(ctx, timeKey, int64(ForkHeight))
vals := stakingKeeper.GetUnbondingValidators(ctx, timeKey, ForkHeight)
require.Equal(t, vals[0], duplicativeVal.OperatorAddress)

}

func checkDuplicateUBDQueue(ctx sdk.Context, realio RealioNetwork) bool {
Expand All @@ -94,14 +90,13 @@ func checkDuplicateUBDQueue(ctx sdk.Context, realio RealioNetwork) bool {
return false
}

func checkDuplicateUBD(eles []stakingtypes.DVPair) bool {
unique_eles := map[string]bool{}
for _, ele := range eles {
unique_eles[ele.String()] = true
func checkDuplicateUBD(eels []stakingtypes.DVPair) bool {
uniqueEles := map[string]bool{}
for _, ele := range eels {
uniqueEles[ele.String()] = true
}
fmt.Println(eles, "eles")

return len(unique_eles) != len(eles)
return len(uniqueEles) != len(eels)
}

func checkDuplicateRelegationQueue(ctx sdk.Context, realio RealioNetwork) bool {
Expand All @@ -119,13 +114,13 @@ func checkDuplicateRelegationQueue(ctx sdk.Context, realio RealioNetwork) bool {
return false
}

func checkDuplicateRedelegation(eles []stakingtypes.DVVTriplet) bool {
unique_eles := map[string]bool{}
for _, ele := range eles {
unique_eles[ele.String()] = true
func checkDuplicateRedelegation(eels []stakingtypes.DVVTriplet) bool {
uniqueEles := map[string]bool{}
for _, ele := range eels {
uniqueEles[ele.String()] = true
}

return len(unique_eles) != len(eles)
return len(uniqueEles) != len(eels)
}

func checkDuplicateValQueue(ctx sdk.Context, realio RealioNetwork) bool {
Expand All @@ -142,11 +137,12 @@ func checkDuplicateValQueue(ctx sdk.Context, realio RealioNetwork) bool {
}
return false
}
func checkDuplicateValAddr(eles []string) bool {
unique_eles := map[string]bool{}
for _, ele := range eles {
unique_eles[ele] = true

func checkDuplicateValAddr(eels []string) bool {
uniqueEles := map[string]bool{}
for _, ele := range eels {
uniqueEles[ele] = true
}

return len(unique_eles) != len(eles)
return len(uniqueEles) != len(eels)
}
32 changes: 13 additions & 19 deletions app/forks.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ import (
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
)

var ForkHeight = 5989487
var (
ForkHeight = int64(5989487)
oneEnternityLater = time.Date(9999, 9, 9, 9, 9, 9, 9, time.UTC)
)

// ScheduleForkUpgrade executes any necessary fork logic for based upon the current
// block height and chain ID (mainnet or testnet). It sets an upgrade plan once
Expand All @@ -19,7 +22,7 @@ var ForkHeight = 5989487
// 1. Release a non-breaking patch version so that the chain can set the scheduled upgrade plan at upgrade-height.
// 2. Release the software defined in the upgrade-info
func (app *RealioNetwork) ScheduleForkUpgrade(ctx sdk.Context) {
if ctx.BlockHeight() == 5989487 {
if ctx.BlockHeight() == ForkHeight {

// remove duplicate UnbondingQueueKey
removeDuplicateValueUnbondingQueueKey(app, ctx)
Expand Down Expand Up @@ -63,11 +66,7 @@ func removeDuplicateValueRedelegationQueueKey(app *RealioNetwork, ctx sdk.Contex
cdc := app.AppCodec()
store := ctx.KVStore(app.keys[stakingtypes.ModuleName])

// remove duplicate UnbondingQueueKey
ubdTime := sk.UnbondingTime(ctx)
currTime := ctx.BlockTime()

redelegationTimesliceIterator := sk.RedelegationQueueIterator(ctx, currTime.Add(ubdTime)) // make sure to iterate all queue
redelegationTimesliceIterator := sk.RedelegationQueueIterator(ctx, oneEnternityLater) // make sure to iterate all queue
defer redelegationTimesliceIterator.Close()

for ; redelegationTimesliceIterator.Valid(); redelegationTimesliceIterator.Next() {
Expand All @@ -80,7 +79,6 @@ func removeDuplicateValueRedelegationQueueKey(app *RealioNetwork, ctx sdk.Contex

store.Set(redelegationTimesliceIterator.Key(), bz)
}

}

func removeDuplicateDVVTriplets(triplets []stakingtypes.DVVTriplet) []stakingtypes.DVVTriplet {
Expand All @@ -105,7 +103,7 @@ func containsDVVTriplets(s []stakingtypes.DVVTriplet, e stakingtypes.DVVTriplet)
}

func removeDuplicateUnbondingValidator(app *RealioNetwork, ctx sdk.Context) {
valIter := app.StakingKeeper.ValidatorQueueIterator(ctx, time.Date(9999, 9, 9, 9, 9, 9, 9, time.UTC), 99999999999999)
valIter := app.StakingKeeper.ValidatorQueueIterator(ctx, oneEnternityLater, 99999999999999)
defer valIter.Close()

for ; valIter.Valid(); valIter.Next() {
Expand All @@ -117,13 +115,13 @@ func removeDuplicateUnbondingValidator(app *RealioNetwork, ctx sdk.Context) {
vals[valAddr] = true
}

unique_addrs := []string{}
for valAddr, _ := range vals {
unique_addrs = append(unique_addrs, valAddr)
uniqueAddrs := []string{}
for valAddr := range vals {
uniqueAddrs = append(uniqueAddrs, valAddr)
}
sort.Strings(unique_addrs)
sort.Strings(uniqueAddrs)

ctx.KVStore(app.GetKey(stakingtypes.StoreKey)).Set(valIter.Key(), app.appCodec.MustMarshal(&stakingtypes.ValAddresses{Addresses: unique_addrs}))
ctx.KVStore(app.GetKey(stakingtypes.StoreKey)).Set(valIter.Key(), app.appCodec.MustMarshal(&stakingtypes.ValAddresses{Addresses: uniqueAddrs}))
}
}

Expand All @@ -133,11 +131,7 @@ func removeDuplicateValueUnbondingQueueKey(app *RealioNetwork, ctx sdk.Context)
cdc := app.AppCodec()
store := ctx.KVStore(app.keys[stakingtypes.ModuleName])

// remove duplicate UnbondingQueueKey
ubdTime := sk.UnbondingTime(ctx)
currTime := ctx.BlockTime()

unbondingTimesliceIterator := sk.UBDQueueIterator(ctx, currTime.Add(ubdTime)) // make sure to iterate all queue
unbondingTimesliceIterator := sk.UBDQueueIterator(ctx, oneEnternityLater) // make sure to iterate all queue
defer unbondingTimesliceIterator.Close()

for ; unbondingTimesliceIterator.Valid(); unbondingTimesliceIterator.Next() {
Expand Down
1 change: 0 additions & 1 deletion x/asset/keeper/msg_server_create_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ func (k msgServer) CreateToken(goCtx context.Context, msg *types.MsgCreateToken)
coin := sdk.Coins{{Denom: baseDenom, Amount: canonicalAmount}}

err = k.bankKeeper.MintCoins(ctx, types.ModuleName, coin)

if err != nil {
panic(err)
}
Expand Down
Loading