Skip to content

Commit

Permalink
update node test
Browse files Browse the repository at this point in the history
  • Loading branch information
MacOMNI committed Jan 9, 2025
1 parent 38e0fa5 commit a5d97d8
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 15 deletions.
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 {
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

0 comments on commit a5d97d8

Please sign in to comment.