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

multiplePeers tests #265

Merged
merged 28 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 1 addition & 2 deletions Blockchain/Sources/Blockchain/Blockchain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ public final class Blockchain: ServiceBase, @unchecked Sendable {
try await dataProvider.blockImported(block: block, state: state)

publish(RuntimeEvents.BlockImported(block: block, state: state, parentState: parent))

logger.info("Block imported: #\(block.header.timeslot) \(block.hash)")
logger.debug(" Import block: #\(block.header.timeslot) \(block.hash)")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public actor BlockchainDataProvider: Sendable {
bestHead = HeadInfo(hash: block.hash, timeslot: block.header.timeslot, number: number)
}

logger.info("block Imported: #\(bestHead.timeslot) \(block.hash)")
logger.debug("Block imported: #\(bestHead.timeslot) \(block.hash)")
}
}

Expand Down
25 changes: 14 additions & 11 deletions Node/Tests/NodeTests/NodeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@ import Utils
@testable import Node

final class NodeTests {
var dataBaseIndex: Int = 0;

let path = {
let tmpDir = FileManager.default.temporaryDirectory
return tmpDir.appendingPathComponent("\(UUID().uuidString)")
}()

func getDatabase(_ idx: Int) -> Database {
Database.rocksDB(path: path.appendingPathComponent("\(idx)"))
func getDatabase() -> Database {
MacOMNI marked this conversation as resolved.
Show resolved Hide resolved
dataBaseIndex += 1;
return Database.rocksDB(path: path.appendingPathComponent("\(dataBaseIndex)"))
}

deinit {
Expand Down Expand Up @@ -49,7 +52,7 @@ final class NodeTests {

@Test func validatorNodeRocksDB() async throws {
let (nodes, scheduler) = try await Topology(
nodes: [NodeDescription(isValidator: true, database: getDatabase(0))]
nodes: [NodeDescription(isValidator: true, database: getDatabase())]
).build(genesis: .preset(.minimal))

let (validatorNode, storeMiddlware) = nodes[0]
Expand Down Expand Up @@ -80,8 +83,8 @@ final class NodeTests {
// Create validator and full node
let (nodes, scheduler) = try await Topology(
nodes: [
NodeDescription(isValidator: true, database: getDatabase(0)),
NodeDescription(devSeed: 1, database: getDatabase(1)),
NodeDescription(isValidator: true, database: getDatabase()),
NodeDescription(devSeed: 1, database: getDatabase()),
],
connections: [(0, 1)]
).build(genesis: .preset(.minimal))
Expand Down Expand Up @@ -129,9 +132,9 @@ final class NodeTests {
// Create multiple nodes
let (nodes, scheduler) = try await Topology(
nodes: [
NodeDescription(isValidator: true, database: getDatabase(0)),
NodeDescription(isValidator: true, devSeed: 1, database: getDatabase(1)),
NodeDescription(devSeed: 2, database: getDatabase(2)),
NodeDescription(isValidator: true, database: getDatabase()),
NodeDescription(isValidator: true, devSeed: 1, database: getDatabase()),
NodeDescription(devSeed: 2, database: getDatabase()),
NodeDescription(devSeed: 3, database: .inMemory),
],
connections: [(0, 1), (0, 2), (0, 3), (1, 2), (1, 3)]
Expand Down Expand Up @@ -171,8 +174,8 @@ final class NodeTests {
@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)),
NodeDescription(isValidator: true, database: getDatabase()),
NodeDescription(isValidator: true, devSeed: 1, database: getDatabase()),
]

// Add 18 non-validator nodes
Expand Down Expand Up @@ -210,7 +213,7 @@ final class NodeTests {
}
}

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

let validator1BestHead = await validator1.dataProvider.bestHead
let validator2BestHead = await validator2.dataProvider.bestHead
Expand Down
1 change: 0 additions & 1 deletion Node/Tests/NodeTests/Topology.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ struct Topology {
let toNode = ret[to].0
let conn = try fromNode.network.network.connect(to: toNode.network.network.listenAddress(), role: .validator)
try? await conn.ready()
try? await Task.sleep(for: .milliseconds(50))
}
return (ret, scheduler)
}
Expand Down
Loading