Skip to content

Commit

Permalink
test(e2e-tests): add e2e-tests for latest runtimes, and blocks (#1155)
Browse files Browse the repository at this point in the history
* test(e2e-tests): outline errors for the process

* add correct error code when sidecar fails to build

* reorg the tsconfig in e2e tests and where the entry file exists

* add endpoints

* change yarn script names to historical for init

* change request format to return statusCode as well as data

* add working script

* some cleanup

* organize naming

* cleanup

* fix tiny grumble

* add license to file

* add script to startup the e2e tests

* fix small blunders, and add scripts to package.json

* set runE2eTests to runHistoricalE2eTests

* add --local to historical e2e tests

* get local working, and fix resolving errors

* fix is local to fail when a chain is not specified

* DRY up code

* update docs in scripts

* docs in e2e-tests

* cleanup

* add all statemint end points

* make `--local` take in an input

* update release notes

* add latest to readme

* new lint
  • Loading branch information
TarikGul committed Dec 20, 2022
1 parent 907ba92 commit 095f57f
Show file tree
Hide file tree
Showing 20 changed files with 747 additions and 124 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,8 @@ and read the release notes for any breaking changes or high priority updates. In
yarn build
yarn lint
yarn test
yarn test:init-e2e-tests
yarn test:historical-e2e-tests
yarn test:latest-e2e-tests
```

1. Commit the dependency updates with a name like `fix(deps): update pjs api` (title depending on what got updated, see commit history for other examples of this), and wait to get it merged.
Expand Down
4 changes: 2 additions & 2 deletions RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

1. Checkout a branch with the format `name-v5-0-1`. When deciding what version will be released it is important to look over 1) PRs since the last release and 2) release notes for any updated polkadot-js dependencies as they may affect type definitions.

1. The next step is making sure the release will work against all relevant runtimes for Polkadot, Kusama, and Westend. This can be handled by running `yarn test:init-e2e-tests`. If you would like to test on an individual chain, you may run the same command followed by its chain, ex: `yarn test:init-e2e-tests:polkadot`. Before moving forward ensure all tests pass, and if it warns of any missing types feel free to make an issue [here](https://github.com/paritytech/substrate-api-sidecar/issues).
1. The next step is to run the e2e tests. There are two types of e2e tests: `yarn test:historical-e2e-tests`, and `yarn test:latest-e2e-tests`. If you would like to run either tests against a single chain you may use the flag `--chain` to specify the chain. If you would also like to test against a local node you may use the `--local` flag in conjunction with `--chain`. Before moving forward ensure all tests pass, and if it warns of any missing types feel free to make an issue [here](https://github.com/paritytech/substrate-api-sidecar/issues).

Note: that the e2e tests will connect to running nodes in order to test sidecar against real data, and they may fail owing to those connections taking too long to establish. If you run into any failures, try running tests just for the chain that failed with something like `yarn test:init-e2e-tests:polkadot`.
Note: that the e2e tests will connect to running nodes in order to test sidecar against real data, and they may fail owing to those connections taking too long to establish. If you run into any failures, try running tests the tests again.

1. Update the version in the package.json (this is very important for releasing on NPM).

Expand Down
38 changes: 26 additions & 12 deletions e2e-tests/README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,36 @@
## Summary

This is a helper library for Sidecar to run e2e tests against specific chains, at certain blocks.
This is a helper library to run e2e tests. There are two types of tests to run:

## Testing
1. Historical: Tests that focus on the integrity of the api service with older runtimes.

The below instructions are specific to running the e2e-tests against one chain.
If you are looking to run the e2e-tests against all chains (Polkadot, Kusama, Westend, Statemine) then run `yarn test:init-e2e-tests` in
the root directory of sidecar.
2. Latest: Tests that focus on the integrity of the api service with the current runtime, and most recent block.

### Polkadot
### Historical

To run the tests against a single chain, you may use the following below. For more examples, reference the `<ROOT>/package.json`
Historical tests use jest to run the api service at specific blocks where the result is known. Jest compares the known result to what we receive, and operates like any other test. It requires having the api service running against a live chain (Archive nodes are preferred).

`yarn test:init-e2e-tests:polkadot`
To run the tests locally:

That's it!
All the tests should come back with green checkmarks. If you find a bug file an issue [here](https://github.com/paritytech/substrate-api-sidecar/issues).
```bash
$ yarn build:e2e-tests
$ node ./e2e-tests/build/historical/historical.js --config=./e2e-tests/jest.config.js
```

### Config
`--chain`: The chain you would like to test against. It defaults to `polkadot`.
`--config`: The path to the jest config.

If you are looking to update the e2e-tests config, the file to do so exists in `<ROOT>/scripts/config.ts`.
### Latest

Latest tests run a set of known endpoints with the latest block against the chain. The tests will pass as long as all the responses are succesfull. If any test is 400 or above it will fail, and log each failed query along with its error.

To run the tests locally:

```bash
$ yarn build:e2e-tests
$ node ./e2e-tests/build/latest/index.js
```

#### Flags

`--chain`: The chain you would like to test against. It defaults to `polkadot`.
14 changes: 12 additions & 2 deletions e2e-tests/helpers/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,26 @@

import http from 'http';

export interface IRequest {
data: string;
path: string;
statusCode?: number;
}

export const request = (
path: string,
hostname: string,
port: number
): Promise<string> => {
): Promise<IRequest> => {
return new Promise((resolve) => {
http.get({ path, hostname, port }, (response) => {
let data = '';
response.on('data', (_data) => (data += _data));
response.on('end', () => resolve(data));
response.on('end', () => resolve({
data,
path,
statusCode: response.statusCode,
}));
});
});
};
8 changes: 4 additions & 4 deletions e2e-tests/historical-e2e-tests.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe('Runtime Tests for blocks', () => {
'Given path %p, it should return the correct JSON response',
async (blockPath, blockResponse) => {
const res = await request(blockPath, HOST, PORT);
const responseJson = JSON.parse(res) as IBlockResponse;
const responseJson = JSON.parse(res.data) as IBlockResponse;

expect(responseJson).toStrictEqual(JSON.parse(blockResponse));
}
Expand All @@ -64,7 +64,7 @@ describe('Runtime Tests for accounts', () => {
'Given path %p, it should return the correct JSON response',
async (accountsPath, accountsResponse) => {
const res = await request(accountsPath, HOST, PORT);
const responseJson = JSON.parse(res) as AccountsResponse;
const responseJson = JSON.parse(res.data) as AccountsResponse;

expect(responseJson).toStrictEqual(JSON.parse(accountsResponse));
}
Expand All @@ -80,7 +80,7 @@ describe('Runtime Tests for `/runtime/*`', () => {
'Given path %p, it should return the correct JSON response',
async (runtimePath, runtimeResponse) => {
const res = await request(runtimePath, HOST, PORT);
const responseJson = JSON.parse(res) as RuntimeResponse;
const responseJson = JSON.parse(res.data) as RuntimeResponse;

expect(responseJson).toStrictEqual(JSON.parse(runtimeResponse));
}
Expand All @@ -97,7 +97,7 @@ describe('Runtime Tests for `/paras/*`', () => {
async (runtimePath, runtimeResponse) => {
const res = await request(runtimePath, HOST, PORT);
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const responseJson = JSON.parse(res);
const responseJson = JSON.parse(res.data);

expect(responseJson).toStrictEqual(JSON.parse(runtimeResponse));
}
Expand Down
5 changes: 3 additions & 2 deletions e2e-tests/index.ts → e2e-tests/historical/historical.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import { ArgumentParser } from 'argparse';

import { IParser } from './historical/types';
import { IParser } from './types';

const config = {
chain: 'polkadot',
Expand All @@ -25,7 +25,8 @@ const config = {
const argv = process.argv.slice(0, 2);

/**
* The arg parser takes in two commands.
* The arg parser takes in two commands. This file also directly relates to the historical e2e-tests.
*
* @arg --chain The chain to be passed into the jest test
* @arg --config The path to the correct jest config. This is important as the
* jest config inside of /runtime-tests ignores all the other tests.
Expand Down
18 changes: 18 additions & 0 deletions e2e-tests/latest/endpoints/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright 2017-2022 Parity Technologies (UK) Ltd.
// This file is part of Substrate API Sidecar.
//
// Substrate API Sidecar is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

export * from './polkadot';
export * from './statemint';
182 changes: 182 additions & 0 deletions e2e-tests/latest/endpoints/polkadot.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
// Copyright 2017-2022 Parity Technologies (UK) Ltd.
// This file is part of Substrate API Sidecar.
//
// Substrate API Sidecar is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

import { IConfig } from '../types/endpoints';

export const polkadot: IConfig = {
'/accounts/{accountId}/balance-info': {
path: '/accounts/12xtAYsRUrmbniiWQqJtECiBQrMn8AypQcXhnQAc6RB6XkLW/balance-info',
queryParams: [
'denominated=true',
'at={blockId}'
],
},
'/accounts/{accountId}/convert': {
path: '/accounts/0xde1894014026720b9918b1b21b488af8a0d4f15953621233830946ec0b4d7b75/convert',
queryParams: [],
},
'/accounts/{accountId}/vesting-info': {
path: '/accounts/15aKvwRqGVAwuBMaogtQXhuz9EQqUWsZJSAzomyb5xYwgBXA/vesting-info',
queryParams: [
'at={blockId}',
],
},
'/accounts/{accountId}/staking-info': {
path: '/accounts/12BnVhXxGBZXoq9QAkSv9UtVcdBs1k38yNx6sHUJWasTgYrm/staking-info',
queryParams: [
'at={blockId}'
]
},
'/accounts/{accountId}/staking-payouts': {
path: '/accounts/12BnVhXxGBZXoq9QAkSv9UtVcdBs1k38yNx6sHUJWasTgYrm/staking-payouts',
queryParams: [
'at={blockId}',
'unclaimedOnly=false',
],
},
'/accounts/{accountId}/validate': {
path: '/accounts/DXgXPAT5zWtPHo6FhVvrDdiaDPgCNGxhJAeVBYLtiwW9hAc/validate',
queryParams: [],
},
'/blocks': {
path: '/blocks?range=1-5',
queryParams: [],
},
'/blocks/{blockId}': {
path: '/blocks/{blockId}',
queryParams: [
'eventDocs=true',
'extrinsicDocs=true',
],
},
'/blocks/{blockId}/header': {
path: '/blocks/{blockId}/header',
queryParams: [],
},
'/blocks/{blockId}/extrinsics/{extrinsicIndex}': {
path: `/blocks/{blockId}/extrinsics/0`,
queryParams: [
'eventDocs=true',
'extrinsicDocs=true',
],
},
'/blocks/head': {
path: `/blocks/head`,
queryParams: [
'eventDocs=true',
'extrinsicDocs=true',
],
},
'/blocks/head/header': {
path: '/blocks/head',
queryParams: [],
},
'/node/network': {
path: '/node/network',
queryParams: [],
},
'/node/transaction-pool': {
path: '/node/transaction-pool',
queryParams: [
'includeFee=true',
],
},
'/node/version': {
path: '/node/version',
queryParams: [],
},
'/pallets/staking/progress': {
path: '/pallets/staking/progress',
queryParams: [
'at={blockId}',
],
},
'/pallets/{palletId}/storage': {
path: '/pallets/System/storage',
queryParams: [
'onlyIds=true',
'at={blockId}',
],
},
'/pallets/{palletId}/storage/{storageItemId}': {
path: '/pallets/System/storage/BlockWeight',
queryParams: [
'metadata=true',
'at={blockId}',
],
},
'/runtime/metadata': {
path: '/runtime/metadata',
queryParams: [
'at={blockId}',
],
},
'/runtime/code': {
path: '/runtime/code',
queryParams: [
'at={blockId}',
],
},
'/runtime/spec': {
path: '/runtime/spec',
queryParams: [
'at={blockId}',
],
},
'/transaction/material': {
path: '/transaction/material',
queryParams: [
'noMeta=true',
],
},
'/paras': {
path: '/paras',
queryParams: [
'at={blockId}',
],
},
'/paras/leases/current': {
path: '/paras/leases/current',
queryParams: [
'at={blockId}',
'currentLeaseHolders=false'
],
},
'/paras/auctions/current': {
path: '/paras/auctions/current',
queryParams: [
'at={blockId}',
],
},
'/paras/crowdloans': {
path: '/paras/crowdloans',
queryParams: [
'at={blockId}',
],
},
'/paras/{paraId}/crowdloan-info': {
path: '/paras/2021/crowdloan-info',
queryParams: [
'at={blockId}',
],
},
'/paras/{paraId}/lease-info': {
path: '/paras/2021/lease-info',
queryParams: [
'at={blockId}',
],
}
}
35 changes: 35 additions & 0 deletions e2e-tests/latest/endpoints/statemint.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright 2017-2022 Parity Technologies (UK) Ltd.
// This file is part of Substrate API Sidecar.
//
// Substrate API Sidecar is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

export const statemint = {
'/accounts/{accountId}/asset-balances': {
path: '/accounts/1ULZhwpUPLLg5VRYiq6rBHY8XaShAmBW7kqGBfvHBqrgBcN/asset-balances',
queryParams: [
'at={blockId}',
'assets[]=100&assets[]=123'
]
},
'/accounts/{accountId}/asset-approvals': {
path: '/accounts/13zCwRqhAj4D33czsm1G82EgHBNq58CCcWRsbwABaby64p1A/asset-approvals?at={blockId}&assetId=1984&delegate=12jU3Wn96uJgfiAe7Zk9s1vKWDz8SBNnqQ8t7s8kj1hDxMMc',
queryParams: [],
},
'/pallets/assets/{assetId}/asset-info': {
path: '/pallets/assets/123/asset-info',
queryParams: [
'at={blockId}'
],
},
};

0 comments on commit 095f57f

Please sign in to comment.