UI tests for bounties (#4284)

* v test

* Cleanup test. Add pull policy.

* Find new bounty on the list. Extract test support.

* Working no-substrate test

* Change imports to local

* Add a test for validation

* Extract local var

* Update package versions

* Read the right const (dataDepositPerByte)

* Update yarn.lock

* Revert fast test changes.

* Update yarn.lock

* Update yarn.lock
This commit is contained in:
Krzysztof Jelski 2020-12-30 11:46:14 +01:00 committed by GitHub
parent deefa52bfd
commit 21f0eb5a06
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 252 additions and 48 deletions

View File

@ -1,7 +1,7 @@
// Copyright 2017-2020 @polkadot/app-accounts authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { GenericContainer, Wait } from 'testcontainers';
import { AlwaysPullPolicy, GenericContainer, Wait } from 'testcontainers';
import { SubstrateTestsGlobal } from './substrateTestsGlobal';
@ -11,6 +11,7 @@ const startSubstrate = async () => {
console.log('Substrate container starting...');
const startedTestContainer = await new GenericContainer('parity/substrate')
.withPullPolicy(new AlwaysPullPolicy())
.withName('polkadot-apps-test-substrate')
.withExposedPorts(9944)
.withCmd(['--dev', '--ws-port=9944', '--unsafe-ws-external'])

View File

@ -0,0 +1 @@
{}

View File

@ -16,7 +16,6 @@
"file-saver": "^2.0.5"
},
"devDependencies": {
"@testing-library/react": "^11.2.2",
"testcontainers": "^4.7.0"
"@polkadot/test-support": "0.73.2-2"
}
}

View File

