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

Download Tangle binary against specific hash #537

Merged
merged 39 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
8517665
feat: add binary download to tangle::run
drewstone Dec 9, 2024
579e1ae
chore: fix error
drewstone Dec 9, 2024
9e4d27f
feat!(blueprint-test-utils): build tnt-core in test-utils with soldeer
Tjemmmic Dec 9, 2024
379026e
feat!(blueprint-test-utils): dynamically get mbsm bytecode from insta…
Tjemmmic Dec 9, 2024
5505e36
chore: add incredible-squaring to CI
Serial-ATA Dec 9, 2024
24b9ab7
feat(blueprint-test-utils): utilize tnt-core bytecode crate
Tjemmmic Dec 9, 2024
76b97a3
Merge branch 'refs/heads/main' into drew/download-binary
Tjemmmic Dec 9, 2024
8525a07
Merge branch 'main' into drew/download-binary
drewstone Dec 10, 2024
a6c2033
Merge remote-tracking branch 'origin/drew/download-binary' into drew/…
Tjemmmic Dec 10, 2024
18e5758
chore(clippy): cleanup and fmt
Tjemmmic Dec 10, 2024
6ed5dfd
fix(blueprint-test-utils): remove tnt-core from lib
Tjemmmic Dec 10, 2024
2cc295e
chore: expose opts through
drewstone Dec 10, 2024
03c9f3e
Merge branch 'serial/incredible-squaring-ci' into drew/download-binary
drewstone Dec 10, 2024
850541c
chore: merge ISQ CI branch
drewstone Dec 10, 2024
c97d394
chore: fix
drewstone Dec 10, 2024
7a5177b
feat: add logging of the node to stdout/stderr, make running local ta…
drewstone Dec 10, 2024
f44bfd6
chore: revert CI change
drewstone Dec 10, 2024
67e8c5e
chore: clippy
drewstone Dec 10, 2024
1077b40
chore: clippy
drewstone Dec 10, 2024
c5d3bc5
Merge branch 'main' into drew/download-binary
drewstone Dec 10, 2024
9472de9
chore: Add in place of bool
drewstone Dec 10, 2024
97addac
chore: fix
drewstone Dec 10, 2024
d598343
Update cli/src/deploy.rs
drewstone Dec 10, 2024
02847d7
Update blueprint-test-utils/src/test_ext.rs
drewstone Dec 10, 2024
d43f70a
Update blueprint-test-utils/src/tangle/node.rs
drewstone Dec 10, 2024
9ed9590
chore: remove timeout
drewstone Dec 10, 2024
4e61000
chore: more changes
drewstone Dec 10, 2024
63e54cd
chore: use downloaded tangle
drewstone Dec 10, 2024
06cdc37
chore: revert
drewstone Dec 10, 2024
07226ef
chore: setup sending balance
drewstone Dec 10, 2024
3acd87d
fix: pass context from job to post-processor without changing post-pr…
tbraun96 Dec 10, 2024
69f482d
chore: fixes
drewstone Dec 10, 2024
f84ea07
Merge branch 'drew/download-binary' of https://github.com/tangle-netw…
tbraun96 Dec 10, 2024
c3c9640
chore: pull in origin HEAD
tbraun96 Dec 10, 2024
c1ad6f0
chore: fmt
drewstone Dec 10, 2024
c92529e
fix: change working dir in incredible-squaring CI
Serial-ATA Dec 10, 2024
9ac5d9f
chore: expand incredible-squaring e2e test
Serial-ATA Dec 10, 2024
0ebddbf
fix: remove file from build.rs
Serial-ATA Dec 10, 2024
97d924e
chore: clippy
Serial-ATA Dec 10, 2024
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
59 changes: 52 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,13 @@ jobs:
runs-on: macos-14
strategy:
matrix:
package: [
gadget-sdk,
gadget-context-derive,
gadget-blueprint-proc-macro,
gadget-blueprint-proc-macro-playground
]
package:
[
gadget-sdk,
gadget-context-derive,
gadget-blueprint-proc-macro,
gadget-blueprint-proc-macro-playground,
]
steps:
- name: checkout code
uses: actions/checkout@v2
Expand Down Expand Up @@ -126,12 +127,14 @@ jobs:
- name: doc tests
run: cargo test --package ${{ matrix.package }} --doc

eigenlayer-tests:
incredible-squaring:
timeout-minutes: 90
runs-on: ubuntu-latest
steps:
- name: checkout code
uses: actions/checkout@v2
with:
path: gadget

- name: Install Foundry
run: |
Expand All @@ -144,6 +147,48 @@ jobs:
- name: Add Foundry to PATH
run: echo "${{ runner.temp }}/foundry/bin" >> $GITHUB_PATH

- name: Forge build
working-directory: gadget/blueprints/incredible-squaring/contracts
run: forge update && forge build

- name: install rust
uses: dtolnay/rust-toolchain@nightly
with:
toolchain: stable

