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

Move user journey tests to a package #562

Merged
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflows/packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,25 +54,25 @@ jobs:
- name: Code format
run: |
npx nx affected --target format:check lint:check \
--exclude tag:type:application \
--exclude tag:type:application,user-journey \
--base=origin/main

- name: Test types
run: |
npx nx affected --target test:type \
--exclude tag:type:application \
--exclude tag:type:application,user-journey \
--base=origin/main

- name: Test unit
run: |
npx nx affected --target test:unit \
--exclude tag:type:application \
--exclude tag:type:application,user-journey \
--base=origin/main

- name: Test integration
run: |
npx nx affected --target test:integration \
--exclude tag:type:application \
--exclude tag:type:application,user-journey \
--base=origin/main

- name: Test end-to-end
Expand All @@ -83,7 +83,7 @@ jobs:
# in-memory. It'd be a good time to revisit this TODO and think about
# using testcontainers.
npx nx affected --target test:e2e \
--exclude tag:type:application \
--exclude tag:type:application,user-journey \
--base=origin/main \
--testPathIgnorePatterns=packages/armory-sdk/src/lib/__test__/e2e/*

Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ include ./packages/policy-engine-shared/Makefile
include ./packages/transaction-request-intent/Makefile
include ./packages/signature/Makefile
include ./packages/armory-sdk/Makefile
include ./packages/user-journey/Makefile

# For more terminal color codes, head over to
# https://opensource.com/article/19/9/linux-terminal-colors
Expand Down
3 changes: 3 additions & 0 deletions packages/armory-sdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ export * from './lib/shared/promise'
export * from './lib/types'
export * from './lib/vault'

export type { AuthorizationResponseDtoStatusEnum, CreateClientResponseDto } from './lib/http/client/auth'
export type { ClientDto, WalletDto } from './lib/http/client/vault'
export type { Signer } from './lib/shared/type'
export { resourceId } from './lib/utils'

export type { Jwk, PrivateKey, PublicKey, RsaPublicKey } from '@narval/signature'
Expand Down
25 changes: 25 additions & 0 deletions packages/user-journey/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"extends": ["../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.json"],
"parser": "jsonc-eslint-parser",
"rules": {
"@nx/dependency-checks": "error"
}
}
]
}
37 changes: 37 additions & 0 deletions packages/user-journey/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
USER_JOURNEY_PROJECT_NAME := user-journey
USER_JOURNEY_PROJECT_DIR := ./packages/user-journey

# === Build ===

user-journey/build:
npx nx build ${USER_JOURNEY_PROJECT_NAME}

# === Code format ===

user-journey/format:
npx nx format:write --projects ${USER_JOURNEY_PROJECT_NAME}

user-journey/lint:
npx nx lint ${USER_JOURNEY_PROJECT_NAME} -- --fix

user-journey/format/check:
npx nx format:check --projects ${USER_JOURNEY_PROJECT_NAME}

user-journey/lint/check:
npx nx lint ${USER_JOURNEY_PROJECT_NAME}

# === Testing ===

user-journey/test/type:
npx tsc \
--project ${USER_JOURNEY_PROJECT_DIR}/tsconfig.lib.json \
--noEmit

user-journey/test/unit/watch:
make user-journey/test/unit ARGS=--watch

user-journey/test/e2e:
npx nx test:e2e ${USER_JOURNEY_PROJECT_NAME} -- ${ARGS}

user-journey/test/e2e/watch:
make user-journey/test/e2e ARGS=--watch
3 changes: 3 additions & 0 deletions packages/user-journey/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# User-journey

This package is an e2e test package. It encapsulate some core usage scenarios for armory stack. In order to run, all
18 changes: 18 additions & 0 deletions packages/user-journey/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import type { Config } from 'jest'

const config: Config = {
displayName: 'armory-sdk',
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
preset: '../../jest.preset.js',
testEnvironment: 'node',
transform: {
'^.+\\.[tj]sx?$': [
'ts-jest',
{
tsconfig: '<rootDir>/tsconfig.spec.json'
}
]
}
}

export default config
9 changes: 9 additions & 0 deletions packages/user-journey/jest.e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import type { Config } from 'jest'
import sharedConfig from './jest.config'

const config: Config = {
...sharedConfig,
testMatch: ['<rootDir>/**/__test__/e2e/**/*.spec.ts']
}

