-
Notifications
You must be signed in to change notification settings - Fork 195
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
feat(eth-rpc): Conversion types and functions between Ethereum txs and blocks and Tendermint ones. #1856
Merged
Merged
feat(eth-rpc): Conversion types and functions between Ethereum txs and blocks and Tendermint ones. #1856
Changes from 12 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
1a05061
feat(eth-pubsub): Implement in-memory EventBus for real-time topic ma…
Unique-Divine 36730c5
feat(eth-rpc): Conversion types and functions between Ethereum txs an…
Unique-Divine 176b6c6
chore: linter
Unique-Divine ac0701a
test(eth-rpc): more tests for types dir
Unique-Divine 372df12
ci: add CODECOV_TOKEN env var to secrets
Unique-Divine fe913dc
test,refactor(eth): remove unnecessary nesting + more tests
Unique-Divine 31bb3bb
Merge branch 'main' into ud/evm
Unique-Divine c3a6215
Merge branch 'ud/evm' into ud/evm-rpc
Unique-Divine a336983
refactor(eth): rpc/types -> rpc
Unique-Divine b32d385
refactor(eth): evm/types -> evm
Unique-Divine bfac1e8
refactor(eth): ethtypes -> eth
Unique-Divine 4f28f8f
test(eth): eip712 more tests
Unique-Divine 433780d
Merge branch 'main' into ud/evm-rpc
Unique-Divine 14f8a2c
test(eth): more tests
Unique-Divine db03210
test(eth-rpc): more tests
Unique-Divine 045cf6d
Merge branch 'main' into ud/evm-rpc
Unique-Divine File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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,101 @@ | ||
package eth | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/suite" | ||
|
||
codectypes "github.com/cosmos/cosmos-sdk/codec/types" | ||
sdktx "github.com/cosmos/cosmos-sdk/types/tx" | ||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" | ||
) | ||
|
||
type CodecTestSuite struct { | ||
suite.Suite | ||
} | ||
|
||
func TestCodecSuite(t *testing.T) { | ||
suite.Run(t, new(CodecTestSuite)) | ||
} | ||
|
||
func (suite *CodecTestSuite) TestRegisterInterfaces() { | ||
type ProtoNameInfo struct { | ||
ProtoName string | ||
Interface interface{} | ||
WantImpls []string | ||
} | ||
protoInfos := []ProtoNameInfo{ | ||
{ | ||
ProtoName: "cosmos.auth.v1beta1.AccountI", | ||
Interface: new(authtypes.AccountI), | ||
WantImpls: []string{ | ||
"/eth.types.v1.EthAccount", | ||
"/cosmos.auth.v1beta1.BaseAccount", | ||
"/cosmos.auth.v1beta1.ModuleAccount", | ||
}, | ||
}, | ||
{ | ||
ProtoName: "cosmos.auth.v1beta1.GenesisAccount", | ||
Interface: new(authtypes.GenesisAccount), | ||
WantImpls: []string{ | ||
"/eth.types.v1.EthAccount", | ||
"/cosmos.auth.v1beta1.BaseAccount", | ||
"/cosmos.auth.v1beta1.ModuleAccount", | ||
}, | ||
}, | ||
{ | ||
ProtoName: "cosmos.tx.v1beta1.TxExtensionOptionI", | ||
Interface: new(sdktx.TxExtensionOptionI), | ||
WantImpls: []string{ | ||
"/eth.types.v1.ExtensionOptionsWeb3Tx", | ||
"/eth.types.v1.ExtensionOptionDynamicFeeTx", | ||
}, | ||
}, | ||
} | ||
|
||
// ------------------------------------------- | ||
// Case 1: Setup: Register all interfaces under test | ||
// ------------------------------------------- | ||
registry := codectypes.NewInterfaceRegistry() | ||
for _, protoInfo := range protoInfos { | ||
registry.RegisterInterface(protoInfo.ProtoName, protoInfo.Interface) | ||
} | ||
RegisterInterfaces(registry) | ||
authtypes.RegisterInterfaces(registry) | ||
sdktx.RegisterInterfaces(registry) | ||
|
||
// Test: Assert that all expected protobuf interface implementations are | ||
// registered (base + Ethereum) | ||
for _, protoInfo := range protoInfos { | ||
gotImpls := registry.ListImplementations(protoInfo.ProtoName) | ||
suite.Require().ElementsMatch(protoInfo.WantImpls, gotImpls) | ||
} | ||
|
||
// ------------------------------------------- | ||
// Case 2: Setup: Register only eth interfaces | ||
// ------------------------------------------- | ||
registry = codectypes.NewInterfaceRegistry() | ||
for _, protoInfo := range protoInfos { | ||
registry.RegisterInterface(protoInfo.ProtoName, protoInfo.Interface) | ||
} | ||
RegisterInterfaces(registry) | ||
|
||
// Test: Assert that all expected protobuf interface implementations are | ||
// registered (Ethereum only) | ||
for _, protoInfo := range protoInfos { | ||
gotImpls := registry.ListImplementations(protoInfo.ProtoName) | ||
wantImpls := filterImplsForEth(protoInfo.WantImpls) | ||
suite.Require().ElementsMatch(wantImpls, gotImpls) | ||
} | ||
} | ||
|
||
func filterImplsForEth(implTypeUrls []string) []string { | ||
typeUrls := []string{} | ||
for _, typeUrl := range implTypeUrls { | ||
if strings.Contains(typeUrl, "eth") { | ||
typeUrls = append(typeUrls, typeUrl) | ||
} | ||
} | ||
return typeUrls | ||
} | ||
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function
filterImplsForEth
is used to filter implementations. Consider adding a test specifically for this function to ensure its correctness across a range of inputs.Would you like me to help by creating a test case for the
filterImplsForEth
function?