2021-03-04 11:30:32 +01:00
|
|
|
import pkg/nitro/protocol/abi
|
2021-02-22 15:32:48 +01:00
|
|
|
import pkg/nimcrypto
|
2021-03-09 13:18:31 +01:00
|
|
|
import ../basics
|
2021-02-22 15:32:48 +01:00
|
|
|
|
2021-03-09 12:41:51 +01:00
|
|
|
suite "channel definition":
|
2021-02-22 15:32:48 +01:00
|
|
|
|
2021-03-09 12:41:51 +01:00
|
|
|
let channel = ChannelDefinition.example
|
2021-02-22 15:32:48 +01:00
|
|
|
|
|
|
|
|
test "calculates channel id":
|
2021-12-06 15:39:27 +01:00
|
|
|
let encoded = AbiEncoder.encode:
|
|
|
|
|
(channel.chainId, channel.participants, channel.nonce)
|
2021-02-22 15:32:48 +01:00
|
|
|
let hashed = keccak256.digest(encoded).data
|
2021-03-09 14:02:01 +01:00
|
|
|
check getChannelId(channel) == Destination(hashed)
|
2021-02-22 15:32:48 +01:00
|
|
|
|
2021-02-25 09:11:46 +01:00
|
|
|
test "produces same id as javascript implementation":
|
2021-03-09 12:41:51 +01:00
|
|
|
let channel = ChannelDefinition(
|
2021-02-25 09:11:46 +01:00
|
|
|
chainId: 9001.u256,
|
|
|
|
|
nonce: 1,
|
|
|
|
|
participants: @[
|
2022-01-19 09:37:42 +01:00
|
|
|
!EthAddress.init("24b905Dcc8A11C0FE57C2592f3D25f0447402C10")
|
2021-02-25 09:11:46 +01:00
|
|
|
]
|
|
|
|
|
)
|
2021-04-19 16:11:30 +02:00
|
|
|
let expected = !Destination.parse(
|
2021-02-25 09:11:46 +01:00
|
|
|
"4f8cce57e9fe88edaab05234972eaf0c2d183e4f6b175aff293375fbe4d5d7cc"
|
2021-04-19 16:11:30 +02:00
|
|
|
)
|
2021-02-25 09:11:46 +01:00
|
|
|
check getChannelId(channel) == expected
|