Skip to content

Commit 44e2da4

Browse files
xlcTarikGul
andauthored
test: add acala & karura to e2e tests and some improvements (#1273)
* some improvements * no need to hardcode chains * add acala for e2e tests * add karura * able to configure url * fix * fix * Update e2e-tests/latest/endpoints/acala.ts Co-authored-by: Tarik Gul <[email protected]> --------- Co-authored-by: Tarik Gul <[email protected]>
1 parent 8fdfef8 commit 44e2da4

File tree

7 files changed

+283
-38
lines changed

7 files changed

+283
-38
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
// Copyright 2017-2022 Parity Technologies (UK) Ltd.
2+
// This file is part of Substrate API Sidecar.
3+
//
4+
// Substrate API Sidecar is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// This program is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
17+
import { IConfig } from '../types/endpoints';
18+
19+
export const acala: IConfig = {
20+
'/blocks': {
21+
path: '/blocks?range=3000000-3000005',
22+
queryParams: [],
23+
},
24+
'/blocks/{blockId}': {
25+
path: '/blocks/{blockId}',
26+
queryParams: ['eventDocs=true', 'extrinsicDocs=true'],
27+
},
28+
'/blocks/{blockId}/header': {
29+
path: '/blocks/{blockId}/header',
30+
queryParams: [],
31+
},
32+
'/blocks/{blockId}/extrinsics/{extrinsicIndex}': {
33+
path: `/blocks/{blockId}/extrinsics/0`,
34+
queryParams: ['eventDocs=true', 'extrinsicDocs=true'],
35+
},
36+
'/blocks/head': {
37+
path: `/blocks/head`,
38+
queryParams: ['eventDocs=true', 'extrinsicDocs=true'],
39+
},
40+
'/blocks/head/header': {
41+
path: '/blocks/head',
42+
queryParams: [],
43+
},
44+
'/node/network': {
45+
path: '/node/network',
46+
queryParams: [],
47+
},
48+
'/node/transaction-pool': {
49+
path: '/node/transaction-pool',
50+
queryParams: ['includeFee=true'],
51+
},
52+
'/node/version': {
53+
path: '/node/version',
54+
queryParams: [],
55+
},
56+
'/pallets/{palletId}/storage': {
57+
path: '/pallets/System/storage',
58+
queryParams: ['onlyIds=true', 'at={blockId}'],
59+
},
60+
'/pallets/{palletId}/storage/{storageItemId}': {
61+
path: '/pallets/System/storage/BlockWeight',
62+
queryParams: ['metadata=true', 'at={blockId}'],
63+
},
64+
'/runtime/metadata': {
65+
path: '/runtime/metadata',
66+
queryParams: ['at={blockId}'],
67+
},
68+
'/runtime/code': {
69+
path: '/runtime/code',
70+
queryParams: ['at={blockId}'],
71+
},
72+
'/runtime/spec': {
73+
path: '/runtime/spec',
74+
queryParams: ['at={blockId}'],
75+
},
76+
'/transaction/material': {
77+
path: '/transaction/material',
78+
queryParams: [],
79+
},
80+
};

e2e-tests/latest/endpoints/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
// You should have received a copy of the GNU General Public License
1515
// along with this program. If not, see <http://www.gnu.org/licenses/>.
1616

17+
export * from './acala';
18+
export * from './karura';
1719
export * from './kusama';
1820
export * from './polkadot';
1921
export * from './statemint';
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2017-2022 Parity Technologies (UK) Ltd.
2+
// This file is part of Substrate API Sidecar.
3+
//
4+
// Substrate API Sidecar is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// This program is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
17+
import { acala } from './acala';
18+
19+
export const karura = acala;

e2e-tests/latest/endpoints/statemint.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
// You should have received a copy of the GNU General Public License
1515
// along with this program. If not, see <http://www.gnu.org/licenses/>.
1616

17-
export const statemint = {
17+
import { IConfig } from '../types/endpoints';
18+
19+
export const statemint: IConfig = {
1820
'/accounts/{accountId}/asset-balances': {
1921
path: '/accounts/1ULZhwpUPLLg5VRYiq6rBHY8XaShAmBW7kqGBfvHBqrgBcN/asset-balances',
2022
queryParams: ['at={blockId}', 'assets[]=100&assets[]=123'],

e2e-tests/latest/index.ts

Lines changed: 33 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,16 @@ import { ArgumentParser } from 'argparse';
1818

1919
import { HOST, PORT } from '../helpers/consts';
2020
import { IRequest, request } from '../helpers/request';
21-
import { kusama, polkadot, statemint, westend } from './endpoints';
22-
import { IConfig } from './types/endpoints';
21+
import * as endpoints from './endpoints';
2322

2423
enum StatusCode {
2524
Success = 0,
2625
Failed = 1,
2726
}
2827

2928
interface ILatestE2eParser {
30-
chain: string;
29+
url: string;
30+
chain: keyof typeof endpoints;
3131
}
3232

3333
// This is a shallow mock of the actual response from `/blocks/head`. We only need the number field.
@@ -38,28 +38,15 @@ interface IBlockResponse {
3838
const main = async (args: ILatestE2eParser): Promise<StatusCode> => {
3939
const { Success, Failed } = StatusCode;
4040

41-
let config: IConfig;
42-
switch (args.chain) {
43-
case 'polkadot':
44-
config = polkadot;
45-
break;
46-
case 'kusama':
47-
config = kusama;
48-
break;
49-
case 'westend':
50-
config = westend;
51-
break;
52-
case 'statemint':
53-
config = statemint;
54-
break;
55-
default:
56-
config = polkadot;
57-
break;
58-
}
41+
const config = endpoints[args.chain] ?? endpoints.polkadot;
42+
43+
const url = new URL(args.url);
44+
const host = url.hostname;
45+
const port = Number(url.port);
5946

6047
let blockId: string;
6148
try {
62-
const res = await request('/blocks/head', HOST, PORT);
49+
const res = await request('/blocks/head', host, port);
6350
blockId = (JSON.parse(res.data) as IBlockResponse).number;
6451
} catch (err) {
6552
throw `Error fetching the latest block: ${err as string}`;
@@ -86,41 +73,51 @@ const main = async (args: ILatestE2eParser): Promise<StatusCode> => {
8673
}
8774
}
8875

89-
const responses = await Promise.all(urls.map((u) => request(u, HOST, PORT)));
76+
const responses = await Promise.all(urls.map((u) => request(u, host, port)));
9077
const errors: IRequest[] = [];
9178
responses.forEach((res) => {
9279
if (res.statusCode && res.statusCode >= 400) {
9380
errors.push(res);
9481
}
9582
});
96-
logErrors(errors);
83+
logResults(errors);
9784

9885
if (errors.length > 0) {
9986
console.log(`Finished with a status code of ${Failed}`);
100-
return Failed;
87+
process.exit(Failed);
10188
} else {
10289
console.log(`Finished with a status code of ${Success}`);
103-
return Success;
90+
process.exit(Success);
10491
}
10592
};
10693

107-
const logErrors = (errors: IRequest[]) => {
108-
console.log('Received the following errors:');
109-
errors.forEach((err) => {
110-
console.log('----------------------------------------------');
111-
console.log(`Queried Endpoint: ${err.path}`);
112-
console.log(`Status Code: ${err.statusCode as number}`);
113-
console.log(`Received logging: ${err.data}`);
114-
});
94+
const logResults = (errors: IRequest[]) => {
95+
if (errors.length > 0) {
96+
console.log('Received the following errors:');
97+
errors.forEach((err) => {
98+
console.log('----------------------------------------------');
99+
console.log(`Queried Endpoint: ${err.path}`);
100+
console.log(`Status Code: ${err.statusCode as number}`);
101+
console.log(`Received logging: ${err.data}`);
102+
});
103+
} else {
104+
console.log('No errors were received');
105+
}
115106
};
116107

117108
const parser = new ArgumentParser();
118109

119110
parser.add_argument('--chain', {
120-
choices: ['polkadot', 'statemint', 'westend', 'kusama'],
111+
choices: Object.keys(endpoints),
121112
default: 'polkadot',
122113
});
114+
parser.add_argument('--url', {
115+
default: `http://${HOST}:${PORT}`,
116+
});
123117

124118
const args = parser.parse_args() as ILatestE2eParser;
125119

126-
main(args).finally(() => process.exit());
120+
main(args).catch((e) => {
121+
console.error('Error', e);
122+
process.exit(1);
123+
});

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
"@types/lru-cache": "^7.10.10",
7373
"@types/morgan": "1.9.3",
7474
"@types/triple-beam": "^1.3.2",
75+
"ts-node": "^10.9.1",
7576
"tsc-watch": "^4.6.2",
7677
"wasm-pack": "^0.10.3"
7778
},

0 commit comments

Comments
 (0)