Skip to content

Commit

Permalink
return correct networkId at method cfxaddress tocommon (#157)
Browse files Browse the repository at this point in the history
Co-authored-by: dayong <[email protected]>
  • Loading branch information
wangdayong228 and dayong authored Feb 16, 2022
1 parent 611ec5a commit a8dd121
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions types/cfxaddress/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ func (a *Address) ToCommon() (address common.Address, networkID uint32, err erro
return
}
address = common.BytesToAddress(validAddr.hex)
networkID = validAddr.networkID
return
}

Expand Down
16 changes: 16 additions & 0 deletions types/cfxaddress/address_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,3 +237,19 @@ func TestShorten(t *testing.T) {
shorten = addr.GetShortenAddress(true)
assert.Equal(t, "net333:acb...sa4w", shorten)
}

func TestToCommon(t *testing.T) {
cfxaddrStr := "net8889:aakn82yd3x6m4594pt57y29r2jnwfdpdxj4btr9fvw"
cfxaddr, err := NewFromBase32(cfxaddrStr)
if err != nil {
t.Fatal(err)
}
commonAddr, chainId, err := cfxaddr.ToCommon()
if err != nil {
t.Fatal(err)
}

assert.Equal(t, cfxaddr.String(), cfxaddrStr)
assert.Equal(t, commonAddr.String(), "0x12Bf6283CcF8Ad6ffA63f7Da63EDc217228d839A")
assert.Equal(t, chainId, uint32(8889))
}

0 comments on commit a8dd121

Please sign in to comment.