- uses: swatinem/rust-cache@v2
with:
cache-on-failure: "true"

- name: install protobuf and gmp
run: |
sudo apt-get update
sudo apt-get install -y protobuf-compiler libprotobuf-dev libgmp-dev

- name: install cargo-nextest
run: cargo install cargo-nextest --locked

- name: tests
working-directory: gadget
run: cargo nextest run --nocapture --package incredible-squaring-blueprint test_blueprint --retries 0

eigenlayer-tests:
timeout-minutes: 90
runs-on: ubuntu-latest
steps:
- name: checkout code
uses: actions/checkout@v2

- name: Install Foundry
run: |
curl -L https://foundry.paradigm.xyz | bash
${FOUNDRY_DIR:-"$HOME/.foundry"}/bin/foundryup
env:
FOUNDRY_DIR: ${{ runner.temp }}/foundry
shell: bash

- name: Add Foundry to PATH
run: echo "${{ runner.temp }}/foundry/bin" >> $GITHUB_PATH

- name: Forge build
run: forge update && cd blueprints/incredible-squaring-eigenlayer && forge build --root ./contracts && cd ../../
Expand Down
13 changes: 13 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ subxt-signer = { version = "0.37.0", default-features = false }
subxt = { version = "0.37.0", default-features = false }
subxt-core = { version = "0.37.0", default-features = false }
round-based = "0.3.0"
tnt-core-bytecode = { git = "https://github.com/tangle-network/tnt-core.git", default-features = false, branch = "donovan/bytecode" }

