Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
mmsqe committed Nov 29, 2023
1 parent 42125a9 commit 2dea6f4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion integration_tests/test_ibc_rly_gas.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ def test_ibc(ibc):
records.append(record)
if len(records) == 2:
for e1, e2 in zip(*records):
res = int(e2) / int(e1)
res = float(e2) / float(e1)
assert 1 - diff <= res <= 1 + diff, res
6 changes: 5 additions & 1 deletion x/cronos/keeper/precompiles/relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package precompiles

import (
"errors"
"fmt"

"github.com/cometbft/cometbft/libs/log"
"github.com/cosmos/cosmos-sdk/codec"
Expand Down Expand Up @@ -180,6 +181,9 @@ func (bc *RelayerContract) Run(evm *vm.EVM, contract *vm.Contract, readonly bool
if readonly {
return nil, errors.New("the method is not readonly")
}
if len(contract.Input) < 4 {
return nil, errors.New("input too short")
}

Check warning on line 186 in x/cronos/keeper/precompiles/relayer.go

View check run for this annotation

Codecov / codecov/patch

x/cronos/keeper/precompiles/relayer.go#L184-L186

Added lines #L184 - L186 were not covered by tests
// parse input
methodID := contract.Input[:4]
method, err := irelayerABI.MethodById(methodID)
Expand Down Expand Up @@ -273,7 +277,7 @@ func (bc *RelayerContract) Run(evm *vm.EVM, contract *vm.Contract, readonly bool
case UpdateClientAndTimeoutOnClose:
res, err = execMultiple(e, bc.ibcKeeper.UpdateClient, bc.ibcKeeper.TimeoutOnClose)

Check warning on line 278 in x/cronos/keeper/precompiles/relayer.go

View check run for this annotation

Codecov / codecov/patch

x/cronos/keeper/precompiles/relayer.go#L203-L278

Added lines #L203 - L278 were not covered by tests
default:
return nil, errors.New("unknown method")
return nil, fmt.Errorf("unknown method: %s", method.Name)

Check warning on line 280 in x/cronos/keeper/precompiles/relayer.go

View check run for this annotation

Codecov / codecov/patch

x/cronos/keeper/precompiles/relayer.go#L280

Added line #L280 was not covered by tests
}
return res, err
}
13 changes: 9 additions & 4 deletions x/cronos/keeper/precompiles/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ func exec[Req any, PReq interface {
if len(signers) != 1 {
return nil, errors.New("don't support multi-signers message")
}
if common.BytesToAddress(signers[0].Bytes()) != e.caller {
return nil, errors.New("caller is not authenticated")
caller := common.BytesToAddress(signers[0].Bytes())
if caller != e.caller {
return nil, fmt.Errorf("caller is not authenticated: expected %s, got %s", e.caller.Hex(), caller.Hex())

Check warning on line 48 in x/cronos/keeper/precompiles/utils.go

View check run for this annotation

Codecov / codecov/patch

x/cronos/keeper/precompiles/utils.go#L46-L48

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

var res Resp
Expand All @@ -56,7 +57,11 @@ func exec[Req any, PReq interface {
return nil, err
}

return e.cdc.Marshal(res)
output, err := e.cdc.Marshal(res)
if err != nil {
return nil, fmt.Errorf("fail to Marshal %T %w", res, err)
}
return output, nil

Check warning on line 64 in x/cronos/keeper/precompiles/utils.go

View check run for this annotation

Codecov / codecov/patch

x/cronos/keeper/precompiles/utils.go#L60-L64

Added lines #L60 - L64 were not covered by tests
}

func execMultipleWithHooks[Req any,
Expand Down Expand Up @@ -89,7 +94,7 @@ func execMultipleWithHooks[Req any,

signers := msg.GetSigners()
if len(signers) != 1 {
return nil, errors.New("don't support multi-signers message")
return nil, fmt.Errorf("expected 1 signer, got %d", len(signers))
}
if common.BytesToAddress(signers[0].Bytes()) != e.caller {
return nil, errors.New("caller is not authenticated")
Expand Down

0 comments on commit 2dea6f4

Please sign in to comment.