Skip to content

Commit

Permalink
chore: free sub prices; extra test case
Browse files Browse the repository at this point in the history
  • Loading branch information
aorumbayev committed Sep 17, 2023
1 parent 4783b39 commit fb2c5e8
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/clients/SubtopiaClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,9 +315,12 @@ export class SubtopiaClient {
);
}

public async getSubscriptionPlatformFee(
priceInCents: number
): Promise<number> {
public async getSubscriptionPlatformFee(): Promise<number> {
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,
Expand Down Expand Up @@ -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,
Expand Down
50 changes: 50 additions & 0 deletions tests/subtopia.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
);
});

0 comments on commit fb2c5e8

Please sign in to comment.