Tomasz Bekas 2396c4d76d
Blockexchange uses merkle root and index to fetch blocks (#566)
* Blockexchange uses merkle root and index to fetch blocks

* Links the network store getTree to the local store.

* Update codex/stores/repostore.nim

Co-authored-by: Dmitriy Ryajov <dryajov@gmail.com>
Signed-off-by: Tomasz Bekas <tomasz.bekas@gmail.com>

* Rework erasure.nim to include recent cleanup

* Revert accidential changes to lib versions

* Addressing review comments

* Storing proofs instead of trees

* Fix a comment

* Fix broken tests

* Fix for broken testerasure.nim

* Addressing PR comments

---------

Signed-off-by: Tomasz Bekas <tomasz.bekas@gmail.com>
Co-authored-by: benbierens <thatbenbierens@gmail.com>
Co-authored-by: Dmitriy Ryajov <dryajov@gmail.com>
2023-11-14 13:02:17 +01:00

44 lines
1.2 KiB
Nim

import pkg/asynctest
import pkg/chronos
import pkg/codex/blockexchange/protobuf/presence
import ../../examples
import ../../helpers
checksuite "block presence protobuf messages":
let
cid = Cid.example
address = BlockAddress(leaf: false, cid: cid)
price = UInt256.example
presence = Presence(address: address, have: true, price: price)
message = PresenceMessage.init(presence)
test "encodes have/donthave":
var presence = presence
presence.have = true
check PresenceMessage.init(presence).`type` == Have
presence.have = false
check PresenceMessage.init(presence).`type` == DontHave
test "encodes price":
check message.price == @(price.toBytesBE)
test "decodes CID":
check Presence.init(message).?address == address.some
test "decodes have/donthave":
var message = message
message.`type` = BlockPresenceType.Have
check Presence.init(message).?have == true.some
message.`type` = BlockPresenceType.DontHave
check Presence.init(message).?have == false.some
test "decodes price":
check Presence.init(message).?price == price.some
test "fails to decode when price is invalid":
var incorrect = message
incorrect.price.add(0)
check Presence.init(incorrect).isNone