Skip to content

Commit

Permalink
👌 Applied suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
nagdahimanshu committed Jan 25, 2024
1 parent 9b0a0bf commit c34a746
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
9 changes: 5 additions & 4 deletions pkg/chain/contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/LiskHQ/op-fault-detector/pkg/encoding"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/ethclient"

"github.com/ethereum-optimism/optimism/op-bindings/bindings"
Expand Down Expand Up @@ -84,9 +85,9 @@ func (oc *OracleAccessor) GetL2Output(index *big.Int) (L2Output, error) {
}

return L2Output{
OutputRoot: "0x" + common.Bytes2Hex(l2Output.OutputRoot[:]),
L1Timestamp: encoding.ConvertBigIntToUint64(l2Output.Timestamp),
L2BlockNumber: encoding.ConvertBigIntToUint64(l2Output.L2BlockNumber),
L2OutputIndex: encoding.ConvertBigIntToUint64(index),
OutputRoot: hexutil.Encode(l2Output.OutputRoot[:]),
L1Timestamp: encoding.MustConvertBigIntToUint64(l2Output.Timestamp),
L2BlockNumber: encoding.MustConvertBigIntToUint64(l2Output.L2BlockNumber),
L2OutputIndex: encoding.MustConvertBigIntToUint64(index),
}, nil
}
13 changes: 8 additions & 5 deletions pkg/encoding/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@ package encoding

import "math/big"

// ConvertBigIntToUint64 converts big integer to integer.
func ConvertBigIntToUint64(value *big.Int) uint64 {
valueToString, _ := new(big.Int).SetString(value.String(), 10)
// MustConvertBigIntToUint64 converts big integer to integer.
func MustConvertBigIntToUint64(value *big.Int) uint64 {
valueToString, ok := new(big.Int).SetString(value.String(), 10)
if !ok {
panic("error while converting big integer to integer")
}
return valueToString.Uint64()
}

// ConvertUint64ToBigInt converts integer to big integer.
func ConvertUint64ToBigInt(value uint64) *big.Int {
// MustConvertUint64ToBigInt converts integer to big integer.
func MustConvertUint64ToBigInt(value uint64) *big.Int {
return new(big.Int).SetUint64(value)
}
8 changes: 4 additions & 4 deletions pkg/encoding/encoding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@ import (
"github.com/stretchr/testify/assert"
)

func TestConvertBigIntToUint64(t *testing.T) {
func TestMustConvertBigIntToUint64(t *testing.T) {
assert := assert.New(t)

bigIntInput := big.NewInt(1000)
const expectedOutput uint64 = 1000
result := ConvertBigIntToUint64(bigIntInput)
result := MustConvertBigIntToUint64(bigIntInput)
assert.Equal(expectedOutput, result)
}

func TestConvertUint64ToBigInt(t *testing.T) {
func TestMustConvertUint64ToBigInt(t *testing.T) {
assert := assert.New(t)

const uint64Output uint64 = 1000
expectedOutput := big.NewInt(1000)
result := ConvertUint64ToBigInt(uint64Output)
result := MustConvertUint64ToBigInt(uint64Output)
assert.Equal(expectedOutput, result)
}

0 comments on commit c34a746

Please sign in to comment.