mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-12-26 00:05:18 +00:00
ffef832d45
- Upgrade cosmos-sdk to v0.44.5 from v0.39.2 - Add Legacy Tx Endpoint for backwards compatibility - Add IBC v1.2.3 Support Co-authored-by: DracoLi <draco@dracoli.com> Co-authored-by: drklee3 <derrick@dlee.dev> Co-authored-by: denalimarsh <denalimarsh@gmail.com> Co-authored-by: Draco Li <draco@kava.io> Co-authored-by: Nick DeLuca <nickdeluca08@gmail.com> Co-authored-by: Kevin Davis <karzak@users.noreply.github.com> Co-authored-by: Denali Marsh <denali@kava.io>
138 lines
3.5 KiB
Go
138 lines
3.5 KiB
Go
package ante_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/cosmos/cosmos-sdk/simapp/helpers"
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/kava-labs/kava/app"
|
|
"github.com/kava-labs/kava/app/ante"
|
|
)
|
|
|
|
var (
|
|
_ sdk.AnteHandler = (&MockAnteHandler{}).AnteHandle
|
|
)
|
|
|
|
type MockAnteHandler struct {
|
|
WasCalled bool
|
|
}
|
|
|
|
func (mah *MockAnteHandler) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool) (sdk.Context, error) {
|
|
mah.WasCalled = true
|
|
return ctx, nil
|
|
}
|
|
|
|
func mockAddressFetcher(addresses ...sdk.AccAddress) ante.AddressFetcher {
|
|
return func(sdk.Context) []sdk.AccAddress { return addresses }
|
|
}
|
|
|
|
func TestAuthenticatedMempoolDecorator_AnteHandle_NotCheckTx(t *testing.T) {
|
|
txConfig := app.MakeEncodingConfig().TxConfig
|
|
|
|
testPrivKeys, testAddresses := app.GeneratePrivKeyAddressPairs(5)
|
|
fetcher := mockAddressFetcher(testAddresses[1:]...)
|
|
|
|
decorator := ante.NewAuthenticatedMempoolDecorator(fetcher)
|
|
tx, err := helpers.GenTx(
|
|
txConfig,
|
|
[]sdk.Msg{
|
|
banktypes.NewMsgSend(
|
|
testAddresses[0],
|
|
testAddresses[1],
|
|
sdk.NewCoins(sdk.NewInt64Coin("ukava", 100_000_000)),
|
|
),
|
|
},
|
|
sdk.NewCoins(), // no fee
|
|
helpers.DefaultGenTxGas,
|
|
"testing-chain-id",
|
|
[]uint64{0},
|
|
[]uint64{0},
|
|
testPrivKeys[0], // address is not authorized
|
|
)
|
|
require.NoError(t, err)
|
|
mmd := MockAnteHandler{}
|
|
ctx := sdk.Context{}.WithIsCheckTx(false) // run as it would be during block update ('DeliverTx'), not just checking entry to mempool
|
|
|
|
_, err = decorator.AnteHandle(ctx, tx, false, mmd.AnteHandle)
|
|
|
|
require.NoError(t, err)
|
|
require.True(t, mmd.WasCalled)
|
|
}
|
|
|
|
func TestAuthenticatedMempoolDecorator_AnteHandle_Pass(t *testing.T) {
|
|
txConfig := app.MakeEncodingConfig().TxConfig
|
|
|
|
testPrivKeys, testAddresses := app.GeneratePrivKeyAddressPairs(5)
|
|
fetcher := mockAddressFetcher(testAddresses[1:]...)
|
|
|
|
decorator := ante.NewAuthenticatedMempoolDecorator(fetcher)
|
|
|
|
tx, err := helpers.GenTx(
|
|
txConfig,
|
|
[]sdk.Msg{
|
|
banktypes.NewMsgSend(
|
|
testAddresses[0],
|
|
testAddresses[1],
|
|
sdk.NewCoins(sdk.NewInt64Coin("ukava", 100_000_000)),
|
|
),
|
|
banktypes.NewMsgSend(
|
|
testAddresses[2],
|
|
testAddresses[1],
|
|
sdk.NewCoins(sdk.NewInt64Coin("ukava", 100_000_000)),
|
|
),
|
|
},
|
|
sdk.NewCoins(), // no fee
|
|
helpers.DefaultGenTxGas,
|
|
"testing-chain-id",
|
|
[]uint64{0, 123},
|
|
[]uint64{0, 123},
|
|
testPrivKeys[0], // not in list of authorized addresses
|
|
testPrivKeys[2], // in list of authorized addresses
|
|
)
|
|
require.NoError(t, err)
|
|
mmd := MockAnteHandler{}
|
|
ctx := sdk.Context{}.WithIsCheckTx(true)
|
|
|
|
_, err = decorator.AnteHandle(ctx, tx, false, mmd.AnteHandle)
|
|
|
|
require.NoError(t, err)
|
|
require.True(t, mmd.WasCalled)
|
|
}
|
|
|
|
func TestAuthenticatedMempoolDecorator_AnteHandle_Reject(t *testing.T) {
|
|
txConfig := app.MakeEncodingConfig().TxConfig
|
|
|
|
testPrivKeys, testAddresses := app.GeneratePrivKeyAddressPairs(5)
|
|
fetcher := mockAddressFetcher(testAddresses[1:]...)
|
|
|
|
decorator := ante.NewAuthenticatedMempoolDecorator(fetcher)
|
|
|
|
tx, err := helpers.GenTx(
|
|
txConfig,
|
|
[]sdk.Msg{
|
|
banktypes.NewMsgSend(
|
|
testAddresses[0],
|
|
testAddresses[1],
|
|
sdk.NewCoins(sdk.NewInt64Coin("ukava", 100_000_000)),
|
|
),
|
|
},
|
|
sdk.NewCoins(), // no fee
|
|
helpers.DefaultGenTxGas,
|
|
"testing-chain-id",
|
|
[]uint64{0},
|
|
[]uint64{0},
|
|
testPrivKeys[0], // not in list of authorized addresses
|
|
)
|
|
require.NoError(t, err)
|
|
mmd := MockAnteHandler{}
|
|
ctx := sdk.Context{}.WithIsCheckTx(true)
|
|
|
|
_, err = decorator.AnteHandle(ctx, tx, false, mmd.AnteHandle)
|
|
|
|
require.Error(t, err)
|
|
require.False(t, mmd.WasCalled)
|
|
}
|