Skip to content

Commit

Permalink
feat: partially implemented grant request outgoing payment test
Browse files Browse the repository at this point in the history
  • Loading branch information
BlairCurrey committed Mar 1, 2024
1 parent afaa594 commit 57f7d7f
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 9 deletions.
56 changes: 49 additions & 7 deletions test/integration/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import assert from 'assert'
import {
OpenPaymentsClientError,
isPendingGrant,
WalletAddress
WalletAddress,
Quote
} from '@interledger/open-payments'
import { C9_CONFIG, HLB_CONFIG } from './lib/config'
import { MockASE } from './lib/MockASE'
import { WebhookEventType } from 'mock-account-servicing-lib'
import { wait } from './lib/utils'
import { resourceLimits } from 'worker_threads'

// jest.setTimeout(20000)
// TODO: remove after fixing tests
Expand All @@ -24,7 +24,7 @@ describe('Open Payments Flow', (): void => {
const receiverOpenPaymentsHost = 'http://localhost:4000'
const senderOpenPaymentsAuthHost = 'http://localhost:3006'
const senderOpenPaymentsHost = 'http://localhost:3000'
const senderWalletAddressUrl = 'https://localhost:3000/accounts/gfranklin'
const senderWalletAddressUrl = 'http://localhost:3000/accounts/gfranklin'
const receiverAssetCode = 'USD'
const receiverAssetScale = 2

Expand All @@ -43,8 +43,12 @@ describe('Open Payments Flow', (): void => {
let continueId: string

Check warning on line 43 in test/integration/integration.test.ts

View workflow job for this annotation

GitHub Actions / checkout

'continueId' is assigned a value but never used
let tokenId: string

Check warning on line 44 in test/integration/integration.test.ts

View workflow job for this annotation

GitHub Actions / checkout

'tokenId' is assigned a value but never used

// Assigned in Create Incoming Payment
let incomingPaymentId: string

// Assigned in Create Quote
let quote: Quote

beforeAll(async () => {
c9 = await MockASE.create(C9_CONFIG)
hlb = await MockASE.create(HLB_CONFIG)
Expand Down Expand Up @@ -197,9 +201,7 @@ describe('Open Payments Flow', (): void => {
})

test('Create Quote', async (): Promise<void> => {
// TODO: Got this working with hacky stuff which needs real solutions:
// - changed receiver regex in open payments schema to icnlude http then set this in body: `http://happy-life-bank-test-backend/incoming-payments/${incomingPaymentId}`
const quote = await c9.opClient.quote.create(
quote = await c9.opClient.quote.create(
{
url: senderOpenPaymentsHost, // TODO: does it need to be https?
accessToken
Expand All @@ -217,7 +219,47 @@ describe('Open Payments Flow', (): void => {
})

test('Grant Request Outgoing Payment', async (): Promise<void> => {
expect(true).toBe(false)
const grant = await hlb.opClient.grant.request(
{
url: senderOpenPaymentsAuthHost
},
{
access_token: {
access: [
{
type: 'outgoing-payment',
actions: ['create', 'read', 'list'],
identifier: senderWalletAddressUrl,
limits: {
debitAmount: quote.debitAmount,
receiveAmount: quote.receiveAmount
}
}
]
},
interact: {
start: ['redirect'],
finish: {
method: 'redirect',
uri: 'https://example.com',
nonce: '456'
}
}
}
)

console.log({ grant })

assert(!isPendingGrant(grant))
const continueId_ = grant.continue.uri.split('/').pop()
assert(continueId_)
const tokenId_ = grant.access_token.manage.split('/').pop()
assert(tokenId_)

accessToken = grant.access_token.value
continueToken = grant.continue.access_token.value
continueId = continueId_
tokenId = tokenId_
})

// test('Continuation Request', async (): Promise<void> => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ services:
OPEN_PAYMENTS_PORT: 80
DATABASE_URL: postgresql://cloud_nine_wallet_test_backend:cloud_nine_wallet_test_backend@shared-database/cloud_nine_wallet_test_backend
OPEN_PAYMENTS_URL: https://localhost:3000
WALLET_ADDRESS_URL: https://cloud-nine-wallet-test-backend/.well-known/pay
# WALLET_ADDRESS_URL: https://cloud-nine-wallet-test-backend/.well-known/pay
WALLET_ADDRESS_URL: https://cloud-nine-wallet-test-backend/accounts/gfranklin
# OPEN_PAYMENTS_URL: http://localhost:3000
# WALLET_ADDRESS_URL: http://cloud-nine-wallet-test-backend/.well-known/pay
KEY_ID: rafiki
Expand Down
3 changes: 2 additions & 1 deletion test/integration/testenv/happy-life-bank/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ services:
NODE_ENV: development
LOG_LEVEL: debug
OPEN_PAYMENTS_URL: https://localhost:4000
WALLET_ADDRESS_URL: https://happy-life-bank-test-backend/.well-known/pay
# WALLET_ADDRESS_URL: https://happy-life-bank-test-backend/.well-known/pay
WALLET_ADDRESS_URL: https://happy-life-bank-test-backend/accounts/pfry
# OPEN_PAYMENTS_URL: http://localhost:4000
# WALLET_ADDRESS_URL: http://happy-life-bank-test-backend/.well-known/pay
ADMIN_PORT: 3001
Expand Down

0 comments on commit 57f7d7f

Please sign in to comment.