Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create shards.cs-e2e.ts #1406

Merged
merged 2 commits into from
Dec 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
});
});
});
Loading