-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix regex of several MQTT topics (#1594)
* Fix regex of several MQTT topics * Add invalid_tags tests * Merge spent * Fmt * Add $ back
- Loading branch information
1 parent
e8422a8
commit 7c7b9b7
Showing
5 changed files
with
111 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// Copyright 2023 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
mod topic; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
// Copyright 2023 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use iota_client::{node_api::mqtt::Topic, Error}; | ||
|
||
#[test] | ||
fn valid_topics() { | ||
assert!(Topic::try_new("milestone-info/latest").is_ok()); | ||
assert!(Topic::try_new("milestone-info/confirmed").is_ok()); | ||
assert!(Topic::try_new("milestones").is_ok()); | ||
assert!(Topic::try_new("blocks").is_ok()); | ||
assert!(Topic::try_new("blocks/transaction").is_ok()); | ||
assert!(Topic::try_new("blocks/transaction/tagged-data").is_ok()); | ||
assert!(Topic::try_new("blocks/transaction/tagged-data/0x0123456789abcdef").is_ok()); | ||
assert!(Topic::try_new("blocks/tagged-data").is_ok()); | ||
assert!(Topic::try_new("blocks/tagged-data/0x0123456789abcdef").is_ok()); | ||
assert!( | ||
Topic::try_new("block-metadata/0x36845227a59864ac12d3d2389fcb4ea0bdd1a5d1d4ed464bde3154216c3246c4").is_ok() | ||
); | ||
assert!(Topic::try_new("block-metadata/referenced").is_ok()); | ||
assert!( | ||
Topic::try_new( | ||
"transactions/0x36845227a59864ac12d3d2389fcb4ea0bdd1a5d1d4ed464bde3154216c3246c4/included-block" | ||
) | ||
.is_ok() | ||
); | ||
assert!(Topic::try_new("outputs/0x36845227a59864ac12d3d2389fcb4ea0bdd1a5d1d4ed464bde3154216c3246c40000").is_ok()); | ||
assert!(Topic::try_new("outputs/alias/0xb21517992e96865d5fd90b403fe05fe25c6d4acfb6cdd6e7c9bbfb4266d05151").is_ok()); | ||
assert!(Topic::try_new("outputs/nft/0x38500750eb788bfb89b4589634a82b0cee9c6a9724bafde505ffa1bb875ab0b5").is_ok()); | ||
assert!( | ||
Topic::try_new( | ||
"outputs/foundry/0x08e10a5c7bcfdce48ff500156040f7548ca511d79a6e253a22759116c2ae8c818d0100000000" | ||
) | ||
.is_ok() | ||
); | ||
assert!( | ||
Topic::try_new("outputs/unlock/address/iota1qrwfnskm4f7utdrxqnkfntfqxehtpj8s0kf68zkcwm0yrhuemzjp5sjfw5v") | ||
.is_ok() | ||
); | ||
assert!( | ||
Topic::try_new("outputs/unlock/address/iota1qrwfnskm4f7utdrxqnkfntfqxehtpj8s0kf68zkcwm0yrhuemzjp5sjfw5v/spent") | ||
.is_ok() | ||
); | ||
assert!(Topic::try_new("receipts").is_ok()); | ||
} | ||
|
||
#[test] | ||
fn invalid_tags() { | ||
// Empty. | ||
assert!(matches!( | ||
Topic::try_new("blocks/transaction/tagged-data/0x"), | ||
Err(Error::InvalidMqttTopic(_)) | ||
)); | ||
assert!(matches!( | ||
Topic::try_new("blocks/tagged-data/0x"), | ||
Err(Error::InvalidMqttTopic(_)) | ||
)); | ||
// Uneven. | ||
assert!(matches!( | ||
Topic::try_new("blocks/transaction/tagged-data/0x0123456789abcde"), | ||
Err(Error::InvalidMqttTopic(_)) | ||
)); | ||
assert!(matches!( | ||
Topic::try_new("blocks/tagged-data/0x0123456789abcde"), | ||
Err(Error::InvalidMqttTopic(_)) | ||
)); | ||
// Too large. | ||
assert!(matches!( | ||
Topic::try_new( | ||
"blocks/transaction/tagged-data/0xb21517992e96865d5fd90b403fe05fe25c6d4acfb6cdd6e7c9bbfb4266d05151b21517992e96865d5fd90b403fe05fe25c6d4acfb6cdd6e7c9bbfb4266d05151ff" | ||
), | ||
Err(Error::InvalidMqttTopic(_)) | ||
)); | ||
assert!(matches!( | ||
Topic::try_new( | ||
"blocks/tagged-data/0xb21517992e96865d5fd90b403fe05fe25c6d4acfb6cdd6e7c9bbfb4266d05151b21517992e96865d5fd90b403fe05fe25c6d4acfb6cdd6e7c9bbfb4266d05151ff" | ||
), | ||
Err(Error::InvalidMqttTopic(_)) | ||
)); | ||
// Invalid chars. | ||
assert!(matches!( | ||
Topic::try_new("blocks/transaction/tagged-data/0x012345@789abcde"), | ||
Err(Error::InvalidMqttTopic(_)) | ||
)); | ||
assert!(matches!( | ||
Topic::try_new("blocks/tagged-data/0x012345@789abcde"), | ||
Err(Error::InvalidMqttTopic(_)) | ||
)); | ||
} |