Skip to content

Commit 6952d84

Browse files
committed
feat: add tenant id to tests; temporary operator tenant id in peer webhook events
1 parent 077cac9 commit 6952d84

9 files changed

Lines changed: 42 additions & 15 deletions

File tree

packages/backend/src/accounting/psql/service.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,13 @@ import {
3535
} from './ledger-transfer'
3636
import { LedgerTransfer, LedgerTransferType } from './ledger-transfer/model'
3737
import { TelemetryService } from '../../telemetry/service'
38+
import { IAppConfig } from '../../config/app'
3839

3940
export interface ServiceDependencies extends BaseService {
4041
knex: TransactionOrKnex
4142
telemetry: TelemetryService
4243
withdrawalThrottleDelay?: number
44+
config: IAppConfig // TODO: remove when peers are tenanted
4345
}
4446

4547
export function createAccountingService(

packages/backend/src/accounting/service.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { TransactionOrKnex } from 'objection'
22
import { BaseService } from '../shared/baseService'
33
import { TransferError, isTransferError } from './errors'
4+
import { IAppConfig } from '../config/app'
45

56
export enum LiquidityAccountType {
67
ASSET = 'ASSET',
@@ -44,6 +45,7 @@ export interface OnCreditOptions {
4445

4546
export interface OnDebitOptions {
4647
balance: bigint
48+
tenantId: string
4749
}
4850

4951
export interface BaseTransfer {
@@ -134,6 +136,7 @@ export interface TransferToCreate {
134136

135137
export interface BaseAccountingServiceDependencies extends BaseService {
136138
withdrawalThrottleDelay?: number
139+
config: IAppConfig // TODO: Remove when peers are tenanted
137140
}
138141

139142
interface CreateAccountToAccountTransferArgs {
@@ -201,8 +204,10 @@ export async function createAccountToAccountTransfer(
201204
const balance = await getAccountBalance(account.id)
202205
if (balance === undefined) throw new Error('undefined account balance')
203206

207+
const { config } = deps
204208
await account.onDebit({
205-
balance
209+
balance,
210+
tenantId: config.operatorTenantId
206211
})
207212
}
208213
}

packages/backend/src/accounting/tigerbeetle/service.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import {
3232
} from './transfers'
3333
import { toTigerBeetleId } from './utils'
3434
import { TelemetryService } from '../../telemetry/service'
35+
import { IAppConfig } from '../../config/app'
3536

3637
export enum TigerBeetleAccountCode {
3738
LIQUIDITY_WEB_MONETIZATION = 1,
@@ -71,6 +72,7 @@ export interface ServiceDependencies extends BaseService {
7172
tigerBeetle: Client
7273
telemetry: TelemetryService
7374
withdrawalThrottleDelay?: number
75+
config: IAppConfig // TODO: remove when peers are tenanted
7476
}
7577

7678
export function createAccountingService(

packages/backend/src/asset/model.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ export class Asset extends BaseModel implements LiquidityAccount {
4444
},
4545
liquidityThreshold: this.liquidityThreshold,
4646
balance
47-
}
47+
},
48+
tenantId: this.tenantId
4849
})
4950
}
5051
}

packages/backend/src/graphql/resolvers/liquidity.test.ts

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1796,7 +1796,8 @@ describe('Liquidity Resolvers', (): void => {
17961796
data: payment.toData({
17971797
amountSent: BigInt(0),
17981798
balance: BigInt(0)
1799-
})
1799+
}),
1800+
tenantId: Config.operatorTenantId
18001801
})
18011802
})
18021803

@@ -1956,6 +1957,7 @@ describe('Liquidity Resolvers', (): void => {
19561957
incomingPaymentId?: string
19571958
outgoingPaymentId?: string
19581959
walletAddressId?: string
1960+
tenantId?: string
19591961
}
19601962

19611963
const isIncomingPaymentEventType = (
@@ -2011,7 +2013,8 @@ describe('Liquidity Resolvers', (): void => {
20112013
accountId: liquidityAccount.id,
20122014
assetId: liquidityAccount.asset.id,
20132015
amount
2014-
}
2016+
},
2017+
tenantId: Config.operatorTenantId
20152018
}
20162019

20172020
if (resourceId) {
@@ -2230,7 +2233,8 @@ describe('Liquidity Resolvers', (): void => {
22302233
accountId: incomingPayment.id,
22312234
assetId: incomingPayment.asset.id,
22322235
amount
2233-
}
2236+
},
2237+
tenantId: Config.operatorTenantId
22342238
})
22352239

