Skip to content

Commit

Permalink
add system lane match handler
Browse files Browse the repository at this point in the history
  • Loading branch information
beer-1 committed Apr 19, 2024
1 parent 3ded8b2 commit f558771
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 1 deletion.
3 changes: 2 additions & 1 deletion x/opchild/lanes/free_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ var _ sdk.Tx = MockTx{}
var _ sdk.FeeTx = &MockTx{}

type MockTx struct {
msgs []sdk.Msg
feePayer []byte
}

Expand All @@ -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 {
Expand Down
28 changes: 28 additions & 0 deletions x/opchild/lanes/system.go
Original file line number Diff line number Diff line change
@@ -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
}
}
44 changes: 44 additions & 0 deletions x/opchild/lanes/system_test.go
Original file line number Diff line number Diff line change
@@ -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{},
},
}))
}

0 comments on commit f558771

Please sign in to comment.