2021-04-07 10:19:00 +00:00
|
|
|
import pkg/asynctest
|
|
|
|
import pkg/chronos
|
2021-04-07 12:30:33 +00:00
|
|
|
import pkg/stew/byteutils
|
2021-04-07 10:19:00 +00:00
|
|
|
import ../../examples
|
|
|
|
import ../../../../dagger/bitswap/protobuf/payments
|
|
|
|
|
|
|
|
suite "pricing protobuf messages":
|
|
|
|
|
|
|
|
let address = EthAddress.example
|
|
|
|
let price = UInt256.example
|
2021-04-22 08:11:24 +00:00
|
|
|
let pricing = Pricing(address: address, price: price)
|
2021-04-07 10:19:00 +00:00
|
|
|
let message = PricingMessage.init(pricing)
|
|
|
|
|
|
|
|
test "encodes recipient of payments":
|
|
|
|
check message.address == @(address.toArray)
|
|
|
|
|
|
|
|
test "encodes price per byte":
|
|
|
|
check message.price == @(price.toBytesBE)
|
|
|
|
|
|
|
|
test "decodes recipient of payments":
|
2021-04-12 14:41:47 +00:00
|
|
|
check Pricing.init(message).?address == address.some
|
2021-04-07 10:19:00 +00:00
|
|
|
|
|
|
|
test "decodes price":
|
2021-04-12 14:41:47 +00:00
|
|
|
check Pricing.init(message).?price == price.some
|
2021-04-07 10:19:00 +00:00
|
|
|
|
|
|
|
test "fails to decode when address has incorrect number of bytes":
|
|
|
|
var incorrect = message
|
|
|
|
incorrect.address.del(0)
|
|
|
|
check Pricing.init(incorrect).isNone
|
|
|
|
|
|
|
|
test "fails to decode when price has too many bytes":
|
|
|
|
var incorrect = message
|
|
|
|
incorrect.price = newSeq[byte](33)
|
|
|
|
check Pricing.init(incorrect).isNone
|
2021-04-07 12:30:33 +00:00
|
|
|
|
|
|
|
suite "channel update messages":
|
|
|
|
|
|
|
|
let state = SignedState.example
|
|
|
|
let update = StateChannelUpdate.init(state)
|
|
|
|
|
|
|
|
test "encodes a nitro signed state":
|
|
|
|
check update.update == state.toJson.toBytes
|
|
|
|
|
|
|
|
test "decodes a channel update":
|
|
|
|
check SignedState.init(update) == state.some
|
|
|
|
|
|
|
|
test "fails to decode incorrect channel update":
|
|
|
|
var incorrect = update
|
|
|
|
incorrect.update.del(0)
|
|
|
|
check SignedState.init(incorrect).isNone
|