From 1bcb4b72e39e29e4fffec89eeba04e85c99d64ab Mon Sep 17 00:00:00 2001 From: Derek Sonnenberg Date: Fri, 1 Nov 2024 12:28:02 -0500 Subject: [PATCH] refactor: use credit sharing in commands/methods/docs PE-6754 --- README.md | 63 ++++++++------- src/cli/cli.ts | 20 +++-- src/cli/commands/listApprovals.ts | 4 +- .../{revokeApprovals.ts => revokeCredits.ts} | 10 +-- .../{createApproval.ts => shareCredits.ts} | 10 +-- src/cli/options.ts | 4 +- src/cli/types.ts | 6 +- src/common/payment.ts | 6 +- src/common/turbo.ts | 26 +++---- src/common/upload.ts | 24 +++--- src/types.ts | 8 +- tests/approval.node.test.ts | 78 +++++++++---------- 12 files changed, 127 insertions(+), 132 deletions(-) rename src/cli/commands/{revokeApprovals.ts => revokeCredits.ts} (78%) rename src/cli/commands/{createApproval.ts => shareCredits.ts} (84%) diff --git a/README.md b/README.md index 3faa8813..4eb6c199 100644 --- a/README.md +++ b/README.md @@ -65,9 +65,9 @@ Welcome to the `@ardrive/turbo-sdk`! This SDK provides functionality for interac - [Polygon (POL / MATIC) Crypto Top Up](#polygon-pol--matic-crypto-top-up) - [Solana (SOL) Crypto Top Up](#solana-sol-crypto-top-up) - [KYVE Crypto Top Up](#kyve-crypto-top-up) - - [`createDelegatedPaymentApproval({ approvedAddress, approvedWincAmount, expiresBySeconds })`](#createdelegatedpaymentapproval-approvedaddress-approvedwincamount-expiresbyseconds-) - - [`revokeDelegatedPaymentApprovals({ approvedAddress })`](#revokedelegatedpaymentapprovals-approvedaddress-) - - [`getDelegatedPaymentApprovals({ userAddress })`](#getdelegatedpaymentapprovals-useraddress-) + - [`shareCredits({ approvedAddress, approvedWincAmount, expiresBySeconds })`](#sharecredits-approvedaddress-approvedwincamount-expiresbyseconds-) + - [`revokeCredits({ approvedAddress })`](#revokecredits-approvedaddress-) + - [`getCreditShareApprovals({ userAddress })`](#getcreditshareapprovals-useraddress-) - [CLI](#cli) - [Install CLI](#install-cli) - [CLI Usage](#cli-usage) @@ -79,8 +79,8 @@ Welcome to the `@ardrive/turbo-sdk`! This SDK provides functionality for interac - [`upload-folder`](#upload-folder) - [`upload-file`](#upload-file) - [`price`](#price) - - [`create-approval`](#create-approval) - - [`revoke-approvals`](#revoke-approvals) + - [`share-credits`](#share-credits) + - [`revoke-credits`](#revoke-credits) - [`list-approvals`](#list-approvals) - [Developers](#developers) - [Requirements](#requirements) @@ -683,22 +683,21 @@ const { winc, status, id, ...fundResult } = await turbo.topUpWithTokens({ }); ``` -#### `createDelegatedPaymentApproval({ approvedAddress, approvedWincAmount, expiresBySeconds })` +#### `shareCredits({ approvedAddress, approvedWincAmount, expiresBySeconds })` -Creates a delegated payment approval from the connected wallet to the provided native address and approved winc amount. This action will create a data item for the approval +Shares credits from the connected wallet to the provided native address and approved winc amount. This action will create a signed data item for the approval ```typescript -const { approvalDataItemId, approvedWincAmount } = - await turbo.createDelegatedPaymentApproval({ - approvedAddress: '2cor...VUa', - approvedWincAmount: 0.08315565032, - expiresBySeconds: 3600, - }); +const { approvalDataItemId, approvedWincAmount } = await turbo.shareCredits({ + approvedAddress: '2cor...VUa', + approvedWincAmount: 0.08315565032, + expiresBySeconds: 3600, +}); ``` -#### `revokeDelegatedPaymentApprovals({ approvedAddress })` +#### `revokeCredits({ approvedAddress })` -Revokes all delegated payment approvals from the connected wallet to the provided native address. +Revokes all credits shared from the connected wallet to the provided native address. ```typescript const revokedApprovals = await turbo.revokeDelegatePaymentApprovals({ @@ -706,13 +705,13 @@ const revokedApprovals = await turbo.revokeDelegatePaymentApprovals({ }); ``` -#### `getDelegatedPaymentApprovals({ userAddress })` +#### `getCreditShareApprovals({ userAddress })` -Returns all delegated payment approvals from the connected wallet or the provided native address. +Returns all given or received credit share approvals for the connected wallet or the provided native address. ```typescript const { givenApprovals, receivedApprovals } = - await turbo.getDelegatedPaymentApprovals({ + await turbo.getCreditShareApprovals({ userAddress: '2cor...VUa', }); ``` @@ -782,8 +781,8 @@ Wallet options: Upload options: - `--paid-by ` - A list of native addresses to pay for the upload. -- `--ignore-approvals` - When no paid by is provided, the CLI will look for and use any received delegated payment approvals to pay for the upload. This flag will ignore any approvals and only use the connected wallet's balance for upload payment. Default: false -- `--use-signer-balance-first` - Use the connected wallet's balance before using any delegated payment approvals for the upload. Default: false +- `--ignore-approvals` - When no paid by is provided, the CLI will look for and use any received credit share approvals to pay for the upload. This flag will ignore any approvals and only use the connected wallet's balance for upload payment. Default: false +- `--use-signer-balance-first` - Use the connected wallet's balance before using any credit share approvals for the upload. Default: false #### Commands @@ -896,43 +895,43 @@ turbo price --value 1024 --type bytes turbo price --value 1.1 --type arweave ``` -##### `create-approval` +##### `share-credits` -Create a delegated payment approval from the connected wallet to the provided native address and approved winc amount. +Shares credits from the connected wallet to the provided native address and approved winc amount. Command Options: -- `-a, --address ` - Native address to that will receive the delegated payment approval -- `-v, --value ` - Value of winc to create delegated payment approval for -- `-e, --expires-by-seconds ` - Expiry time in seconds for the delegated payment approval +- `-a, --address ` - Native address to that will receive the Credits +- `-v, --value ` - Value of winc to share to the target address +- `-e, --expires-by-seconds ` - Expiry time in seconds for the credit share approval e.g: ```shell -turbo create-approval --address 2cor...VUa --value 0.083155650320 --wallet-file ../path/to/my/wallet --expires-by-seconds 3600 +turbo share-credits --address 2cor...VUa --value 0.083155650320 --wallet-file ../path/to/my/wallet --expires-by-seconds 3600 ``` -##### `revoke-approvals` +##### `revoke-credits` -Revoke all delegated payment approvals from the connected wallet to the provided native address. +Revoke all credits shared from the connected wallet to the provided native address. Command Options: -- `-a, --address ` - Native address to revoke delegated payment approvals for +- `-a, --address ` - Native address to revoke credit share approvals for e.g: ```shell -turbo revoke-approvals --wallet-file ../path/to/my/wallet +turbo revoke-credits --wallet-file ../path/to/my/wallet ``` ##### `list-approvals` -List all given and received delegated payment approvals from the connected wallet or the provided native address. +List all given and received credit share approvals from the connected wallet or the provided native address. Command Options: -- `-a, --address ` - Native address to list delegated payment approvals for +- `-a, --address ` - Native address to list credit share approvals for e.g: diff --git a/src/cli/cli.ts b/src/cli/cli.ts index 5b8cbdcd..e54a5b79 100644 --- a/src/cli/cli.ts +++ b/src/cli/cli.ts @@ -20,7 +20,6 @@ import { Command, program } from 'commander'; import { version } from '../version.js'; -import { createApproval } from './commands/createApproval.js'; import { balance, cryptoFund, @@ -30,7 +29,8 @@ import { uploadFolder, } from './commands/index.js'; import { listApprovals } from './commands/listApprovals.js'; -import { revokeApprovals } from './commands/revokeApprovals.js'; +import { revokeCredits } from './commands/revokeCredits.js'; +import { shareCredits } from './commands/shareCredits.js'; import { createApprovalOptions, globalOptions, @@ -101,29 +101,27 @@ applyOptions( applyOptions( program - .command('create-approval') - .description('Create a Turbo delegated payment approval'), + .command('share-credits') + .description('Create a Turbo credit share approval'), createApprovalOptions, ).action(async (_commandOptions, command: Command) => { - await runCommand(command, createApproval); + await runCommand(command, shareCredits); }); applyOptions( program - .command('revoke-approvals') - .description( - 'Revokes all Turbo delegated payment approvals for given address', - ), + .command('revoke-credits') + .description('Revokes all Turbo credit share approvals for given address'), revokeApprovalsOptions, ).action(async (_commandOptions, command: Command) => { - await runCommand(command, revokeApprovals); + await runCommand(command, revokeCredits); }); applyOptions( program .command('list-approvals') .description( - 'Lists all Turbo delegated payment approvals for given address or wallet', + 'Lists all given or received Turbo credit share approvals for specified address or connected wallet', ), listApprovalsOptions, ).action(async (_commandOptions, command: Command) => { diff --git a/src/cli/commands/listApprovals.ts b/src/cli/commands/listApprovals.ts index 5fccd2f8..a4af7ac7 100644 --- a/src/cli/commands/listApprovals.ts +++ b/src/cli/commands/listApprovals.ts @@ -28,7 +28,7 @@ export async function listApprovals( if (address !== undefined) { const approvals = await TurboFactory.unauthenticated( config, - ).getDelegatedPaymentApprovals({ + ).getCreditShareApprovals({ userAddress: address, }); return { ...approvals, nativeAddress: address }; @@ -40,7 +40,7 @@ export async function listApprovals( ...config, privateKey, }); - const approvals = await turbo.getDelegatedPaymentApprovals(); + const approvals = await turbo.getCreditShareApprovals(); return { ...approvals, nativeAddress: await turbo.signer.getNativeAddress(), diff --git a/src/cli/commands/revokeApprovals.ts b/src/cli/commands/revokeCredits.ts similarity index 78% rename from src/cli/commands/revokeApprovals.ts rename to src/cli/commands/revokeCredits.ts index 48959d58..82bd7ad6 100644 --- a/src/cli/commands/revokeApprovals.ts +++ b/src/cli/commands/revokeCredits.ts @@ -13,11 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { RevokeApprovalsOptions } from '../types.js'; +import { RevokeCreditsOptions } from '../types.js'; import { turboFromOptions } from '../utils.js'; -export async function revokeApprovals( - options: RevokeApprovalsOptions, +export async function revokeCredits( + options: RevokeCreditsOptions, ): Promise { const { address: revokedAddress } = options; if (revokedAddress === undefined) { @@ -28,13 +28,13 @@ export async function revokeApprovals( const turbo = await turboFromOptions(options); - const revokedApprovals = await turbo.revokeDelegatedPaymentApprovals({ + const revokedApprovals = await turbo.revokeCredits({ revokedAddress, }); console.log( JSON.stringify( - { message: 'Revoked delegated payment approvals!', revokedApprovals }, + { message: 'Revoked credit share approvals!', revokedApprovals }, null, 2, ), diff --git a/src/cli/commands/createApproval.ts b/src/cli/commands/shareCredits.ts similarity index 84% rename from src/cli/commands/createApproval.ts rename to src/cli/commands/shareCredits.ts index ba797c4a..1e76ff94 100644 --- a/src/cli/commands/createApproval.ts +++ b/src/cli/commands/shareCredits.ts @@ -15,11 +15,11 @@ */ import { BigNumber } from 'bignumber.js'; -import { CreateApprovalOptions } from '../types.js'; +import { ShareCreditsOptions } from '../types.js'; import { turboFromOptions } from '../utils.js'; -export async function createApproval( - options: CreateApprovalOptions, +export async function shareCredits( + options: ShareCreditsOptions, ): Promise { const { address: approvedAddress, @@ -40,7 +40,7 @@ export async function createApproval( const approvedWincAmount = new BigNumber(creditAmount) .shiftedBy(12) .toFixed(0); - const result = await turbo.createDelegatedPaymentApproval({ + const result = await turbo.shareCredits({ approvedAddress, approvedWincAmount, expiresBySeconds, @@ -48,7 +48,7 @@ export async function createApproval( console.log( JSON.stringify( - { message: 'Created delegated payment approval!', ...result }, + { message: 'Created credit share approval!', ...result }, null, 2, ), diff --git a/src/cli/options.ts b/src/cli/options.ts index 7b82b7cd..fef0dc71 100644 --- a/src/cli/options.ts +++ b/src/cli/options.ts @@ -137,13 +137,13 @@ export const optionMap = { ignoreApprovals: { alias: '--ignore-approvals', description: - "Ignore all delegated payment approvals, only use signing wallet's balance", + "Ignore all credit share approvals, only use signing wallet's balance", default: false, }, useSignerBalanceFirst: { alias: '--use-signer-balance-first', description: - 'Use the signer balance first before using delegated payment approvals', + 'Use the signer balance first before using credit share approvals', default: false, }, } as const; diff --git a/src/cli/types.ts b/src/cli/types.ts index 4123b477..ea5d7b2d 100644 --- a/src/cli/types.ts +++ b/src/cli/types.ts @@ -69,14 +69,14 @@ export type CryptoFundOptions = WalletOptions & { txId: string | undefined; }; -export type CreateApprovalOptions = WalletOptions & { +export type ShareCreditsOptions = WalletOptions & { address: string | undefined; value: string | undefined; expiresBySeconds: number | undefined; }; -export type RevokeApprovalsOptions = WalletOptions & { +export type RevokeCreditsOptions = WalletOptions & { address: string | undefined; }; -export type ListApprovalsOptions = RevokeApprovalsOptions; +export type ListApprovalsOptions = RevokeCreditsOptions; diff --git a/src/common/payment.ts b/src/common/payment.ts index b7709206..a3ff9e6d 100644 --- a/src/common/payment.ts +++ b/src/common/payment.ts @@ -265,7 +265,7 @@ export class TurboUnauthenticatedPaymentService throw new Error('Unknown response from payment service: ' + response); } - public async getDelegatedPaymentApprovals({ + public async getCreditShareApprovals({ userAddress, }: { userAddress: UserAddress; @@ -314,13 +314,13 @@ export class TurboAuthenticatedPaymentService return super.getBalance(userAddress); } - public async getDelegatedPaymentApprovals({ + public async getCreditShareApprovals({ userAddress, }: { userAddress?: string; }): Promise { userAddress ??= await this.signer.getNativeAddress(); - return super.getDelegatedPaymentApprovals({ userAddress }); + return super.getCreditShareApprovals({ userAddress }); } public async getWincForFiat({ diff --git a/src/common/turbo.ts b/src/common/turbo.ts index 621182dd..5cd3483d 100644 --- a/src/common/turbo.ts +++ b/src/common/turbo.ts @@ -213,12 +213,12 @@ export class TurboUnauthenticatedClient } /** - * Returns a list of all delegated payment approvals for the user. + * Returns a list of all credit share approvals for the user. */ - getDelegatedPaymentApprovals(p: { + getCreditShareApprovals(p: { userAddress: NativeAddress; }): Promise { - return this.paymentService.getDelegatedPaymentApprovals(p); + return this.paymentService.getCreditShareApprovals(p); } } @@ -248,14 +248,14 @@ export class TurboAuthenticatedClient } /** - * Returns a list of all delegated payment approvals for the user. + * Returns a list of all credit share approvals for the user. */ - getDelegatedPaymentApprovals( + getCreditShareApprovals( p: { userAddress?: NativeAddress; } = {}, ): Promise { - return this.paymentService.getDelegatedPaymentApprovals(p); + return this.paymentService.getCreditShareApprovals(p); } /** @@ -291,25 +291,25 @@ export class TurboAuthenticatedClient } /** - * Creates a data item with tags that designate it as a delegated payment approval. + * Creates a data item with tags that designate it as a credit share approval. * Signs the data item and sends it to the Turbo Upload Service, which will verify * the signature and forward the admin action towards the Turbo Payment Service. */ - createDelegatedPaymentApproval( + shareCredits( p: TurboCreateDelegatedPaymentApprovalParams, ): Promise { - return this.uploadService.createDelegatedPaymentApproval(p); + return this.uploadService.shareCredits(p); } /** - * Creates a data item with tags that designate it as a revoke action for delegated - * payment approvals for target revokedAddress. Signs the data item and sends it to + * Creates a data item with tags that designate it as a revoke action for credit + * share approvals for target revokedAddress. Signs the data item and sends it to * the Turbo Upload Service, which will verify the signature and forward the admin * action towards the Turbo Payment Service. */ - revokeDelegatedPaymentApprovals( + revokeCredits( p: TurboRevokeDelegatePaymentApprovalsParams, ): Promise { - return this.uploadService.revokeDelegatedPaymentApprovals(p); + return this.uploadService.revokeCredits(p); } } diff --git a/src/common/upload.ts b/src/common/upload.ts index e600251a..01446664 100644 --- a/src/common/upload.ts +++ b/src/common/upload.ts @@ -40,11 +40,11 @@ import { import { TurboHTTPService } from './http.js'; import { TurboWinstonLogger } from './logger.js'; -export const delegatedPaymentTagNames = { - createDelegatedPaymentApproval: 'x-approve-payment', - approvalAmount: 'x-amount', +export const creditSharingTagNames = { + shareCredits: 'x-approve-payment', + sharedWincAmount: 'x-amount', approvalExpiresBySeconds: 'x-expires-seconds', - revokeDelegatePaymentApproval: 'x-delete-payment-approval', + revokeCredits: 'x-delete-payment-approval', }; export const developmentUploadServiceURL = 'https://upload.ardrive.dev'; @@ -318,7 +318,7 @@ export abstract class TurboAuthenticatedBaseUploadService }; } - public async createDelegatedPaymentApproval({ + public async shareCredits({ approvedAddress, approvedWincAmount, expiresBySeconds, @@ -326,18 +326,18 @@ export abstract class TurboAuthenticatedBaseUploadService const dataItemOpts = { tags: [ { - name: delegatedPaymentTagNames.createDelegatedPaymentApproval, + name: creditSharingTagNames.shareCredits, value: approvedAddress, }, { - name: delegatedPaymentTagNames.approvalAmount, + name: creditSharingTagNames.sharedWincAmount, value: approvedWincAmount.toString(), }, ], }; if (expiresBySeconds !== undefined) { dataItemOpts.tags.push({ - name: delegatedPaymentTagNames.approvalExpiresBySeconds, + name: creditSharingTagNames.approvalExpiresBySeconds, value: expiresBySeconds.toString(), }); } @@ -352,14 +352,14 @@ export abstract class TurboAuthenticatedBaseUploadService }); if (!createdApproval) { throw new Error( - 'Failed to create delegated payment approval but upload has succeeded\n' + + 'Failed to create credit share approval but upload has succeeded\n' + JSON.stringify(uploadResponse), ); } return createdApproval; } - public async revokeDelegatedPaymentApprovals({ + public async revokeCredits({ revokedAddress, }: TurboRevokeDelegatePaymentApprovalsParams): Promise< DelegatedPaymentApproval[] @@ -367,7 +367,7 @@ export abstract class TurboAuthenticatedBaseUploadService const dataItemOpts = { tags: [ { - name: delegatedPaymentTagNames.revokeDelegatePaymentApproval, + name: creditSharingTagNames.revokeCredits, value: revokedAddress, }, ], @@ -381,7 +381,7 @@ export abstract class TurboAuthenticatedBaseUploadService }); if (!revokedApprovals) { throw new Error( - 'Failed to revoke delegated payment approvals but upload has succeeded\n' + + 'Failed to revoke credit share approvals but upload has succeeded\n' + JSON.stringify(uploadResponse), ); } diff --git a/src/types.ts b/src/types.ts index 6c1e9806..7a5aacaa 100644 --- a/src/types.ts +++ b/src/types.ts @@ -587,7 +587,7 @@ export interface TurboUnauthenticatedPaymentServiceInterface { submitFundTransaction(p: { txId: string; }): Promise; - getDelegatedPaymentApprovals(p: { + getCreditShareApprovals(p: { userAddress: UserAddress; }): Promise; } @@ -602,7 +602,7 @@ export interface TurboAuthenticatedPaymentServiceInterface extends TurboUnauthenticatedPaymentServiceInterface { getBalance: (userAddress?: UserAddress) => Promise; - getDelegatedPaymentApprovals(p: { + getCreditShareApprovals(p: { userAddress?: UserAddress; }): Promise; @@ -628,11 +628,11 @@ export interface TurboAuthenticatedUploadServiceInterface uploadFolder(p: TurboUploadFolderParams): Promise; - createDelegatedPaymentApproval( + shareCredits( p: TurboCreateDelegatedPaymentApprovalParams, ): Promise; - revokeDelegatedPaymentApprovals( + revokeCredits( p: TurboRevokeDelegatePaymentApprovalsParams, ): Promise; } diff --git a/tests/approval.node.test.ts b/tests/approval.node.test.ts index db4e45cf..205f4246 100644 --- a/tests/approval.node.test.ts +++ b/tests/approval.node.test.ts @@ -63,13 +63,12 @@ describe('Delegated Payments', () => { let oldestApprovalId: string; - describe('createDelegatedPaymentApproval', () => { - it('should properly create a delegated payment approval', async () => { - const { approvalDataItemId, payingAddress } = - await turbo.createDelegatedPaymentApproval({ - approvedWincAmount: '100', - approvedAddress: unfundedSignerAddress1, - }); + describe('shareCredits', () => { + it('should properly create a credit share approval', async () => { + const { approvalDataItemId, payingAddress } = await turbo.shareCredits({ + approvedWincAmount: '100', + approvedAddress: unfundedSignerAddress1, + }); oldestApprovalId = approvalDataItemId; expect(approvalDataItemId).to.be.a('string'); expect(payingAddress).to.equal(arweavePayerAddress); @@ -90,13 +89,12 @@ describe('Delegated Payments', () => { expect(receivedApprovals).to.have.length(0); }); - it('should properly create a delegated payment approval with expiration, and the approval should expire as expected', async () => { - const { approvalDataItemId, payingAddress } = - await turbo.createDelegatedPaymentApproval({ - approvedWincAmount: '100', - approvedAddress: unfundedSignerAddress1, - expiresBySeconds: 1, - }); + it('should properly create a credit share approval with expiration, and the approval should expire as expected', async () => { + const { approvalDataItemId, payingAddress } = await turbo.shareCredits({ + approvedWincAmount: '100', + approvedAddress: unfundedSignerAddress1, + expiresBySeconds: 1, + }); expect(approvalDataItemId).to.be.a('string'); expect(payingAddress).to.equal(arweavePayerAddress); @@ -134,23 +132,23 @@ describe('Delegated Payments', () => { it('should fail to create payment approvals to invalid addresses', async () => { await expectAsyncErrorThrow({ - promiseToError: turbo.createDelegatedPaymentApproval({ + promiseToError: turbo.shareCredits({ approvedWincAmount: '100', approvedAddress: 'invalidAddress', }), errorMessage: - 'Failed request: 400: Unable to create delegated payment approval : Invalid approved address', + 'Failed request: 400: Unable to create credit share approval : Invalid approved address', errorType: 'FailedRequestError', }); }); it('should fail to create payment approvals when payer has insufficient balance for approval', async () => { await expectAsyncErrorThrow({ - promiseToError: turbo.createDelegatedPaymentApproval({ + promiseToError: turbo.shareCredits({ approvedWincAmount: '10000', approvedAddress: unfundedSignerAddress1, }), - errorMessage: `Failed request: 400: Unable to create delegated payment approval : Insufficient balance for '${arweavePayerAddress}'`, + errorMessage: `Failed request: 400: Unable to create credit share approval : Insufficient balance for '${arweavePayerAddress}'`, errorType: 'FailedRequestError', }); }); @@ -164,40 +162,40 @@ describe('Delegated Payments', () => { owner: 'owner', }); await expectAsyncErrorThrow({ - promiseToError: turbo.createDelegatedPaymentApproval({ + promiseToError: turbo.shareCredits({ approvedAddress: 'stub-43-char-address-stub-43-char-address-0', approvedWincAmount: '100', }), - errorMessage: `Failed to create delegated payment approval but upload has succeeded\n{"winc":"100","dataCaches":[],"fastFinalityIndexes":[],"id":"id","owner":"owner"}`, + errorMessage: `Failed to create credit share approval but upload has succeeded\n{"winc":"100","dataCaches":[],"fastFinalityIndexes":[],"id":"id","owner":"owner"}`, errorType: 'Error', }); }); }); - describe('getDelegatedPaymentApprovals', () => { - it('should properly get all delegated payment approvals for given signer -- sorted by expiration date first, then by creation date', async () => { + describe('getCreditShareApprovals', () => { + it('should properly get all credit share approvals for given signer -- sorted by expiration date first, then by creation date', async () => { const newApprovalWithNoExpirationId = ( - await turbo.createDelegatedPaymentApproval({ + await turbo.shareCredits({ approvedWincAmount: '100', approvedAddress: unfundedSignerAddress1, }) ).approvalDataItemId; const approvalWithFarExpirationId = ( - await turbo.createDelegatedPaymentApproval({ + await turbo.shareCredits({ approvedWincAmount: '100', approvedAddress: unfundedSignerAddress1, expiresBySeconds: 10000, }) ).approvalDataItemId; const approvalWithNearExpirationId = ( - await turbo.createDelegatedPaymentApproval({ + await turbo.shareCredits({ approvedWincAmount: '100', approvedAddress: unfundedSignerAddress1, expiresBySeconds: 10, }) ).approvalDataItemId; - const { givenApprovals } = await turbo.getDelegatedPaymentApprovals(); + const { givenApprovals } = await turbo.getCreditShareApprovals(); expect(givenApprovals).to.have.length(4); expect(givenApprovals[0].approvalDataItemId).to.equal( approvalWithNearExpirationId, @@ -211,22 +209,22 @@ describe('Delegated Payments', () => { ); }); - it('should properly get delegated payment approvals when no approvals are present', async () => { + it('should properly get credit share approvals when no approvals are present', async () => { const { givenApprovals } = await TurboFactory.unauthenticated( {}, - ).getDelegatedPaymentApprovals({ + ).getCreditShareApprovals({ userAddress: 'stub-43-char-address-stub-43-char-address-0', }); expect(givenApprovals).to.have.length(0); }); }); - describe('revokeDelegatedPaymentApprovals', () => { - it('should properly revoke all delegated payment approvals for given address', async () => { + describe('revokeCredits', () => { + it('should properly revoke all credit share approvals for given address', async () => { const { givenApprovals } = await turbo.getBalance(); expect(givenApprovals).to.have.length(4); - await turbo.revokeDelegatedPaymentApprovals({ + await turbo.revokeCredits({ revokedAddress: unfundedSignerAddress1, }); @@ -234,13 +232,13 @@ describe('Delegated Payments', () => { expect(givenApprovalsLater).to.have.length(0); }); - it('should fail to revoke if there are no delegated payment approvals for given address', async () => { + it('should fail to revoke if there are no credit share approvals for given address', async () => { await expectAsyncErrorThrow({ - promiseToError: turbo.revokeDelegatedPaymentApprovals({ + promiseToError: turbo.revokeCredits({ revokedAddress: 'stub-43-char-address-stub-43-char-address-0', }), errorMessage: - 'Failed request: 400: Unable to revoke delegated payment approval !', + 'Failed request: 400: Unable to revoke credit share approval !', errorType: 'FailedRequestError', }); }); @@ -254,17 +252,17 @@ describe('Delegated Payments', () => { owner: 'owner', }); await expectAsyncErrorThrow({ - promiseToError: turbo.revokeDelegatedPaymentApprovals({ + promiseToError: turbo.revokeCredits({ revokedAddress: 'stub-43-char-address-stub-43-char-address-0', }), errorMessage: - 'Failed to revoke delegated payment approvals but upload has succeeded\n{"winc":"100","dataCaches":[],"fastFinalityIndexes":[],"id":"id","owner":"owner"}', + 'Failed to revoke credit share approvals but upload has succeeded\n{"winc":"100","dataCaches":[],"fastFinalityIndexes":[],"id":"id","owner":"owner"}', errorType: 'Error', }); }); }); - describe('using delegated payment approvals', () => { + describe('using credit share approvals', () => { let signerJwk: JWKInterface; let payingJwk: JWKInterface; @@ -296,7 +294,7 @@ describe('Delegated Payments', () => { txId: id, }); - await payingTurbo.createDelegatedPaymentApproval({ + await payingTurbo.shareCredits({ approvedWincAmount: 766_000_000_000, approvedAddress: signerAddress, }); @@ -312,7 +310,7 @@ describe('Delegated Payments', () => { const filePath = new URL('files/1MB_file', import.meta.url).pathname; const fileSize = statSync(filePath).size; - it('should properly use a delegated payment approvals to upload data when paid-by is provided', async () => { + it('should properly use a credit share approvals to upload data when paid-by is provided', async () => { const { winc } = await signerTurbo.uploadFile({ dataItemOpts: { paidBy: payingAddress }, fileStreamFactory: () => createReadStream(filePath), @@ -330,7 +328,7 @@ describe('Delegated Payments', () => { expect(+signerBalance.effectiveBalance).to.equal(766_000_000_000 - +winc); }); - it('should properly use a delegated payment approvals to upload data when multiple paid-bys are provided', async () => { + it('should properly use a credit share approvals to upload data when multiple paid-bys are provided', async () => { const payerBalance = await payingTurbo.getBalance(); const { winc } = await signerTurbo.uploadFile({