Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Orion integration tests: Proof of concept #4790

Draft
wants to merge 19 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions start-orion.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#!/usr/bin/env bash
set -e

SCRIPT_PATH="$(dirname "${BASH_SOURCE[0]}")"
cd $SCRIPT_PATH

docker-compose up -d orion-db
docker-compose up -d squid-archive
docker-compose up -d squid-archive-gateway
Expand Down
6 changes: 6 additions & 0 deletions tests/network-tests/run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ then
../../query-node/start.sh
fi

# Start orion
if [ "${NO_ORION}" != true ]
then
../../start-orion.sh
fi

# Execute tests

if [ "${NO_STORAGE}" != true ]
Expand Down
28 changes: 26 additions & 2 deletions tests/network-tests/src/Fixture.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Api } from './Api'
import { assert } from 'chai'
import { ISubmittableResult } from '@polkadot/types/types/'
import { DispatchResult } from '@polkadot/types/interfaces/system'
import { QueryNodeApi } from './QueryNodeApi'
import { SubmittableExtrinsic } from '@polkadot/api/types'
import { extendDebug, Debugger } from './Debugger'
Expand Down Expand Up @@ -90,6 +89,13 @@ export abstract class BaseQueryNodeFixture extends BaseFixture {
// Implement in child class!
}

public async runOrionChecks(): Promise<void> {
if (!this.executed) {
throw new Error('Cannot run orion checks before Fixture is executed')
}
// Implement in child class!
}

protected findMatchingQueryNodeEvent<T extends AnyQueryNodeEvent>(
eventToFind: EventDetails,
queryNodeEvents: T[]
Expand Down Expand Up @@ -125,7 +131,7 @@ export abstract class StandardizedFixture extends BaseQueryNodeFixture {
})
}

public setErrorName(errName: string) {
public setErrorName(errName: string): void {
this.expectedErrorName = errName
}

Expand Down Expand Up @@ -154,6 +160,7 @@ export class FixtureRunner {
private fixture: BaseFixture
private ran = false
private queryNodeChecksRan = false
private orionChecksRan = false

constructor(fixture: BaseFixture) {
this.fixture = fixture
Expand Down Expand Up @@ -190,8 +197,25 @@ export class FixtureRunner {
await this.fixture.runQueryNodeChecks()
}

public async runOrionChecks(): Promise<void> {
if (process.env.SKIP_ORION_CHECKS) {
return
}
if (!(this.fixture instanceof BaseQueryNodeFixture)) {
throw new Error('Tried to run orion checks for non-query-node fixture!')
}
if (this.orionChecksRan) {
throw new Error('Fixture orion checks already ran')
}

this.orionChecksRan = true

await this.fixture.runOrionChecks()
}

public async runWithQueryNodeChecks(): Promise<void> {
await this.run()
await this.runQueryNodeChecks()
await this.runOrionChecks()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { MembershipBoughtEventFieldsFragment, MembershipFieldsFragment } from '.
import { Utils } from '../../utils'
import { StandardizedFixture } from '../../Fixture'
import { SubmittableResult } from '@polkadot/api'
import axios from 'axios'

type MembershipBoughtEventDetails = EventDetails<EventType<'members', 'MembershipBought'>>

Expand Down Expand Up @@ -124,4 +125,22 @@ export class BuyMembershipHappyCaseFixture extends StandardizedFixture {
const qMembers = await this.query.getMembersByIds(this.events.map((e) => e.event.data[0]))
this.assertQueriedMembersAreValid(qMembers, qEvents)
}

public async runOrionChecks(): Promise<void> {
await super.runOrionChecks()
// Wait a minute, let Orion catch up
await Utils.wait(60_000)
const result = await axios.post('http://localhost:4350/graphql', {
query: `
query {
memberships(where: { id_in: [${this.getCreatedMembers()
.map((id) => `"${id}"`)
.join(', ')}] }) {
id
}
}
`,
})
assert.equal(result.data.data.memberships.length, this.getCreatedMembers().length)
}
}
7 changes: 7 additions & 0 deletions tests/network-tests/src/scenarios/orion.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { scenario } from '../Scenario'
import buyingMemberships from '../flows/membership/buyingMemberships'

// eslint-disable-next-line @typescript-eslint/no-floating-promises
scenario('Orion', async ({ job }) => {
job('buying memberships', buyingMemberships)
})