Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow authz msgupdateoracle to systemlane #126

Merged
merged 2 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion x/opchild/lanes/free.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,16 @@
} else if payer, err := h.ac.BytesToString(feeTx.FeePayer()); err != nil {
return false
} else {
var granter string
if feeTx.FeeGranter() != nil {
granter, err = h.ac.BytesToString(feeTx.FeeGranter())
if err != nil {
return false
}

Check warning on line 47 in x/opchild/lanes/free.go

View check run for this annotation

Codecov / codecov/patch

x/opchild/lanes/free.go#L46-L47

Added lines #L46 - L47 were not covered by tests
}

for _, addr := range whitelist {
if addr == payer {
if addr == payer || addr == granter {
return true
}
}
Expand Down
22 changes: 19 additions & 3 deletions x/opchild/lanes/free_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,30 @@ func Test_FreeLaneMatchHandler(t *testing.T) {
require.True(t, handler(ctx, MockTx{
feePayer: []byte{3, 4, 5, 6},
}))

require.True(t, handler(ctx, MockTx{
feePayer: []byte{2, 3, 4, 5},
feeGranter: []byte{0, 1, 2, 3},
}))

require.True(t, handler(ctx, MockTx{
feePayer: []byte{2, 3, 4, 5},
feeGranter: []byte{3, 4, 5, 6},
}))

require.False(t, handler(ctx, MockTx{
feePayer: []byte{2, 3, 4, 5},
feeGranter: []byte{2, 3, 5, 6},
}))
}

var _ sdk.Tx = MockTx{}
var _ sdk.FeeTx = &MockTx{}

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

func (tx MockTx) GetMsgsV2() ([]protov2.Message, error) {
Expand All @@ -82,5 +98,5 @@ func (tx MockTx) FeePayer() []byte {
return tx.feePayer
}
func (tx MockTx) FeeGranter() []byte {
return nil
return tx.feeGranter
}
10 changes: 9 additions & 1 deletion x/opchild/lanes/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

blockbase "github.com/skip-mev/block-sdk/v2/block/base"

"github.com/cosmos/cosmos-sdk/x/authz"
"github.com/initia-labs/OPinit/x/opchild/types"
)

Expand All @@ -16,8 +17,15 @@
}

for _, msg := range tx.GetMsgs() {
switch msg.(type) {
switch msg := msg.(type) {
case *types.MsgUpdateOracle:
case *authz.MsgExec:
msgs, err := msg.GetMessages()
if err != nil || len(msgs) != 1 {
return false

Check warning on line 25 in x/opchild/lanes/system.go

View check run for this annotation

Codecov / codecov/patch

x/opchild/lanes/system.go#L25

Added line #L25 was not covered by tests
} else if _, ok := msgs[0].(*types.MsgUpdateOracle); !ok {
return false
}
default:
return false
}
Expand Down
23 changes: 23 additions & 0 deletions x/opchild/lanes/system_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"cosmossdk.io/log"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/authz"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"

"github.com/cometbft/cometbft/proto/tendermint/types"
Expand Down Expand Up @@ -41,4 +42,26 @@ func Test_SystemLaneMatchHandler(t *testing.T) {
&banktypes.MsgSend{},
},
}))

authzMsg := authz.NewMsgExec(nil, []sdk.Msg{
&opchildtypes.MsgUpdateOracle{},
})

// 1 system message and authz.MsgExec
require.True(t, handler(ctx, MockTx{
msgs: []sdk.Msg{
&authzMsg,
},
}))

authzMsg = authz.NewMsgExec(nil, []sdk.Msg{
&banktypes.MsgSend{},
})

// authz.MsgExec with non-system message
require.False(t, handler(ctx, MockTx{
msgs: []sdk.Msg{
&authzMsg,
},
}))
}
Loading