Skip to content

Commit

Permalink
Add test case
Browse files Browse the repository at this point in the history
  • Loading branch information
yukaitu-cb committed Jun 7, 2022
1 parent 4986258 commit df207a7
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
3 changes: 2 additions & 1 deletion service/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ func ChecksumAddress(address string) (string, bool) {

// isPChain checks network identifier to make sure sub-network identifier set to "P"
func isPChain(networkIdentifier *types.NetworkIdentifier) bool {
if networkIdentifier.SubNetworkIdentifier != nil &&
if networkIdentifier != nil &&
networkIdentifier.SubNetworkIdentifier != nil &&
networkIdentifier.SubNetworkIdentifier.Network == mapper.PChainNetworkIdentifier {
return true
}
Expand Down
2 changes: 1 addition & 1 deletion service/service_construction.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ func (s ConstructionService) ConstructionDerive(
}

chainIDAlias, hrp, getErr := getAliasAndHRP(req.NetworkIdentifier)
if err != nil {
if getErr != nil {
return nil, getErr
}

Expand Down
27 changes: 27 additions & 0 deletions service/service_construction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,33 @@ func TestConstructionDerive(t *testing.T) {
resp.AccountIdentifier.Address,
)
})

t.Run("p-chain address", func(t *testing.T) {
src := "02e0d4392cfa224d4be19db416b3cf62e90fb2b7015e7b62a95c8cb490514943f6"
b, _ := hex.DecodeString(src)

resp, err := service.ConstructionDerive(
context.Background(),
&types.ConstructionDeriveRequest{
NetworkIdentifier: &types.NetworkIdentifier{
Network: mapper.FujiNetwork,
SubNetworkIdentifier: &types.SubNetworkIdentifier{
Network: mapper.PChainNetworkIdentifier,
},
},
PublicKey: &types.PublicKey{
Bytes: b,
CurveType: types.Secp256k1,
},
},
)
assert.Nil(t, err)
assert.Equal(
t,
"P-fuji15f9g0h5xkr5cp47n6u3qxj6yjtzzzrdr23a3tl",
resp.AccountIdentifier.Address,
)
})
}

func forceMarshalMap(t *testing.T, i interface{}) map[string]interface{} {
Expand Down

0 comments on commit df207a7

Please sign in to comment.