UNPKG

1.47 kBJavaScriptView Raw
1/* global ORE_TESTA_ACCOUNT_NAME:true */
2/* global ORE_NETWORK_URI:true */
3
4const { expectFetch, mock, mockInstruments } = require('./helpers/fetch');
5const { constructOrejs } = require('./helpers/orejs');
6
7describe('usagelog', () => {
8 let orejs;
9
10 beforeAll(() => {
11 orejs = constructOrejs();
12 });
13
14 describe('getRightStats', () => {
15 let rightName;
16 let totalCpu;
17 let totalCount;
18
19 beforeEach(() => {
20 rightName = 'com.company.right';
21 totalCpu = 10;
22 totalCount = 20;
23
24 fetch.resetMocks();
25 fetch.mockResponses(
26 mockInstruments([
27 { owner: ORE_TESTA_ACCOUNT_NAME, instrument: { rights: [{ right_name: rightName }] } },
28 { owner: ORE_TESTA_ACCOUNT_NAME, instrument: { rights: [{ right_name: rightName }] } },
29 ]),
30 mock({ rows: [{ right_name: rightName, total_cpu: `${totalCpu}.0000 CPU`, total_count: totalCount }] }),
31 mock({ rows: [{ right_name: rightName, total_cpu: `${totalCpu}.0000 CPU`, total_count: totalCount }] }),
32 );
33 orejs = constructOrejs({ fetch });
34 });
35
36 it('returns summed stats', async () => {
37 const stats = await orejs.getRightStats(rightName, ORE_TESTA_ACCOUNT_NAME);
38 expectFetch(`${ORE_NETWORK_URI}/v1/chain/get_table_rows`, `${ORE_NETWORK_URI}/v1/chain/get_table_rows`, `${ORE_NETWORK_URI}/v1/chain/get_table_rows`);
39 expect(stats).toEqual({ totalCpuUsage: totalCpu * 2, totalCalls: totalCount * 2 });
40 });
41 });
42});