Skip to content

Commit

Permalink
fix test data
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Coats committed Jan 17, 2024
1 parent 160d89a commit 76ba15d
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 37 deletions.
6 changes: 3 additions & 3 deletions sdk/src/types/block/output/unlock_condition/timelock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,14 @@ pub(crate) mod dto {
struct TimelockUnlockConditionDto {
#[serde(rename = "type")]
kind: u8,
slot_index: SlotIndex,
slot: SlotIndex,
}

impl From<&TimelockUnlockCondition> for TimelockUnlockConditionDto {
fn from(value: &TimelockUnlockCondition) -> Self {
Self {
kind: TimelockUnlockCondition::KIND,
slot_index: value.slot_index(),
slot: value.slot_index(),
}
}
}
Expand All @@ -75,7 +75,7 @@ pub(crate) mod dto {
type Error = Error;

fn try_from(value: TimelockUnlockConditionDto) -> Result<Self, Error> {
Self::new(value.slot_index).map_err(|_| Error::InvalidField("timelockUnlockCondition"))
Self::new(value.slot).map_err(|_| Error::InvalidField("timelockUnlockCondition"))
}
}

Expand Down
16 changes: 8 additions & 8 deletions sdk/tests/types/fixtures/tip42_account_output.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@
}
],
"features": [
{
"type": 0,
"address": {
"type": 0,
"pubKeyHash": "0xed1484f4d1f7d8c037087fed661dd92faccae1eed3c01182d6fdd6828cea144a"
}
},
{
"type": 6,
"expirySlot": 888,
Expand All @@ -38,13 +45,6 @@
}
],
"immutableFeatures": [
{
"type": 0,
"address": {
"type": 0,
"pubKeyHash": "0xed1484f4d1f7d8c037087fed661dd92faccae1eed3c01182d6fdd6828cea144a"
}
},
{
"type": 2,
"entries": {
Expand All @@ -53,6 +53,6 @@
}
]
},
"bytes": "0x0100c2eb0b00000000402dd91300000000e8494fe353f99783d3771c78798e1e839e649310513770fc6dc974fe53cf1a8600000000010000ed1484f4d1f7d8c037087fed661dd92faccae1eed3c01182d6fdd6828cea144a02067803000002009e05a32eafedefd40298e24ad4f8c334580187f7e9afbd9da13b5ba4007dd1b500a504844f7a0df2c5101d31696593b309040f8660d41035aba508f24c00668b210780d1f00800000000900100000000000019000000ffffffff020000ed1484f4d1f7d8c037087fed661dd92faccae1eed3c01182d6fdd6828cea144a020104696f74610300322e30",
"bytes": "0x0100c2eb0b00000000402dd91300000000e8494fe353f99783d3771c78798e1e839e649310513770fc6dc974fe53cf1a8600000000010000ed1484f4d1f7d8c037087fed661dd92faccae1eed3c01182d6fdd6828cea144a030000ed1484f4d1f7d8c037087fed661dd92faccae1eed3c01182d6fdd6828cea144a067803000002009e05a32eafedefd40298e24ad4f8c334580187f7e9afbd9da13b5ba4007dd1b500a504844f7a0df2c5101d31696593b309040f8660d41035aba508f24c00668b210780d1f00800000000900100000000000019000000ffffffff01020104696f74610300322e30",
"storage_score": 621
}
6 changes: 3 additions & 3 deletions sdk/tests/types/fixtures/tip44_foundry_output.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"output": {
"type": 3,
"amount": "420000000",
"serialNumber": 0,
"serialNumber": 1,
"tokenScheme": {
"type": 0,
"mintedTokens": "0x9c40",
Expand All @@ -27,11 +27,11 @@
},
{
"type": 5,
"id": "0x0817432c5a7a672503480241125e3952414a7a320441080c624c264b004e09614a0000000000",
"id": "0x0817432c5a7a672503480241125e3952414a7a320441080c624c264b004e09614a0100000000",
"amount": "0xa410"
}
]
},
"bytes": "0x0300b10819000000000000000000409c000000000000000000000000000000000000000000000000000000000000102700000000000000000000000000000000000000000000000000000000000050c300000000000000000000000000000000000000000000000000000000000001060817432c5a7a672503480241125e3952414a7a320441080c624c264b004e09614a02020104696f74612e00322e3030303030303030303030303030303030303030303030303030303030303030303030303030303030303030050817432c5a7a672503480241125e3952414a7a320441080c624c264b004e09614a000000000010a400000000000000000000000000000000000000000000000000000000000000",
"bytes": "0x0300b10819000000000100000000409c000000000000000000000000000000000000000000000000000000000000102700000000000000000000000000000000000000000000000000000000000050c300000000000000000000000000000000000000000000000000000000000001060817432c5a7a672503480241125e3952414a7a320441080c624c264b004e09614a02020104696f74612e00322e3030303030303030303030303030303030303030303030303030303030303030303030303030303030303030050817432c5a7a672503480241125e3952414a7a320441080c624c264b004e09614a010000000010a400000000000000000000000000000000000000000000000000000000000000",
"storage_score": 361
}
11 changes: 2 additions & 9 deletions sdk/tests/types/fixtures/tip54_anchor_output.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,6 @@
}
],
"features": [
{
"type": 0,
"address": {
"type": 0,
"pubKeyHash": "0xed1484f4d1f7d8c037087fed661dd92faccae1eed3c01182d6fdd6828cea144a"
}
},
{
"type": 2,
"entries": {
Expand All @@ -45,6 +38,6 @@
}
]
},
"bytes": "0x0200b10819000000002a0000000000000000000000000000000000000000000000000000000000000000000000000000000000000002040817432c5a7a672503480241125e3952414a7a320441080c624c264b004e09614a050817432c5a7a672503480241125e3952414a7a320441080c624c264b004e09614a020000ed1484f4d1f7d8c037087fed661dd92faccae1eed3c01182d6fdd6828cea144a020104696f74610300322e3001020104696f74610300322e30",
"storage_score": 270
"bytes": "0x0200b10819000000002a0000000000000000000000000000000000000000000000000000000000000000000000000000000000000002040817432c5a7a672503480241125e3952414a7a320441080c624c264b004e09614a050817432c5a7a672503480241125e3952414a7a320441080c624c264b004e09614a01020104696f74610300322e3001020104696f74610300322e30",
"storage_score": 236
}
32 changes: 18 additions & 14 deletions sdk/tests/types/storage_score.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
// Copyright 2022 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

