diff --git a/x/opchild/lanes/free_test.go b/x/opchild/lanes/free_test.go index 80421a9f..c18fcdf9 100644 --- a/x/opchild/lanes/free_test.go +++ b/x/opchild/lanes/free_test.go @@ -58,6 +58,7 @@ var _ sdk.Tx = MockTx{} var _ sdk.FeeTx = &MockTx{} type MockTx struct { + msgs []sdk.Msg feePayer []byte } @@ -66,7 +67,7 @@ func (tx MockTx) GetMsgsV2() ([]protov2.Message, error) { } func (tx MockTx) GetMsgs() []sdk.Msg { - return nil + return tx.msgs } func (tx MockTx) GetGas() uint64 { diff --git a/x/opchild/lanes/system.go b/x/opchild/lanes/system.go new file mode 100644 index 00000000..5e5ea1e7 --- /dev/null +++ b/x/opchild/lanes/system.go @@ -0,0 +1,28 @@ +package lanes + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + + blockbase "github.com/skip-mev/block-sdk/v2/block/base" + + "github.com/initia-labs/OPinit/x/opchild/types" +) + +// SystemLaneMatchHandler returns the default match handler for the system lane. +func SystemLaneMatchHandler() blockbase.MatchHandler { + return func(ctx sdk.Context, tx sdk.Tx) bool { + if len(tx.GetMsgs()) != 1 { + return false + } + + for _, msg := range tx.GetMsgs() { + switch msg.(type) { + case *types.MsgUpdateOracle: + default: + return false + } + } + + return true + } +} diff --git a/x/opchild/lanes/system_test.go b/x/opchild/lanes/system_test.go new file mode 100644 index 00000000..c6b24570 --- /dev/null +++ b/x/opchild/lanes/system_test.go @@ -0,0 +1,44 @@ +package lanes_test + +import ( + "testing" + + "cosmossdk.io/log" + sdk "github.com/cosmos/cosmos-sdk/types" + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + + "github.com/cometbft/cometbft/proto/tendermint/types" + + "github.com/stretchr/testify/require" + + "github.com/initia-labs/OPinit/x/opchild/lanes" + opchildtypes "github.com/initia-labs/OPinit/x/opchild/types" +) + +func Test_SystemLaneMatchHandler(t *testing.T) { + ctx := sdk.NewContext(nil, types.Header{}, false, log.NewNopLogger()) + + handler := lanes.SystemLaneMatchHandler() + + // 1 system message + require.True(t, handler(ctx, MockTx{ + msgs: []sdk.Msg{ + &opchildtypes.MsgUpdateOracle{}, + }, + })) + + // 2 system messages + require.False(t, handler(ctx, MockTx{ + msgs: []sdk.Msg{ + &opchildtypes.MsgUpdateOracle{}, + &opchildtypes.MsgUpdateOracle{}, + }, + })) + + // 1 non-system message + require.False(t, handler(ctx, MockTx{ + msgs: []sdk.Msg{ + &banktypes.MsgSend{}, + }, + })) +}