Skip to content

Commit

Permalink
[feat]: Allure reports in integration tests PoC (#190)
Browse files Browse the repository at this point in the history
* [feat]: Allure reports in integration tests PoC

Signed-off-by: Dmitry Balashov <[email protected]>

* [fix]: lint, format, type errors

Signed-off-by: Dmitry Balashov <[email protected]>

* [docs]: extend docs

Signed-off-by: Dmitry Balashov <[email protected]>

* [docs]: typos

Signed-off-by: Dmitry Balashov <[email protected]>

---------

Signed-off-by: Dmitry Balashov <[email protected]>
  • Loading branch information
0x009922 authored Mar 13, 2024
1 parent d31c0f0 commit b0ebbd3
Show file tree
Hide file tree
Showing 23 changed files with 898 additions and 607 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ module.exports = {
},
globals: {
BigInt: true,
globalThis: true
},
overrides: [
{
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,9 @@ Each monorepo package might have its own scripts and tasks. You can find the pac
> This package targets `hyperledger/iroha` at current `iroha2-lts` branch, which has a hash `b783f10fa7de26ed1fdd4c526bd162f8636f1a65`.

Put here a new Iroha 2 reference commit information.

### SDK Compatibility Matrix Tests

There are certain integration tests
that are part of the [Compatibility Matrix](https://hyperledger.github.io/iroha-2-docs/reference/compatibility-matrix.html) endeavour.
To read more about it, follow the [client Node integration tests](./packages/client/test/integration/test-node).
4 changes: 3 additions & 1 deletion etc/jakefile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ namespace('test', () => {
await $`pnpm --filter monorepo-crypto test`
})

task('client-integration', ['build:all'], async () => {
task('prepare-client-integration', ['build:all'])

task('client-integration', ['prepare-client-integration'], async () => {
await $`pnpm --filter client test:integration`
})

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
"tsx": "^3.12.2",
"type-fest": "^3.9.0",
"typescript": "^5.2.2",
"vite": "^4.5.0",
"vitest": "^0.34.6",
"vite": "^5.1.5",
"vitest": "^1.3.1",
"zx": "^7.2.0"
}
}
1 change: 1 addition & 0 deletions packages/client/test/integration/test-node/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
allure-results
1 change: 1 addition & 0 deletions packages/client/test/integration/test-node/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
allure-results
27 changes: 27 additions & 0 deletions packages/client/test/integration/test-node/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Client Node Integration Tests

This project is a collection of integration tests running from Node.js with actual Iroha peer.

## SDK Compatibility Matrix

Tests for [compatibility matrix](https://hyperledger.github.io/iroha-2-docs/reference/compatibility-matrix.html)
are defined at [`compatibility.spec.ts`](./test/compatibility.spec.ts).

The easiest way to run tests:

```shell
# run these commands anywhere in the repo

# install packages, once
pnpm i

# prepare artifacts for tests, once
pnpm jake test:prepare-client-integration

# run tests
pnpm --filter client-test-node test
```

Allure reports are stored after tests run at `./allure-results` directory.
**Note:** these reports contain _all_ tests, not only compatibility tests results.
So, be sure to filter the results by their metadata before submitting them to TestOps.
6 changes: 4 additions & 2 deletions packages/client/test/integration/test-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@
"name": "@iroha2/client-test-node",
"private": true,
"scripts": {
"test": "cross-env DEBUG=@iroha2* vitest run main.spec"
"test": "cross-env DEBUG=@iroha2* vitest run",
"typecheck": "tsc --noEmit"
},
"devDependencies": {
"@iroha2/client": "workspace:^7.0.0",
"@iroha2/crypto-target-node": "workspace:^1.1.1",
"@iroha2/test-configuration": "workspace:^",
"@iroha2/test-peer": "workspace:^0.0.1",
"allure-vitest": "^2.14.0",
"cross-env": "^7.0.3",
"fp-ts": "^2.13.1",
"immer": "^9.0.19",
"vite": "^4.5.0"
"vite": "^5.1.5"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/**
* This file is for Compatibility Matrix tests, which assigns specific
* Allure context tags.
*/

import * as allure from 'allure-vitest'
import { pipe } from 'fp-ts/function'
import { describe, expect, test } from 'vitest'
import { clientFactory, setupPeerTestsLifecycle } from './util'
import { datamodel, sugar } from '@iroha2/data-model'

setupPeerTestsLifecycle()

// TODO: consider adding shared context for tests?
// beforeEach(() => { ... })

// Read Allure API: https://allurereport.org/docs/vitest-reference/
describe('Compatibility Matrix tests', () => {
// Based on https://github.com/AlexStroke/iroha-java/blob/007a9ac55991cd8a2b519e62a10144156d9f8301/modules/client/src/test/kotlin/jp/co/soramitsu/iroha2/InstructionsTest.kt#L134
test('register domain', async (ctx) => {
await allure.feature(ctx, 'Domains')
await allure.story(ctx, 'Account registers a domain')
// TODO: add more Allure context

const DOMAIN_NAME = 'new_domain_name'

const { pre, client, getBlocksListener } = clientFactory()
const blocks = await getBlocksListener()

await blocks.wait(async () => {
await client.submitExecutable(
pre,
pipe(sugar.identifiable.newDomain(DOMAIN_NAME), sugar.instruction.register, sugar.executable.instructions),
)
})

const result = (
await client.requestWithQueryBox(
pre,
datamodel.QueryBox(
'FindDomainById',
datamodel.FindDomainById({
id: datamodel.Expression(
'Raw',
datamodel.Value('Id', datamodel.IdBox('DomainId', sugar.domainId(DOMAIN_NAME))),
),
}),
),
)
)
.as('Ok')
.batch.enum.as('Identifiable')
.enum.as('Domain')

expect(result.id.name).toEqual(DOMAIN_NAME)
})
})
59 changes: 6 additions & 53 deletions packages/client/test/integration/test-node/test/main.spec.ts
Original file line number Diff line number Diff line change
@@ -1,57 +1,14 @@
import { Torii, type ToriiRequirementsForApiHttp, setCrypto } from '@iroha2/client'
import { FREE_HEAP } from '@iroha2/crypto-core'
import { crypto } from '@iroha2/crypto-target-node'
import { type RustResult, Logger as ScaleLogger, datamodel, sugar, variant } from '@iroha2/data-model'
import * as TestPeer from '@iroha2/test-peer'
import { Torii } from '@iroha2/client'
import { type RustResult, datamodel, sugar, variant } from '@iroha2/data-model'
import { CLIENT_CONFIG } from '@iroha2/test-configuration'
import { Seq } from 'immutable'
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, test } from 'vitest'
import { delay } from '../../util'
import { clientFactory, keyPair } from './test-util'
import { describe, expect, test } from 'vitest'
import { clientFactory, setupPeerTestsLifecycle } from './util'
import { pipe } from 'fp-ts/function'

// for debugging convenience
new ScaleLogger().mount()
setCrypto(crypto)
setupPeerTestsLifecycle()

let startedPeer: TestPeer.StartPeerReturn | null = null

async function killStartedPeer() {
await startedPeer?.kill()
startedPeer = null
}

async function waitForGenesisCommitted(pre: ToriiRequirementsForApiHttp) {
while (true) {
const { blocks } = await Torii.getStatus(pre)
if (blocks >= 1) return
await delay(50)
}
}

// and now tests...

beforeAll(async () => {
await TestPeer.clearAll()
await TestPeer.prepareConfiguration()
})

beforeEach(async () => {
await TestPeer.clearPeerStorage()
startedPeer = await TestPeer.startPeer()
await waitForGenesisCommitted(clientFactory().pre)
})

afterEach(async () => {
await killStartedPeer()
})

afterAll(async () => {
keyPair.free()
expect(FREE_HEAP.size).toEqual(0)
})

// Actually it is already tested within `@iroha2/test-peer`
// Actually, it is already tested within `@iroha2/test-peer`
test('Peer is healthy', async () => {
const { pre } = clientFactory()

Expand Down Expand Up @@ -209,10 +166,6 @@ test('When querying for not existing domain, returns FindError', async () => {
expect(result.as('Err').enum.as('QueryFailed').enum.as('Find').enum.as('AssetDefinition').name).toBe('XOR')
})

test('Multisignature', async () => {
await import('./multisignature')
})

describe('Events API', () => {
test('transaction-committed event is triggered after AddAsset instruction has been committed', async () => {
const { pre, client } = clientFactory()
Expand Down
Loading

0 comments on commit b0ebbd3

Please sign in to comment.