Skip to content

Commit

Permalink
update test
Browse files Browse the repository at this point in the history
  • Loading branch information
MacOMNI committed Jan 9, 2025
1 parent b3514f9 commit 8793718
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public actor BlockchainDataProvider: Sendable {
if header.value.timeslot > bestHead.timeslot {
let number = try await dataProvider.getBlockNumber(hash: head).unwrap()
bestHead = HeadInfo(hash: head, timeslot: header.value.timeslot, number: number)
logger.info("best head with timeslot \(header.value.timeslot) updated to \(bestHead.hash)")

Check warning on line 30 in Blockchain/Sources/Blockchain/BlockchainDataProvider/BlockchainDataProvider.swift

View check run for this annotation

Codecov / codecov/patch

Blockchain/Sources/Blockchain/BlockchainDataProvider/BlockchainDataProvider.swift#L30

Added line #L30 was not covered by tests
} else {
logger.warning("Found a block with timeslot \(header.value.timeslot) but best head is \(bestHead.timeslot)")
}
Expand Down Expand Up @@ -102,7 +103,7 @@ extension BlockchainDataProvider {

// add forks of finalized head is not allowed
public func add(block: BlockRef) async throws {
logger.debug("adding block: \(block.hash)")
logger.info("adding block: \(block.hash)")

// require parent exists (i.e. not purged) and block is not fork of any finalized block
guard try await hasBlock(hash: block.header.parentHash), block.header.timeslot > finalizedHead.timeslot else {
Expand Down
2 changes: 1 addition & 1 deletion Database/Sources/Database/RocksDBBackend.swift
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ extension RocksDBBackend: BlockchainDataProviderProtocol {
}

public func add(block: BlockRef) async throws {
logger.trace("add(block:) \(block.hash)")
logger.info("add(block:) \(block.hash)")

// TODO: batch put

Expand Down
4 changes: 2 additions & 2 deletions Node/Sources/Node/Config.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public enum Database {
public func open(chainspec: ChainSpec) async throws -> BlockchainDataProvider {
switch self {
case let .rocksDB(path):
logger.info("Using RocksDB backend at \(path.absoluteString)")
logger.debug("Using RocksDB backend at \(path.absoluteString)")
let backend = try await RocksDBBackend(
path: path,
config: chainspec.getConfig(),
Expand All @@ -27,7 +27,7 @@ public enum Database {
)
return try await BlockchainDataProvider(backend)
case .inMemory:
logger.info("Using in-memory backend")
logger.debug("Using in-memory backend")
let genesisBlock = try chainspec.getBlock()
let genesisStateData = try chainspec.getState()
let backend = try StateBackend(InMemoryBackend(), config: chainspec.getConfig(), rootHash: Data32())
Expand Down
17 changes: 8 additions & 9 deletions Node/Tests/NodeTests/NodeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ import Utils
@testable import Node

final class NodeTests {
var dataBaseIndex: Int = 0;

Check failure on line 9 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
var dataBaseIndex: Int = 0

Check failure on line 11 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 path = {
let tmpDir = FileManager.default.temporaryDirectory
return tmpDir.appendingPathComponent("\(UUID().uuidString)")
}()

Check failure on line 16 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
func getDatabase() -> Database {
dataBaseIndex += 1;

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

View workflow job for this annotation

GitHub Actions / Swift Lint

Trailing Semicolon (trailing_semicolon)

Lines should not have trailing semicolons
return Database.rocksDB(path: path.appendingPathComponent("\(dataBaseIndex)"))
Expand All @@ -21,6 +22,7 @@ final class NodeTests {
deinit {
try? FileManager.default.removeItem(at: path)
}

Check failure on line 25 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 validatorNodeInMemory() async throws {
let (nodes, scheduler) = try await Topology(
nodes: [NodeDescription(isValidator: true)]
Expand Down Expand Up @@ -135,12 +137,9 @@ final class NodeTests {
NodeDescription(isValidator: true, devSeed: 1, database: getDatabase()),
]
// Add 18 non-validator nodes
for i in 2...10 {
for i in 2...19 {
nodeDescriptions.append(NodeDescription(devSeed: UInt32(i), database: getDatabase()))
}
for i in 11...19 {
nodeDescriptions.append(NodeDescription(devSeed: UInt32(i), database: .inMemory))
}

let (nodes, scheduler) = try await Topology(
nodes: nodeDescriptions,
Expand All @@ -162,7 +161,7 @@ final class NodeTests {
#expect(node1.network.peersCount == 19)
#expect(node2.network.peersCount == 19)
// Advance time and verify sync
for _ in 0..<10 {
for _ in 0..<20 {
await scheduler.advance(by: TimeInterval(validator1.blockchain.config.value.slotPeriodSeconds))
await validator1StoreMiddlware.wait()
await validator2StoreMiddlware.wait()
Expand All @@ -172,7 +171,7 @@ final class NodeTests {
}
}

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

let validator1BestHead = await validator1.dataProvider.bestHead
let validator2BestHead = await validator2.dataProvider.bestHead
Expand Down Expand Up @@ -216,7 +215,7 @@ final class NodeTests {
#expect(node1.network.peersCount == 19)
#expect(node2.network.peersCount == 19)
// Advance time and verify sync
for _ in 0..<10 {
for _ in 0..<3 {
await scheduler.advance(by: TimeInterval(validator1.blockchain.config.value.slotPeriodSeconds))
await validator1StoreMiddlware.wait()
await validator2StoreMiddlware.wait()
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 8793718

Please sign in to comment.