export default config
25 changes: 25 additions & 0 deletions packages/user-journey/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "user-journey",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "packages/user-journey/src",
"projectType": "library",
"tags": [],
"targets": {
"lint": {
"executor": "@nx/eslint:lint",
"outputs": ["{options.outputFile}"],
"options": {
"lintFilePatterns": ["packages/user-journey/**/*.ts"]
}
},
"test:e2e": {
"executor": "@nx/jest:jest",
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
"options": {
"jestConfig": "packages/user-journey/jest.e2e.ts",
"verbose": true,
"runInBand": true
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Action, Decision, entitiesSchema, FIXTURE, Request } from '@narval/policy-engine-shared'
import { v4 } from 'uuid'
import defaultEntities from '../../resource/entity/test.default.json'
import twoAdminApproval from '../../resource/policy/checkApprovals/2-admin-approval-required.json'
import adminApproval from '../../resource/policy/checkApprovals/admin-approval-required.json'
import adminPermitAll from '../../resource/policy/checkPrincipalRole/admin-permit-all.json'
import defaultEntities from '../../../resource/entity/test.default.json'
import twoAdminApproval from '../../../resource/policy/checkApprovals/2-admin-approval-required.json'
import adminApproval from '../../../resource/policy/checkApprovals/admin-approval-required.json'
import adminPermitAll from '../../../resource/policy/checkPrincipalRole/admin-permit-all.json'
import {
buildAuthClient,
buildPolicy,
Expand All @@ -12,7 +12,7 @@ import {
getAuthAdminApiKey,
getAuthHost,
saveDataStore
} from '../../util/setup'
} from '../../../util/setup'

const systemManagerHexPk = FIXTURE.UNSAFE_PRIVATE_KEY.Root
const ericPrivateKey = FIXTURE.UNSAFE_PRIVATE_KEY.Eric
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Action, entitiesSchema, FIXTURE, Request } from '@narval/policy-engine-shared'
import { v4 } from 'uuid'
import defaultEntities from '../../resource/entity/test.default.json'
import adminPermitAll from '../../resource/policy/checkPrincipalRole/admin-permit-all.json'
import memberTwoTransferPerDay from '../../resource/policy/checkRateLimit/members-2-transfer-per-day.json'
import defaultEntities from '../../../resource/entity/test.default.json'
import adminPermitAll from '../../../resource/policy/checkPrincipalRole/admin-permit-all.json'
import memberTwoTransferPerDay from '../../../resource/policy/checkRateLimit/members-2-transfer-per-day.json'
import {
buildAuthClient,
buildPolicy,
Expand All @@ -11,7 +11,7 @@ import {
getAuthAdminApiKey,
getAuthHost,
saveDataStore
} from '../../util/setup'
} from '../../../util/setup'

const systemManagerHexPk = FIXTURE.UNSAFE_PRIVATE_KEY.Root
const ericPrivateKey = FIXTURE.UNSAFE_PRIVATE_KEY.Eric
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Action, entitiesSchema, FIXTURE, Request } from '@narval/policy-engine-shared'
import { v4 } from 'uuid'
import defaultEntities from '../../resource/entity/test.default.json'
import adminPermitAll from '../../resource/policy/checkPrincipalRole/admin-permit-all.json'
import treasuryMemberCanTransferOneEthFixed from '../../resource/policy/checkSpendingLimit/treasury-groupMember-can-transfer-1-eth-fixed.json'
import treasuryMemberCanTransferOneEthRolling from '../../resource/policy/checkSpendingLimit/treasury-groupMember-can-transfer-1-eth-rolling.json'
import defaultEntities from '../../../resource/entity/test.default.json'
import adminPermitAll from '../../../resource/policy/checkPrincipalRole/admin-permit-all.json'
import treasuryMemberCanTransferOneEthFixed from '../../../resource/policy/checkSpendingLimit/treasury-groupMember-can-transfer-1-eth-fixed.json'
import treasuryMemberCanTransferOneEthRolling from '../../../resource/policy/checkSpendingLimit/treasury-groupMember-can-transfer-1-eth-rolling.json'
import {
buildAuthClient,
buildPolicy,
Expand All @@ -12,7 +12,7 @@ import {
getAuthAdminApiKey,
getAuthHost,
saveDataStore
} from '../../util/setup'
} from '../../../util/setup'

const systemManagerHexPk = FIXTURE.UNSAFE_PRIVATE_KEY.Root
const ericPrivateKey = FIXTURE.UNSAFE_PRIVATE_KEY.Eric
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import { AddressBookAddresses } from 'packages/policy-engine-shared/src/lib/dev.
import { v4 } from 'uuid'
import { Hex } from 'viem'
import { generatePrivateKey, privateKeyToAccount } from 'viem/accounts'
import defaultEntities from '../../resource/entity/test.default.json'
import addressBookAndRoles from '../../resource/policy/set/address-book-and-roles.json'
import { buildAuthClient, createClient, saveDataStore } from '../../util/setup'
import defaultEntities from '../../../resource/entity/test.default.json'
import addressBookAndRoles from '../../../resource/policy/set/address-book-and-roles.json'
import { buildAuthClient, createClient, saveDataStore } from '../../../util/setup'

const TEST_TIMEOUT_MS = 30_000

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
/* eslint-disable jest/consistent-test-it */
import { Action, Decision, entitiesSchema, FIXTURE, policySchema, Request } from '@narval/policy-engine-shared'
import { v4 } from 'uuid'
import defaultEntities from '../../resource/entity/test.default.json'
import approvalsAndSpendingLimit from '../../resource/policy/set/approvals-and-spending-limit.json'
import { buildAuthClient, createClient, saveDataStore } from '../../util/setup'
import defaultEntities from '../../../resource/entity/test.default.json'
import approvalsAndSpendingLimit from '../../../resource/policy/set/approvals-and-spending-limit.json'
import { buildAuthClient, createClient, saveDataStore } from '../../../util/setup'

