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

feat: integration tests #2380

Merged
merged 68 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
9e3a707
feat: setup basic test env
BlairCurrey Jan 30, 2024
11200cd
Merge branch 'main' into bc/2049/rafiki-to-rafiki-test
BlairCurrey Jan 30, 2024
5c6acb5
feat: seed integration environment
BlairCurrey Feb 2, 2024
aaa2103
Merge branch 'main' into bc/2049/rafiki-to-rafiki-test
BlairCurrey Feb 2, 2024
71b0257
refactor(localenv,integration): move graphql url to config from seed
BlairCurrey Feb 5, 2024
ec4fe8f
refactor: move testenv configuration into new dir
BlairCurrey Feb 5, 2024
5ab8b67
refactor: cleanup env vars
BlairCurrey Feb 5, 2024
b64d369
feat: add webhook server, fix env vars
BlairCurrey Feb 6, 2024
b95aff8
chore: comment
BlairCurrey Feb 6, 2024
322970e
feat: start grant request test
BlairCurrey Feb 12, 2024
c9096ec
fix: eslint errors
BlairCurrey Feb 12, 2024
9a654a9
fix: docker compose env vars
BlairCurrey Feb 13, 2024
dcc156e
feat: add --build arg
BlairCurrey Feb 13, 2024
83431e0
fix: incoming-payment grant initiation request
BlairCurrey Feb 13, 2024
551ffc3
Merge branch 'main' into bc/2049/rafiki-to-rafiki-test
BlairCurrey Feb 20, 2024
f02db32
fix: ts error
BlairCurrey Feb 20, 2024
24a46f0
Merge branch 'main' into bc/2049/rafiki-to-rafiki-test
BlairCurrey Feb 22, 2024
b7378f6
Merge branch 'main' into bc/2049/rafiki-to-rafiki-test
BlairCurrey Feb 22, 2024
fb0d87f
Merge branch 'main' into bc/2049/rafiki-to-rafiki-test
BlairCurrey Feb 26, 2024
a12910d
feat: implement tests through Create Quote
BlairCurrey Feb 28, 2024
f1f1c59
Merge branch 'main' into bc/2049/rafiki-to-rafiki-test
BlairCurrey Feb 29, 2024
3be48e1
Merge branch 'main' into bc/2049/rafiki-to-rafiki-test
BlairCurrey Mar 1, 2024
afaa594
chore: upgrade op client
BlairCurrey Mar 1, 2024
57f7d7f
feat: partially implemented grant request outgoing payment test
BlairCurrey Mar 1, 2024
52f35b9
feat: rework to host.docker.internal
BlairCurrey Mar 4, 2024
7702441
Merge branch 'main' into bc/2049/rafiki-to-rafiki-test
BlairCurrey Mar 4, 2024
83dc970
feat: add p2p flow test
BlairCurrey Mar 5, 2024
716891e
Merge branch 'main' into bc/2049/rafiki-to-rafiki-test
BlairCurrey Mar 5, 2024
cc93982
feat: add continuation step with consent mocking
BlairCurrey Mar 7, 2024
9e1e215
fix: rm obsolete type cast to any and comment
BlairCurrey Mar 8, 2024
51fc325
feat: add create ougoing payment test
BlairCurrey Mar 8, 2024
b845cd7
Merge branch 'main' into bc/2049/rafiki-to-rafiki-test
BlairCurrey Mar 8, 2024
09e1314
fix: bad pnpm-lock merge
BlairCurrey Mar 8, 2024
b94f452
feat: build deps in mock ase job
BlairCurrey Mar 8, 2024
82e84d6
feat: get non existant wallet address test
BlairCurrey Mar 9, 2024
7dd1f13
fix: update open payments pkg
BlairCurrey Mar 11, 2024
53773cc
chore: fix lint warnings
BlairCurrey Mar 11, 2024
4cd2646
feat: implement continuation polling
BlairCurrey Mar 11, 2024
b17465d
chore: test cleanup
BlairCurrey Mar 12, 2024
af0a038
Merge branch 'main' into bc/2049/rafiki-to-rafiki-test
BlairCurrey Mar 12, 2024
42ab964
refactor: generate gql in tests instead of import from lib
BlairCurrey Mar 12, 2024
e29b58c
chore: rm old comment
BlairCurrey Mar 12, 2024
187df0b
chore: use latest http-singature-utils to match other deps
BlairCurrey Mar 12, 2024
d9a425e
chore: pnpm i
BlairCurrey Mar 12, 2024
5c53d9c
chore: use latest koa-bodyparser
BlairCurrey Mar 12, 2024
d312900
chore: rm engine strict
BlairCurrey Mar 12, 2024
b33ca1f
chore: revert rm engine strict
BlairCurrey Mar 13, 2024
36fd545
chore(integration): dont ignore env, rm example env
BlairCurrey Mar 13, 2024
366d02f
refactor: use docker healthcheck for running tests
BlairCurrey Mar 13, 2024
f85a804
chore: move healthcheck to last started docker container
BlairCurrey Mar 13, 2024
1320b98
feat: use latest open payments pkg, no body requird on continuation
BlairCurrey Mar 14, 2024
2f587d8
Merge branch 'main' into bc/2049/rafiki-to-rafiki-test
BlairCurrey Mar 14, 2024
636832d
chore: pnpm i, fix broken lockfile (no apollo version)
BlairCurrey Mar 14, 2024
f4ad75c
refactor: move webhook event enum to types
BlairCurrey Mar 16, 2024
9c19b9a
refactor: move run integration script to test/integration
BlairCurrey Mar 16, 2024
12c4cb7
Merge branch 'main' into bc/2049/rafiki-to-rafiki-test
BlairCurrey Mar 16, 2024
6085663
Update packages/mock-account-servicing-lib/package.json
BlairCurrey Mar 16, 2024
8994ead
refactor: simplify mock-account-servicing-entity ci step
BlairCurrey Mar 16, 2024
bb98b70
feat(integration): exit run-tests early if containers fail to start
BlairCurrey Mar 16, 2024
0ab5844
feat: use pino logger
BlairCurrey Mar 17, 2024
43d536b
refactor: rename mock account servicing lib
BlairCurrey Mar 18, 2024
a154e4c
Merge branch 'main' into bc/2049/rafiki-to-rafiki-test
BlairCurrey Mar 18, 2024
c4262bb
refactor: rename class files to camel case
BlairCurrey Mar 18, 2024
7f39cd4
fix: import correct body parser
BlairCurrey Mar 18, 2024
a6b937e
refactor: poll instead of delay
BlairCurrey Mar 18, 2024
53c3f30
refactor: simplify call to poll condition only
BlairCurrey Mar 18, 2024
ba612eb
fix: update filenames
BlairCurrey Mar 18, 2024
20c135f
refactor: change filename name to kebab case
BlairCurrey Mar 18, 2024
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
1 change: 1 addition & 0 deletions localenv/cloud-nine-wallet/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ services:
OPEN_PAYMENTS_URL: ${CLOUD_NINE_OPEN_PAYMENTS_URL:-https://cloud-nine-wallet-backend}
AUTH_SERVER_DOMAIN: ${CLOUD_NINE_AUTH_SERVER_DOMAIN:-http://localhost:3006}
TESTNET_AUTOPEER_URL: ${TESTNET_AUTOPEER_URL}
GRAPHQL_URL: http://cloud-nine-wallet-backend:3001/graphql
volumes:
- ../cloud-nine-wallet/seed.yml:/workspace/seed.yml
- ../cloud-nine-wallet/private-key.pem:/workspace/private-key.pem
Expand Down
4 changes: 0 additions & 4 deletions localenv/cloud-nine-wallet/seed.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
self:
graphqlUrl: http://cloud-nine-wallet-backend:3001/graphql
mapHostname: 'primary-mase'
openPaymentPublishedPort: 3000
assets:
- code: USD
scale: 2
Expand Down
1 change: 1 addition & 0 deletions localenv/happy-life-bank/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ services:
SEED_FILE_LOCATION: /workspace/seed.yml
KEY_FILE: /workspace/private-key.pem
OPEN_PAYMENTS_URL: ${HAPPY_LIFE_BANK_OPEN_PAYMENTS_URL:-https://happy-life-bank-backend}
GRAPHQL_URL: http://happy-life-bank-backend:3001/graphql
volumes:
- ../happy-life-bank/seed.yml:/workspace/seed.yml
- ../happy-life-bank/private-key.pem:/workspace/private-key.pem
Expand Down
4 changes: 0 additions & 4 deletions localenv/happy-life-bank/seed.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
self:
graphqlUrl: http://happy-life-bank-backend:3001/graphql
mapHostname: 'primary-mase'
openPaymentPublishedPort: 4000
Comment on lines -1 to -4
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved the graphqlUrl to an environment variable and got rid of self because the other properties were not used. ditto for localenv/happy-life-bank/docker-compose.yml. I could not track down the original intention of these unused properties - looks like they were never used. Just mentioning it in case someone knows something I dont.

assets:
- code: USD
scale: 2
Expand Down
5 changes: 5 additions & 0 deletions localenv/mock-account-servicing-entity/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ FROM base AS prod-deps

COPY package.json pnpm-workspace.yaml .npmrc ./
COPY localenv/mock-account-servicing-entity/package.json ./localenv/mock-account-servicing-entity/package.json
COPY packages/mock-account-servicing-lib/package.json ./packages/mock-account-servicing-lib/package.json

RUN pnpm clean
RUN --mount=type=cache,id=pnpm,target=/pnpm/store \
Expand All @@ -36,6 +37,7 @@ FROM base AS builder

COPY package.json pnpm-workspace.yaml .npmrc tsconfig.json tsconfig.build.json ./
COPY localenv/mock-account-servicing-entity ./localenv/mock-account-servicing-entity
COPY packages/mock-account-servicing-lib ./packages/mock-account-servicing-lib

RUN --mount=type=cache,id=pnpm,target=/pnpm/store \
pnpm install \
Expand All @@ -54,9 +56,12 @@ COPY localenv/happy-life-bank/seed.yml ./localenv/happy-life-bank/seed.yml
COPY --from=prod-deps /home/rafiki/node_modules ./node_modules
COPY --from=prod-deps /home/rafiki/localenv/mock-account-servicing-entity/node_modules ./localenv/mock-account-servicing-entity/node_modules
COPY --from=prod-deps /home/rafiki/localenv/mock-account-servicing-entity/package.json ./localenv/mock-account-servicing-entity/package.json
COPY --from=prod-deps /home/rafiki/packages/mock-account-servicing-lib/node_modules ./packages/mock-account-servicing-lib/node_modules
COPY --from=prod-deps /home/rafiki/packages/mock-account-servicing-lib/package.json ./packages/mock-account-servicing-lib/package.json

COPY --from=builder /home/rafiki/localenv/mock-account-servicing-entity/build ./localenv/mock-account-servicing-entity/build
COPY --from=builder /home/rafiki/localenv/mock-account-servicing-entity/public ./localenv/mock-account-servicing-entity/public
COPY --from=builder /home/rafiki/packages/mock-account-servicing-lib/dist ./packages/mock-account-servicing-lib/dist

WORKDIR /home/rafiki/localenv/mock-account-servicing-entity
CMD ["sh", "./node_modules/.bin/remix-serve", "./build/index.js"]
10 changes: 8 additions & 2 deletions localenv/mock-account-servicing-entity/app/entry.server.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import type { EntryContext } from '@remix-run/node'
import { createReadableStreamFromReadable } from '@remix-run/node'
import { RemixServer } from '@remix-run/react'
import { renderToPipeableStream } from 'react-dom/server'
import { runSeed } from './lib/run_seed.server'
import { setupFromSeed } from 'mock-account-servicing-lib'
import { CONFIG } from './lib/parse_config.server'
import { apolloClient } from './lib/apolloClient'
import { mockAccounts } from './lib/accounts.server'

declare global {
// eslint-disable-next-line no-var
Expand All @@ -27,7 +30,10 @@ async function callWithRetry(fn: () => any, depth = 0): Promise<void> {
}

if (!global.__seeded) {
callWithRetry(runSeed)
callWithRetry(async () => {
console.log('setting up from seed...')
return setupFromSeed(CONFIG, apolloClient, mockAccounts, { debug: true })
})
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as it was before, but inlined runSeed. I did this because everything else from './lib/run_seed.server' was moved to the new shared mock-account-servicing-lib and runSeed was the only thing left.

.then(() => {
global.__seeded = true
})
Expand Down
272 changes: 1 addition & 271 deletions localenv/mock-account-servicing-entity/app/lib/accounts.server.ts
Original file line number Diff line number Diff line change
@@ -1,273 +1,3 @@
export interface Account {
id: string
name: string
path: string
walletAddressID: string
walletAddress: string
debitsPending: bigint
debitsPosted: bigint
creditsPending: bigint
creditsPosted: bigint
assetCode: string
assetScale: number
assetId: string
}

export interface AccountsServer {
clearAccounts(): Promise<void>
setWalletAddress(
id: string,
walletID: string,
walletAddress: string
): Promise<void>
create(
id: string,
path: string,
name: string,
assetCode: string,
assetScale: number,
assetId: string
): Promise<void>
listAll(): Promise<Account[]>
get(id: string): Promise<Account | undefined>
getByWalletAddressId(walletAddressId: string): Promise<Account | undefined>
getByPath(path: string): Promise<Account | undefined>
getByWalletAddressUrl(walletAddressUrl: string): Promise<Account | undefined>
voidPendingDebit(id: string, amount: bigint): Promise<void>
voidPendingCredit(id: string, amount: bigint): Promise<void>
pendingDebit(id: string, amount: bigint): Promise<void>
pendingCredit(id: string, amount: bigint): Promise<void>
debit(id: string, amount: bigint, clearPending: boolean): Promise<void>
credit(id: string, amount: bigint, clearPending: boolean): Promise<void>
}

export class AccountProvider implements AccountsServer {
accounts = new Map<string, Account>()

async clearAccounts(): Promise<void> {
this.accounts.clear()
}

async setWalletAddress(
id: string,
walletID: string,
walletAddress: string
): Promise<void> {
if (!this.accounts.has(id)) {
throw new Error('account already exists')
}

const acc = this.accounts.get(id)

if (!acc) {
throw new Error()
}

acc.walletAddress = walletAddress
acc.walletAddressID = walletID
}

async create(
id: string,
path: string,
name: string,
assetCode: string,
assetScale: number,
assetId: string
): Promise<void> {
if (this.accounts.has(id)) {
throw new Error('account already exists')
}
this.accounts.set(id, {
id,
name,
path,
walletAddress: '',
walletAddressID: '',
creditsPending: BigInt(0),
creditsPosted: BigInt(0),
debitsPending: BigInt(0),
debitsPosted: BigInt(0),
assetCode,
assetScale,
assetId
})
}

async listAll(): Promise<Account[]> {
return [...this.accounts.values()]
}

async get(id: string): Promise<Account | undefined> {
return this.accounts.get(id)
}

async getByWalletAddressId(
walletAddressId: string
): Promise<Account | undefined> {
for (const acc of this.accounts.values()) {
if (acc.walletAddressID == walletAddressId) {
return acc
}
}
}

async getByWalletAddressUrl(
walletAddressUrl: string
): Promise<Account | undefined> {
return (await this.listAll()).find(
(acc) => acc.walletAddress === walletAddressUrl
)
}

async getByPath(path: string): Promise<Account | undefined> {
return (await this.listAll()).find((acc) => acc.path === path)
}

async credit(
id: string,
amount: bigint,
clearPending: boolean
): Promise<void> {
if (!this.accounts.has(id)) {
throw new Error('account does not exist')
}
if (amount < 0) {
throw new Error('invalid credit amount')
}

const acc = this.accounts.get(id)

if (!acc) {
throw new Error()
}

if (clearPending && acc.creditsPending - amount < 0) {
throw new Error('invalid amount, credits pending cannot be less than 0')
}

acc.creditsPosted += amount
if (clearPending) {
acc.creditsPending -= amount
}
}

async debit(
id: string,
amount: bigint,
clearPending: boolean
): Promise<void> {
if (!this.accounts.has(id)) {
throw new Error('account does not exist')
}
if (amount < 0) {
throw new Error('invalid debit amount')
}

const acc = this.accounts.get(id)

if (!acc) {
throw new Error()
}

if (
(clearPending && acc.debitsPending - amount < 0) ||
acc.debitsPosted + amount < 0
) {
throw new Error('invalid amount, debits pending cannot be less than 0')
}

if (
!clearPending &&
acc.creditsPosted < acc.debitsPosted + acc.debitsPending + amount
) {
throw new Error('invalid debit, insufficient funds')
}
acc.debitsPosted += amount
if (clearPending) {
acc.debitsPending -= amount
}
}

async pendingCredit(id: string, amount: bigint): Promise<void> {
if (!this.accounts.has(id)) {
throw new Error('account does not exist')
}
if (amount < 0) {
throw new Error('invalid pending credit amount')
}

const acc = this.accounts.get(id)

if (!acc) {
throw new Error()
}

acc.creditsPending += amount
}

async pendingDebit(id: string, amount: bigint): Promise<void> {
if (!this.accounts.has(id)) {
throw new Error('account does not exist')
}
if (amount < 0) {
throw new Error('invalid pending debit amount')
}

const acc = this.accounts.get(id)

if (!acc) {
throw new Error()
}

if (acc.creditsPosted < acc.debitsPosted + acc.debitsPending + amount) {
throw new Error('invalid pending debit amount, insufficient funds')
}

acc.debitsPending += amount
}

async voidPendingDebit(id: string, amount: bigint): Promise<void> {
if (!this.accounts.has(id)) {
throw new Error('account does not exist')
}
if (amount < 0) {
throw new Error('invalid void pending debit amount')
}

const acc = this.accounts.get(id)

if (!acc) {
throw new Error()
}

if (acc.debitsPending - amount < 0) {
throw new Error('invalid amount, debits pending cannot be less than 0')
}

acc.debitsPending -= amount
}

async voidPendingCredit(id: string, amount: bigint): Promise<void> {
if (!this.accounts.has(id)) {
throw new Error('account does not exist')
}
if (amount < 0) {
throw new Error('invalid void pending credit amount')
}

const acc = this.accounts.get(id)

if (!acc) {
throw new Error()
}

if (acc.debitsPending - amount < 0) {
throw new Error('invalid amount, credits pending cannot be less than 0')
}

acc.creditsPending -= amount
}
}
import { AccountProvider } from 'mock-account-servicing-lib'

export const mockAccounts = new AccountProvider()
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { CONFIG } from './parse_config.server'
import { onError } from '@apollo/client/link/error'

const httpLink = createHttpLink({
uri: CONFIG.seed.self.graphqlUrl
uri: CONFIG.graphqlUrl
})

const errorLink = onError(({ graphQLErrors }) => {
Expand Down
Loading