use iota_sdk::{
types::block::output::{Output, StorageScore, StorageScoreParameters},
utils::serde::prefix_hex_bytes,
};
use iota_sdk::types::block::output::{Output, StorageScore, StorageScoreParameters};
use packable::PackableExt;
use pretty_assertions::assert_eq;
use serde::Deserialize;

Expand All @@ -20,8 +18,7 @@ fn storage_score_parameters() -> Result<StorageScoreParameters, Box<dyn std::err
#[derive(Deserialize)]
struct OutputFixture {
output: Output,
#[serde(with = "prefix_hex_bytes")]
bytes: Vec<u8>,
bytes: String,
storage_score: u64,
}

Expand All @@ -34,17 +31,24 @@ fn output_fixture(filename: &str) -> Result<OutputFixture, Box<dyn std::error::E
// From https://github.com/iotaledger/tips/blob/tip41/tips/TIP-0041/tip-0041.md#storage-score
#[test]
fn output_storage_score() {
for fixture in [
output_fixture("tip41_basic_output.json").unwrap(),
output_fixture("tip42_account_output.json").unwrap(),
output_fixture("tip43_nft_output.json").unwrap(),
output_fixture("tip44_foundry_output.json").unwrap(),
output_fixture("tip54_anchor_output.json").unwrap(),
output_fixture("tip40_delegation_output.json").unwrap(),
for filename in [
"tip41_basic_output.json",
"tip42_account_output.json",
"tip43_nft_output.json",
"tip44_foundry_output.json",
"tip54_anchor_output.json",
"tip40_delegation_output.json",
] {
let fixture = output_fixture(filename).expect(&format!("failed to deserialize {filename}"));
assert_eq!(
fixture.output.storage_score(storage_score_parameters().unwrap()),
fixture.storage_score
fixture.storage_score,
"storage score mismatch for {filename}"
);
assert_eq!(
prefix_hex::encode(fixture.output.pack_to_vec()),
fixture.bytes,
"byte mismatch for {filename}"
);
}
}

0 comments on commit 76ba15d

Please sign in to comment.