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
|
2023-06-22 18:01:21 +00:00
|
|
|
import ../../helpers
|
2022-05-19 19:56:03 +00:00
|
|
|
import pkg/codex/stores
|
2021-04-07 10:19:00 +00:00
|
|
|
|
2023-06-22 18:01:21 +00:00
|
|
|
checksuite "account protobuf messages":
|
2021-04-07 10:19:00 +00:00
|
|
|
|
2021-05-10 14:21:47 +00:00
|
|
|
let account = Account(address: EthAddress.example)
|
|
|
|
let message = AccountMessage.init(account)
|
2021-04-07 10:19:00 +00:00
|
|
|
|
|
|
|
test "encodes recipient of payments":
|
2021-05-10 14:21:47 +00:00
|
|
|
check message.address == @(account.address.toArray)
|
2021-04-07 10:19:00 +00:00
|
|
|
|
|
|
|
test "decodes recipient of payments":
|
2021-05-10 14:21:47 +00:00
|
|
|
check Account.init(message).?address == account.address.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)
|
2021-05-10 14:21:47 +00:00
|
|
|
check Account.init(incorrect).isNone
|
2021-04-07 12:30:33 +00:00
|
|
|
|
2023-06-22 18:01:21 +00:00
|
|
|
checksuite "channel update messages":
|
2021-04-07 12:30:33 +00:00
|
|
|
|
|
|
|
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
|