@ -4,23 +4,16 @@
import '@polkadot/react-components/i18n';
import { fireEvent, render, waitForElementToBeRemoved } from '@testing-library/react';
import React, { PropsWithChildren } from 'react';
import React from 'react';
import { MemoryRouter } from 'react-router-dom';
import { ThemeProvider } from 'styled-components';
import AccountsApp from '@polkadot/app-accounts';
import { MemoryStore } from '@polkadot/app-accounts/test-support/MemoryStore';
import { lightTheme } from '@polkadot/apps/themes';
import { Api } from '@polkadot/react-api';
import { useApi } from '@polkadot/react-hooks';
const SUBSTRATE_PORT = Number.parseInt(process.env.TEST_SUBSTRATE_PORT || '30333');
const WaitForApi = ({ children }: { children: React.ReactNode }): PropsWithChildren<any> | null => {
const api = useApi();
return api.isApiReady ? (children) : null;
};
import { MemoryStore } from '@polkadot/test-support/keyring';
import { WaitForApi } from '@polkadot/test-support/react';
import { SUBSTRATE_PORT } from '@polkadot/test-support/substrate';
const renderAccounts = () => {
const memoryStore = new MemoryStore();
@ -44,7 +37,7 @@ const renderAccounts = () => {
};
describe.only('--SLOW--: Account Create', () => {
it('new create modal', async () => {
it('created account is added to list', async () => {
const { findByTestId, findByText, queryByText } = renderAccounts();
const addAccountButton = await findByText('Add account', {}, { timeout: 5000 });
@ -85,7 +78,7 @@ describe.only('--SLOW--: Account Create', () => {
expect(await findByText('MY NEW ACCOUNT')).toBeTruthy();
});
it('error message for derivation path', async () => {
it('gives an error message when entering invalid derivation path', async () => {
const { findByTestId, findByText } = renderAccounts();
const addAccountButton = await findByText('Add account', {}, { timeout: 5000 });

View File

@ -15,6 +15,6 @@
},
"devDependencies": {
"@testing-library/react": "^11.2.2",
"testcontainers": "^4.7.0"
"testcontainers": "^6.4.0"
}
}

View File

@ -13,7 +13,6 @@
"@polkadot/react-components": "^0.73.2-16"
},
"devDependencies": {
"@testing-library/react": "^11.2.2",
"testcontainers": "^4.7.0"
"@polkadot/test-support": "0.73.2-2"
}
}

View File

@ -0,0 +1,54 @@
// Copyright 2017-2020 @polkadot/app-accounts authors & contributors
// SPDX-License-Identifier: Apache-2.0
import '@polkadot/react-components/i18n';
import { render } from '@testing-library/react';
import BN from 'bn.js';
import React, { Suspense } from 'react';
import { MemoryRouter } from 'react-router-dom';
import { ThemeProvider } from 'styled-components';
import BountiesApp from '@polkadot/app-bounties/index';
import { lightTheme } from '@polkadot/apps/themes';
import { Api } from '@polkadot/react-api';
import { createApi } from '@polkadot/test-support/api';
import { MemoryStore } from '@polkadot/test-support/keyring';
import { aliceSigner } from '@polkadot/test-support/keyring/signers';
import { WaitForApi } from '@polkadot/test-support/react';
import { execute } from '@polkadot/test-support/transaction/execute';
const SUBSTRATE_PORT = Number.parseInt(process.env.TEST_SUBSTRATE_PORT || '30333');
const renderBounties = () => {
const memoryStore = new MemoryStore();
return render(
<Suspense fallback='...'>
<MemoryRouter>
<ThemeProvider theme={lightTheme}>
<Api store={memoryStore}
url={`ws://127.0.0.1:${SUBSTRATE_PORT}`}>
<WaitForApi>
<div>
<BountiesApp basePath='/bounties' />
</div>
</WaitForApi>
</Api>
</ThemeProvider>
</MemoryRouter>
</Suspense>
);
};
describe('--SLOW--: Bounties', () => {
it('list shows an existing bounty', async () => {
const api = await createApi();
await execute(api.tx.bounties.proposeBounty(new BN(500_000_000_000_000), 'new bounty hello hello more bytes'), aliceSigner());
const { findByText } = renderBounties();
expect(await findByText('new bounty hello hello more bytes', {}, { timeout: 20_000 })).toBeTruthy();
});
});

View File

View File

View File

@ -0,0 +1,14 @@
{
"name": "@polkadot/test-support",
"version": "0.73.2-2",
"main": "index.js",
"repository": "github:polkadot-js/apps",
"author": "Jaco Greeff <jacogr@gmail.com>",
"maintainers": [],
"contributors": [],
"license": "Apache-2.0",
"dependencies": {
"@testing-library/react": "^11.2.2",
"testcontainers": "^6.4.0"
}
}

View File

@ -0,0 +1,24 @@
// Copyright 2017-2020 @polkadot/test-support authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { ApiPromise } from '@polkadot/api/promise';
import { WsProvider } from '@polkadot/rpc-provider';
import { SUBSTRATE_PORT } from '@polkadot/test-support/substrate';
export async function createApi (): Promise<ApiPromise> {
process.env.NODE_ENV = 'test';
const provider = new WsProvider(`ws://127.0.0.1:${SUBSTRATE_PORT}`);
const api = await ApiPromise.create({ provider });
const [chain, nodeName, nodeVersion] = await Promise.all([
api.rpc.system.chain(),
api.rpc.system.name(),
api.rpc.system.version()
]);
console.log(`You are connected to chain ${chain.toString()} using ${nodeName.toString()} v${nodeVersion.toString()}`);
return api;
}

View File

@ -0,0 +1,4 @@
// Copyright 2017-2020 @polkadot/test-support authors & contributors
// SPDX-License-Identifier: Apache-2.0
export * from './createApi';

View File

@ -1,4 +1,4 @@
// Copyright 2017-2020 @polkadot/app-accounts authors & contributors
// Copyright 2017-2020 @polkadot/test-support authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { KeyringJson, KeyringStore } from '@polkadot/ui-keyring/types';

View File

@ -0,0 +1,5 @@
// Copyright 2017-2020 @polkadot/test-support authors & contributors
// SPDX-License-Identifier: Apache-2.0
export * from './MemoryStore';
export * from './signers';

View File

@ -0,0 +1,11 @@
// Copyright 2017-2020 @polkadot/test-support authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { Keyring } from '@polkadot/keyring';
import { KeyringPair } from '@polkadot/keyring/types';
export function aliceSigner (): KeyringPair {
const keyring = new Keyring({ type: 'sr25519' });
return keyring.addFromUri('//Alice');
}

View File

@ -0,0 +1,12 @@
// Copyright 2017-2020 @polkadot/test-support authors & contributors
// SPDX-License-Identifier: Apache-2.0
import React, { PropsWithChildren } from 'react';
import { useApi } from '@polkadot/react-hooks';
export const WaitForApi = ({ children }: { children: React.ReactNode }): PropsWithChildren<any> | null => {
const api = useApi();
return api.isApiReady ? (children) : null;
};

View File

@ -0,0 +1,4 @@
// Copyright 2017-2020 @polkadot/test-support authors & contributors
// SPDX-License-Identifier: Apache-2.0
export * from './apiInTests';

View File

@ -0,0 +1,4 @@
// Copyright 2017-2020 @polkadot/test-support authors & contributors
// SPDX-License-Identifier: Apache-2.0
export const SUBSTRATE_PORT = Number.parseInt(process.env.TEST_SUBSTRATE_PORT || '30333');

View File

@ -0,0 +1,4 @@
// Copyright 2017-2020 @polkadot/test-support authors & contributors
// SPDX-License-Identifier: Apache-2.0
export * from './constants';

View File

@ -0,0 +1,40 @@
// Copyright 2017-2020 @polkadot/test-support authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { waitFor } from '@testing-library/react';
import { SubmittableExtrinsic } from '@polkadot/api/types';
import { KeyringPair } from '@polkadot/keyring/types';
import { EventRecord, ExtrinsicStatus } from '@polkadot/types/interfaces';
export async function execute (extrinsic: SubmittableExtrinsic<'promise'>, singer: KeyringPair, logger = { info: console.log }): Promise<void> {
let currentTxDone = false;
function sendStatusCb ({ events = [], status }: { events?: EventRecord[], status: ExtrinsicStatus; }) {
if (status.isInvalid) {
logger.info('Transaction invalid');
currentTxDone = true;
} else if (status.isReady) {
logger.info('Transaction is ready');
} else if (status.isBroadcast) {
logger.info('Transaction has been broadcasted');
} else if (status.isInBlock) {
logger.info('Transaction is in block');
} else if (status.isFinalized) {
logger.info(`Transaction has been included in blockHash ${status.asFinalized.toHex()}`);
events.forEach(
({ event }) => {
if (event.method === 'ExtrinsicSuccess') {
logger.info('Transaction succeeded');
} else if (event.method === 'ExtrinsicFailed') {
logger.info('Transaction failed');
}
}
);
currentTxDone = true;
}
}
await extrinsic.signAndSend(singer, sendStatusCb);
await waitFor(() => expect(currentTxDone).toBeTruthy(), { timeout: 20000 });
}

View File

@ -0,0 +1,4 @@
// Copyright 2017-2020 @polkadot/test-support authors & contributors
// SPDX-License-Identifier: Apache-2.0
export * from './execute';

View File

@ -73,7 +73,9 @@
"@polkadot/react-query": [ "packages/react-query/src" ],
"@polkadot/react-query/*": [ "packages/react-query/src/*" ],
"@polkadot/react-signer": [ "packages/react-signer/src" ],
"@polkadot/react-signer/*": [ "packages/react-signer/src/*" ]
"@polkadot/react-signer/*": [ "packages/react-signer/src/*" ],
"@polkadot/test-support/": [ "packages/test-support/src/" ],
"@polkadot/test-support/*": [ "packages/test-support/src/*" ]
},
"skipLibCheck": true,
"typeRoots": [

View File

@ -1958,11 +1958,10 @@ __metadata:
dependencies:
"@babel/runtime": ^7.12.5
"@polkadot/react-components": ^0.73.2-16
"@polkadot/test-support": 0.73.2-2
"@polkadot/vanitygen": ^0.25.2-0
"@testing-library/react": ^11.2.2
detect-browser: ^5.2.0
file-saver: ^2.0.5
testcontainers: ^4.7.0
languageName: unknown
linkType: soft
@ -1974,7 +1973,7 @@ __metadata:
"@polkadot/react-components": ^0.73.2-16
"@testing-library/react": ^11.2.2
file-saver: ^2.0.5
testcontainers: ^4.7.0
testcontainers: ^6.4.0
languageName: unknown
linkType: soft
@ -1984,8 +1983,7 @@ __metadata:
dependencies:
"@babel/runtime": ^7.12.5
"@polkadot/react-components": ^0.73.2-16
"@testing-library/react": ^11.2.2
testcontainers: ^4.7.0
"@polkadot/test-support": 0.73.2-2
languageName: unknown
linkType: soft
@ -2620,6 +2618,15 @@ __metadata:
languageName: node
linkType: hard
"@polkadot/test-support@0.73.2-2, @polkadot/test-support@workspace:packages/test-support":
version: 0.0.0-use.local
resolution: "@polkadot/test-support@workspace:packages/test-support"
dependencies:
"@testing-library/react": ^11.2.2
testcontainers: ^6.4.0
languageName: unknown
linkType: soft
"@polkadot/ts@npm:^0.3.58":
version: 0.3.58
resolution: "@polkadot/ts@npm:0.3.58"
@ -3149,12 +3156,12 @@ __metadata:
languageName: node
linkType: hard
"@types/dockerode@npm:^2.5.34":
version: 2.5.34
resolution: "@types/dockerode@npm:2.5.34"
"@types/dockerode@npm:^3.2.1":
version: 3.2.1
resolution: "@types/dockerode@npm:3.2.1"
dependencies:
"@types/node": "*"
checksum: ae3893a618b3cc43569b4face73196d82065a82b28fafc379dd75eb812097e33c8ec5151d608f3dd28cf5f60e313f3ea1b88e4f11954c46aaad371346709ad56
checksum: 3e4d1bfe2056bb14959715216583c7f10b4da7660592e676d9e5d1a556cd006c3ad517a96e9468d6bdff4884f434806e5c567476e6add1eb00ced5b9b50ee278
languageName: node
linkType: hard
@ -3517,6 +3524,25 @@ __metadata:
languageName: node
linkType: hard
"@types/ssh2-streams@npm:*":
version: 0.1.8
resolution: "@types/ssh2-streams@npm:0.1.8"
dependencies:
"@types/node": "*"
checksum: 32adc38f70e525225571525959fa3ac7920400fe53032003af021281424f61dd43a727a2f4ee54d3c395656ed814dcac7e09cdc11edf8878d7acb13934ce3914
languageName: node
linkType: hard
"@types/ssh2@npm:^0.5.45":
version: 0.5.46
resolution: "@types/ssh2@npm:0.5.46"
dependencies:
"@types/node": "*"
"@types/ssh2-streams": "*"
checksum: b22aea80fa2f37b1d0bde6d704ffd2ca539a453f50d895834460c6f1408fc39d8917983f5af54dddfdfab9073dff10aeacc8e299fa6c66ee5bba7d7ebdd08562
languageName: node
linkType: hard
"@types/stack-utils@npm:^2.0.0":
version: 2.0.0
resolution: "@types/stack-utils@npm:2.0.0"
@ -6673,7 +6699,7 @@ __metadata:
languageName: node
linkType: hard
"debug@npm:^4.0.0, debug@npm:^4.0.1, debug@npm:^4.1.0, debug@npm:^4.1.1, debug@npm:^4.2.0, debug@npm:^4.2.1, debug@npm:^4.3.0":
"debug@npm:^4.0.0, debug@npm:^4.0.1, debug@npm:^4.1.0, debug@npm:^4.1.1, debug@npm:^4.2.0, debug@npm:^4.2.1, debug@npm:^4.3.0, debug@npm:^4.3.1":
version: 4.3.2
resolution: "debug@npm:4.3.2"
dependencies:
@ -13062,13 +13088,6 @@ fsevents@~2.1.2:
languageName: node
linkType: hard
"node-duration@npm:^1.0.4":
version: 1.0.4
resolution: "node-duration@npm:1.0.4"
checksum: 28e395acc52d294b3970e06081047cfb7ca1226fe0ccbd8f9988e02fee0b8c057117775a318c781f9e2536ecfe1277dcb337722502f5c26d1b52b9af5e691403
languageName: node
linkType: hard
"node-fetch@npm:^2.6.0, node-fetch@npm:^2.6.1":
version: 2.6.1
resolution: "node-fetch@npm:2.6.1"
@ -16699,6 +16718,16 @@ fsevents@~2.1.2:
languageName: node
linkType: hard
"ssh-remote-port-forward@npm:^1.0.3":
version: 1.0.3
resolution: "ssh-remote-port-forward@npm:1.0.3"
dependencies:
"@types/ssh2": ^0.5.45
ssh2: ^0.8.9
checksum: ef77606569ecd08a3d1fb1e497528e90a662ce9695fa3384371a5fa7a393d8585b60b8e1e24f2f71a33b8e59c11f042e90350dfe8bfd74292449d4f4716df659
languageName: node
linkType: hard
"ssh2-streams@npm:~0.4.10":
version: 0.4.10
resolution: "ssh2-streams@npm:0.4.10"
@ -16710,7 +16739,7 @@ fsevents@~2.1.2:
languageName: node
linkType: hard
"ssh2@npm:^0.8.7":
"ssh2@npm:^0.8.7, ssh2@npm:^0.8.9":
version: 0.8.9
resolution: "ssh2@npm:0.8.9"
dependencies:
@ -17297,7 +17326,7 @@ fsevents@~2.1.2:
languageName: node
linkType: hard
"tar-fs@npm:^2.0.0, tar-fs@npm:^2.1.0":
"tar-fs@npm:^2.0.0, tar-fs@npm:^2.1.1":
version: 2.1.1
resolution: "tar-fs@npm:2.1.1"
dependencies:
@ -17445,22 +17474,22 @@ fsevents@~2.1.2:
languageName: node
linkType: hard
"testcontainers@npm:^4.7.0":
version: 4.7.0
resolution: "testcontainers@npm:4.7.0"
"testcontainers@npm:^6.4.0":
version: 6.4.1
resolution: "testcontainers@npm:6.4.1"
dependencies:
"@types/dockerode": ^2.5.34
"@types/dockerode": ^3.2.1
byline: ^5.0.0
debug: ^4.1.1
debug: ^4.3.1
docker-compose: ^0.23.5
dockerode: ^3.2.1
get-port: ^5.1.1
glob: ^7.1.6
node-duration: ^1.0.4
slash: ^3.0.0
ssh-remote-port-forward: ^1.0.3
stream-to-array: ^2.3.0
tar-fs: ^2.1.0
checksum: 185d072665aab469c61767c9b74f95e0f33680a786817f9ab499c40520e07b78f77a166c22666273fae87697d871249f96d63e0772da5858ddab0648d152b56b
tar-fs: ^2.1.1
checksum: 7ce872319fe15ec6a56b000ed0e9fb9955e98937945d6a8234c1368d34601dce150553c819eda71730d21892ab4b8157f1383fc42890355376da769ca8b946ba
languageName: node
linkType: hard