Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MacOMNI committed Jan 6, 2025
1 parent df660c6 commit d38313e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public final class GuaranteeingService: ServiceBase2, @unchecked Sendable {
try await workPackagePool.removeWorkPackages(packages: [workPackage])
let event = RuntimeEvents.WorkReportGenerated(items: [workReport])
publish(event)
break
} else {
logger.error("WorkPackage validation failed")
}

Check warning on line 89 in Blockchain/Sources/Blockchain/Validator/GuaranteeingService.swift

View check run for this annotation

Codecov / codecov/patch

Blockchain/Sources/Blockchain/Validator/GuaranteeingService.swift#L88-L89

Added lines #L88 - L89 were not covered by tests
Expand Down
52 changes: 22 additions & 30 deletions Blockchain/Tests/BlockchainTests/WorkPackagePoolServiceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,46 +6,38 @@ import Utils
@testable import Blockchain

struct WorkPackagePoolServiceTests {
let config: ProtocolConfigRef
let timeProvider: MockTimeProvider
let dataProvider: BlockchainDataProvider
let eventBus: EventBus
let keystore: KeyStore
let storeMiddleware: StoreMiddleware
let workPackagecPoolService: WorkPackagePoolService

let ringContext: Bandersnatch.RingContext

init() async throws {
config = ProtocolConfigRef.dev
timeProvider = MockTimeProvider(time: 1000)

let (genesisState, genesisBlock) = try State.devGenesis(config: config)
dataProvider = try await BlockchainDataProvider(InMemoryDataProvider(genesisState: genesisState, genesisBlock: genesisBlock))

storeMiddleware = StoreMiddleware()
eventBus = EventBus(eventMiddleware: .serial(Middleware(storeMiddleware), .noError), handlerMiddleware: .noError)

keystore = try await DevKeyStore(devKeysCount: config.value.totalNumberOfValidators)

workPackagecPoolService = await WorkPackagePoolService(config: config, dataProvider: dataProvider, eventBus: eventBus)
ringContext = try Bandersnatch.RingContext(size: UInt(config.value.totalNumberOfValidators))
func setup(
config: ProtocolConfigRef = .dev,
time: TimeInterval = 988,
keysCount: Int = 12
) async throws -> (BlockchainServices, WorkPackagePoolService) {
let services = await BlockchainServices(
config: config,
timeProvider: MockTimeProvider(time: time),
keysCount: keysCount
)
let workPackagecPoolService = await WorkPackagePoolService(
config: services.config,
dataProvider: services.dataProvider,
eventBus: services.eventBus
)
return (services, workPackagecPoolService)
}

@Test
func testAddPendingWorkPackage() async throws {
let (services, workPackagecPoolService) = try await setup()
var allWorkPackages = [WorkPackage]()
for _ in 0 ..< config.value.totalNumberOfCores {
let workpackage = WorkPackage.dummy(config: config)
for _ in 0 ..< services.config.value.totalNumberOfCores {
let workpackage = WorkPackage.dummy(config: services.config)
allWorkPackages.append(workpackage)
}
await eventBus.publish(RuntimeEvents.WorkPackagesGenerated(items: allWorkPackages))
await storeMiddleware.wait()
await services.eventBus.publish(RuntimeEvents.WorkPackagesGenerated(items: allWorkPackages))
let workPackages = await workPackagecPoolService.getWorkPackages()
#expect(workPackages.array == Array(allWorkPackages).sorted())
let workpackage = WorkPackage.dummy(config: config)
let workpackage = WorkPackage.dummy(config: services.config)
try await workPackagecPoolService.addWorkPackages(packages: [workpackage])
try await workPackagecPoolService.removeWorkPackages(packages: [workpackage])
#expect(workPackages.array.count == config.value.totalNumberOfCores)
#expect(workPackages.array.count == services.config.value.totalNumberOfCores)
}
}

0 comments on commit d38313e

Please sign in to comment.