Skip to content

Commit

Permalink
Move tests
Browse files Browse the repository at this point in the history
  • Loading branch information
thibault-martinez committed Sep 15, 2023
1 parent 17a6675 commit a428a21
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 80 deletions.
80 changes: 0 additions & 80 deletions sdk/src/types/block/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,83 +324,3 @@ impl_id!(

#[cfg(feature = "serde")]
string_serde_impl!(ProtocolParametersHash);

#[cfg(test)]
mod test {
use super::*;

#[test]
fn params_serde_hash() {
// Data from https://github.com/iotaledger/tips-draft/blob/tip49/tips/TIP-0049/tip-0049.md#protocol-parameter-example
let protocol_params_json = serde_json::json!(
{
"type": 0,
"version": 3,
"networkName": "xxxNetwork",
"bech32Hrp": "xxx",
"rentStructure": {
"vByteCost": 6,
"vByteFactorData": 7,
"vByteFactorKey": 8,
"vByteFactorIssuerKeys": 9,
"vByteFactorStakingFeature": 10,
"vByteFactorDelegation": 10
},
"workScoreStructure": {
"dataKilobyte": 1,
"block": 2,
"missingParent": 3,
"input": 4,
"contextInput": 5,
"output": 6,
"nativeToken": 7,
"staking": 8,
"blockIssuer": 9,
"allotment": 10,
"signatureEd25519": 11,
"minStrongParentsThreshold": 12
},
"tokenSupply": "1234567890987654321",
"genesisUnixTimestamp": "1681373293",
"slotDurationInSeconds": 10,
"slotsPerEpochExponent": 13,
"manaStructure": {
"manaBitsCount": 1,
"manaGenerationRate": 1,
"manaGenerationRateExponent": 27,
"manaDecayFactors": [ 10, 20 ],
"manaDecayFactorsExponent": 32,
"manaDecayFactorEpochsSum": 1337,
"manaDecayFactorEpochsSumExponent": 20
},
"stakingUnbondingPeriod": "11",
"validationBlocksPerSlot": 10,
"livenessThreshold": "3",
"minCommittableAge": "10",
"maxCommittableAge": "20",
"epochNearingThreshold": "24",
"congestionControlParameters": {
"rmcMin": "500",
"increase": "500",
"decrease": "500",
"increaseThreshold": 800000,
"decreaseThreshold": 500000,
"schedulerRate": 100000,
"minMana": "1",
"maxBufferSize": 3276800
},
"versionSignaling": {
"windowSize": 3,
"windowTargetRatio": 4,
"activationOffset": 1
}
}
);
let protocol_params = serde_json::from_value::<ProtocolParameters>(protocol_params_json).unwrap();
let hash = protocol_params.hash();
assert_eq!(
hash.to_string(),
"0xd379bdceb68aa77dada50ae7e3493b8f0b6ed28d26813620ce893afad541eb29"
);
}
}
1 change: 1 addition & 0 deletions sdk/tests/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ mod input;
mod output_id;
mod parents;
mod payload;
mod protocol;
mod rent;
mod slot;
mod tagged_data_payload;
Expand Down
80 changes: 80 additions & 0 deletions sdk/tests/types/protocol.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// Copyright 2023 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

use iota_sdk::types::block::protocol::ProtocolParameters;

#[test]
fn params_serde_hash() {
// Data from https://github.com/iotaledger/tips-draft/blob/tip49/tips/TIP-0049/tip-0049.md#protocol-parameter-example
let protocol_params_json = serde_json::json!(
{
"type": 0,
"version": 3,
"networkName": "xxxNetwork",
"bech32Hrp": "xxx",
"rentStructure": {
"vByteCost": 6,
"vByteFactorData": 7,
"vByteFactorKey": 8,
"vByteFactorIssuerKeys": 9,
"vByteFactorStakingFeature": 10,
"vByteFactorDelegation": 10
},
"workScoreStructure": {
"dataKilobyte": 1,
"block": 2,
"missingParent": 3,
"input": 4,
"contextInput": 5,
"output": 6,
"nativeToken": 7,
"staking": 8,
"blockIssuer": 9,
"allotment": 10,
"signatureEd25519": 11,
"minStrongParentsThreshold": 12
},
"tokenSupply": "1234567890987654321",
"genesisUnixTimestamp": "1681373293",
"slotDurationInSeconds": 10,
"slotsPerEpochExponent": 13,
"manaStructure": {
"manaBitsCount": 1,
"manaGenerationRate": 1,
"manaGenerationRateExponent": 27,
"manaDecayFactors": [ 10, 20 ],
"manaDecayFactorsExponent": 32,
"manaDecayFactorEpochsSum": 1337,
"manaDecayFactorEpochsSumExponent": 20
},
"stakingUnbondingPeriod": "11",
"validationBlocksPerSlot": 10,
"livenessThreshold": "3",
"minCommittableAge": "10",
"maxCommittableAge": "20",
"epochNearingThreshold": "24",
"congestionControlParameters": {
"rmcMin": "500",
"increase": "500",
"decrease": "500",
"increaseThreshold": 800000,
"decreaseThreshold": 500000,
"schedulerRate": 100000,
"minMana": "1",
"maxBufferSize": 3276800
},
"versionSignaling": {
"windowSize": 3,
"windowTargetRatio": 4,
"activationOffset": 1
}
}
);
let protocol_params = serde_json::from_value::<ProtocolParameters>(protocol_params_json).unwrap();
let hash = protocol_params.hash();

assert_eq!(
hash.to_string(),
"0xd379bdceb68aa77dada50ae7e3493b8f0b6ed28d26813620ce893afad541eb29"
);
}

0 comments on commit a428a21

Please sign in to comment.