Skip to content

Commit

Permalink
Merge pull request #108 from renproject/fix/fil-undef-address
Browse files Browse the repository at this point in the history
fix(filecoin): catch and return error on undefined address
  • Loading branch information
roynalnaruto authored Jun 28, 2021
2 parents 9f1a2b4 + ccc0b1c commit 46fd194
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
8 changes: 8 additions & 0 deletions chain/filecoin/address.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package filecoin

import (
"fmt"

filaddress "github.com/filecoin-project/go-address"
"github.com/renproject/multichain/api/address"
)
Expand Down Expand Up @@ -32,6 +34,9 @@ func (encoder AddressEncoder) EncodeAddress(raw address.RawAddress) (address.Add
if err != nil {
return address.Address(""), err
}
if addr == filaddress.Undef {
return address.Address(""), fmt.Errorf("encoding address: undefined address=%v", raw)
}
return address.Address(addr.String()), nil
}

Expand All @@ -42,5 +47,8 @@ func (addrDecoder AddressDecoder) DecodeAddress(addr address.Address) (address.R
if err != nil {
return nil, err
}
if rawAddr == filaddress.Undef {
return nil, fmt.Errorf("decoding address: undefined address=%v", addr)
}
return address.RawAddress(rawAddr.Bytes()), nil
}
14 changes: 14 additions & 0 deletions chain/filecoin/address_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,18 @@ var _ = Describe("Address", func() {
})
})
})

Context("when encoding empty address", func() {
It("should fail", func() {
_, err := encoderDecoder.EncodeAddress(address.RawAddress(pack.Bytes([]byte{})))
Expect(err).To(HaveOccurred())
})
})

Context("when decoding empty address", func() {
It("should fail", func() {
_, err := encoderDecoder.DecodeAddress(address.Address(""))
Expect(err).To(HaveOccurred())
})
})
})
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ dmitri.shuralyov.com/html/belt v0.0.0-20180602232347-f7d459c86be0/go.mod h1:JLBr
dmitri.shuralyov.com/service/change v0.0.0-20181023043359-a85b471d5412/go.mod h1:a1inKt/atXimZ4Mv927x+r7UpyzRUf4emIoiiSC2TN4=
dmitri.shuralyov.com/state v0.0.0-20180228185332-28bcc343414c/go.mod h1:0PRwlb0D6DFvNNtx+9ybjezNCa8XF0xaYcETyp6rHWU=
git.apache.org/thrift.git v0.0.0-20180902110319-2566ecd5d999/go.mod h1:fPE2ZNJGynbRyZ4dJvy6G277gSllfV2HJqblrnkyeyg=
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 h1:/vQbFIOMbk2FiG/kXiLl8BRyzTWDw7gX/Hz7Dd5eDMs=
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4/go.mod h1:hN7oaIRCjzsZ2dE+yG5k+rsdt3qcwykqK6HVGcKwsw4=
github.com/99designs/keyring v1.1.3 h1:mEV3iyZWjkxQ7R8ia8GcG97vCX5zQQ7n4o8R2BylwQY=
github.com/99designs/keyring v1.1.3/go.mod h1:657DQuMrBZRtuL/voxVyiyb6zpMehlm5vLB9Qwrv904=
Expand Down

0 comments on commit 46fd194

Please sign in to comment.