Fix MultiAddress.protoAddress() bug for fixed arrays.
Add tests for it.
This commit is contained in:
parent
8a22c073c7
commit
290ba712e9
|
@ -482,7 +482,7 @@ proc protoArgument*(ma: MultiAddress, value: var openarray[byte]): int =
|
|||
if proto.kind == Fixed:
|
||||
result = proto.size
|
||||
if len(value) >= result:
|
||||
if vb.data.readArray(value) != proto.size:
|
||||
if vb.data.readArray(value.toOpenArray(0, proto.size - 1)) != proto.size:
|
||||
raise newException(MultiAddressError, "Decoding protocol error")
|
||||
elif proto.kind in {Length, Path}:
|
||||
if vb.data.readSeq(buffer) == -1:
|
||||
|
|
|
@ -391,3 +391,11 @@ suite "MultiAddress test suite":
|
|||
discard MultiAddress.init(multiCodec("udp"), -1)
|
||||
discard MultiAddress.init(multiCodec("dccp"), -1)
|
||||
discard MultiAddress.init(multiCodec("sctp"), -1)
|
||||
|
||||
test "MultiAddress protoAddress(fixed) test":
|
||||
var
|
||||
address_v4: array[4, byte]
|
||||
address_v6: array[16, byte]
|
||||
check:
|
||||
MultiAddress.init("/ip4/0.0.0.0").protoAddress() == address_v4
|
||||
MultiAddress.init("/ip6/::0").protoAddress() == address_v6
|
||||
|
|
Loading…
Reference in New Issue