Skip to content

Commit

Permalink
Create shards.cs-e2e.ts (#1406)
Browse files Browse the repository at this point in the history
  • Loading branch information
cfaur09 authored Dec 5, 2024
1 parent fc6a1f5 commit 5707d61
Showing 1 changed file with 75 additions and 0 deletions.
75 changes: 75 additions & 0 deletions src/test/chain-simulator/shards.cs-e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import axios from 'axios';
import { config } from "./config/env.config";
import { ChainSimulatorUtils } from "./utils/test.utils";

describe('Shards e2e tests with chain simulator', () => {
beforeAll(async () => {
await ChainSimulatorUtils.waitForEpoch(2);
});

describe('GET /shards', () => {
it('should return status code 200 and a list of shards', async () => {
const response = await axios.get(`${config.apiServiceUrl}/shards`);

expect(response.status).toBe(200);
expect(response.data).toBeInstanceOf(Array);
});
});
describe('GET /shards with pagination', () => {
it('should return status code 200 and paginated shards with default values', async () => {
const response = await axios.get(`${config.apiServiceUrl}/shards`);
expect(response.status).toBe(200);
expect(response.data).toBeInstanceOf(Array);
expect(response.data.length).toBe(4);
});

it('should return paginated shards with custom size', async () => {
const size = 2;
const response = await axios.get(`${config.apiServiceUrl}/shards?size=${size}`);
expect(response.status).toBe(200);
expect(response.data).toBeInstanceOf(Array);
expect(response.data.length).toBe(size);
});

it('should return paginated shards with custom from', async () => {
const from = 1;
const response = await axios.get(`${config.apiServiceUrl}/shards?from=${from}`);
expect(response.status).toBe(200);
expect(response.data).toBeInstanceOf(Array);
expect(response.data.length).toBe(3);
});

it('should return paginated shards with both from and size', async () => {
const from = 1;
const size = 2;
const response = await axios.get(`${config.apiServiceUrl}/shards?from=${from}&size=${size}`);
expect(response.status).toBe(200);
expect(response.data).toBeInstanceOf(Array);
expect(response.data.length).toBe(size);
});

it('should validate shard structure and data', async () => {
const response = await axios.get(`${config.apiServiceUrl}/shards`);
const shards = response.data;

for (const shard of shards) {
expect(shard).toHaveProperty('shard');
expect(shard).toHaveProperty('validators');
expect(shard).toHaveProperty('activeValidators');
expect(typeof shard.shard).toBe('number');
expect(typeof shard.validators).toBe('number');
expect(typeof shard.activeValidators).toBe('number');
}
});

it('should contain metachain shard (4294967295)', async () => {
const response = await axios.get(`${config.apiServiceUrl}/shards`);
const shards = response.data;
const metachainShard = shards.find((shard: { shard: number }) => shard.shard === 4294967295);

expect(metachainShard).toBeDefined();
expect(metachainShard?.validators).toBeGreaterThanOrEqual(1);
expect(metachainShard?.activeValidators).toBeGreaterThanOrEqual(1);
});
});
});

0 comments on commit 5707d61

Please sign in to comment.