22362240
const response = await appContainer.apolloClient
@@ -2278,7 +2282,8 @@ describe('Liquidity Resolvers', (): void => {
22782282
accountId: incomingPayment.id,
22792283
assetId: incomingPayment.asset.id,
22802284
amount
2281-
}
2285+
},
2286+
tenantId: Config.operatorTenantId
22822287
})
22832288
let error
22842289
try {
@@ -2376,7 +2381,8 @@ describe('Liquidity Resolvers', (): void => {
23762381
accountId: incomingPayment.id,
23772382
assetId: incomingPayment.asset.id,
23782383
amount
2379-
}
2384+
},
2385+
tenantId: Config.operatorTenantId
23802386
})
23812387
await expect(
23822388
accountingService.createWithdrawal({
@@ -2463,7 +2469,8 @@ describe('Liquidity Resolvers', (): void => {
24632469
accountId: outgoingPayment.id,
24642470
assetId: outgoingPayment.asset.id,
24652471
amount
2466-
}
2472+
},
2473+
tenantId: Config.operatorTenantId
24672474
})
24682475

24692476
const response = await appContainer.apolloClient
@@ -2604,7 +2611,8 @@ describe('Liquidity Resolvers', (): void => {
26042611
accountId: outgoingPayment.id,
26052612
assetId: outgoingPayment.asset.id,
26062613
amount
2607-
}
2614+
},
2615+
tenantId: Config.operatorTenantId
26082616
})
26092617
await expect(
26102618
accountingService.createWithdrawal({
@@ -2673,7 +2681,8 @@ describe('Liquidity Resolvers', (): void => {
26732681
data: outgoingPayment.toData({
26742682
amountSent: BigInt(0),
26752683
balance: BigInt(0)
2676-
})
2684+
}),
2685+
tenantId: Config.operatorTenantId
26772686
})
26782687
})
26792688

packages/backend/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,7 @@ export function initIocContainer(
358358
return createTigerbeetleAccountingService({
359359
logger,
360360
knex,
361+
config,
361362
tigerBeetle,
362363
withdrawalThrottleDelay: config.withdrawalThrottleDelay,
363364
telemetry
@@ -367,6 +368,7 @@ export function initIocContainer(
367368
return createPsqlAccountingService({
368369
logger,
369370
knex,
371+
config,
370372
withdrawalThrottleDelay: config.withdrawalThrottleDelay,
371373
telemetry
372374
})

packages/backend/src/open_payments/payment/incoming/service.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,8 @@ describe('Incoming Payment Service', (): void => {
324324
const incomingPayment = await incomingPaymentService.create({
325325
walletAddressId,
326326
...options,
327-
incomingAmount: options.incomingAmount ? amount : undefined
327+
incomingAmount: options.incomingAmount ? amount : undefined,
328+
tenantId: Config.operatorTenantId
328329
})
329330
assert.ok(!isIncomingPaymentError(incomingPayment))
330331
expect(incomingPayment).toMatchObject({

packages/backend/src/payment-method/ilp/peer/model.test.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ describe('Models', (): void => {
7373
`(
7474
'creates webhook event if balance=$balance <= liquidityThreshold',
7575
async ({ balance }): Promise<void> => {
76-
await peer.onDebit({ balance })
76+
await peer.onDebit({ balance, tenantId: Config.operatorTenantId })
7777
const event = (
7878
await PeerEvent.query(knex).where(
7979
'type',
@@ -91,12 +91,16 @@ describe('Models', (): void => {
9191
},
9292
liquidityThreshold: peer.liquidityThreshold?.toString(),
9393
balance: balance.toString()
94-
}
94+
},
95+
tenantId: Config.operatorTenantId
9596
})
9697
}
9798
)
9899
test('does not create webhook event if balance > liquidityThreshold', async (): Promise<void> => {
99-
await peer.onDebit({ balance: BigInt(110) })
100+
await peer.onDebit({
101+
balance: BigInt(110),
102+
tenantId: Config.operatorTenantId
103+
})
100104
await expect(
101105
PeerEvent.query(knex).where('type', PeerEventType.LiquidityLow)
102106
).resolves.toEqual([])

packages/backend/src/payment-method/ilp/peer/model.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ export class Peer
7070
},
7171
liquidityThreshold: this.liquidityThreshold,
7272
balance
73-
}
73+
},
74+
tenantId // TODO: update when peers are tenanted
7475
})
7576
}
7677
}

0 commit comments

Comments
 (0)