From fb2c5e8cef87563e5875000836500dac5c985161 Mon Sep 17 00:00:00 2001 From: Altynbek Orumbayev Date: Sun, 17 Sep 2023 18:35:01 +0200 Subject: [PATCH] chore: free sub prices; extra test case --- src/clients/SubtopiaClient.ts | 13 ++++----- tests/subtopia.test.ts | 50 +++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 6 deletions(-) diff --git a/src/clients/SubtopiaClient.ts b/src/clients/SubtopiaClient.ts index 73924ce..dbbde94 100644 --- a/src/clients/SubtopiaClient.ts +++ b/src/clients/SubtopiaClient.ts @@ -315,9 +315,12 @@ export class SubtopiaClient { ); } - public async getSubscriptionPlatformFee( - priceInCents: number - ): Promise { + public async getSubscriptionPlatformFee(): Promise { + if (this.price === 0) { + return new Promise((resolve) => resolve(0)); + } + + const priceInCents = SUBSCRIPTION_PLATFORM_FEE_CENTS; const computePlatformFeeAtc = new AtomicTransactionComposer(); computePlatformFeeAtc.addMethodCall({ appID: this.oracleID, @@ -572,9 +575,7 @@ export class SubtopiaClient { // @ts-ignore oracleAdminState.valueRaw ); - const platformFeeAmount = await this.getSubscriptionPlatformFee( - SUBSCRIPTION_PLATFORM_FEE_CENTS - ); + const platformFeeAmount = await this.getSubscriptionPlatformFee(); const creatorLockerId = await SubtopiaRegistryClient.getLocker({ registryID: TESTNET_SUBTOPIA_REGISTRY_ID, algodClient: this.algodClient, diff --git a/tests/subtopia.test.ts b/tests/subtopia.test.ts index 3236425..e543ae0 100644 --- a/tests/subtopia.test.ts +++ b/tests/subtopia.test.ts @@ -343,4 +343,54 @@ describe("subtopia", () => { timeout: 10e6, } ); + + it( + "should not withdraw platform fee for free subscription", + async () => { + // Setup + const { subtopiaRegistryClient, lockerID } = + await setupSubtopiaRegistryClient(creatorSignerAccount); + + // Create a new infrastructure with price 0 + const response = await subtopiaRegistryClient.createInfrastructure({ + productName: "Freeflix", + subscriptionName: "Free", + price: 0, + subType: SubscriptionType.UNLIMITED, + maxSubs: 0, + coinID: 0, + lockerID: lockerID, + }); + + // Initialize a new SubtopiaClient + const productClient = await SubtopiaClient.init( + algodClient, + response.infrastructureID, + creatorSignerAccount + ); + + // Subscribe a user to the product + const subscriberSigner = transactionSignerAccount( + makeBasicAccountTransactionSigner(bobTestAccount), + bobTestAccount.addr + ); + + const subscribeResponse = await productClient.createSubscription({ + subscriber: subscriberSigner, + duration: Duration.UNLIMITED, + }); + + expect(subscribeResponse.subscriptionID).toBeGreaterThan(0); + expect(subscribeResponse.txID).toBeDefined(); + + // Get the platform fee + const platformFee = await productClient.getSubscriptionPlatformFee(); + + // Assert that the platform fee is 0 + expect(platformFee).toBe(0); + }, + { + timeout: 10e6, + } + ); });