Skip to content

Commit

Permalink
update service test
Browse files Browse the repository at this point in the history
  • Loading branch information
MacOMNI committed Dec 12, 2024
1 parent c9838bc commit 52468e7
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
shouldAutocreateTestPlan = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "BlockchainTests"
BuildableName = "BlockchainTests"
BlueprintName = "BlockchainTests"
ReferencedContainer = "container:">
</BuildableReference>
</TestableReference>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ extension Guaranteeing {
}
}

private func toCoreAssignment(_ source: [UInt32], n: UInt32, max: UInt32) -> [CoreIndex] {
public static func toCoreAssignment(_ source: [UInt32], n: UInt32, max: UInt32) -> [CoreIndex] {
source.map { CoreIndex(($0 + n) % max) }
}

private func getCoreAssignment(config: ProtocolConfigRef, randomness: Data32, timeslot: TimeslotIndex) -> [CoreIndex] {
public static func getCoreAssignment(config: ProtocolConfigRef, randomness: Data32, timeslot: TimeslotIndex) -> [CoreIndex] {
var source = Array(repeating: UInt32(0), count: config.value.totalNumberOfValidators)
for i in 0 ..< config.value.totalNumberOfValidators {
source[i] = UInt32(config.value.totalNumberOfCores * i / config.value.totalNumberOfValidators)
Expand All @@ -94,14 +94,14 @@ extension Guaranteeing {
> {
let coreAssignmentRotationPeriod = UInt32(config.value.coreAssignmentRotationPeriod)

let currentCoreAssignment = getCoreAssignment(config: config, randomness: entropyPool.t2, timeslot: timeslot)
let currentCoreAssignment = Self.getCoreAssignment(config: config, randomness: entropyPool.t2, timeslot: timeslot)
let currentCoreKeys = withoutOffenders(keys: currentValidators.map(\.ed25519))

let isEpochChanging = (timeslot % UInt32(config.value.epochLength)) < coreAssignmentRotationPeriod
let previousRandomness = isEpochChanging ? entropyPool.t3 : entropyPool.t2
let previousValidators = isEpochChanging ? previousValidators : currentValidators

let previousCoreAssignment = getCoreAssignment(
let previousCoreAssignment = Self.getCoreAssignment(
config: config,
randomness: previousRandomness,
timeslot: timeslot - coreAssignmentRotationPeriod
Expand Down
55 changes: 55 additions & 0 deletions Blockchain/Tests/BlockchainTests/GuaranteeingServiceTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import Foundation
import Testing
import TracingUtils
import Utils

@testable import Blockchain

struct GuaranteeingServiceTests {
func setup(
config: ProtocolConfigRef = .dev,
time: TimeInterval = 988,
keysCount: Int = 12
) async throws -> (BlockchainServices, GuaranteeingService) {
let services = await BlockchainServices(
config: config,
timeProvider: MockTimeProvider(time: time),
keysCount: keysCount
)

let extrinsicPoolService = await ExtrinsicPoolService(
config: config,
dataProvider: services.dataProvider,
eventBus: services.eventBus
)

let runtime = Runtime(config: config)

let guaranteeingService = await GuaranteeingService(
config: config,
eventBus: services.eventBus,
scheduler: services.scheduler,
dataProvider: services.dataProvider,
keystore: services.keystore,
runtime: runtime,
extrinsicPool: extrinsicPoolService
)
return (services, guaranteeingService)
}

@Test func onGenesis() async throws {
let (services, validatorService) = try await setup()
let genesisState = services.genesisState
let storeMiddleware = services.storeMiddleware
let scheduler = services.scheduler

await validatorService.on(genesis: genesisState)

let events = await storeMiddleware.wait()

// Check if xxx events were published

// Check if block author tasks were scheduled
#expect(scheduler.taskCount == 0)
}
}

0 comments on commit 52468e7

Please sign in to comment.