sp-core = { version = "31.0.0", default-features = false }
sp-io = { version = "33.0.0", default-features = false }
Expand Down Expand Up @@ -97,6 +98,7 @@ cargo-generate = { version = "0.21.3", default-features = false }
cfg-if = "1.0.0"
clap = "4.5.16"
clap-cargo = "0.14"
dirs = "5.0.1"
eyre = { version = "0.6.12" }
color-eyre = { version = "0.6", features = ["tracing-error", "color-spantrace"] }
ed25519-zebra = { version = "4" }
Expand Down Expand Up @@ -126,7 +128,7 @@ proc-macro2 = "1.0"
prometheus = { version = "0.13.4", default-features = false }
quote = "1.0"
rand = { version = "0.8.5", default-features = false }
reqwest = "0.12.7"
reqwest = "0.12.9"
rustdoc-types = "0.31.0"
schnorrkel = { version = "0.11.4", default-features = false, features = ["preaudit_deprecated", "getrandom"] }
serde = { version = "1.0.208", default-features = false }
Expand Down
2 changes: 1 addition & 1 deletion blueprint-build-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ pub fn soldeer_update() {

let status = Command::new(&forge_executable)
.current_dir(&root)
.args(["soldeer", "update"])
.args(["soldeer", "update", "-d"])
.status()
.expect("Failed to execute 'forge soldeer update'");

Expand Down
7 changes: 7 additions & 0 deletions blueprint-test-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ blueprint-manager = { workspace = true }
futures = { workspace = true }
parking_lot = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
tokio = { workspace = true, features = ["full"] }

# Logging and error handling
Expand All @@ -44,6 +45,7 @@ url = { workspace = true }
cargo-tangle = { workspace = true, default-features = true }
gadget-io = { workspace = true, default-features = false }
gadget-sdk = { workspace = true }
tnt-core-bytecode = { workspace = true, default-features = false }

# Alloy-related
alloy-contract = { workspace = true }
Expand All @@ -55,10 +57,15 @@ alloy-sol-types = { workspace = true }
alloy-transport = { workspace = true }

# Utility
dirs = { workspace = true }
testcontainers = { workspace = true }
uuid = { workspace = true, features = ["v4"] }
tempfile = { workspace = true }
cargo_toml = { workspace = true }
reqwest = { workspace = true }

[dev-dependencies]
cargo_metadata = { workspace = true }

[build-dependencies]
blueprint-build-utils = { workspace = true }
1 change: 1 addition & 0 deletions blueprint-test-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ fn inject_tangle_key<P: AsRef<Path>>(keystore_path: P, name: &str) -> color_eyre
let suri = format!("//{name}");

let sr = sp_core::sr25519::Pair::from_string(&suri, None).expect("Should be valid SR keypair");

let sr_seed = &sr.as_ref().secret.to_bytes();

let ed = sp_core::ed25519::Pair::from_string(&suri, None).expect("Should be valid ED keypair");
Expand Down
113 changes: 100 additions & 13 deletions blueprint-test-utils/src/tangle/mod.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,108 @@
use crate::tangle::node::{Error, SubstrateNode, TANGLE_NODE_ENV};
use reqwest;
use std::env;
use std::fs;
use std::io::Write;
use std::path::PathBuf;

pub mod node;
pub mod transactions;

/// Run a Tangle node with the default settings.
pub use node::NodeConfig;

const TANGLE_RELEASE_MAC: &str = "https://github.com/tangle-network/tangle/releases/download/83f587f/tangle-testnet-manual-seal-darwin-amd64";
const TANGLE_RELEASE_LINUX: &str = "https://github.com/tangle-network/tangle/releases/download/83f587f/tangle-testnet-manual-seal-linux-amd64";

/// Downloads the appropriate Tangle binary for the current platform and returns the path
pub async fn download_tangle_binary() -> Result<PathBuf, Box<dyn std::error::Error>> {
let download_url = if cfg!(target_os = "macos") {
TANGLE_RELEASE_MAC
} else if cfg!(target_os = "linux") {
TANGLE_RELEASE_LINUX
} else {
return Err("Unsupported platform".into());
};

// Create cache directory in user's home directory
let cache_dir = dirs::cache_dir()
.ok_or("Could not determine cache directory")?
.join("tangle-binary");
fs::create_dir_all(&cache_dir)?;

let binary_path = cache_dir.join("tangle");

let version_path = cache_dir.join("version.txt");
drewstone marked this conversation as resolved.
Show resolved Hide resolved
let commit_hash = download_url.split('/').nth(7).unwrap_or_default();

let should_download = if binary_path.exists() && version_path.exists() {
// Check if version matches
let stored_version = fs::read_to_string(&version_path)?;
stored_version.trim() != commit_hash
} else {
true
};

if should_download {
let response = reqwest::get(download_url).await?;
let bytes = response.bytes().await?;

let mut file = fs::File::create(&binary_path)?;
file.write_all(&bytes)?;

// Make binary executable
#[cfg(unix)]
{
use std::os::unix::fs::PermissionsExt;
let mut perms = fs::metadata(&binary_path)?.permissions();
perms.set_mode(0o755);
fs::set_permissions(&binary_path, perms)?;
}

// Write version file
fs::write(&version_path, commit_hash)?;
}

Ok(binary_path)
}

/// Run a Tangle node with the given configuration.
/// The node will shut down when the returned handle is dropped.
pub fn run() -> Result<SubstrateNode, Error> {
let tangle_from_env = std::env::var(TANGLE_NODE_ENV).unwrap_or_else(|_| "tangle".to_string());
let builder = SubstrateNode::builder()
.binary_paths([
&tangle_from_env,
"../tangle/target/release/tangle",
"../../tangle/target/release/tangle",
"../../../tangle/target/release/tangle",
])
pub async fn run(config: NodeConfig) -> Result<SubstrateNode, Error> {
let mut builder = SubstrateNode::builder();

// Add binary paths
if config.use_local_tangle {
let tangle_from_env =
std::env::var(TANGLE_NODE_ENV).unwrap_or_else(|_| "tangle".to_string());
builder
.add_binary_path(tangle_from_env)
.add_binary_path("../tangle/target/release/tangle")
.add_binary_path("../../tangle/target/release/tangle")
.add_binary_path("../../../tangle/target/release/tangle");
} else {
let binary_path = download_tangle_binary().await.map_err(|e| {
Error::Io(std::io::Error::new(
std::io::ErrorKind::Other,
e.to_string(),
))
})?;
builder.add_binary_path(binary_path.to_string_lossy().to_string());
}

// Add standard arguments
builder
.arg("validator")
.arg_val("rpc-cors", "all")
.arg_val("rpc-methods", "unsafe")
.arg("rpc-external")
.arg_val("sealing", "manual")
.clone();
.arg_val("sealing", "manual");

// Add log configuration
let log_string = config.to_log_string();
if !log_string.is_empty() {
builder.arg_val("log", log_string);
}

builder.spawn()
}

Expand All @@ -29,6 +112,7 @@ macro_rules! tangle_blueprint_test_template {
(
$N:tt,
$test_logic:expr,
$node_config:expr,
) => {
use $crate::test_ext::new_test_ext_blueprint_manager;

Expand All @@ -42,6 +126,7 @@ macro_rules! tangle_blueprint_test_template {
::blueprint_test_utils::test_ext::new_test_ext_blueprint_manager::<$N, 1, String, _, _>(
tmp_dir_path,
::blueprint_test_utils::run_test_blueprint_manager,
$node_config,
)
.await
.execute_with_async($test_logic)
Expand All @@ -59,10 +144,11 @@ macro_rules! test_tangle_blueprint {
[$($inputs:expr),*],
[$($expected_output:expr),*],
$call_id:expr,
$node_config:expr,
) => {
::blueprint_test_utils::tangle_blueprint_test_template!(
$N,
|client, handles, blueprint| async move {
|client, handles, blueprint, _| async move {
let keypair = handles[0].sr25519_id().clone();
let selected_service = &blueprint.services[0];
let service_id = selected_service.id;
Expand Down Expand Up @@ -109,6 +195,7 @@ macro_rules! test_tangle_blueprint {
assert_eq!(result, expected);
}
},
$node_config,
);
};
(
Expand Down
Loading
Loading