From 5707d6113969c1252c3708d01127817cf5174765 Mon Sep 17 00:00:00 2001 From: Catalin Faur <52102171+cfaur09@users.noreply.github.com> Date: Thu, 5 Dec 2024 14:40:15 +0200 Subject: [PATCH] Create shards.cs-e2e.ts (#1406) --- src/test/chain-simulator/shards.cs-e2e.ts | 75 +++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 src/test/chain-simulator/shards.cs-e2e.ts diff --git a/src/test/chain-simulator/shards.cs-e2e.ts b/src/test/chain-simulator/shards.cs-e2e.ts new file mode 100644 index 000000000..3bac5a645 --- /dev/null +++ b/src/test/chain-simulator/shards.cs-e2e.ts @@ -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); + }); + }); +});