Skip to content

Commit

Permalink
moved sdk e2e tests to separate package
Browse files Browse the repository at this point in the history
  • Loading branch information
Ptroger committed Oct 10, 2024
1 parent 016b14b commit e226098
Show file tree
Hide file tree
Showing 31 changed files with 160 additions and 14 deletions.
18 changes: 18 additions & 0 deletions packages/user-journey/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": ["../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
}
]
}
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
10 changes: 10 additions & 0 deletions packages/user-journey/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "user-journey",
"version": "0.0.1",
"description": "it's a test suite that covers core scenario for narval's armory.",
"dependencies": {
"@narval-xyz/armory-sdk": "0.8.3"
},
"author": "",
"license": "ISC"
}
21 changes: 21 additions & 0 deletions packages/user-journey/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"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"
},
"test:e2e": {
"executor": "@nx/jest:jest",
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
"options": {
"jestConfig": "packages/armory-sdk/jest.e2e.ts",
"verbose": true,
"runInBand": true
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
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 {
buildAuthClient,
buildPolicy,
Expand All @@ -12,6 +9,9 @@ import {
getAuthHost,
saveDataStore
} from '../../util/setup'
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'

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 { 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'

const TEST_TIMEOUT_MS = 30_000

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable jest/consistent-test-it */
import { Action, Decision, entitiesSchema, FIXTURE, policySchema, Request } from '@narval/policy-engine-shared'
import { Action, Decision, entitiesSchema, FIXTURE, policySchema, Request } from '@narval-xyz/armory-sdk'
import { v4 } from 'uuid'
import defaultEntities from '../../resource/entity/test.default.json'
import approvalsAndSpendingLimit from '../../resource/policy/set/approvals-and-spending-limit.json'
Expand All @@ -9,7 +9,7 @@ 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 @@ -6,11 +6,11 @@ import {
FIXTURE,
policySchema,
Request
} from '@narval/policy-engine-shared'
} from '@narval-xyz/armory-sdk'
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
File renamed without changes.
19 changes: 19 additions & 0 deletions packages/user-journey/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"module": "commonjs",
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitOverride": true,
"noPropertyAccessFromIndexSignature": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true
},
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.lib.json"
}
]
}
10 changes: 10 additions & 0 deletions packages/user-journey/tsconfig.lib.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"declaration": true,
"types": ["node"]
},
"include": ["src/**/*.ts"],
"exclude": ["src/**/*.spec.ts", "src/**/*.test.ts"]
}
3 changes: 2 additions & 1 deletion tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"@narval/nestjs-shared": ["packages/nestjs-shared/src/index.ts"],
"@narval/policy-engine-shared": ["packages/policy-engine-shared/src/index.ts"],
"@narval/signature": ["packages/signature/src/index.ts"],
"@narval/transaction-request-intent": ["packages/transaction-request-intent/src/index.ts"]
"@narval/transaction-request-intent": ["packages/transaction-request-intent/src/index.ts"],
"@narval/user-journey": ["packages/user-journey/src/index.ts"]
},
"removeComments": true,
"rootDir": ".",
Expand Down

0 comments on commit e226098

Please sign in to comment.