2021-03-23 10:04:51 +02:00
|
|
|
{.used.}
|
|
|
|
|
2020-11-13 14:02:17 +08:00
|
|
|
import
|
2022-11-04 10:52:08 +01:00
|
|
|
std/tables,
|
2022-11-21 09:36:41 +01:00
|
|
|
stew/shims/net as stewNet,
|
2021-03-26 10:52:04 +01:00
|
|
|
testutils/unittests,
|
2022-11-21 09:36:41 +01:00
|
|
|
chronos,
|
|
|
|
chronicles,
|
2020-11-21 13:31:48 +08:00
|
|
|
libp2p/switch,
|
|
|
|
libp2p/protobuf/minprotobuf,
|
2022-11-08 16:10:23 +01:00
|
|
|
libp2p/stream/bufferstream,
|
|
|
|
libp2p/stream/connection,
|
|
|
|
libp2p/crypto/crypto,
|
|
|
|
libp2p/crypto/secp,
|
2022-09-20 11:39:52 +02:00
|
|
|
eth/keys
|
|
|
|
import
|
2022-11-08 16:10:23 +01:00
|
|
|
../../waku/v2/node/waku_node,
|
2020-11-23 10:27:45 +08:00
|
|
|
../../waku/v2/protocol/waku_swap/waku_swap,
|
2021-10-06 14:29:08 +02:00
|
|
|
../../waku/v2/utils/peers,
|
2022-11-21 09:36:41 +01:00
|
|
|
../test_helpers,
|
2022-10-21 15:01:39 +02:00
|
|
|
./utils,
|
|
|
|
./testlib/common
|
2022-09-21 18:27:40 +02:00
|
|
|
|
2020-11-13 14:02:17 +08:00
|
|
|
|
|
|
|
procSuite "Waku SWAP Accounting":
|
|
|
|
test "Handshake Encode/Decode":
|
|
|
|
let
|
|
|
|
beneficiary = @[byte 0, 1, 2]
|
|
|
|
handshake = Handshake(beneficiary: beneficiary)
|
|
|
|
pb = handshake.encode()
|
|
|
|
|
|
|
|
let decodedHandshake = Handshake.init(pb.buffer)
|
|
|
|
|
|
|
|
check:
|
|
|
|
decodedHandshake.isErr == false
|
|
|
|
decodedHandshake.get().beneficiary == beneficiary
|
|
|
|
|
|
|
|
test "Cheque Encode/Decode":
|
|
|
|
let
|
|
|
|
amount = 1'u32
|
|
|
|
date = 9000'u32
|
|
|
|
beneficiary = @[byte 0, 1, 2]
|
|
|
|
cheque = Cheque(beneficiary: beneficiary, amount: amount, date: date)
|
|
|
|
pb = cheque.encode()
|
|
|
|
|
|
|
|
let decodedCheque = Cheque.init(pb.buffer)
|
|
|
|
|
|
|
|
check:
|
|
|
|
decodedCheque.isErr == false
|
|
|
|
decodedCheque.get() == cheque
|