-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(eth-rpc): Conversion types and functions between Ethereum txs an…
…d blocks and Tendermint ones. (#1856) * feat(eth-pubsub): Implement in-memory EventBus for real-time topic management and event distribution * feat(eth-rpc): Conversion types and functions between Ethereum txs and blocks and Tendermint ones. * chore: linter * test(eth-rpc): more tests for types dir * ci: add CODECOV_TOKEN env var to secrets * test,refactor(eth): remove unnecessary nesting + more tests * refactor(eth): rpc/types -> rpc * refactor(eth): evm/types -> evm * refactor(eth): ethtypes -> eth * test(eth): eip712 more tests * test(eth): more tests * test(eth-rpc): more tests
- Loading branch information
1 parent
ffcea96
commit 2bd7a14
Showing
90 changed files
with
4,248 additions
and
852 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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,5 +1,5 @@ | ||
// Copyright (c) 2023-2024 Nibi, Inc. | ||
package types | ||
package eth | ||
|
||
import ( | ||
"bytes" | ||
|
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,145 @@ | ||
package eth_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/NibiruChain/nibiru/eth" | ||
"github.com/NibiruChain/nibiru/x/common/testutil" | ||
) | ||
|
||
func TestIsEmptyHash(t *testing.T) { | ||
testCases := []struct { | ||
name string | ||
hash string | ||
expEmpty bool | ||
}{ | ||
{ | ||
"empty string", "", true, | ||
}, | ||
{ | ||
"zero hash", common.Hash{}.String(), true, | ||
}, | ||
|
||
{ | ||
"non-empty hash", common.BytesToHash([]byte{1, 2, 3, 4}).String(), false, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
require.Equal(t, tc.expEmpty, eth.IsEmptyHash(tc.hash), tc.name) | ||
} | ||
} | ||
|
||
func TestIsZeroAddress(t *testing.T) { | ||
testCases := []struct { | ||
name string | ||
address string | ||
expEmpty bool | ||
}{ | ||
{ | ||
"empty string", "", true, | ||
}, | ||
{ | ||
"zero address", common.Address{}.String(), true, | ||
}, | ||
|
||
{ | ||
"non-empty address", common.BytesToAddress([]byte{1, 2, 3, 4}).String(), false, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
require.Equal(t, tc.expEmpty, eth.IsZeroAddress(tc.address), tc.name) | ||
} | ||
} | ||
|
||
func TestValidateAddress(t *testing.T) { | ||
testCases := []struct { | ||
name string | ||
address string | ||
expError bool | ||
}{ | ||
{ | ||
"empty string", "", true, | ||
}, | ||
{ | ||
"invalid address", "0x", true, | ||
}, | ||
{ | ||
"zero address", common.Address{}.String(), false, | ||
}, | ||
{ | ||
"valid address", testutil.NewEthAddr().Hex(), false, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
err := eth.ValidateAddress(tc.address) | ||
|
||
if tc.expError { | ||
require.Error(t, err, tc.name) | ||
} else { | ||
require.NoError(t, err, tc.name) | ||
} | ||
} | ||
} | ||
|
||
func TestValidateNonZeroAddress(t *testing.T) { | ||
testCases := []struct { | ||
name string | ||
address string | ||
expError bool | ||
}{ | ||
{ | ||
"empty string", "", true, | ||
}, | ||
{ | ||
"invalid address", "0x", true, | ||
}, | ||
{ | ||
"zero address", common.Address{}.String(), true, | ||
}, | ||
{ | ||
"valid address", testutil.NewEthAddr().Hex(), false, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
err := eth.ValidateNonZeroAddress(tc.address) | ||
|
||
if tc.expError { | ||
require.Error(t, err, tc.name) | ||
} else { | ||
require.NoError(t, err, tc.name) | ||
} | ||
} | ||
} | ||
|
||
func TestSafeInt64(t *testing.T) { | ||
testCases := []struct { | ||
name string | ||
value uint64 | ||
expError bool | ||
}{ | ||
{ | ||
"no overflow", 10, false, | ||
}, | ||
{ | ||
"overflow", 18446744073709551615, true, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
value, err := eth.SafeInt64(tc.value) | ||
if tc.expError { | ||
require.Error(t, err, tc.name) | ||
continue | ||
} | ||
|
||
require.NoError(t, err, tc.name) | ||
require.Equal(t, int64(tc.value), value, tc.name) | ||
} | ||
} |
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,5 +1,5 @@ | ||
// Copyright (c) 2023-2024 Nibi, Inc. | ||
package types | ||
package eth | ||
|
||
import ( | ||
"fmt" | ||
|
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
Oops, something went wrong.