Skip to content
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

[BREAKING] client-sdk: Fix ETH address format for test accounts #1352

Merged
merged 1 commit into from
May 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion client-sdk/go/helpers/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func ResolveAddress(net *config.Network, address string) (*types.Address, *ethCo
case addressExplicitTest:
// Test key.
if testKey, ok := testing.TestAccounts[data]; ok {
return &testKey.Address, &testKey.EthAddress, nil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's in testKey.EthAddress if it's not secp256k1eth?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh it's all zeroed out

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we just make the test key struct have a *ethCommon.Address instead then?

return &testKey.Address, testKey.EthAddress, nil
}
return nil, nil, fmt.Errorf("unsupported test account: %s", data)
default:
Expand Down
6 changes: 3 additions & 3 deletions client-sdk/go/testing/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type TestKey struct {
SigSpec types.SignatureAddressSpec

// EthAddress is the corresponding Ethereum address if the key is secp256k1.
EthAddress ethCommon.Address
EthAddress *ethCommon.Address
}

func newEd25519TestKey(seed string) TestKey {
Expand All @@ -48,15 +48,15 @@ func newSecp256k1TestKey(seed string) TestKey {
h := sha3.NewLegacyKeccak256()
untaggedPk, _ := sigspec.Secp256k1Eth.MarshalBinaryUncompressedUntagged()
h.Write(untaggedPk)
var ethAddress [20]byte
var ethAddress ethCommon.Address
copy(ethAddress[:], h.Sum(nil)[32-20:])

return TestKey{
SecretKey: sk[:],
Signer: signer,
Address: types.NewAddress(sigspec),
SigSpec: sigspec,
EthAddress: ethAddress,
EthAddress: &ethAddress,
}
}

Expand Down
10 changes: 5 additions & 5 deletions tools/gen_runtime_vectors/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,15 @@ func main() {
// Valid Deposit: Alice -> Dave's native address on ParaTime
{testing.Dave.Address.String(), nil, context.ChainContext, true},
// Valid Deposit: Alice -> Dave's ethereum address on ParaTime
{testing.Dave.EthAddress.String(), &testing.Dave.EthAddress, context.ChainContext, true},
{testing.Dave.EthAddress.String(), testing.Dave.EthAddress, context.ChainContext, true},
// Valid Deposit: Alice -> Frank's native address on ParaTime
{testing.Frank.Address.String(), nil, context.ChainContext, true},
// Invalid Deposit: orig_to doesn't match transaction's to
{testing.Dave.EthAddress.String(), &unknownEthAddr, context.ChainContext, false},
// Invalid Deposit: chain_context empty
{testing.Dave.EthAddress.String(), &testing.Dave.EthAddress, emptyChainContext, false},
{testing.Dave.EthAddress.String(), testing.Dave.EthAddress, emptyChainContext, false},
// Invalid Deposit: chain_context invalid
{testing.Dave.EthAddress.String(), &testing.Dave.EthAddress, invalidChainContext, false},
{testing.Dave.EthAddress.String(), testing.Dave.EthAddress, invalidChainContext, false},
} {
to, ethTo, _ := helpers.ResolveAddress(nil, t.to)
txBody := &consensusaccounts.Deposit{
Expand Down Expand Up @@ -165,13 +165,13 @@ func main() {
// Valid Transfer: Alice -> Dave's native address on ParaTime
{testing.Dave.Address.String(), nil, testing.Alice, true},
// Valid Transfer: Alice -> Dave's ethereum address on ParaTime
{testing.Dave.EthAddress.String(), &testing.Dave.EthAddress, testing.Alice, true},
{testing.Dave.EthAddress.String(), testing.Dave.EthAddress, testing.Alice, true},
// Valid Transfer: Alice -> Frank's native address on ParaTime
{testing.Frank.Address.String(), nil, testing.Alice, true},
// Valid Transfer: Dave -> Alice's native address on ParaTime
{testing.Alice.Address.String(), nil, testing.Dave, true},
// Valid Transfer: Dave -> Erin's ethereum address on ParaTime
{testing.Erin.EthAddress.String(), &testing.Erin.EthAddress, testing.Dave, true},
{testing.Erin.EthAddress.String(), testing.Erin.EthAddress, testing.Dave, true},
// Valid Transfer: Frank -> Alice's native address on ParaTime
{testing.Alice.Address.String(), nil, testing.Frank, true},
// Valid Transfer: Frank -> Grace native address on ParaTime
Expand Down