Skip to content

Commit

Permalink
chore: extra test cases; adding timeout handler
Browse files Browse the repository at this point in the history
  • Loading branch information
aorumbayev committed Oct 2, 2023
1 parent 1e6d6b5 commit f8a516c
Show file tree
Hide file tree
Showing 7 changed files with 183 additions and 23 deletions.
11 changes: 5 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

56 changes: 48 additions & 8 deletions src/clients/SubtopiaClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@ import {
calculateProductDiscountBoxCreateMbr,
calculateProductSubscriptionBoxCreateMbr,
optInAsset,
asyncWithTimeout,
} from "../utils";
import { getAssetByID } from "../utils";
import {
SUBSCRIPTION_PLATFORM_FEE_CENTS,
TESTNET_SUBTOPIA_REGISTRY_ID,
MIN_APP_CREATE_MBR,
MIN_ASA_CREATE_MBR,
DEFAULT_TXN_SIGN_TIMEOUT_SECONDS,
} from "../constants";
import {
PriceNormalizationType,
Expand Down Expand Up @@ -69,6 +71,7 @@ export class SubtopiaClient {
appID: number;
appAddress: string;
appSpec: ApplicationSpec;
timeout: number;

protected constructor({
algodClient,
Expand All @@ -82,6 +85,7 @@ export class SubtopiaClient {
price,
coin,
version,
timeout,
}: {
algodClient: AlgodClient;
productName: string;
Expand All @@ -94,6 +98,7 @@ export class SubtopiaClient {
price: number;
coin: AssetMetadata;
version: string;
timeout: number;
}) {
this.algodClient = algodClient;
this.productName = productName;
Expand All @@ -106,12 +111,14 @@ export class SubtopiaClient {
this.price = price;
this.coin = coin;
this.version = version;
this.timeout = timeout;
}

public static async init(
algodClient: AlgodClient,
productID: number,
creator: TransactionSignerAccount
creator: TransactionSignerAccount,
timeout: number = DEFAULT_TXN_SIGN_TIMEOUT_SECONDS
): Promise<SubtopiaClient> {
const productGlobalState = await getAppGlobalState(
productID,
Expand Down Expand Up @@ -194,6 +201,7 @@ export class SubtopiaClient {
price: productPrice,
coin,
version,
timeout,
});
}

Expand Down Expand Up @@ -224,7 +232,12 @@ export class SubtopiaClient {
suggestedParams: await getParamsWithFeeCount(this.algodClient, 1),
});

const response = await updateLifecycleAtc.execute(this.algodClient, 10);
const response = await asyncWithTimeout(
updateLifecycleAtc.execute.bind(updateLifecycleAtc),
this.timeout,
this.algodClient,
10
);

return {
txID: response.txIDs.pop() as string,
Expand Down Expand Up @@ -509,7 +522,12 @@ export class SubtopiaClient {
suggestedParams: await getParamsWithFeeCount(this.algodClient, 2),
});

const response = await createDiscountAtc.execute(this.algodClient, 10);
const response = await asyncWithTimeout(
createDiscountAtc.execute.bind(createDiscountAtc),
this.timeout,
this.algodClient,
10
);

return {
txID: response.txIDs.pop() as string,
Expand Down Expand Up @@ -545,7 +563,12 @@ export class SubtopiaClient {
suggestedParams: await getParamsWithFeeCount(this.algodClient, 2),
});

const response = await deleteDiscountAtc.execute(this.algodClient, 10);
const response = await asyncWithTimeout(
deleteDiscountAtc.execute.bind(deleteDiscountAtc),
this.timeout,
this.algodClient,
10
);

return {
txID: response.txIDs.pop() as string,
Expand Down Expand Up @@ -706,7 +729,12 @@ export class SubtopiaClient {
),
});

const response = await createSubscriptionAtc.execute(this.algodClient, 10);
const response = await asyncWithTimeout(
createSubscriptionAtc.execute.bind(createSubscriptionAtc),
this.timeout,
this.algodClient,
10
);

return {
txID: response.txIDs.pop() as string,
Expand Down Expand Up @@ -760,7 +788,9 @@ export class SubtopiaClient {
suggestedParams: await getParamsWithFeeCount(this.algodClient, 2),
});

const response = await transferSubscriptionAtc.execute(
const response = await asyncWithTimeout(
transferSubscriptionAtc.execute.bind(transferSubscriptionAtc),
this.timeout,
this.algodClient,
10
);
Expand Down Expand Up @@ -822,7 +852,12 @@ export class SubtopiaClient {
suggestedParams: await getParamsWithFeeCount(this.algodClient, 2),
});

const response = await claimSubscriptionAtc.execute(this.algodClient, 10);
const response = await asyncWithTimeout(
claimSubscriptionAtc.execute.bind(claimSubscriptionAtc),
this.timeout,
this.algodClient,
10
);

return {
txID: response.txIDs.pop() as string,
Expand Down Expand Up @@ -878,7 +913,12 @@ export class SubtopiaClient {
),
});

const response = await deleteSubscriptionAtc.execute(this.algodClient, 10);
const response = await asyncWithTimeout(
deleteSubscriptionAtc.execute.bind(deleteSubscriptionAtc),
this.timeout,
this.algodClient,
10
);

return {
txID: response.txIDs.pop() as string,
Expand Down
38 changes: 33 additions & 5 deletions src/clients/SubtopiaRegistryClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
calculateLockerCreationMbr,
calculateRegistryLockerBoxCreateMbr,
getLockerBoxPrefix,
asyncWithTimeout,
} from "../utils";
import { getAssetByID } from "../utils";
import {
Expand All @@ -37,6 +38,7 @@ import {
LOCKER_CLEAR_KEY,
SUBTOPIA_REGISTRY_ID,
MIN_APP_CREATE_MBR,
DEFAULT_TXN_SIGN_TIMEOUT_SECONDS,
} from "../constants";
import {
SubscriptionType,
Expand Down Expand Up @@ -65,6 +67,7 @@ export class SubtopiaRegistryClient {
appAddress: string;
appSpec: ApplicationSpec;
oracleID: number;
timeout: number;

protected constructor({
algodClient,
Expand All @@ -74,6 +77,7 @@ export class SubtopiaRegistryClient {
appSpec,
oracleID,
version,
timeout,
}: {
algodClient: AlgodClient;
creator: TransactionSignerAccount;
Expand All @@ -82,6 +86,7 @@ export class SubtopiaRegistryClient {
appSpec: ApplicationSpec;
oracleID: number;
version: string;
timeout: number;
}) {
this.algodClient = algodClient;
this.creator = creator;
Expand All @@ -90,12 +95,14 @@ export class SubtopiaRegistryClient {
this.appSpec = appSpec;
this.oracleID = oracleID;
this.version = version;
this.timeout = timeout;
}

public static async init(
algodClient: AlgodClient,
creator: TransactionSignerAccount,
chainType: ChainType
chainType: ChainType,
timeout: number = DEFAULT_TXN_SIGN_TIMEOUT_SECONDS
): Promise<SubtopiaRegistryClient> {
const registryID = SUBTOPIA_REGISTRY_ID(chainType);
const registryAddress = getApplicationAddress(registryID);
Expand Down Expand Up @@ -157,6 +164,7 @@ export class SubtopiaRegistryClient {
},
oracleID: oracleID,
version: version,
timeout: timeout,
});
}

Expand Down Expand Up @@ -301,7 +309,12 @@ export class SubtopiaRegistryClient {
suggestedParams: await getParamsWithFeeCount(this.algodClient, 4),
});

const response = await createLockerAtc.execute(this.algodClient, 10);
const response = await asyncWithTimeout(
createLockerAtc.execute.bind(createLockerAtc),
this.timeout,
this.algodClient,
10
);

return {
txID: response.txIDs.pop() as string,
Expand Down Expand Up @@ -449,7 +462,12 @@ export class SubtopiaRegistryClient {
),
});

const response = await transferInfraAtc.execute(this.algodClient, 10);
const response = await asyncWithTimeout(
transferInfraAtc.execute.bind(transferInfraAtc),
this.timeout,
this.algodClient,
10
);

return {
txID: response.txIDs.pop() as string,
Expand Down Expand Up @@ -642,7 +660,12 @@ export class SubtopiaRegistryClient {
),
});

const response = await createInfraAtc.execute(this.algodClient, 10);
const response = await asyncWithTimeout(
createInfraAtc.execute.bind(createInfraAtc),
this.timeout,
this.algodClient,
10
);

return {
txID: response.txIDs.pop() as string,
Expand Down Expand Up @@ -693,7 +716,12 @@ export class SubtopiaRegistryClient {
suggestedParams: await getParamsWithFeeCount(this.algodClient, 4),
});

const response = await deleteInfraAtc.execute(this.algodClient, 10);
const response = await asyncWithTimeout(
deleteInfraAtc.execute.bind(deleteInfraAtc),
this.timeout,
this.algodClient,
10
);

return {
txID: response.txIDs.pop() as string,
Expand Down
3 changes: 3 additions & 0 deletions src/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,6 @@ export const LOCKER_GLOBAL_NUM_UINTS = 1;
export const LOCKER_GLOBAL_NUM_BYTE_SLICES = 1;
export const LOCKER_LOCAL_NUM_UINTS = 0;
export const LOCKER_LOCAL_NUM_BYTE_SLICES = 0;

// Misc
export const DEFAULT_TXN_SIGN_TIMEOUT_SECONDS = 60;
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ export {
ORACLE_VERSION,
PRODUCT_VERSION,
SUBTOPIA_REGISTRY_ID,
DEFAULT_TXN_SIGN_TIMEOUT_SECONDS,
} from "./constants";
Loading

0 comments on commit f8a516c

Please sign in to comment.