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

Reenable tests and cleanup #2104

Merged
merged 4 commits into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions bindings/python/iota_sdk/types/output_id_proof.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class OutputCommitmentProofType(IntEnum):
Attributes:
HashableNode (0): Denotes a HashableNode.
LeafHash (1): Denotes a LeafHash.
Valuehash (2): Denotes a Valuehash.
ValueHash (2): Denotes a ValueHash.
"""
HashableNode = 0
LeafHash = 1
Expand Down Expand Up @@ -88,7 +88,9 @@ class OutputIdProof:
slot: SlotIndex
output_index: int
transaction_commitment: HexStr
output_commitment_proof: OutputCommitmentProof
output_commitment_proof: OutputCommitmentProof = field(metadata=config(
decoder=deserialize_proof
))


OutputCommitmentProof: TypeAlias = Union[HashableNode, LeafHash, ValueHash]
13 changes: 5 additions & 8 deletions bindings/python/tests/test_api_responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from typing import Generic, TypeVar
from json import load, loads, dumps
from iota_sdk import RoutesResponse, CongestionResponse, ManaRewardsResponse, ValidatorResponse, CommitteeResponse, IssuanceBlockHeaderResponse, Block, BlockMetadataResponse, BlockWithMetadataResponse, OutputMetadata, OutputResponse, TransactionMetadataResponse, SlotCommitment, UtxoChangesResponse, UtxoChangesFullResponse
from iota_sdk import RoutesResponse, CongestionResponse, OutputWithMetadataResponse, ManaRewardsResponse, ValidatorsResponse, ValidatorResponse, InfoResponse, CommitteeResponse, IssuanceBlockHeaderResponse, Block, BlockMetadataResponse, BlockWithMetadataResponse, OutputMetadata, OutputResponse, TransactionMetadataResponse, SlotCommitment, UtxoChangesResponse, UtxoChangesFullResponse


base_path = '../../sdk/tests/types/api/fixtures/'
Expand All @@ -27,16 +27,14 @@ def test_api_response(cls_type: Generic[T], path: str):
# GET /api/routes
test_api_response(RoutesResponse, "get-routes-response-example.json")
# GET /api/core/v3/info
# TODO: enable when the fixture is updated https://github.com/iotaledger/iota-sdk/issues/2015
# test_api_response(InfoResponse, "get-info-response-example.json")
test_api_response(InfoResponse, "get-info-response-example.json")
# GET /api/core/v3/accounts/{bech32Address}/congestion
test_api_response(CongestionResponse,
"get-congestion-estimate-response-example.json")
# GET /api/core/v3/rewards/{outputId}
test_api_response(ManaRewardsResponse, "get-mana-rewards-example.json")
# GET /api/core/v3/validators
# TODO: enable when TIP is updated
# test_api_response(ValidatorsResponse, "get-validators-example.json")
test_api_response(ValidatorsResponse, "get-validators-example.json")
# GET /api/core/v3/validators/{bech32Address}
test_api_response(ValidatorResponse, "get-validator-example.json")
# GET /api/core/v3/committee
Expand Down Expand Up @@ -73,9 +71,8 @@ def test_api_response(cls_type: Generic[T], path: str):
test_api_response(
OutputMetadata, "get-output-metadata-by-id-response-spent-example.json")
# GET /api/core/v3/outputs/{outputId}/full
# TODO: enable when OutputWithMetadata is updated with OutputIdProof https://github.com/iotaledger/iota-sdk/issues/2021
# test_api_response(OutputWithMetadata,
# "get-full-output-metadata-example.json")
test_api_response(OutputWithMetadataResponse,
"get-full-output-metadata-example.json")
# GET /api/core/v3/transactions/{transactionId}/metadata
test_api_response(TransactionMetadataResponse,
"get-transaction-metadata-by-id-response-example.json")
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/types/block/core/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ impl Packable for Block {
};

if block_len > Self::LENGTH_MAX {
return Err(UnpackError::Packable(BlockError::InvalidBlockLength(block_len).into()));
return Err(UnpackError::Packable(BlockError::InvalidBlockLength(block_len)));
}
}

Expand Down
2 changes: 1 addition & 1 deletion sdk/src/types/block/output/delegation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ pub struct DelegationOutput {
delegation_id: DelegationId,
/// Account address of the validator to which this output is delegating.
#[packable(verify_with = verify_validator_address_packable)]
#[packable(unpack_error_with = |err| OutputError::ValidatorAddress(err))]
#[packable(unpack_error_with = OutputError::ValidatorAddress)]
validator_address: Address,
/// Index of the first epoch for which this output delegates.
start_epoch: EpochIndex,
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/wallet/operations/syncing/foundries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ where
match client.foundry_output_id(foundry_id).await {
Ok(output_id) => Ok(Some(client.get_output(&output_id).await?)),
Err(crate::client::Error::NoOutput(_)) => Ok(None),
Err(e) => Err(crate::wallet::Error::Client(e.into())),
Err(e) => Err(crate::wallet::Error::Client(e)),
}
})
.await?
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/wallet/operations/syncing/outputs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ where
Err(crate::client::Error::Node(crate::client::node_api::error::Error::NotFound(_))) => {
Ok((transaction_id, None))
}
Err(e) => Err(crate::wallet::Error::Client(e.into())),
Err(e) => Err(crate::wallet::Error::Client(e)),
}
}))
.await
Expand Down
3 changes: 1 addition & 2 deletions sdk/tests/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ use iota_sdk::{
slot::{SlotCommitmentHash, SlotCommitmentId, SlotIndex},
},
};
use pretty_assertions::assert_ne;

const ACCOUNT_ID_0: &str = "0x0000000000000000000000000000000000000000000000000000000000000000";
const ACCOUNT_ID_1: &str = "0x1111111111111111111111111111111111111111111111111111111111111111";
Expand All @@ -56,7 +55,7 @@ const BECH32_ADDRESS_ED25519_0: &str = "rms1qr2xsmt3v3eyp2ja80wd2sq8xx0fslefmxgu
const BECH32_ADDRESS_ED25519_1: &str = "rms1qqhvvur9xfj6yhgsxfa4f8xst7vz9zxeu3vcxds8mh4a6jlpteq9xrajhtf";
const BECH32_ADDRESS_ED25519_2: &str = "rms1qr47gz3xxjqpjrwd0yu5glhqrth6w0t08npney8000ust2lcw2r92j5a8rt";
const BECH32_ADDRESS_ACCOUNT_1: &str = "rms1pqg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zws5524"; // Corresponds to ACCOUNT_ID_1
const BECH32_ADDRESS_ACCOUNT_2: &str = "rms1pq3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zymxrh9z"; // Corresponds to ACCOUNT_ID_2
const _BECH32_ADDRESS_ACCOUNT_2: &str = "rms1pq3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zymxrh9z"; // Corresponds to ACCOUNT_ID_2
const BECH32_ADDRESS_NFT_1: &str = "rms1zqg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zxddmy7"; // Corresponds to NFT_ID_1
const _BECH32_ADDRESS_NFT_2: &str = "rms1zq3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zynm6ctf"; // Corresponds to NFT_ID_2
const SLOT_INDEX: SlotIndex = SlotIndex(10);
Expand Down
5 changes: 2 additions & 3 deletions sdk/tests/types/api/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,13 @@ fn responses() {
// GET /api/routes
json_response::<RoutesResponse>("get-routes-response-example.json").unwrap();
// GET /api/core/v3/info
// json_response::<InfoResponse>("get-info-response-example.json").unwrap();
json_response::<InfoResponse>("get-info-response-example.json").unwrap();
// GET /api/core/v3/accounts/{bech32Address}/congestion
json_response::<CongestionResponse>("get-congestion-estimate-response-example.json").unwrap();
// GET /api/core/v3/rewards/{outputId}
json_response::<ManaRewardsResponse>("get-mana-rewards-example.json").unwrap();
// GET /api/core/v3/validators
// TODO reenable when TIP is updated
// json_response::<ValidatorsResponse>("get-validators-example.json").unwrap();
json_response::<ValidatorsResponse>("get-validators-example.json").unwrap();
// GET /api/core/v3/validators/{bech32Address}
json_response::<ValidatorResponse>("get-validator-example.json").unwrap();
// GET /api/core/v3/committee
Expand Down
56 changes: 28 additions & 28 deletions sdk/tests/types/api/fixtures/get-info-response-example.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,27 @@
"parameters": {
"type": 0,
"version": 3,
"networkName": "TestJungle",
"bech32Hrp": "tgl",
"networkName": "testnet",
"bech32Hrp": "rms",
"storageScoreParameters": {
"storageCost": "0",
"factorData": 0,
"offsetOutputOverhead": "0",
"offsetEd25519BlockIssuerKey": "0",
"offsetStakingFeature": "0",
"offsetDelegation": "0"
"storageCost": "100",
"factorData": 1,
"offsetOutputOverhead": "10",
"offsetEd25519BlockIssuerKey": "100",
"offsetStakingFeature": "100",
"offsetDelegation": "100"
},
"workScoreParameters": {
"dataByte": 0,
"block": 1,
"input": 0,
"contextInput": 0,
"output": 0,
"nativeToken": 0,
"staking": 0,
"blockIssuer": 0,
"allotment": 0,
"signatureEd25519": 0
"dataByte": 1,
"block": 2,
"input": 3,
"contextInput": 4,
"output": 5,
"nativeToken": 6,
"staking": 7,
"blockIssuer": 8,
"allotment": 9,
"signatureEd25519": 10
},
"manaParameters": {
"bitsCount": 63,
Expand All @@ -55,11 +55,11 @@
20
],
"decayFactorsExponent": 32,
"decayFactorEpochsSum": 2420916375,
"decayFactorEpochsSum": 2262417561,
"decayFactorEpochsSumExponent": 21,
"annualDecayFactorPercentage": 50
"annualDecayFactorPercentage": 70
},
"tokenSupply": "2779530283277761",
"tokenSupply": "1813620509061365",
"genesisSlot": 0,
"genesisUnixTimestamp": "1695275822",
"slotDurationInSeconds": 10,
Expand All @@ -71,7 +71,7 @@
"livenessThresholdUpperBound": 30,
"minCommittableAge": 10,
"maxCommittableAge": 20,
"epochNearingThreshold": 24,
"epochNearingThreshold": 60,
"congestionControlParameters": {
"minReferenceManaCost": "1",
"increase": "0",
Expand All @@ -89,15 +89,15 @@
},
"rewardsParameters": {
"profitMarginExponent": 8,
"bootstrappingDuration": 1154,
"manaShareCoefficient": "2",
"decayBalancingConstantExponent": 8,
"decayBalancingConstant": "1",
"bootstrappingDuration": 1079,
"rewardToGenerationRatio": 5,
"initialTargetRewardsRate": "10",
"finalTargetRewardsRate": "20",
"poolCoefficientExponent": 11,
"retentionPeriod": 684
"retentionPeriod": 384
},
"targetCommitteeSize": 32,
"chainSwitchingThreshold": 2
"chainSwitchingThreshold": 3
}
}
],
Expand Down
2 changes: 1 addition & 1 deletion sdk/tests/types/api/fixtures/get-validators-example.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"stakers": [
"validators": [
{
"address": "rms1pp4wuuz0y42caz48vv876qfpmffswsvg40zz8v79sy8cp0jfxm4kunflcgt",
"stakingEndEpoch": 100,
Expand Down
100 changes: 50 additions & 50 deletions sdk/tests/types/block_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,53 +77,53 @@ fn protocol_parameters() -> ProtocolParameters {
serde_json::from_value::<ProtocolParameters>(params_json.clone()).unwrap()
}

// #[test]
// fn basic_block_tagged_data_payload_id() {
// // Test vector from https://github.com/iotaledger/tips/blob/tip46/tips/TIP-0046/tip-0046.md#basic-block-id-tagged-data-payload
// let protocol_parameters = protocol_parameters();
// let file = std::fs::read_to_string("./tests/types/fixtures/basic_block_tagged_data_payload.json").unwrap();
// let json = serde_json::from_str::<serde_json::Value>(&file).unwrap();
// let block_json = &json["block"];
// let block_dto = serde_json::from_value::<BlockDto>(block_json.clone()).unwrap();
// let block = Block::try_from_dto(block_dto).unwrap();
// let block_bytes = block.pack_to_vec();
// let block_work_score = block.as_basic().work_score(protocol_parameters.work_score_parameters());

// assert_eq!(prefix_hex::encode(&block_bytes), json["bytes"]);
// assert_eq!(block, Block::unpack_unverified(block_bytes).unwrap());
// assert_eq!(block.id(&protocol_parameters).to_string(), json["id"]);
// assert_eq!(block_work_score, json["workScore"]);
// }

// #[test]
// fn basic_block_transaction_payload_id() {
// // Test vector from https://github.com/iotaledger/tips/blob/tip46/tips/TIP-0046/tip-0046.md#basic-block-id-transaction-payload
// let protocol_parameters = protocol_parameters();
// let file = std::fs::read_to_string("./tests/types/fixtures/basic_block_transaction_payload.json").unwrap();
// let json = serde_json::from_str::<serde_json::Value>(&file).unwrap();
// let block_json = &json["block"];
// let block_dto = serde_json::from_value::<BlockDto>(block_json.clone()).unwrap();
// let block = Block::try_from_dto(block_dto).unwrap();
// let block_bytes = block.pack_to_vec();
// let block_work_score = block.as_basic().work_score(protocol_parameters.work_score_parameters());

// assert_eq!(prefix_hex::encode(&block_bytes), json["bytes"]);
// assert_eq!(block, Block::unpack_unverified(block_bytes).unwrap());
// assert_eq!(block.id(&protocol_parameters).to_string(), json["id"]);
// assert_eq!(block_work_score, json["workScore"]);
// }

// #[test]
// fn validation_block_id() {
// // Test vector from https://github.com/iotaledger/tips/blob/tip46/tips/TIP-0046/tip-0046.md#validation-block-id
// let file = std::fs::read_to_string("./tests/types/fixtures/validation_block.json").unwrap();
// let json = serde_json::from_str::<serde_json::Value>(&file).unwrap();
// let block_json = &json["block"];
// let block_dto = serde_json::from_value::<BlockDto>(block_json.clone()).unwrap();
// let block = Block::try_from_dto(block_dto).unwrap();
// let block_bytes = block.pack_to_vec();

// assert_eq!(prefix_hex::encode(&block_bytes), json["bytes"]);
// assert_eq!(block, Block::unpack_unverified(block_bytes).unwrap());
// assert_eq!(block.id(&protocol_parameters()).to_string(), json["id"]);
// }
#[test]
fn basic_block_tagged_data_payload_id() {
// Test vector from https://github.com/iotaledger/tips/blob/tip46/tips/TIP-0046/tip-0046.md#basic-block-id-tagged-data-payload
let protocol_parameters = protocol_parameters();
let file = std::fs::read_to_string("./tests/types/fixtures/basic_block_tagged_data_payload.json").unwrap();
let json = serde_json::from_str::<serde_json::Value>(&file).unwrap();
let block_json = &json["block"];
let block_dto = serde_json::from_value::<BlockDto>(block_json.clone()).unwrap();
let block = Block::try_from_dto(block_dto).unwrap();
let block_bytes = block.pack_to_vec();
let block_work_score = block.as_basic().work_score(protocol_parameters.work_score_parameters());

assert_eq!(prefix_hex::encode(&block_bytes), json["bytes"]);
assert_eq!(block, Block::unpack_bytes_unverified(block_bytes).unwrap());
assert_eq!(block.id(&protocol_parameters).to_string(), json["id"]);
assert_eq!(block_work_score, json["workScore"]);
}

#[test]
fn basic_block_transaction_payload_id() {
// Test vector from https://github.com/iotaledger/tips/blob/tip46/tips/TIP-0046/tip-0046.md#basic-block-id-transaction-payload
let protocol_parameters = protocol_parameters();
let file = std::fs::read_to_string("./tests/types/fixtures/basic_block_transaction_payload.json").unwrap();
let json = serde_json::from_str::<serde_json::Value>(&file).unwrap();
let block_json = &json["block"];
let block_dto = serde_json::from_value::<BlockDto>(block_json.clone()).unwrap();
let block = Block::try_from_dto(block_dto).unwrap();
let block_bytes = block.pack_to_vec();
let block_work_score = block.as_basic().work_score(protocol_parameters.work_score_parameters());

assert_eq!(prefix_hex::encode(&block_bytes), json["bytes"]);
assert_eq!(block, Block::unpack_bytes_unverified(block_bytes).unwrap());
assert_eq!(block.id(&protocol_parameters).to_string(), json["id"]);
assert_eq!(block_work_score, json["workScore"]);
}

#[test]
fn validation_block_id() {
// Test vector from https://github.com/iotaledger/tips/blob/tip46/tips/TIP-0046/tip-0046.md#validation-block-id
let file = std::fs::read_to_string("./tests/types/fixtures/validation_block.json").unwrap();
let json = serde_json::from_str::<serde_json::Value>(&file).unwrap();
let block_json = &json["block"];
let block_dto = serde_json::from_value::<BlockDto>(block_json.clone()).unwrap();
let block = Block::try_from_dto(block_dto).unwrap();
let block_bytes = block.pack_to_vec();

assert_eq!(prefix_hex::encode(&block_bytes), json["bytes"]);
assert_eq!(block, Block::unpack_bytes_unverified(block_bytes).unwrap());
assert_eq!(block.id(&protocol_parameters()).to_string(), json["id"]);
}
Loading