-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update contract utility GetL2Output (#18)
* Update output of GetL2Output function * 👌 Applied suggestions
- Loading branch information
1 parent
6a8fa43
commit e35a0d0
Showing
3 changed files
with
64 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,18 @@ | ||
// Package encoding implements all the utils/helpers for encoding incoming/outgoing RPC requests | ||
package encoding | ||
|
||
import "math/big" | ||
|
||
// 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() | ||
} | ||
|
||
// MustConvertUint64ToBigInt converts integer to big integer. | ||
func MustConvertUint64ToBigInt(value uint64) *big.Int { | ||
return new(big.Int).SetUint64(value) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package encoding | ||
|
||
import ( | ||
"math/big" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestMustConvertBigIntToUint64(t *testing.T) { | ||
assert := assert.New(t) | ||
|
||
bigIntInput := big.NewInt(1000) | ||
const expectedOutput uint64 = 1000 | ||
result := MustConvertBigIntToUint64(bigIntInput) | ||
assert.Equal(expectedOutput, result) | ||
} | ||
|
||
func TestMustConvertUint64ToBigInt(t *testing.T) { | ||
assert := assert.New(t) | ||
|
||
const uint64Output uint64 = 1000 | ||
expectedOutput := big.NewInt(1000) | ||
result := MustConvertUint64ToBigInt(uint64Output) | ||
assert.Equal(expectedOutput, result) | ||
} |