Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs cleanup from TIPs #1116

Merged
merged 14 commits into from
Sep 18, 2023
51 changes: 31 additions & 20 deletions sdk/tests/types/slot.rs
Original file line number Diff line number Diff line change
@@ -1,29 +1,40 @@
// Copyright 2023 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

use core::str::FromStr;

use iota_sdk::types::block::{
slot::{RootsId, SlotCommitment, SlotCommitmentId, SlotIndex},
PROTOCOL_VERSION,
};
use iota_sdk::types::block::slot::SlotCommitment;
use packable::PackableExt;

#[test]
fn slot_commitment_id() {
let commitment = SlotCommitment::new(
PROTOCOL_VERSION,
SlotIndex::new(10),
SlotCommitmentId::from_str(
"0x20e07a0ea344707d69a08b90be7ad14eec8326cf2b8b86c8ec23720fab8dcf8ec43a30e4a8cc3f1f",
)
.unwrap(),
RootsId::from_str("0xcf077d276686ba64c0404b9eb2d15556782113c5a1985f262b70f9964d3bbd7f").unwrap(),
5,
10,
// Test from https://github.com/iotaledger/tips-draft/blob/tip46/tips/TIP-0046/tip-0046.md#slot-commitment-id-1
let slot_commitment_json = r#"
DaughterOfMars marked this conversation as resolved.
Show resolved Hide resolved
{
"version":3,
"index":"10",
"previousCommitmentId":"0x4b024b3e47280d05272a7d136f0c464e4e136b734e6c427749413e286162077560652c007e37241a",
"rootsId":"0x75614402763f5f045c040334631b791b4d755d626d504b134a505c001c516549",
"cumulativeWeight":"100",
"referenceManaCost":"6000"
}
"#;

let slot_commitment = serde_json::from_str::<SlotCommitment>(slot_commitment_json).unwrap();
let slot_commitment_bytes = slot_commitment.pack_to_vec();

assert_eq!(
slot_commitment_bytes,
[
3, 10, 0, 0, 0, 0, 0, 0, 0, 75, 2, 75, 62, 71, 40, 13, 5, 39, 42, 125, 19, 111, 12, 70, 78, 78, 19, 107,
DaughterOfMars marked this conversation as resolved.
Show resolved Hide resolved
115, 78, 108, 66, 119, 73, 65, 62, 40, 97, 98, 7, 117, 96, 101, 44, 0, 126, 55, 36, 26, 117, 97, 68, 2,
118, 63, 95, 4, 92, 4, 3, 52, 99, 27, 121, 27, 77, 117, 93, 98, 109, 80, 75, 19, 74, 80, 92, 0, 28, 81,
101, 73, 100, 0, 0, 0, 0, 0, 0, 0, 112, 23, 0, 0, 0, 0, 0, 0
]
);
// TODO: Independently verify this value

let slot_commitment_id = slot_commitment.id().to_string();

assert_eq!(
&commitment.id().to_string(),
"0x2f3ad38aa65d20ede9dcd6a045dccdd3332cf38192c4875308bb77116e8650880a00000000000000"
)
slot_commitment_id,
"0x3a73079f3dbf8c1744ae0b020b9767546e32f5bbbf4c6f0233da7b64f16581f80a00000000000000"
);
}
Loading
You are viewing a condensed version of this merge commit. You can view the full changes here.