Skip to content

Commit

Permalink
passing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
filvecchiato committed Dec 20, 2024
1 parent a05d3e5 commit e4e995f
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 17 deletions.
38 changes: 29 additions & 9 deletions src/services/coretime/CoretimeService.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,16 @@ const mockCoretimeApi = {
},
query: {
broker: {
status: () =>
Promise.resolve().then(() =>
mockKusamaCoretimeApiBlock26187139.registry.createType('PalletBrokerStatusRecord', {
coreCount: 100,
privatePoolSize: 0,
systemPoolSize: 80,
lastCommittedTimeslice: 328585,
lastTimeslice: 328585,
}),
),
configuration: () =>
Promise.resolve().then(() =>
mockKusamaCoretimeApiBlock26187139.registry.createType('Option<PalletBrokerConfigRecord>', {
Expand Down Expand Up @@ -333,19 +343,30 @@ describe('CoretimeService', () => {
const info = await CoretimeServiceAtRelayChain.getCoretimeInfo(blockHash22887036);
expect(info).toHaveProperty('at');
expect(info).toHaveProperty('brokerId');
expect(info.brokerId).not.toBeNull();
expect(info).toHaveProperty('palletVersion');
expect(info.palletVersion).not.toBeNull();

if ('brokerId' in info) {
expect(info.brokerId).not.toBeNull();
expect(info).toHaveProperty('palletVersion');
expect(info.palletVersion).not.toBeNull();
} else {
throw new Error('BrokerId is not present in the info object');
}
});

it('should return info data for coretime chain coretime', async () => {
const info = await CoretimeServiceAtCoretimeChain.getCoretimeInfo(blockHash26187139);
expect(info).toHaveProperty('at');
expect(info).toHaveProperty('configuration');
expect(info.configuration).not.toBeNull();
expect(info.configuration?.advanceNotice).toBe(10);
expect(info).toHaveProperty('saleInfo');
expect(info.saleInfo).not.toBeNull();
if ('configuration' in info) {
expect(info.configuration).not.toBeNull();
expect(info.configuration?.leadinLength).toBe(50400);
expect(info).toHaveProperty('currentRegion');
expect(info).toHaveProperty('cores');
expect(info).toHaveProperty('phase');
expect(info.currentRegion).not.toBeNull();
} else {
throw new Error('Configuration is not present in the info object');
}
});
});

Expand All @@ -356,12 +377,11 @@ describe('CoretimeService', () => {
expect(cores.at).toHaveProperty('hash');
expect(cores.cores && cores.cores[0]).toHaveProperty('coreId');
expect(cores.cores && cores.cores[0]).toHaveProperty('regions');
expect(cores.cores && cores.cores[0]).toHaveProperty('taskId');
expect(cores.cores && cores.cores[0]).toHaveProperty('paraId');
});

it('should get cores for relay chain', async () => {
const cores = await CoretimeServiceAtRelayChain.getCoretimeCores(blockHash26187139);
console.log(cores);
expect(cores.cores).toHaveLength(2);
expect(cores.at).toHaveProperty('hash');
expect(cores.cores && cores.cores[0]).toHaveProperty('paraId');
Expand Down
11 changes: 5 additions & 6 deletions src/services/coretime/CoretimeService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -539,9 +539,7 @@ export class CoretimeService extends AbstractService {
]);

const systemParas = reservations.map((el) => el.task);
const cores = [];

workload.map((wl) => {
const cores = workload.map((wl) => {
const coreType = systemParas.includes(wl.info.task)
? wl.info.task === 'Pool'
? 'ondemand'
Expand All @@ -559,13 +557,14 @@ export class CoretimeService extends AbstractService {
}

const coreRegions = regions.filter((region) => region.core === wl.core);
cores.push({
return {
coreId: wl.core,
taskId: wl.info.task,
paraId: wl.info.task,
workload: wl.info,
workplan: workplan.filter((f) => f.core === wl.core),
type: { condition: coreType, details },
regions: coreRegions,
});
};
});

return {
Expand Down
4 changes: 2 additions & 2 deletions src/types/responses/Coretime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,8 @@ export interface ICoretimeCores {
at: IAt;
cores?: (
| {
coreId: string;
taskId: string;
coreId: number;
paraId: string;
workload: TWorkloadInfo['info'];
type: {
condition: string;
Expand Down

0 comments on commit e4e995f

Please sign in to comment.