-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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: EthAPI: Add EthAddressToFilecoinAddress #10286
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package itests | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/filecoin-project/go-state-types/builtin" | ||
|
||
"github.com/filecoin-project/lotus/chain/types" | ||
"github.com/filecoin-project/lotus/chain/types/ethtypes" | ||
"github.com/filecoin-project/lotus/chain/wallet/key" | ||
"github.com/filecoin-project/lotus/itests/kit" | ||
) | ||
|
||
func TestEthAddressToFilecoinAddress(t *testing.T) { | ||
client, _, _ := kit.EnsembleMinimal(t, kit.MockProofs(), kit.ThroughRPC()) | ||
|
||
ctx, cancel := context.WithTimeout(context.Background(), time.Minute) | ||
defer cancel() | ||
|
||
secpKey, err := key.GenerateKey(types.KTDelegated) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this still a secpKey since the type here is delegated? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, "Delegated" signature keys are solely secp. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For my own knowledge, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So this is a little gnarly. Secp addresses correspond to secp keys. Delegated addresses today solely correspond to secp keys. They will eventually support other kinds of signatures, such as "account abstraction". So why do we have the KTDelegated sigtype today? It's because the Lotus keystore couples the stored key with its address representation. So when working with keys, we need to treat delegated sigtypes differently from secp sigtypes (eg. here). |
||
require.NoError(t, err) | ||
|
||
filecoinKeyAddr, err := client.WalletImport(ctx, &secpKey.KeyInfo) | ||
require.NoError(t, err) | ||
|
||
ethAddr, err := ethtypes.EthAddressFromFilecoinAddress(filecoinKeyAddr) | ||
require.NoError(t, err) | ||
|
||
apiFilAddr, err := client.EthAddressToFilecoinAddress(ctx, ethAddr) | ||
require.NoError(t, err) | ||
|
||
require.Equal(t, filecoinKeyAddr, apiFilAddr) | ||
|
||
filecoinIdArr := builtin.StorageMarketActorAddr | ||
ethAddr, err = ethtypes.EthAddressFromFilecoinAddress(filecoinIdArr) | ||
require.NoError(t, err) | ||
|
||
apiFilAddr, err = client.EthAddressToFilecoinAddress(ctx, ethAddr) | ||
require.NoError(t, err) | ||
|
||
require.Equal(t, filecoinIdArr, apiFilAddr) | ||
|
||
} |
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.
Don't have a strong opinion on this but maybe move this to fevm_address_test.go and rename that file to eth_address_test.go since that name does cover this domain
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.
I think we need to have a dedicated test suite for the EthAPI, my hope is that this will be the start of that.
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.
Fair point but the Eth API seems very large to stick in a single file?