const TEST_TIMEOUT_MS = 30_000

jest.setTimeout(TEST_TIMEOUT_MS)

export const advanceTime = (hours: number): void => {
export const peradvanceTime = (hours: number): void => {
jest.useFakeTimers()
jest.setSystemTime(Date.now() + hours * 60 * 60 * 1000)
}
Expand All @@ -25,7 +25,7 @@ const ericPrivateKey = FIXTURE.UNSAFE_PRIVATE_KEY.Eric
const genNonce = (request: Request) => ({ ...request, nonce: `${request.nonce}-${v4()}` })

describe('approvals and spending limits', () => {
describe('members can spend up to 1 eth per day, above an approval is required', () => {
describe('members can spend up to 1 eth day, above an approval is required', () => {
const request: Request = {
action: Action.SIGN_TRANSACTION,
nonce: 'test-nonce-4',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import {
Request
} from '@narval/policy-engine-shared'
import { v4 } from 'uuid'
import defiEntities from '../../resource/entity/defi-interaction.json'
import defiInteractionPolicy from '../../resource/policy/set/defi-interaction.json'
import { buildAuthClient, createClient, saveDataStore } from '../../util/setup'
import defiEntities from '../../../resource/entity/defi-interaction.json'
import defiInteractionPolicy from '../../../resource/policy/set/defi-interaction.json'
import { buildAuthClient, createClient, saveDataStore } from '../../../util/setup'

const TEST_TIMEOUT_MS = 30_000

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/* eslint-disable jest/consistent-test-it */
import { Action, Decision, entitiesSchema, FIXTURE, policySchema, Request, toHex } from '@narval/policy-engine-shared'
import { v4 } from 'uuid'
import defaultEntities from '../../resource/entity/test.default.json'
import tieredEthTransfer from '../../resource/policy/set/tiered-eth-transfer.json'
import { buildAuthClient, createClient, saveDataStore } from '../../util/setup'
import defaultEntities from '../../../resource/entity/test.default.json'
import tieredEthTransfer from '../../../resource/policy/set/tiered-eth-transfer.json'
import { buildAuthClient, createClient, saveDataStore } from '../../../util/setup'

const TEST_TIMEOUT_MS = 30_000

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,23 @@
/* eslint-disable jest/consistent-test-it */
import {
AuthAdminClient,
AuthClient,
AuthorizationResponseDtoStatusEnum,
ClientDto,
CreateClientResponseDto,
DataStoreConfig,
EntityStoreClient,
Permission,
PolicyStoreClient,
SignOptions,
Signer,
VaultAdminClient,
VaultClient,
WalletDto,
createHttpDataStore,
credential,
resourceId
} from '@narval/armory-sdk'
import {
AccessToken,
AccountEntity,
Expand Down Expand Up @@ -26,16 +45,6 @@ import {
import { format } from 'date-fns'
import { v4 as uuid } from 'uuid'
import { english, generateMnemonic, generatePrivateKey, privateKeyToAccount } from 'viem/accounts'
import { AuthAdminClient, AuthClient } from '../../../auth/client'
import { EntityStoreClient, PolicyStoreClient } from '../../../data-store/client'
import { DataStoreConfig } from '../../../data-store/type'
import { createHttpDataStore, credential } from '../../../data-store/util'
import { Permission } from '../../../domain'
import { AuthorizationResponseDtoStatusEnum, CreateClientResponseDto } from '../../../http/client/auth'
import { ClientDto, WalletDto } from '../../../http/client/vault'
import { SignOptions, Signer } from '../../../shared/type'
import { resourceId } from '../../../utils'
import { VaultAdminClient, VaultClient } from '../../../vault/client'

const TEST_TIMEOUT_MS = 30_000

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
import {
AuthAdminClient,
AuthClient,
AuthConfig,
createHttpDataStore,
DataStoreConfig,
EntityStoreClient,
PolicyStoreClient,
VaultAdminClient,
VaultConfig
} from '@narval/armory-sdk'
import { Entities, Hex, Policy, policySchema, Request } from '@narval/policy-engine-shared'
import { buildSignerForAlg, getPublicKey, privateKeyToJwk } from '@narval/signature'
import { format } from 'date-fns'
import { v4 } from 'uuid'
import { AuthAdminClient, AuthClient, AuthConfig } from '../../auth'
import { createHttpDataStore, DataStoreConfig, EntityStoreClient, PolicyStoreClient } from '../../data-store'
import { VaultAdminClient, VaultConfig } from '../../vault'

export const getAuthHost = () => 'http://localhost:3005'
export const getAuthAdminApiKey = () => 'armory-admin-api-key'
Expand Down
18 changes: 18 additions & 0 deletions packages/user-journey/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": "../../tsconfig.base.json",
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.lib.json"
},
{
"path": "./tsconfig.spec.json"
}
],
"compilerOptions": {
"module": "commonjs",
"strict": true,
"resolveJsonModule": true
}
}
Loading