Skip to content

Commit 5e5a172

Browse files
committed
passing tests cores info
1 parent 8b3e237 commit 5e5a172

File tree

2 files changed

+57
-36
lines changed

2 files changed

+57
-36
lines changed

src/services/coretime/CoretimeService.spec.ts

Lines changed: 46 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,13 @@ import { kusamaCoretimeMetadata } from '../../test-helpers/metadata/coretimeKusa
2222
// import { coretimeKusamaRegistryV1003003 } from '../../test-helpers/registries/coretimeChainKusamaRegistry';
2323
import { createApiWithAugmentations, TypeFactory } from '../../test-helpers/typeFactory';
2424
import { blockHash22887036 } from '../test-helpers/mock';
25-
import { mockLeases, mockRegions, mockReservations, potentialRenewalsMocks } from '../test-helpers/mock/coretime';
25+
import {
26+
mockLeases,
27+
mockRegions,
28+
mockReservations,
29+
mockWorkloads,
30+
potentialRenewalsMocks,
31+
} from '../test-helpers/mock/coretime';
2632
import { blockHash26187139 } from '../test-helpers/mock/mockBlock26187139';
2733
import { mockKusamaCoretimeApiBlock26187139 } from '../test-helpers/mock/mockCoretimeChainApi';
2834
import { mockKusamaApiBlock26187139 } from '../test-helpers/mock/mockKusamaApiBlock26187139';
@@ -35,9 +41,9 @@ const mockKusamaApi = {
3541
...mockKusamaApiBlock26187139.consts,
3642
coretime: {
3743
brokerId: 1,
38-
onDemandAssignmentProvider: {
39-
maxHistoricalRevenue: {},
40-
},
44+
},
45+
onDemandAssignmentProvider: {
46+
maxHistoricalRevenue: '50',
4147
},
4248
},
4349
query: {
@@ -48,7 +54,7 @@ const mockKusamaApi = {
4854
coreDescriptors: {
4955
entries: () => [],
5056
},
51-
palletVersion: {},
57+
palletVersion: () => Promise.resolve().then(() => '1'),
5258
},
5359
onDemandAssignmentProvider: {
5460
palletVersion: () => {},
@@ -61,32 +67,6 @@ const mockKusamaApi = {
6167
},
6268
} as unknown as ApiPromise;
6369

64-
// const mockRenewals = [
65-
// {
66-
// completion: 'Complete',
67-
// core: '7',
68-
// mask: '0xffffffffffffffffffff',
69-
// price: '7767758517',
70-
// task: '2004',
71-
// when: '336168',
72-
// },
73-
// {
74-
// completion: 'Complete',
75-
// core: '8',
76-
// mask: '0xffffffffffffffffffff',
77-
// price: '7769145866',
78-
// task: '2011',
79-
// when: '326088',
80-
// },
81-
// {
82-
// completion: 'Complete',
83-
// core: '11',
84-
// mask: '0xffffffffffffffffffff',
85-
// price: '7767758517',
86-
// task: '2095',
87-
// when: '336168',
88-
// },
89-
// ];
9070
const coretimeApi = createApiWithAugmentations(kusamaCoretimeMetadata);
9171
const coretimeTypeFactory = new TypeFactory(coretimeApi);
9272

@@ -124,13 +104,22 @@ const potentialRenewalsEntries = () =>
124104
}),
125105
);
126106

107+
const workloadsEntries = () =>
108+
Promise.resolve().then(() =>
109+
mockWorkloads.map((workload) => {
110+
const storageEntry = coretimeApi.query.broker.workload;
111+
const key = coretimeTypeFactory.storageKey(workload.key, 'U32', storageEntry);
112+
return [key, [mockKusamaCoretimeApiBlock26187139.registry.createType('PalletBrokerScheduleItem', workload)]];
113+
}),
114+
);
115+
127116
const mockCoretimeApi = {
128117
...mockKusamaCoretimeApiBlock26187139,
129118
at: (_hash: Hash) => mockCoretimeApi,
130119
consts: {
131120
...mockKusamaApiBlock26187139.consts,
132121
broker: {
133-
timeslicePeriod: 1,
122+
timeslicePeriod: mockKusamaCoretimeApiBlock26187139.registry.createType('U32', '80'),
134123
},
135124
},
136125
query: {
@@ -160,7 +149,7 @@ const mockCoretimeApi = {
160149
leases: leases,
161150
saleInfo: () =>
162151
Promise.resolve().then(() =>
163-
mockKusamaCoretimeApiBlock26187139.registry.createType('PalletBrokerSaleInfoRecord', {
152+
mockKusamaCoretimeApiBlock26187139.registry.createType('Option<PalletBrokerSaleInfoRecord>', {
164153
saleStart: 1705849,
165154
leadinLength: 50400,
166155
endPrice: 776775851,
@@ -178,7 +167,7 @@ const mockCoretimeApi = {
178167
},
179168
workload: {
180169
multi: () => [],
181-
entries: () => [],
170+
entries: workloadsEntries,
182171
},
183172
regions: {
184173
entries: regionsEntries,
@@ -271,10 +260,31 @@ describe('CoretimeService', () => {
271260
});
272261

273262
describe('getInfo', () => {
274-
return;
263+
it('should return info data for relay chain coretime', async () => {
264+
const info = await CoretimeServiceAtRelayChain.getCoretimeInfo(blockHash22887036);
265+
expect(info).toHaveProperty('at');
266+
expect(info).toHaveProperty('brokerId');
267+
expect(info.brokerId).not.toBeNull();
268+
expect(info).toHaveProperty('palletVersion');
269+
expect(info.palletVersion).not.toBeNull();
270+
});
271+
272+
it('should return info data for coretime chain coretime', async () => {
273+
const info = await CoretimeServiceAtCoretimeChain.getCoretimeInfo(blockHash26187139);
274+
expect(info).toHaveProperty('at');
275+
expect(info).toHaveProperty('configuration');
276+
expect(info.configuration).not.toBeNull();
277+
expect(info.configuration?.advanceNotice).toBe(10);
278+
expect(info).toHaveProperty('saleInfo');
279+
expect(info.saleInfo).not.toBeNull();
280+
});
275281
});
276282

277283
describe('getCores', () => {
278-
return;
284+
it('should get workloads', async () => {
285+
const cores = await CoretimeServiceAtCoretimeChain.getCoretimeCores(blockHash26187139);
286+
expect(cores.cores).toHaveLength(2);
287+
expect(cores.at).toHaveProperty('hash');
288+
});
279289
});
280290
});

src/services/test-helpers/mock/coretime/index.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,17 @@ export const mockRegions = [
1717
},
1818
];
1919

20+
export const mockWorkloads = [
21+
{
22+
key: '95',
23+
value: { mask: '0xffffffffffffffffffff', assignment: { task: 2023 } },
24+
},
25+
{
26+
key: '20',
27+
value: { mask: '0xffffffffffffffffffff', assignment: { task: 2222 } },
28+
},
29+
];
30+
2031
export const potentialRenewalsMocks = [
2132
{
2233
key: '0x4dcb50595177a3177648411a42aca0f5689a1593a634a1c1e2cd84ab4db3337ffc046620dd7b3b82380018e60400',

0 commit comments

Comments
 (0)