Skip to content

Commit

Permalink
update more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MacOMNI committed Jan 8, 2025
1 parent ea1540a commit a15467c
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions Node/Tests/NodeTests/NodeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,61 @@ final class NodeTests {
#expect(validator1BestHead.hash == node2BestHead.hash)
#expect(validator2BestHead.hash == node1BestHead.hash)
}

Check failure on line 175 in Node/Tests/NodeTests/NodeTests.swift

View workflow job for this annotation

GitHub Actions / Swift Lint

Trailing Whitespace (trailing_whitespace)

Lines should not have trailing whitespace
@Test
func moreMultiplePeers() async throws {
// Create multiple nodes
var nodeDescriptions: [NodeDescription] = [
NodeDescription(isValidator: true, database: getDatabase(0)),
NodeDescription(isValidator: true, devSeed: 1, database: getDatabase(1))
]

Check failure on line 183 in Node/Tests/NodeTests/NodeTests.swift

View workflow job for this annotation

GitHub Actions / Swift Lint

Trailing Whitespace (trailing_whitespace)

Lines should not have trailing whitespace
// Add 18 non-validator nodes
for i in 2...19 {
nodeDescriptions.append(NodeDescription(devSeed: UInt32(i), database: .inMemory))
}

Check failure on line 188 in Node/Tests/NodeTests/NodeTests.swift

View workflow job for this annotation

GitHub Actions / Swift Lint

Trailing Whitespace (trailing_whitespace)

Lines should not have trailing whitespace
let (nodes, scheduler) = try await Topology(
nodes: nodeDescriptions,
connections: (0..<20).flatMap { i in
(i + 1..<20).map { j in (i, j) } // Fully connected topology
}
).build(genesis: .preset(.minimal))

let (validator1, validator1StoreMiddlware) = nodes[0]
let (validator2, validator2StoreMiddlware) = nodes[1]

// Extract non-validator nodes and their middleware
let nonValidatorNodes = nodes[2...].map { $0 }

try await Task.sleep(for: .milliseconds(nodes.count * 200))
let (node1, node1StoreMiddlware) = nonValidatorNodes[0]
let (node2, node2StoreMiddlware) = nonValidatorNodes[1]
// Verify connections for a sample of non-validator nodes
#expect(node1.network.peersCount == 19)
#expect(node2.network.peersCount == 19)
// Advance time and verify sync
for _ in 0 ..< 10 {
await scheduler.advance(by: TimeInterval(validator1.blockchain.config.value.slotPeriodSeconds))
await validator1StoreMiddlware.wait()
await validator2StoreMiddlware.wait()

Check failure on line 213 in Node/Tests/NodeTests/NodeTests.swift

View workflow job for this annotation

GitHub Actions / Swift Lint

Trailing Whitespace (trailing_whitespace)

Lines should not have trailing whitespace
for (_, middleware) in nonValidatorNodes {
await middleware.wait()
}
}

try await Task.sleep(for: .milliseconds(nodes.count * 200))

let validator1BestHead = await validator1.dataProvider.bestHead
let validator2BestHead = await validator2.dataProvider.bestHead

Check failure on line 223 in Node/Tests/NodeTests/NodeTests.swift

View workflow job for this annotation

GitHub Actions / Swift Lint

Trailing Whitespace (trailing_whitespace)

Lines should not have trailing whitespace
for (node, _) in nonValidatorNodes {
let nodeBestHead = await node.dataProvider.bestHead
#expect(validator1BestHead.hash == nodeBestHead.hash)
#expect(validator2BestHead.hash == nodeBestHead.hash)
}
}


Check failure on line 231 in Node/Tests/NodeTests/NodeTests.swift

View workflow job for this annotation

GitHub Actions / Swift Lint

Trailing Whitespace (trailing_whitespace)

Lines should not have trailing whitespace

Check failure on line 231 in Node/Tests/NodeTests/NodeTests.swift

View workflow job for this annotation

GitHub Actions / Swift Lint

Vertical Whitespace (vertical_whitespace)

Limit vertical whitespace to a single empty line; currently 2
}

0 comments on commit a15467c

Please sign in to comment.