From a5d97d8e13355cbd01be9cab447b8d066880d1b2 Mon Sep 17 00:00:00 2001 From: MacOMNI <414294494@qq.com> Date: Thu, 9 Jan 2025 14:27:17 +0800 Subject: [PATCH] update node test --- .../Sources/Blockchain/Blockchain.swift | 3 +-- .../BlockchainDataProvider.swift | 2 +- Node/Tests/NodeTests/NodeTests.swift | 25 +++++++++++-------- Node/Tests/NodeTests/Topology.swift | 1 - 4 files changed, 16 insertions(+), 15 deletions(-) diff --git a/Blockchain/Sources/Blockchain/Blockchain.swift b/Blockchain/Sources/Blockchain/Blockchain.swift index 8b578e33..3288c2b3 100644 --- a/Blockchain/Sources/Blockchain/Blockchain.swift +++ b/Blockchain/Sources/Blockchain/Blockchain.swift @@ -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)") } } diff --git a/Blockchain/Sources/Blockchain/BlockchainDataProvider/BlockchainDataProvider.swift b/Blockchain/Sources/Blockchain/BlockchainDataProvider/BlockchainDataProvider.swift index 83a69a18..3ad95efb 100644 --- a/Blockchain/Sources/Blockchain/BlockchainDataProvider/BlockchainDataProvider.swift +++ b/Blockchain/Sources/Blockchain/BlockchainDataProvider/BlockchainDataProvider.swift @@ -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)") } } diff --git a/Node/Tests/NodeTests/NodeTests.swift b/Node/Tests/NodeTests/NodeTests.swift index 29af3a40..5ad651d3 100644 --- a/Node/Tests/NodeTests/NodeTests.swift +++ b/Node/Tests/NodeTests/NodeTests.swift @@ -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 { @@ -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] @@ -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)) @@ -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)] @@ -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 @@ -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 diff --git a/Node/Tests/NodeTests/Topology.swift b/Node/Tests/NodeTests/Topology.swift index 74625c96..7b42fb14 100644 --- a/Node/Tests/NodeTests/Topology.swift +++ b/Node/Tests/NodeTests/Topology.swift @@ -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) }