Skip to content

Commit

Permalink
fix(application-client): Resolving problem where call() wasn't wrappi…
Browse files Browse the repository at this point in the history
…ng the logic error due to lack of await
  • Loading branch information
robdmoore committed Mar 25, 2023
1 parent 83af190 commit fd13f42
Show file tree
Hide file tree
Showing 14 changed files with 137 additions and 284 deletions.
24 changes: 12 additions & 12 deletions docs/code/classes/types_application_client.ApplicationClient.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Create a new ApplicationClient instance

#### Defined in

[src/types/application-client.ts:151](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/application-client.ts#L151)
[src/types/application-client.ts:158](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/application-client.ts#L158)

## Properties

Expand Down Expand Up @@ -201,7 +201,7 @@ ___

#### Defined in

[src/types/application-client.ts:408](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/application-client.ts#L408)
[src/types/application-client.ts:412](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/application-client.ts#L412)

___

Expand All @@ -221,7 +221,7 @@ ___

#### Defined in

[src/types/application-client.ts:388](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/application-client.ts#L388)
[src/types/application-client.ts:392](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/application-client.ts#L392)

___

Expand All @@ -241,7 +241,7 @@ ___

#### Defined in

[src/types/application-client.ts:400](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/application-client.ts#L400)
[src/types/application-client.ts:404](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/application-client.ts#L404)

___

Expand All @@ -261,7 +261,7 @@ ___

#### Defined in

[src/types/application-client.ts:396](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/application-client.ts#L396)
[src/types/application-client.ts:400](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/application-client.ts#L400)

___

Expand All @@ -281,7 +281,7 @@ ___

#### Defined in

[src/types/application-client.ts:293](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/application-client.ts#L293)
[src/types/application-client.ts:297](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/application-client.ts#L297)

___

Expand All @@ -301,13 +301,13 @@ ___

#### Defined in

[src/types/application-client.ts:404](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/application-client.ts#L404)
[src/types/application-client.ts:408](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/application-client.ts#L408)

___

### deploy

**deploy**(`deploy`): `Promise`<`Partial`<[`AppCompilationResult`](../interfaces/types_app.AppCompilationResult.md)\> & [`ConfirmedTransactionResult`](../interfaces/types_transaction.ConfirmedTransactionResult.md) & [`AppMetadata`](../interfaces/types_app.AppMetadata.md) & { `operationPerformed`: ``"update"`` \| ``"create"`` } \| `Partial`<[`AppCompilationResult`](../interfaces/types_app.AppCompilationResult.md)\> & [`ConfirmedTransactionResult`](../interfaces/types_transaction.ConfirmedTransactionResult.md) & [`AppMetadata`](../interfaces/types_app.AppMetadata.md) & { `deleteResult`: [`ConfirmedTransactionResult`](../interfaces/types_transaction.ConfirmedTransactionResult.md) ; `operationPerformed`: ``"replace"`` } \| `Partial`<[`AppCompilationResult`](../interfaces/types_app.AppCompilationResult.md)\> & [`AppMetadata`](../interfaces/types_app.AppMetadata.md) & { `operationPerformed`: ``"nothing"`` }\>
**deploy**(`deploy?`): `Promise`<`Partial`<[`AppCompilationResult`](../interfaces/types_app.AppCompilationResult.md)\> & [`ConfirmedTransactionResult`](../interfaces/types_transaction.ConfirmedTransactionResult.md) & [`AppMetadata`](../interfaces/types_app.AppMetadata.md) & { `operationPerformed`: ``"update"`` \| ``"create"`` } \| `Partial`<[`AppCompilationResult`](../interfaces/types_app.AppCompilationResult.md)\> & [`ConfirmedTransactionResult`](../interfaces/types_transaction.ConfirmedTransactionResult.md) & [`AppMetadata`](../interfaces/types_app.AppMetadata.md) & { `deleteResult`: [`ConfirmedTransactionResult`](../interfaces/types_transaction.ConfirmedTransactionResult.md) ; `operationPerformed`: ``"replace"`` } \| `Partial`<[`AppCompilationResult`](../interfaces/types_app.AppCompilationResult.md)\> & [`AppMetadata`](../interfaces/types_app.AppMetadata.md) & { `operationPerformed`: ``"nothing"`` }\>

Idempotently deploy (create, update/delete if changed) an app against the given name via the given creator account, including deploy-time template placeholder substitutions.

Expand All @@ -325,7 +325,7 @@ https://github.com/algorandfoundation/algokit-cli/blob/main/docs/architecture-de

| Name | Type | Description |
| :------ | :------ | :------ |
| `deploy` | [`AppClientDeployParams`](../interfaces/types_application_client.AppClientDeployParams.md) | Deployment details |
| `deploy?` | [`AppClientDeployParams`](../interfaces/types_application_client.AppClientDeployParams.md) | Deployment details |

#### Returns

Expand All @@ -335,7 +335,7 @@ The metadata and transaction result(s) of the deployment, or just the metadata i

#### Defined in

[src/types/application-client.ts:195](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/application-client.ts#L195)
[src/types/application-client.ts:200](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/application-client.ts#L200)

___

Expand Down Expand Up @@ -440,7 +440,7 @@ ___

#### Defined in

[src/types/application-client.ts:392](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/application-client.ts#L392)
[src/types/application-client.ts:396](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/application-client.ts#L396)

___

Expand All @@ -460,4 +460,4 @@ ___

#### Defined in

[src/types/application-client.ts:346](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/application-client.ts#L346)
[src/types/application-client.ts:350](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/application-client.ts#L350)
14 changes: 7 additions & 7 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"generate:code-docs": "typedoc"
},
"dependencies": {
"algosdk": "^2.1.0",
"algosdk": "^2.2.0",
"buffer": "^6.0.3"
},
"devDependencies": {
Expand Down
20 changes: 10 additions & 10 deletions src/__snapshots__/deploy-app.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`deploy-app Deploy failure for replacement of permanent, updated app 1`] = `
"INFO: Idempotently deploying app "test" from creator ACCOUNT_1 using 2203 bytes of teal code and 39 bytes of teal code
"INFO: Idempotently deploying app "test" from creator ACCOUNT_1 using 2456 bytes of teal code and 39 bytes of teal code
INFO: Existing app test found by creator ACCOUNT_1, with app id APP_1 and version 1.0.
INFO: Detected a TEAL update in app APP_1 for creator ACCOUNT_1
WARN: App is not deletable and onUpdate=ReplaceApp, will attempt to create new app and delete old app, delete will most likely fail
Expand All @@ -10,26 +10,26 @@ WARN: Deleting existing test app with id APP_1 from ACCOUNT_1 account."
`;

exports[`deploy-app Deploy failure for replacement of schema broken app fails if onSchemaBreak = Fail 1`] = `
"INFO: Idempotently deploying app "test" from creator ACCOUNT_1 using 2203 bytes of teal code and 39 bytes of teal code
"INFO: Idempotently deploying app "test" from creator ACCOUNT_1 using 2456 bytes of teal code and 39 bytes of teal code
INFO: Existing app test found by creator ACCOUNT_1, with app id APP_1 and version 1.0.
WARN: Detected a breaking app schema change in app APP_1: | [{"from":{"global":{"num-byte-slice":0,"num-uint":1},"local":{"num-byte-slice":0,"num-uint":0}},"to":{"global":{"num-byte-slice":1,"num-uint":1},"local":{"num-byte-slice":0,"num-uint":0}}}]"
`;

exports[`deploy-app Deploy failure for updated app fails if onupdate = Fail 1`] = `
"INFO: Idempotently deploying app "test" from creator ACCOUNT_1 using 2203 bytes of teal code and 39 bytes of teal code
"INFO: Idempotently deploying app "test" from creator ACCOUNT_1 using 2456 bytes of teal code and 39 bytes of teal code
INFO: Existing app test found by creator ACCOUNT_1, with app id APP_1 and version 1.0.
INFO: Detected a TEAL update in app APP_1 for creator ACCOUNT_1"
`;

exports[`deploy-app Deploy new app 1`] = `
"INFO: Idempotently deploying app "test" from creator ACCOUNT_1 using 2203 bytes of teal code and 39 bytes of teal code
"INFO: Idempotently deploying app "test" from creator ACCOUNT_1 using 2456 bytes of teal code and 39 bytes of teal code
INFO: App test not found in apps created by ACCOUNT_1; deploying app with version 1.0.
INFO: Sent transaction ID TXID_1 appl from ACCOUNT_1
DEBUG: Created app APP_1 from creator ACCOUNT_1"
`;

exports[`deploy-app Deploy replacement of deletable schema broken app 1`] = `
"INFO: Idempotently deploying app "test" from creator ACCOUNT_1 using 2203 bytes of teal code and 39 bytes of teal code
"INFO: Idempotently deploying app "test" from creator ACCOUNT_1 using 2456 bytes of teal code and 39 bytes of teal code
INFO: Existing app test found by creator ACCOUNT_1, with app id APP_1 and version 1.0.
WARN: Detected a breaking app schema change in app APP_1: | [{"from":{"global":{"num-byte-slice":0,"num-uint":1},"local":{"num-byte-slice":0,"num-uint":0}},"to":{"global":{"num-byte-slice":1,"num-uint":1},"local":{"num-byte-slice":0,"num-uint":0}}}]
INFO: App is deletable and onSchemaBreak=ReplaceApp, will attempt to create new app and delete old app
Expand All @@ -39,7 +39,7 @@ WARN: Sent transactions TXID_2 to create app with id APP_2 and TXID_3 to delete
`;

exports[`deploy-app Deploy replacement to deletable, updated app 1`] = `
"INFO: Idempotently deploying app "test" from creator ACCOUNT_1 using 2203 bytes of teal code and 39 bytes of teal code
"INFO: Idempotently deploying app "test" from creator ACCOUNT_1 using 2456 bytes of teal code and 39 bytes of teal code
INFO: Existing app test found by creator ACCOUNT_1, with app id APP_1 and version 1.0.
INFO: Detected a TEAL update in app APP_1 for creator ACCOUNT_1
WARN: App is deletable and onUpdate=ReplaceApp, creating new app and deleting old app...
Expand All @@ -49,7 +49,7 @@ WARN: Sent transactions TXID_2 to create app with id APP_2 and TXID_3 to delete
`;

exports[`deploy-app Deploy replacement to schema broken, permanent app fails 1`] = `
"INFO: Idempotently deploying app "test" from creator ACCOUNT_1 using 2203 bytes of teal code and 39 bytes of teal code
"INFO: Idempotently deploying app "test" from creator ACCOUNT_1 using 2456 bytes of teal code and 39 bytes of teal code
INFO: Existing app test found by creator ACCOUNT_1, with app id APP_1 and version 1.0.
WARN: Detected a breaking app schema change in app APP_1: | [{"from":{"global":{"num-byte-slice":0,"num-uint":1},"local":{"num-byte-slice":0,"num-uint":0}},"to":{"global":{"num-byte-slice":1,"num-uint":1},"local":{"num-byte-slice":0,"num-uint":0}}}]
INFO: App is not deletable but onSchemaBreak=ReplaceApp, will attempt to delete app, delete will most likely fail
Expand All @@ -58,7 +58,7 @@ WARN: Deleting existing test app with id APP_1 from ACCOUNT_1 account."
`;

exports[`deploy-app Deploy update to immutable updated app fails 1`] = `
"INFO: Idempotently deploying app "test" from creator ACCOUNT_1 using 2203 bytes of teal code and 39 bytes of teal code
"INFO: Idempotently deploying app "test" from creator ACCOUNT_1 using 2456 bytes of teal code and 39 bytes of teal code
INFO: Existing app test found by creator ACCOUNT_1, with app id APP_1 and version 1.0.
INFO: Detected a TEAL update in app APP_1 for creator ACCOUNT_1
WARN: App is not updatable but onUpdate=UpdateApp, will attempt to update app, update will most likely fail
Expand All @@ -67,7 +67,7 @@ DEBUG: Updating app APP_1"
`;

exports[`deploy-app Deploy update to updatable updated app 1`] = `
"INFO: Idempotently deploying app "test" from creator ACCOUNT_1 using 2203 bytes of teal code and 39 bytes of teal code
"INFO: Idempotently deploying app "test" from creator ACCOUNT_1 using 2456 bytes of teal code and 39 bytes of teal code
INFO: Existing app test found by creator ACCOUNT_1, with app id APP_1 and version 1.0.
INFO: Detected a TEAL update in app APP_1 for creator ACCOUNT_1
INFO: App is updatable and onUpdate=UpdateApp, updating app...
Expand All @@ -77,7 +77,7 @@ INFO: Sent transaction ID TXID_2 appl from ACCOUNT_1"
`;

exports[`deploy-app Do nothing if deploying app with no changes 1`] = `
"INFO: Idempotently deploying app "test" from creator ACCOUNT_1 using 2203 bytes of teal code and 39 bytes of teal code
"INFO: Idempotently deploying app "test" from creator ACCOUNT_1 using 2456 bytes of teal code and 39 bytes of teal code
INFO: Existing app test found by creator ACCOUNT_1, with app id APP_1 and version 1.0.
DEBUG: No detected changes in app, nothing to do."
`;
37 changes: 37 additions & 0 deletions src/types/application-client.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,4 +164,41 @@ describe('application-client', () => {
const methodArg = new ABIStringType().encode('test')
expect(call.transaction.appArgs).toEqual([methodSelector, methodArg])
})

test('Display nice error messages when there is a logic error', async () => {
const { algod, indexer, testAccount } = localnet.context
const client = algokit.getApplicationClient(
{
app: appSpec,
sender: testAccount,
creatorAddress: testAccount.addr,
indexer: indexer,
},
algod,
)
await client.deploy({
deployTimeParameters: { VALUE: 1 },
})

try {
await client.call({
method: 'error',
methodArgs: [],
})
} catch (e: any) {
expect(e.toString()).toMatchInlineSnapshot(`"Error: assert failed pc=279. at:165"`)
expect(e.stack).toMatchInlineSnapshot(`
"
// error
error_2:
proto 0 0
intc_0 // 0
assert <--- Error
retsub
// create
create_3:"
`)
}
})
})
6 changes: 3 additions & 3 deletions src/types/application-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,8 @@ export class ApplicationClient {
* @param deploy Deployment details
* @returns The metadata and transaction result(s) of the deployment, or just the metadata if it didn't need to issue transactions
*/
async deploy(deploy: AppClientDeployParams) {
const { sender, version, allowUpdate, allowDelete, sendParams, createArgs, updateArgs, deleteArgs, ...deployArgs } = deploy
async deploy(deploy?: AppClientDeployParams) {
const { sender, version, allowUpdate, allowDelete, sendParams, createArgs, updateArgs, deleteArgs, ...deployArgs } = deploy ?? {}

if (this._appId !== 0) {
throw new Error(`Attempt to deploy app which already has an app id of ${this._appId}`)
Expand Down Expand Up @@ -422,7 +422,7 @@ export class ApplicationClient {
}

try {
return callApp(
return await callApp(
{
appId: appMetadata.appId,
callType: callType,
Expand Down
Loading

0 comments on commit fd13f42

Please sign in to comment.