Skip to content
Open
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
11 changes: 9 additions & 2 deletions bindings/ergo-lib-ios/Sources/ErgoLib/SwiftyJSON.swift
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,6 @@ public struct JSON {
rawString = string
case _ as NSNull:
type = .null
case nil:
type = .null
case let array as [Any]:
type = .array
rawArray = array
Expand All @@ -259,6 +257,15 @@ public struct JSON {

/// Private method to unwarp an object recursively
private func unwrap(_ object: Any) -> Any {
// Swift Optionals stored in `Any` are not `nil`; unwrap them explicitly.
let mirror = Mirror(reflecting: object)
if mirror.displayStyle == .optional {
if let child = mirror.children.first {
return unwrap(child.value)
}
return NSNull()
}

switch object {
case let json as JSON:
return unwrap(json.object)
Expand Down
26 changes: 23 additions & 3 deletions bindings/ergo-lib-ios/Tests/ErgoLibTests/RestNodeApiTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,26 @@ final class RestNodeApiTests: XCTestCase {
}

func testSPVWorkflow() async throws {
let env = ProcessInfo.processInfo.environment
if env["CI"] != nil && env["ERGO_SPV_WORKFLOW_TEST"] == nil {
throw XCTSkip("SPV workflow test requires public ergo nodes; set ERGO_SPV_WORKFLOW_TEST=1 (and optionally ERGO_SPV_PROOF_NODE_1, ERGO_SPV_PROOF_NODE_2, ERGO_SPV_VERIFY_NODE) to run in CI")
}

let proofNode1Str = env["ERGO_SPV_PROOF_NODE_1"] ?? "http://159.65.11.55:9053"
let proofNode2Str = env["ERGO_SPV_PROOF_NODE_2"] ?? "http://76.22.82.80:9053"
let verifyNodeRaw = env["ERGO_SPV_VERIFY_NODE"] ?? "76.22.82.80:9053"

let proofNode1 = URL(string: proofNode1Str)!
let proofNode2 = URL(string: proofNode2Str)!
let verifyNodeAddrString: String = {
if verifyNodeRaw.contains("://"),
let url = URL(string: verifyNodeRaw),
let host = url.host {
let port = url.port ?? 9053
return "\(host):\(port)"
}
return verifyNodeRaw
}()
let headerId = try BlockId(
withString: "d1366f762e46b7885496aaab0c42ec2950b0422d48aec3b91f45d4d0cdeb41e5")
let txId = try TxId(
Expand All @@ -111,12 +131,12 @@ final class RestNodeApiTests: XCTestCase {
group -> [NipopowProof] in
group.addTask {
let proof = try await getNipopowProof(
url: URL(string: "http://159.65.11.55:9053")!, headerId: headerId)!
url: proofNode1, headerId: headerId)!
return [proof]
}
group.addTask {
let proof = try await getNipopowProof(
url: URL(string: "http://76.22.82.80:9053")!, headerId: headerId)!
url: proofNode2, headerId: headerId)!
return [proof]
}
return try await group.reduce(into: [NipopowProof]()) { $0 += $1 }
Expand All @@ -131,7 +151,7 @@ final class RestNodeApiTests: XCTestCase {
XCTAssertEqual(try bestProof.suffixHead().getHeader().getBlockId(), headerId)

// Now verify with 3rd node
let nodeConf = try NodeConf(withAddrString: "76.22.82.80:9053")
let nodeConf = try NodeConf(withAddrString: verifyNodeAddrString)
let restNodeApi = try RestNodeApi()
let header = try await restNodeApi.getHeaderAsync(nodeConf: nodeConf, blockId: headerId)
let merkleProof = try await restNodeApi.getBlocksHeaderIdProofForTxIdAsync(
Expand Down
22 changes: 22 additions & 0 deletions ergo-rest/src/api/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,22 @@ mod tests {

use super::*;

fn should_run_network_tests() -> bool {
// These tests hit public Ergo nodes and can be flaky in CI due to network instability.
// Keep them enabled locally by default, but require explicit opt-in in CI.
if std::env::var_os("CI").is_some() && std::env::var_os("ERGO_REST_NETWORK_TESTS").is_none()
{
return false;
}
true
}

#[test]
fn test_get_info() {
if !should_run_network_tests() {
eprintln!("skipping network test (set ERGO_REST_NETWORK_TESTS=1 to enable in CI)");
return;
}
let runtime_inner = tokio::runtime::Builder::new_multi_thread()
.enable_all()
.build()
Expand All @@ -197,6 +211,10 @@ mod tests {

#[test]
fn test_get_nipopow_proof_by_header_id() {
if !should_run_network_tests() {
eprintln!("skipping network test (set ERGO_REST_NETWORK_TESTS=1 to enable in CI)");
return;
}
use ergo_chain_types::{BlockId, Digest32};
let header_id = BlockId(
Digest32::try_from(String::from(
Expand Down Expand Up @@ -228,6 +246,10 @@ mod tests {

#[test]
fn test_peer_discovery() {
if !should_run_network_tests() {
eprintln!("skipping network test (set ERGO_REST_NETWORK_TESTS=1 to enable in CI)");
return;
}
let seeds: Vec<_> = [
"http://213.239.193.208:9030",
"http://159.65.11.55:9030",
Expand Down
Loading