mirror of
https://github.com/status-im/nim-rlp.git
synced 2025-01-09 13:55:50 +00:00
Fixed listElem
This commit is contained in:
parent
61da7236f4
commit
069d73df31
2
rlp.nim
2
rlp.nim
@ -247,7 +247,7 @@ iterator items*(self: var Rlp): var Rlp =
|
|||||||
position = elemEnd
|
position = elemEnd
|
||||||
|
|
||||||
proc listElem*(self: Rlp, i: int): Rlp =
|
proc listElem*(self: Rlp, i: int): Rlp =
|
||||||
let payload = bytes.slice payloadOffset()
|
let payload = bytes.slice(position + payloadOffset())
|
||||||
result = rlpFromBytes payload
|
result = rlpFromBytes payload
|
||||||
var pos = 0
|
var pos = 0
|
||||||
while pos < i and result.hasData:
|
while pos < i and result.hasData:
|
||||||
|
@ -70,6 +70,18 @@ test "encode and decode lists":
|
|||||||
rlp.listElem(1).toString == "Lorem ipsum dolor sit amet"
|
rlp.listElem(1).toString == "Lorem ipsum dolor sit amet"
|
||||||
rlp.listElem(2).toString == "Donec ligula tortor, egestas eu est vitae"
|
rlp.listElem(2).toString == "Donec ligula tortor, egestas eu est vitae"
|
||||||
|
|
||||||
|
test "nested lists":
|
||||||
|
let listBytes = encode([[1, 2, 3], [5, 6, 7]])
|
||||||
|
let listRlp = rlpFromBytes listBytes
|
||||||
|
let sublistRlp0 = listRlp.listElem(0)
|
||||||
|
let sublistRlp1 = listRlp.listElem(1)
|
||||||
|
check sublistRlp0.listElem(0).toInt(int) == 1
|
||||||
|
check sublistRlp0.listElem(1).toInt(int) == 2
|
||||||
|
check sublistRlp0.listElem(2).toInt(int) == 3
|
||||||
|
check sublistRlp1.listElem(0).toInt(int) == 5
|
||||||
|
check sublistRlp1.listElem(1).toInt(int) == 6
|
||||||
|
check sublistRlp1.listElem(2).toInt(int) == 7
|
||||||
|
|
||||||
test "encoding length":
|
test "encoding length":
|
||||||
let listBytes = encode([1,2,3,4,5])
|
let listBytes = encode([1,2,3,4,5])
|
||||||
let listRlp = rlpFromBytes listBytes
|
let listRlp = rlpFromBytes listBytes
|
||||||
|
Loading…
x
Reference in New Issue
Block a user