2022-01-08 00:39:27 +00:00
|
|
|
package ante_test
|
|
|
|
|
|
|
|
import (
|
2023-04-04 00:08:45 +00:00
|
|
|
"math/rand"
|
2022-01-08 00:39:27 +00:00
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
2024-02-06 22:54:10 +00:00
|
|
|
"github.com/cosmos/cosmos-sdk/testutil/sims"
|
2022-01-08 00:39:27 +00:00
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
vesting "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
|
2023-04-06 20:21:56 +00:00
|
|
|
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
|
2022-01-08 00:39:27 +00:00
|
|
|
|
2024-05-01 03:17:24 +00:00
|
|
|
"github.com/0glabs/0g-chain/app"
|
|
|
|
"github.com/0glabs/0g-chain/app/ante"
|
2024-05-09 11:35:16 +00:00
|
|
|
"github.com/0glabs/0g-chain/chaincfg"
|
2022-01-08 00:39:27 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestVestingMempoolDecorator_MsgCreateVestingAccount_Unauthorized(t *testing.T) {
|
|
|
|
txConfig := app.MakeEncodingConfig().TxConfig
|
|
|
|
|
|
|
|
testPrivKeys, testAddresses := app.GeneratePrivKeyAddressPairs(5)
|
|
|
|
|
|
|
|
decorator := ante.NewVestingAccountDecorator()
|
|
|
|
|
2023-04-06 20:21:56 +00:00
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
msg sdk.Msg
|
|
|
|
wantHasErr bool
|
|
|
|
wantErr string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
"MsgCreateVestingAccount",
|
2022-01-08 00:39:27 +00:00
|
|
|
vesting.NewMsgCreateVestingAccount(
|
|
|
|
testAddresses[0], testAddresses[1],
|
2024-05-09 11:35:16 +00:00
|
|
|
sdk.NewCoins(chaincfg.MakeCoinForAuxiliaryDenom(100)),
|
2023-04-06 20:21:56 +00:00
|
|
|
time.Date(1998, 1, 1, 0, 0, 0, 0, time.UTC).Unix(),
|
|
|
|
false,
|
|
|
|
),
|
|
|
|
true,
|
|
|
|
"MsgTypeURL /cosmos.vesting.v1beta1.MsgCreateVestingAccount not supported",
|
2022-01-08 00:39:27 +00:00
|
|
|
},
|
2023-04-06 20:21:56 +00:00
|
|
|
{
|
|
|
|
"MsgCreateVestingAccount",
|
|
|
|
vesting.NewMsgCreatePermanentLockedAccount(
|
|
|
|
testAddresses[0], testAddresses[1],
|
2024-05-09 11:35:16 +00:00
|
|
|
sdk.NewCoins(chaincfg.MakeCoinForAuxiliaryDenom(100)),
|
2023-04-06 20:21:56 +00:00
|
|
|
),
|
|
|
|
true,
|
|
|
|
"MsgTypeURL /cosmos.vesting.v1beta1.MsgCreatePermanentLockedAccount not supported",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"MsgCreateVestingAccount",
|
|
|
|
vesting.NewMsgCreatePeriodicVestingAccount(
|
|
|
|
testAddresses[0], testAddresses[1],
|
|
|
|
time.Date(1998, 1, 1, 0, 0, 0, 0, time.UTC).Unix(),
|
|
|
|
nil,
|
|
|
|
),
|
|
|
|
true,
|
|
|
|
"MsgTypeURL /cosmos.vesting.v1beta1.MsgCreatePeriodicVestingAccount not supported",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"other messages not affected",
|
|
|
|
banktypes.NewMsgSend(
|
|
|
|
testAddresses[0], testAddresses[1],
|
2024-05-09 11:35:16 +00:00
|
|
|
sdk.NewCoins(chaincfg.MakeCoinForAuxiliaryDenom(100)),
|
2023-04-06 20:21:56 +00:00
|
|
|
),
|
|
|
|
false,
|
|
|
|
"",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
2024-02-06 22:54:10 +00:00
|
|
|
tx, err := sims.GenSignedMockTx(
|
2023-04-06 20:21:56 +00:00
|
|
|
rand.New(rand.NewSource(time.Now().UnixNano())),
|
|
|
|
txConfig,
|
|
|
|
[]sdk.Msg{
|
|
|
|
tt.msg,
|
|
|
|
},
|
|
|
|
sdk.NewCoins(),
|
2024-02-06 22:54:10 +00:00
|
|
|
sims.DefaultGenTxGas,
|
2023-04-06 20:21:56 +00:00
|
|
|
"testing-chain-id",
|
|
|
|
[]uint64{0},
|
|
|
|
[]uint64{0},
|
|
|
|
testPrivKeys[0],
|
|
|
|
)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
mmd := MockAnteHandler{}
|
|
|
|
ctx := sdk.Context{}.WithIsCheckTx(true)
|
|
|
|
|
|
|
|
_, err = decorator.AnteHandle(ctx, tx, false, mmd.AnteHandle)
|
|
|
|
|
|
|
|
if tt.wantHasErr {
|
|
|
|
require.Error(t, err)
|
|
|
|
require.Contains(t, err.Error(), tt.wantErr)
|
|
|
|
} else {
|
|
|
|
require.NoError(t, err)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2022-01-08 00:39:27 +00:00
|
|
|
}
|