mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-12-24 15:25:18 +00:00
fix(x/precisebank): Avoid blocked addr error on SendCoinsFromAccountToModule (#2012)
This commit is contained in:
parent
8023be0067
commit
65d091d458
@ -179,10 +179,17 @@ func (k Keeper) sendExtendedCoins(
|
||||
// Always send carry from reserve before receiving borrow from sender to
|
||||
// ensure reserve always has sufficient balance starting from 0.
|
||||
if !senderNeedsBorrow && recipientNeedsCarry {
|
||||
reserveAddr := k.ak.GetModuleAddress(types.ModuleName)
|
||||
|
||||
// We use SendCoins instead of SendCoinsFromModuleToAccount to avoid
|
||||
// the blocked addrs check. Blocked accounts should not be checked in
|
||||
// a SendCoins operation. Only SendCoinsFromModuleToAccount should check
|
||||
// blocked addrs which is done by the parent SendCoinsFromModuleToAccount
|
||||
// method.
|
||||
carryCoin := sdk.NewCoin(types.IntegerCoinDenom, sdk.NewInt(1))
|
||||
if err := k.bk.SendCoinsFromModuleToAccount(
|
||||
if err := k.bk.SendCoins(
|
||||
ctx,
|
||||
types.ModuleName,
|
||||
reserveAddr,
|
||||
to, // recipient carrying
|
||||
sdk.NewCoins(carryCoin),
|
||||
); err != nil {
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"testing"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
|
||||
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
|
||||
"github.com/kava-labs/kava/app"
|
||||
@ -622,6 +623,65 @@ func (suite *sendIntegrationTestSuite) TestSendCoinsFromAccountToModule() {
|
||||
)
|
||||
}
|
||||
|
||||
func (suite *sendIntegrationTestSuite) TestSendCoinsFromAccountToModule_BlockedRecipientCarry() {
|
||||
// Carrying to module account balance. This tests that SendCoinsFromAccountToModule
|
||||
// does not fail when sending to a blocked module account.
|
||||
|
||||
sender := sdk.AccAddress([]byte{1})
|
||||
|
||||
sendAmt := cs(c(types.ExtendedCoinDenom, 1000))
|
||||
sendAmt2 := cs(ci(types.ExtendedCoinDenom, types.ConversionFactor().SubRaw(10)))
|
||||
|
||||
suite.MintToAccount(sender, sendAmt.Add(sendAmt2...))
|
||||
|
||||
err := suite.Keeper.SendCoinsFromAccountToModule(
|
||||
suite.Ctx,
|
||||
sender,
|
||||
authtypes.FeeCollectorName,
|
||||
sendAmt,
|
||||
)
|
||||
suite.Require().NoError(err)
|
||||
|
||||
// Trigger carry for fee_collector module account
|
||||
err = suite.Keeper.SendCoinsFromAccountToModule(
|
||||
suite.Ctx,
|
||||
sender,
|
||||
authtypes.FeeCollectorName,
|
||||
sendAmt2,
|
||||
)
|
||||
suite.Require().NoError(err)
|
||||
}
|
||||
|
||||
func (suite *sendIntegrationTestSuite) TestSendCoins_BlockedRecipientCarry() {
|
||||
// Same test as TestSendCoinsFromModuleToAccount_Blocked, but with SendCoins
|
||||
// which also should not fail when sending to a blocked module account.
|
||||
sender := sdk.AccAddress([]byte{1})
|
||||
|
||||
sendAmt := cs(c(types.ExtendedCoinDenom, 1000))
|
||||
sendAmt2 := cs(ci(types.ExtendedCoinDenom, types.ConversionFactor().SubRaw(10)))
|
||||
|
||||
suite.MintToAccount(sender, sendAmt.Add(sendAmt2...))
|
||||
|
||||
recipient := suite.App.GetAccountKeeper().GetModuleAddress(authtypes.FeeCollectorName)
|
||||
|
||||
err := suite.Keeper.SendCoins(
|
||||
suite.Ctx,
|
||||
sender,
|
||||
recipient,
|
||||
sendAmt,
|
||||
)
|
||||
suite.Require().NoError(err)
|
||||
|
||||
// Trigger carry for fee_collector module account
|
||||
err = suite.Keeper.SendCoins(
|
||||
suite.Ctx,
|
||||
sender,
|
||||
recipient,
|
||||
sendAmt2,
|
||||
)
|
||||
suite.Require().NoError(err)
|
||||
}
|
||||
|
||||
func (suite *sendIntegrationTestSuite) TestSendCoinsFromModuleToAccount() {
|
||||
// Ensure sender correctly matches the specified module account. Opposite
|
||||
// of SendCoinsFromAccountToModule, so we are only checking the correct
|
||||
|
Loading…
Reference in New Issue
Block a user