2021-10-09 11:22:03 +00:00
|
|
|
# Nimbus
|
|
|
|
# Copyright (c) 2021 Status Research & Development GmbH
|
|
|
|
# Licensed and distributed under either of
|
|
|
|
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
|
|
|
|
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
|
|
|
|
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
|
|
|
|
|
|
|
{.used.}
|
|
|
|
|
|
|
|
import
|
2021-12-15 07:48:56 +00:00
|
|
|
unittest2, stew/byteutils,
|
2021-10-09 11:22:03 +00:00
|
|
|
../network/history/history_content
|
|
|
|
|
|
|
|
suite "History ContentKey Encodings":
|
|
|
|
test "ContentKey":
|
2021-12-15 07:48:56 +00:00
|
|
|
var blockHash: BlockHash
|
|
|
|
blockHash.data = hexToByteArray[sizeof(BlockHash)](
|
|
|
|
"0x0100000000000000000000000000000000000000000000000000000000000000")
|
|
|
|
let contentKey =
|
|
|
|
ContentKey(chainId: 1'u16, contentType: BlockBody, blockHash: blockHash)
|
2021-10-09 11:22:03 +00:00
|
|
|
|
|
|
|
let encoded = encode(contentKey)
|
|
|
|
check encoded.asSeq.toHex ==
|
2021-12-15 07:48:56 +00:00
|
|
|
"0100020100000000000000000000000000000000000000000000000000000000000000"
|
2021-10-09 11:22:03 +00:00
|
|
|
let decoded = decode(encoded)
|
|
|
|
check decoded.isSome()
|
|
|
|
|
2021-12-15 07:48:56 +00:00
|
|
|
let contentKeyDecoded = decoded.get()
|
2021-10-09 11:22:03 +00:00
|
|
|
check:
|
2021-12-15 07:48:56 +00:00
|
|
|
contentKeyDecoded.chainId == contentKey.chainId
|
|
|
|
contentKeyDecoded.contentType == contentKey.contentType
|
|
|
|
contentKeyDecoded.blockHash == contentKey.blockHash
|
|
|
|
|
|
|
|
toContentId(contentKey).toHex() ==
|
|
|
|
"36a55e9aa5125c5fecc16bcb0234d9d3d6065eabc890c0d3b24d413d6ae9f9da"
|