forked from lavanet/lava
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CNS-844: call dualstaking ante handler + ante unit test
- Loading branch information
Showing
3 changed files
with
66 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package ante_test | ||
|
||
import ( | ||
"testing" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" | ||
commontypes "github.com/lavanet/lava/common/types" | ||
"github.com/lavanet/lava/testutil/common" | ||
"github.com/lavanet/lava/x/dualstaking/ante" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
// TestDisableRedelegationHooks verifies that the DisableRedelegationHooks works as expected, i.e. disables | ||
// the dualstaking hooks only for redelegations message | ||
func TestDisableRedelegationHooks(t *testing.T) { | ||
ts := *common.NewTester(t) | ||
testCases := []struct { | ||
msg sdk.Msg | ||
expectedFlagValue bool | ||
}{ | ||
{newStakingRedelegateMsg(), true}, | ||
{newStakingDelegateMsg(), false}, | ||
{newStakingUndelegateMsg(), false}, | ||
} | ||
|
||
rf := ante.NewRedelegationFlager(ts.Keepers.Dualstaking) | ||
|
||
for _, testCase := range testCases { | ||
err := rf.DisableRedelegationHooks(ts.Ctx, []sdk.Msg{testCase.msg}) | ||
require.NoError(t, err) | ||
disableHooksFlag := ts.Keepers.Dualstaking.GetDisableDualstakingHook(ts.Ctx) | ||
require.Equal(t, testCase.expectedFlagValue, disableHooksFlag) | ||
} | ||
} | ||
|
||
func newStakingRedelegateMsg() *stakingtypes.MsgBeginRedelegate { | ||
return stakingtypes.NewMsgBeginRedelegate( | ||
sdk.AccAddress("del1"), | ||
sdk.ValAddress("val1"), | ||
sdk.ValAddress("val2"), | ||
sdk.NewCoin(commontypes.TokenDenom, sdk.OneInt()), | ||
) | ||
} | ||
|
||
func newStakingDelegateMsg() *stakingtypes.MsgDelegate { | ||
return stakingtypes.NewMsgDelegate( | ||
sdk.AccAddress("del1"), | ||
sdk.ValAddress("val1"), | ||
sdk.NewCoin(commontypes.TokenDenom, sdk.OneInt()), | ||
) | ||
} | ||
|
||
func newStakingUndelegateMsg() *stakingtypes.MsgUndelegate { | ||
return stakingtypes.NewMsgUndelegate( | ||
sdk.AccAddress("del1"), | ||
sdk.ValAddress("val1"), | ||
sdk.NewCoin(commontypes.TokenDenom, sdk.OneInt()), | ||
) | ||
} |