Skip to content

Commit

Permalink
Merge branch 'main' into 2893/multi-tenancy-v1
Browse files Browse the repository at this point in the history
  • Loading branch information
mkurapov committed Dec 9, 2024
2 parents 07630c1 + b83ac58 commit 8e04749
Show file tree
Hide file tree
Showing 36 changed files with 444 additions and 110 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/node-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ jobs:
- backend
- frontend
steps:
- uses: actions/checkout@v4
- name: Fetch docker image from cache
uses: actions/cache/restore@v4
with:
Expand Down Expand Up @@ -326,6 +327,7 @@ jobs:
- backend
- frontend
steps:
- uses: actions/checkout@v4
- name: Fetch docker image from cache
uses: actions/cache/restore@v4
with:
Expand Down
2 changes: 2 additions & 0 deletions .grype.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ignore:
- vulnerability: GHSA-3xgq-45jj-v275
1 change: 0 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,4 @@ build
**/styles/*.css
.docusaurus
.cache-loader
packages/documentation/**
.astro
1 change: 1 addition & 0 deletions .trivyignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CVE-2024-21538 exp:2024-12-31
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ body:graphql {
transferType
ledger
createdAt
state
expiresAt
}
credits {
id
Expand All @@ -30,6 +32,8 @@ body:graphql {
transferType
ledger
createdAt
state
expiresAt
}
}
}
Expand Down
16 changes: 16 additions & 0 deletions localenv/mock-account-servicing-entity/generated/graphql.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
"license": "Apache-2.0",
"repository": "https://github.com/interledger/rafiki",
"engines": {
"pnpm": "^8.15.4",
"pnpm": "^8.15.9",
"node": "20"
},
"packageManager": "[email protected].5",
"packageManager": "[email protected].9",
"scripts": {
"preinstall": "npx only-allow pnpm",
"lint": "eslint --max-warnings=0 --fix .",
Expand Down Expand Up @@ -78,7 +78,8 @@
"tar@<6.2.1": ">=6.2.1",
"braces@<3.0.3": ">=3.0.3",
"@grpc/grpc-js@>=1.10.0 <1.10.9": ">=1.10.9",
"dset@<3.1.4": ">=3.1.4"
"dset@<3.1.4": ">=3.1.4",
"cross-spawn@>=7.0.0 <7.0.5": ">=7.0.5"
}
}
}
35 changes: 35 additions & 0 deletions packages/backend/src/accounting/tigerbeetle/service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,41 @@ describe('TigerBeetle Accounting Service', (): void => {
expect(transferDebit.expiresAt).toBeUndefined()
})

test('Returns expiry date correctly', async (): Promise<void> => {
const receivingAccount = await accountFactory.build()
const balances = [BigInt(100), BigInt(100)]
const accounts = await Promise.all(
balances.map(async (balance) => {
return await accountFactory.build({
balance,
asset: receivingAccount.asset
})
})
)
const timeout = 10
await Promise.all(
accounts.map(async (account, i) => {
const transfer = await accountingService.createTransfer({
sourceAccount: account,
sourceAmount: BigInt(10 * (i + 1)),
destinationAccount: receivingAccount,
timeout: timeout
})
assert.ok(!isTransferError(transfer))
await transfer.post()
})
)
const transfer = await accountingService.getAccountTransfers(
receivingAccount.id
)
expect(transfer.credits).not.toHaveLength(0)
const timestamp = transfer.credits[0].timestamp
const expiresAtTime = transfer.credits[0].expiresAt?.getTime()
expect(expiresAtTime).toBe(
new Date(Number(timestamp) + timeout * 1000).getTime()
)
})

test('Returns undefined for nonexistent account', async (): Promise<void> => {
await expect(
accountingService.getTotalReceived(uuid())
Expand Down
15 changes: 14 additions & 1 deletion packages/backend/src/accounting/tigerbeetle/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,19 @@ export function tbTransferToLedgerTransfer(
transferRef: fromTigerBeetleId(tbTransfer.user_data_128),
type: transferTypeFromCode(tbTransfer.code),
state: state,
ledger: tbTransfer.ledger
ledger: tbTransfer.ledger,
expiresAt: expiresAtFromTimestampAndTimeout(
tbTransfer.timestamp,
tbTransfer.timeout
)
}
}

function expiresAtFromTimestampAndTimeout(
timestamp: bigint,
timeout: number
): Date | undefined {
return timeout
? new Date(Number(timestamp / 1_000_000n) + timeout * 1000)
: undefined
}
57 changes: 57 additions & 0 deletions packages/backend/src/graphql/generated/graphql.schema.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions packages/backend/src/graphql/generated/graphql.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Config } from '../../config/app'
import { truncateTables } from '../../tests/tableManager'
import {
AccountingTransferConnection,
TransferState,
TransferType
} from '../generated/graphql'
import { createAsset } from '../../tests/asset'
Expand Down Expand Up @@ -99,6 +100,7 @@ describe('Accounting Transfer', (): void => {
// Top up debit account first:
const transferAmount = 123
const ledger = 1
const tomorrow = new Date(new Date().getDate() + 1)
const queryLimit = 20

const insertedTransfer = await createLedgerTransfer(
Expand All @@ -109,7 +111,8 @@ describe('Accounting Transfer', (): void => {
ledger: ledger,
state: LedgerTransferState.POSTED,
transferRef: uuid(),
type: LedgerTransferType.DEPOSIT
type: LedgerTransferType.DEPOSIT,
expiresAt: tomorrow
},
appContainer.knex
)
Expand All @@ -127,6 +130,8 @@ describe('Accounting Transfer', (): void => {
transferType
ledger
createdAt
state
expiresAt
}
credits {
id
Expand All @@ -136,6 +141,8 @@ describe('Accounting Transfer', (): void => {
transferType
ledger
createdAt
state
expiresAt
}
}
}
Expand All @@ -161,7 +168,9 @@ describe('Accounting Transfer', (): void => {
debitAccountId: accountDebitId,
amount: `${transferAmount}`,
transferType: TransferType.Deposit,
ledger
ledger,
state: TransferState.Posted,
expiresAt: tomorrow.toISOString()
})

// Credit:
Expand All @@ -179,6 +188,8 @@ describe('Accounting Transfer', (): void => {
transferType
ledger
createdAt
state
expiresAt
}
credits {
id
Expand All @@ -188,6 +199,8 @@ describe('Accounting Transfer', (): void => {
transferType
ledger
createdAt
state
expiresAt
}
}
}
Expand All @@ -214,7 +227,9 @@ describe('Accounting Transfer', (): void => {
creditAccountId: accountCreditId,
amount: `${transferAmount}`,
transferType: TransferType.Deposit,
ledger
ledger,
state: TransferState.Posted,
expiresAt: tomorrow.toISOString()
})
})
})
Loading

0 comments on commit 8e04749

Please sign in to comment.