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 bug store #103

Closed
wants to merge 2 commits into from
Closed
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
10 changes: 7 additions & 3 deletions x/multi-staking/keeper/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ func (k Keeper) BondWeightIterator(ctx sdk.Context, cb func(denom string, bondWe

func (k Keeper) GetMultiStakingUnlock(ctx sdk.Context, multiStakingUnlockID types.UnlockID) (unlock types.MultiStakingUnlock, found bool) {
store := ctx.KVStore(k.storeKey)
value := store.Get(multiStakingUnlockID.ToBytes())

key := append(multiStakingUnlockID.ToBytes(), []byte{0x1}...)
value := store.Get(key)
if value == nil {
return unlock, false
}
Expand All @@ -172,8 +172,12 @@ func (k Keeper) SetMultiStakingUnlock(ctx sdk.Context, unlock types.MultiStaking
store := ctx.KVStore(k.storeKey)

bz := k.cdc.MustMarshal(&unlock)
if unlock.UnlockID == nil {
panic("unlock.UnlockID cannot be nil")
}
key := append(unlock.UnlockID.ToBytes(), []byte{0x1}...)

store.Set(unlock.UnlockID.ToBytes(), bz)
store.Set(key, bz)
}

func (k Keeper) DeleteMultiStakingUnlock(ctx sdk.Context, unlockID types.UnlockID) {
Expand Down
40 changes: 39 additions & 1 deletion x/multi-staking/keeper/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ package keeper_test
import (
"github.com/realio-tech/multi-staking-module/testutil"
multistakingkeeper "github.com/realio-tech/multi-staking-module/x/multi-staking/keeper"
mulStakingtypes "github.com/realio-tech/multi-staking-module/x/multi-staking/types"

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

func (suite *KeeperTestSuite) TestSetBondWeight() {
suite.SetupTest()

gasDenom := "ario"
const gasDenom = "ario"
govDenom := "arst"
gasWeight := sdk.OneDec()
govWeight := sdk.NewDecWithPrec(2, 4)
Expand Down Expand Up @@ -86,3 +87,40 @@ func (suite *KeeperTestSuite) TestSetValidatorMultiStakingCoin() {
})
}
}

func (suite *KeeperTestSuite) TestSetAndGetMultiStakingUnlock() {
suite.SetupTest()
val := testutil.GenValAddress()
del := testutil.GenAddress()
denom := "ario"

// set:
unLockID := mulStakingtypes.UnlockID{
MultiStakerAddr: del.String(),
ValAddr: val.String(),
}

Entries := []mulStakingtypes.UnlockEntry{
{
CreationHeight: 1,
UnlockingCoin: mulStakingtypes.MultiStakingCoin{
Denom: denom,
},
},
}

mulStakingUnllock := mulStakingtypes.MultiStakingUnlock{
UnlockID: &unLockID,
Entries: Entries,
}

_, found := suite.msKeeper.GetMultiStakingUnlock(suite.ctx, unLockID)
suite.Require().False(found)

suite.msKeeper.SetMultiStakingUnlock(suite.ctx, mulStakingUnllock)

unLocks, found := suite.msKeeper.GetMultiStakingUnlock(suite.ctx, unLockID)
suite.Require().True(found)

suite.Require().Equal(unLocks.Entries[0].CreationHeight, Entries[0].CreationHeight)
}
2 changes: 1 addition & 1 deletion x/multi-staking/keeper/unlock.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (k Keeper) SetMultiStakingUnlockEntry(
if found {
unlock.AddEntry(ctx.BlockHeight(), multistakingCoin)
} else {
unlock = types.NewMultiStakingUnlock(ctx.BlockHeight(), multistakingCoin)
unlock = types.NewMultiStakingUnlock(&unlockID, ctx.BlockHeight(), multistakingCoin)
}

k.SetMultiStakingUnlock(ctx, unlock)
Expand Down
2 changes: 2 additions & 0 deletions x/multi-staking/types/unlock.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ func (e UnlockEntry) String() string {
//
//nolint:interfacer
func NewMultiStakingUnlock(
unlockID *UnlockID,
creationHeight int64, weightedCoin MultiStakingCoin,
) MultiStakingUnlock {
return MultiStakingUnlock{
UnlockID: unlockID,
Entries: []UnlockEntry{
NewUnlockEntry(creationHeight, weightedCoin),
},
Expand Down
Loading