-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: setup basic test env * feat: seed integration environment - cmd to start integration environment and run tests - seeds environment on test run - extracts common MASE functionality into new mock-account-servicing-lib * refactor(localenv,integration): move graphql url to config from seed - moves graphql url to config from seed - also removes self section which only contained unused properties * refactor: move testenv configuration into new dir * refactor: cleanup env vars * feat: add webhook server, fix env vars * chore: comment * feat: start grant request test * fix: eslint errors * fix: docker compose env vars * feat: add --build arg * fix: incoming-payment grant initiation request Grant request was failing with invalid signature. This was fixed by directing hte backend to use the same private key being used to create the open payments client. * fix: ts error * feat: implement tests through Create Quote * chore: upgrade op client * feat: partially implemented grant request outgoing payment test * feat: rework to host.docker.internal - switches hostname to host.docker.internal to resolve url mismatch problem - finishes grant request outgoing payment test - cleans up some configuration and test variables * feat: add p2p flow test * feat: add continuation step with consent mocking * fix: rm obsolete type cast to any and comment * feat: add create ougoing payment test * fix: bad pnpm-lock merge * feat: build deps in mock ase job * feat: get non existant wallet address test * fix: update open payments pkg * chore: fix lint warnings * feat: implement continuation polling * chore: test cleanup * refactor: generate gql in tests instead of import from lib * chore: rm old comment * chore: use latest http-singature-utils to match other deps * chore: pnpm i * chore: use latest koa-bodyparser * chore: rm engine strict * chore: revert rm engine strict - fixes netlify ci failure but ultimately not the correct fix * chore(integration): dont ignore env, rm example env * refactor: use docker healthcheck for running tests * chore: move healthcheck to last started docker container * feat: use latest open payments pkg, no body requird on continuation * chore: pnpm i, fix broken lockfile (no apollo version) * refactor: move webhook event enum to types * refactor: move run integration script to test/integration * Update packages/mock-account-servicing-lib/package.json Co-authored-by: Sabine Schaller <[email protected]> * refactor: simplify mock-account-servicing-entity ci step * feat(integration): exit run-tests early if containers fail to start * feat: use pino logger * refactor: rename mock account servicing lib * refactor: rename class files to camel case * fix: import correct body parser * refactor: poll instead of delay * refactor: simplify call to poll condition only * fix: update filenames * refactor: change filename name to kebab case --------- Co-authored-by: Sabine Schaller <[email protected]>
- Loading branch information
1 parent
2c930ee
commit 642e7a2
Showing
50 changed files
with
7,214 additions
and
924 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,6 +53,7 @@ build | |
|
||
# Env variables | ||
.env | ||
!test/**/.env | ||
|
||
# AWS Lambda | ||
*.zip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
272 changes: 1 addition & 271 deletions
272
localenv/mock-account-servicing-entity/app/lib/accounts.server.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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-service-lib' | ||
|
||
export const mockAccounts = new AccountProvider() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.