diff --git a/.github/actions/private-tangle/setup/action.yml b/.github/actions/private-tangle/setup/action.yml index 5061735206..be937278b9 100644 --- a/.github/actions/private-tangle/setup/action.yml +++ b/.github/actions/private-tangle/setup/action.yml @@ -1,47 +1,37 @@ -name: 'private-tangle-setup' -description: 'Setup a private tangle' +name: "private-tangle-setup" +description: "Setup a private tangle" runs: using: "composite" steps: - name: Clone private tangle files uses: actions/checkout@v3 with: - repository: iotaledger/hornet - path: hornet + repository: iotaledger/iota-core + path: iota-core + + - name: Prepare files for start and stop + shell: bash + run: | + echo "docker compose down -v" >> cleanup.sh + echo "rm *.snapshot" >> cleanup.sh + chmod +x cleanup.sh + + # remove the last 5 lines and add docker compose with `-d` to run it in the background + sed -i -n -e :a -e '1,5!{P;N;D;};N;ba' run.sh + echo "docker compose -f \$DOCKER_COMPOSE_FILE up -d" >> run.sh + working-directory: iota-core/tools/docker-network - name: Setup private tangle shell: bash run: | - # TODO: use next lines when a working hornet release is published - # # Download the private_tangle setup from the hornet repo. - # mkdir private_tangle - # cd private_tangle - # # Use the output of https://api.github.com/repos/iotaledger/hornet/releases/latest once there's a 2.0 Hornet release. - # DOWNLOAD_URL=$(curl "https://api.github.com/repos/iotaledger/hornet/releases" | jq -r '.[0].assets[] | select(.name | contains("private_tangle")) | .browser_download_url') - # echo "Downloading private tangle from $DOWNLOAD_URL" - # curl -L -o private_tangle.tar.gz $DOWNLOAD_URL - # tar -xf private_tangle.tar.gz - # TODO: remove next lines when a working hornet release is published - # Set protocol_parameters to the same values as in the shimmer network - jq '.tokenSupply="1813620509061365" | .rentStructure.vByteCost=100 | .bech32HRP="rms"' protocol_parameters.json > tmp.json && mv tmp.json protocol_parameters.json - jq --color-output . protocol_parameters.json - - # Reduce milestone interval to 1 second - yq eval '.services.inx-coordinator.command += "--coordinator.interval=1s"' docker-compose.yml > tmp.yml && mv tmp.yml docker-compose.yml - jq --color-output . config_private_tangle.json # Start Tangle - sudo ./cleanup.sh - sudo ./bootstrap.sh - sudo ./run.sh -d --quiet-pull - working-directory: hornet/private_tangle + sudo ./run.sh + working-directory: iota-core/tools/docker-network - name: Wait for tangle to start shell: bash - run: wget -qO- https://raw.githubusercontent.com/eficode/wait-for/$WAIT_FOR_VERSION/wait-for | sh -s -- -t 60 http://localhost:14265/health -- echo "Tangle is up" - env: - WAIT_FOR_VERSION: 4df3f9262d84cab0039c07bf861045fbb3c20ab7 # v2.2.3 - - name: Wait for faucet to start - shell: bash - run: wget -qO- https://raw.githubusercontent.com/eficode/wait-for/$WAIT_FOR_VERSION/wait-for | sh -s -- -t 60 http://localhost:8091/api/info -- echo "Faucet is up" - env: - WAIT_FOR_VERSION: 4df3f9262d84cab0039c07bf861045fbb3c20ab7 # v2.2.3 + run: wget -qO- https://raw.githubusercontent.com/eficode/wait-for/v2.2.4/wait-for | sh -s -- -t 120 http://localhost:8080/health -- echo "Tangle is up" + # TODO enable, maybe need another URL + # - name: Wait for faucet to start + # shell: bash + # run: wget -qO- https://raw.githubusercontent.com/eficode/wait-for/v2.2.4/wait-for | sh -s -- -t 120 http://localhost:8081/api/info -- echo "Faucet is up" diff --git a/.github/actions/private-tangle/tear-down/action.yml b/.github/actions/private-tangle/tear-down/action.yml index cf46081319..cf3e7dc4c5 100644 --- a/.github/actions/private-tangle/tear-down/action.yml +++ b/.github/actions/private-tangle/tear-down/action.yml @@ -6,9 +6,5 @@ runs: - name: Tear down private tangle shell: bash run: | - # TODO: use next line when a working hornet release is published - #cd private_tangle - - # TODO: remove next line when a working hornet release is published sudo ./cleanup.sh - working-directory: hornet/private_tangle + working-directory: iota-core/tools/docker-network diff --git a/.github/workflows/private-tangle-tests.yml b/.github/workflows/private-tangle-tests.yml index 726307049f..0c042fb369 100644 --- a/.github/workflows/private-tangle-tests.yml +++ b/.github/workflows/private-tangle-tests.yml @@ -42,29 +42,32 @@ jobs: steps: - uses: actions/checkout@v3 - # - name: Install toolchain - # uses: dtolnay/rust-toolchain@stable + - name: Install toolchain + uses: dtolnay/rust-toolchain@stable - # - name: Install required packages - # run: | - # sudo apt-get update - # sudo apt-get install libudev-dev libusb-1.0-0-dev + - name: Install required packages + run: | + sudo apt-get update + sudo apt-get install libudev-dev libusb-1.0-0-dev - # - name: Install Nextest - # uses: taiki-e/install-action@nextest + - name: Install Nextest + uses: taiki-e/install-action@nextest - # - name: Cache dependencies - # uses: Swatinem/rust-cache@v2 + - name: Cache dependencies + uses: Swatinem/rust-cache@v2 - # - name: Start private tangle - # uses: "./.github/actions/private-tangle/setup" + - name: Start private tangle + uses: "./.github/actions/private-tangle/setup" - # - name: Start ledger nano - # uses: "./.github/actions/ledger-nano" + - name: Start ledger nano + uses: "./.github/actions/ledger-nano" - # - name: Run tests - # run: cargo nextest run --tests --all-features --run-ignored ignored-only --profile ci --cargo-profile ci -p iota-sdk -p iota-sdk-bindings-core + - name: Run nodeinfo test + run: | + cargo nextest run test_get_info --all-features --run-ignored ignored-only --profile ci --cargo-profile ci -p iota-sdk -p iota-sdk-bindings-core --no-capture + # TODO: change in the future to run all tests and not only test_get_info + # cargo nextest run --tests --all-features --run-ignored ignored-only --profile ci --cargo-profile ci -p iota-sdk -p iota-sdk-bindings-core - # - name: Tear down private tangle - # if: always() - # uses: "./.github/actions/private-tangle/tear-down" + - name: Tear down private tangle + if: always() + uses: "./.github/actions/private-tangle/tear-down" diff --git a/bindings/nodejs/lib/types/models/info/node-info-status.ts b/bindings/nodejs/lib/types/models/info/node-info-status.ts index 51f0854dd9..ee4d1ca608 100644 --- a/bindings/nodejs/lib/types/models/info/node-info-status.ts +++ b/bindings/nodejs/lib/types/models/info/node-info-status.ts @@ -42,7 +42,7 @@ export interface INodeInfoStatus { */ latestConfirmedBlockSlot?: string; /** - * The index of the slot before which the tangle history is pruned. + * The index of the epoch before which the tangle history is pruned. */ - pruningSlot: string; + pruningEpoch: string; } diff --git a/sdk/src/types/api/core/response.rs b/sdk/src/types/api/core/response.rs index 3d94c17c62..6d088605f4 100644 --- a/sdk/src/types/api/core/response.rs +++ b/sdk/src/types/api/core/response.rs @@ -66,7 +66,7 @@ pub struct StatusResponse { pub latest_finalized_slot: SlotIndex, pub latest_accepted_block_slot: Option, pub latest_confirmed_block_slot: Option, - pub pruning_slot: SlotIndex, + pub pruning_epoch: EpochIndex, } /// Returned in [`InfoResponse`]. diff --git a/sdk/src/types/block/output/feature/metadata.rs b/sdk/src/types/block/output/feature/metadata.rs index 293257261f..aa768e0e9d 100644 --- a/sdk/src/types/block/output/feature/metadata.rs +++ b/sdk/src/types/block/output/feature/metadata.rs @@ -81,13 +81,13 @@ pub(crate) mod dto { use serde::{Deserialize, Serialize}; use super::*; - use crate::utils::serde::cow_boxed_slice_prefix; + use crate::utils::serde::cow_boxed_slice_prefix_hex_bytes; #[derive(Serialize, Deserialize)] struct MetadataFeatureDto<'a> { #[serde(rename = "type")] kind: u8, - #[serde(with = "cow_boxed_slice_prefix")] + #[serde(with = "cow_boxed_slice_prefix_hex_bytes")] data: Cow<'a, BoxedSlicePrefix>, } diff --git a/sdk/src/types/block/output/feature/tag.rs b/sdk/src/types/block/output/feature/tag.rs index f7b8cc2961..aa9ae7130f 100644 --- a/sdk/src/types/block/output/feature/tag.rs +++ b/sdk/src/types/block/output/feature/tag.rs @@ -73,13 +73,13 @@ pub(crate) mod dto { use serde::{Deserialize, Serialize}; use super::*; - use crate::utils::serde::cow_boxed_slice_prefix; + use crate::utils::serde::cow_boxed_slice_prefix_hex_bytes; #[derive(Serialize, Deserialize)] struct TagFeatureDto<'a> { #[serde(rename = "type")] kind: u8, - #[serde(with = "cow_boxed_slice_prefix")] + #[serde(with = "cow_boxed_slice_prefix_hex_bytes")] tag: Cow<'a, BoxedSlicePrefix>, } diff --git a/sdk/src/types/block/protocol.rs b/sdk/src/types/block/protocol.rs index df6813fc45..5533921db2 100644 --- a/sdk/src/types/block/protocol.rs +++ b/sdk/src/types/block/protocol.rs @@ -55,6 +55,7 @@ pub struct ProtocolParameters { /// The scaling of `mana_generation_rate` expressed as an exponent of 2. pub(crate) mana_generation_rate_exponent: u8, #[packable(unpack_error_with = |_| Error::InvalidManaDecayFactors)] + #[cfg_attr(feature = "serde", serde(with = "crate::utils::serde::boxed_slice_prefix"))] #[getset(skip)] /// A lookup table of epoch index diff to mana decay factor. pub(crate) mana_decay_factors: BoxedSlicePrefix, diff --git a/sdk/src/utils/serde.rs b/sdk/src/utils/serde.rs index b6363fef80..cb7de80138 100644 --- a/sdk/src/utils/serde.rs +++ b/sdk/src/utils/serde.rs @@ -131,7 +131,7 @@ pub mod string_prefix { } } -pub mod boxed_slice_prefix { +pub mod boxed_slice_prefix_hex_bytes { use alloc::boxed::Box; use packable::{bounded::Bounded, prefix::BoxedSlicePrefix}; @@ -158,14 +158,14 @@ pub mod boxed_slice_prefix { } } -pub mod cow_boxed_slice_prefix { +pub mod cow_boxed_slice_prefix_hex_bytes { use alloc::{borrow::Cow, boxed::Box}; use packable::{bounded::Bounded, prefix::BoxedSlicePrefix}; use prefix_hex::FromHexPrefixed; use serde::Deserializer; - pub use super::boxed_slice_prefix::serialize; + pub use super::boxed_slice_prefix_hex_bytes::serialize; pub fn deserialize<'de, 'a, D, B>(deserializer: D) -> Result>, D::Error> where @@ -174,7 +174,37 @@ pub mod cow_boxed_slice_prefix { Box<[u8]>: FromHexPrefixed, >::Error: core::fmt::Display, { - Ok(Cow::Owned(super::boxed_slice_prefix::deserialize(deserializer)?)) + Ok(Cow::Owned(super::boxed_slice_prefix_hex_bytes::deserialize( + deserializer, + )?)) + } +} + +pub mod boxed_slice_prefix { + use alloc::vec::Vec; + + use packable::{bounded::Bounded, prefix::BoxedSlicePrefix}; + use serde::{de, ser::SerializeSeq, Deserialize, Deserializer, Serialize, Serializer}; + + pub fn serialize(value: &BoxedSlicePrefix, serializer: S) -> Result + where + S: Serializer, + T: Serialize, + { + let mut seq = serializer.serialize_seq(Some(value.len()))?; + for e in value.into_iter() { + seq.serialize_element(e)?; + } + seq.end() + } + + pub fn deserialize<'de, D, T, B: Bounded>(deserializer: D) -> Result, D::Error> + where + D: Deserializer<'de>, + T: Deserialize<'de>, + >::Error: core::fmt::Display, + { + BoxedSlicePrefix::try_from(Vec::::deserialize(deserializer)?.into_boxed_slice()).map_err(de::Error::custom) } } diff --git a/sdk/tests/client/common/constants.rs b/sdk/tests/client/common/constants.rs index 73f3acba5a..c55f5c5e6f 100644 --- a/sdk/tests/client/common/constants.rs +++ b/sdk/tests/client/common/constants.rs @@ -1,6 +1,6 @@ // Copyright 2023 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 -pub static NODE_LOCAL: &str = "http://localhost:14265"; +pub static NODE_LOCAL: &str = "http://localhost:8080"; pub static FAUCET_URL: &str = "http://localhost:8091/api/enqueue";