Skip to content

Commit

Permalink
feat: add populateAppCallResources to Config (#228)
Browse files Browse the repository at this point in the history
* feat: add populateAppCallResources to Config

* format and generate docs

* resroucePopEnabled -> populateResources
  • Loading branch information
joe-p authored Feb 20, 2024
1 parent 3bbb883 commit 2145566
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 34 deletions.
43 changes: 31 additions & 12 deletions docs/code/classes/types_config.UpdatableConfig.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Updatable AlgoKit config
- [debug](types_config.UpdatableConfig.md#debug)
- [logger](types_config.UpdatableConfig.md#logger)
- [maxSearchDepth](types_config.UpdatableConfig.md#maxsearchdepth)
- [populateAppCallResources](types_config.UpdatableConfig.md#populateappcallresources)
- [projectRoot](types_config.UpdatableConfig.md#projectroot)
- [traceAll](types_config.UpdatableConfig.md#traceall)
- [traceBufferSizeMb](types_config.UpdatableConfig.md#tracebuffersizemb)
Expand All @@ -48,7 +49,7 @@ Updatable AlgoKit config

#### Defined in

[src/types/config.ts:75](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/config.ts#L75)
[src/types/config.ts:88](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/config.ts#L88)

## Properties

Expand All @@ -58,7 +59,7 @@ Updatable AlgoKit config

#### Defined in

[src/types/config.ts:22](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/config.ts#L22)
[src/types/config.ts:31](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/config.ts#L31)

## Accessors

Expand All @@ -76,7 +77,7 @@ Readonly.debug

#### Defined in

[src/types/config.ts:28](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/config.ts#L28)
[src/types/config.ts:41](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/config.ts#L41)

___

Expand All @@ -94,7 +95,7 @@ Readonly.logger

#### Defined in

[src/types/config.ts:24](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/config.ts#L24)
[src/types/config.ts:37](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/config.ts#L37)

___

Expand All @@ -112,7 +113,25 @@ Readonly.maxSearchDepth

#### Defined in

[src/types/config.ts:44](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/config.ts#L44)
[src/types/config.ts:57](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/config.ts#L57)

___

### populateAppCallResources

`get` **populateAppCallResources**(): `boolean`

#### Returns

`boolean`

#### Implementation of

Readonly.populateAppCallResources

#### Defined in

[src/types/config.ts:33](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/config.ts#L33)

___

Expand All @@ -130,7 +149,7 @@ Readonly.projectRoot

#### Defined in

[src/types/config.ts:32](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/config.ts#L32)
[src/types/config.ts:45](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/config.ts#L45)

___

Expand All @@ -148,7 +167,7 @@ Readonly.traceAll

#### Defined in

[src/types/config.ts:36](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/config.ts#L36)
[src/types/config.ts:49](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/config.ts#L49)

___

Expand All @@ -166,7 +185,7 @@ Readonly.traceBufferSizeMb

#### Defined in

[src/types/config.ts:40](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/config.ts#L40)
[src/types/config.ts:53](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/config.ts#L53)

## Methods

Expand All @@ -188,7 +207,7 @@ Update the AlgoKit configuration with your own configuration settings

#### Defined in

[src/types/config.ts:121](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/config.ts#L121)
[src/types/config.ts:135](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/config.ts#L135)

___

Expand All @@ -205,7 +224,7 @@ This is only supported in a Node environment.

#### Defined in

[src/types/config.ts:94](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/config.ts#L94)
[src/types/config.ts:108](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/config.ts#L108)

___

Expand All @@ -229,7 +248,7 @@ The requested logger

#### Defined in

[src/types/config.ts:53](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/config.ts#L53)
[src/types/config.ts:66](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/config.ts#L66)

___

Expand All @@ -251,4 +270,4 @@ Temporarily run with debug set to true.

#### Defined in

[src/types/config.ts:65](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/config.ts#L65)
[src/types/config.ts:78](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/config.ts#L78)
18 changes: 18 additions & 0 deletions docs/code/interfaces/types_config.Config.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ The AlgoKit configuration type
- [debug](types_config.Config.md#debug)
- [logger](types_config.Config.md#logger)
- [maxSearchDepth](types_config.Config.md#maxsearchdepth)
- [populateAppCallResources](types_config.Config.md#populateappcallresources)
- [projectRoot](types_config.Config.md#projectroot)
- [traceAll](types_config.Config.md#traceall)
- [traceBufferSizeMb](types_config.Config.md#tracebuffersizemb)
Expand Down Expand Up @@ -55,6 +56,23 @@ The maximum depth to search for a specific file

___

### populateAppCallResources

**populateAppCallResources**: `boolean`

**WARNING**: This is not production-ready due incompatability with rekeyed
accounts and simulate. This will eventually be enabled by default once
[this issue](https://github.com/algorand/go-algorand/issues/5914) is closed.

Whether to enable populateAppCallResources in sendParams by default.
Default value is false.

#### Defined in

[src/types/config.ts:26](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/config.ts#L26)

___

### projectRoot

**projectRoot**: ``null`` \| `string`
Expand Down
18 changes: 9 additions & 9 deletions docs/code/modules/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ the estimated rate.

#### Defined in

[src/transaction/transaction.ts:665](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction/transaction.ts#L665)
[src/transaction/transaction.ts:667](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction/transaction.ts#L667)

___

Expand Down Expand Up @@ -405,7 +405,7 @@ Allows for control of fees on a `Transaction` or `SuggestedParams` object

#### Defined in

[src/transaction/transaction.ts:688](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction/transaction.ts#L688)
[src/transaction/transaction.ts:690](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction/transaction.ts#L690)

___

Expand Down Expand Up @@ -1477,7 +1477,7 @@ The array of transactions with signers

#### Defined in

[src/transaction/transaction.ts:720](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction/transaction.ts#L720)
[src/transaction/transaction.ts:722](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction/transaction.ts#L722)

___

Expand Down Expand Up @@ -1810,7 +1810,7 @@ The suggested transaction parameters

#### Defined in

[src/transaction/transaction.ts:711](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction/transaction.ts#L711)
[src/transaction/transaction.ts:713](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction/transaction.ts#L713)

___

Expand Down Expand Up @@ -2145,7 +2145,7 @@ The dryrun result

#### Defined in

[src/transaction/transaction.ts:545](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction/transaction.ts#L545)
[src/transaction/transaction.ts:547](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction/transaction.ts#L547)

___

Expand Down Expand Up @@ -2276,7 +2276,7 @@ A new ATC with the resources packed into the transactions

#### Defined in

[src/transaction/transaction.ts:287](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction/transaction.ts#L287)
[src/transaction/transaction.ts:288](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction/transaction.ts#L288)

___

Expand Down Expand Up @@ -2436,7 +2436,7 @@ An object with transaction IDs, transactions, group transaction ID (`groupTransa

#### Defined in

[src/transaction/transaction.ts:418](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction/transaction.ts#L418)
[src/transaction/transaction.ts:419](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction/transaction.ts#L419)

___

Expand All @@ -2461,7 +2461,7 @@ An object with transaction IDs, transactions, group transaction ID (`groupTransa

#### Defined in

[src/transaction/transaction.ts:563](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction/transaction.ts#L563)
[src/transaction/transaction.ts:565](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction/transaction.ts#L565)

___

Expand Down Expand Up @@ -2740,4 +2740,4 @@ Throws an error if the transaction is not confirmed or rejected in the next `tim

#### Defined in

[src/transaction/transaction.ts:608](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction/transaction.ts#L608)
[src/transaction/transaction.ts:610](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction/transaction.ts#L610)
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,4 @@
"@semantic-release/github"
]
}
}
}
26 changes: 18 additions & 8 deletions src/transaction/transaction.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ const tests = (version: 8 | 9) => () => {
beforeEach(fixture.beforeEach)

beforeAll(async () => {
algokit.Config.configure({ populateAppCallResources: true })
await fixture.beforeEach()
const { algod, testAccount } = fixture.context

Expand Down Expand Up @@ -436,6 +437,10 @@ const tests = (version: 8 | 9) => () => {
)
})

afterAll(() => {
algokit.Config.configure({ populateAppCallResources: false })
})

let alice: algosdk.Account

describe('accounts', () => {
Expand All @@ -448,7 +453,7 @@ const tests = (version: 8 | 9) => () => {
})

test('addressBalance', async () => {
await appClient.call({ method: 'addressBalance', methodArgs: [alice.addr], sendParams: { populateAppCallResources: true } })
await appClient.call({ method: 'addressBalance', methodArgs: [alice.addr] })
})
})

Expand All @@ -460,11 +465,11 @@ const tests = (version: 8 | 9) => () => {
})

test('smallBox', async () => {
await appClient.call({ method: 'smallBox', methodArgs: [], sendParams: { populateAppCallResources: true } })
await appClient.call({ method: 'smallBox', methodArgs: [] })
})

test('mediumBox', async () => {
await appClient.call({ method: 'mediumBox', methodArgs: [], sendParams: { populateAppCallResources: true } })
await appClient.call({ method: 'mediumBox', methodArgs: [] })
})
})

Expand All @@ -483,7 +488,7 @@ const tests = (version: 8 | 9) => () => {
await appClient.call({
method: 'externalAppCall',
methodArgs: [],
sendParams: { populateAppCallResources: true, fee: algokit.microAlgos(2_000) },
sendParams: { fee: algokit.microAlgos(2_000) },
})
})
})
Expand All @@ -498,7 +503,7 @@ const tests = (version: 8 | 9) => () => {
})

test('assetTotal', async () => {
await appClient.call({ method: 'assetTotal', methodArgs: [], sendParams: { populateAppCallResources: true } })
await appClient.call({ method: 'assetTotal', methodArgs: [] })
})
})

Expand All @@ -515,7 +520,7 @@ const tests = (version: 8 | 9) => () => {

test('hasAsset', async () => {
const { testAccount } = fixture.context
await appClient.call({ method: 'hasAsset', methodArgs: [testAccount.addr], sendParams: { populateAppCallResources: true } })
await appClient.call({ method: 'hasAsset', methodArgs: [testAccount.addr] })
})

test(`externalLocal: ${hasAssetErrorMsg}`, async () => {
Expand All @@ -533,7 +538,6 @@ const tests = (version: 8 | 9) => () => {
await appClient.call({
method: 'externalLocal',
methodArgs: [testAccount.addr],
sendParams: { populateAppCallResources: true },
sender: testAccount,
})
})
Expand Down Expand Up @@ -583,7 +587,7 @@ const tests = (version: 8 | 9) => () => {

txn.txn.group = undefined

await algokit.sendTransaction({ transaction: txn.txn, from: testAccount, sendParams: { populateAppCallResources: true } }, algod)
await algokit.sendTransaction({ transaction: txn.txn, from: testAccount }, algod)
})
})
}
Expand All @@ -601,6 +605,8 @@ describe.skip('Resource Packer: Mixed', () => {
beforeEach(fixture.beforeEach)

beforeAll(async () => {
algokit.Config.configure({ populateAppCallResources: true })

await fixture.beforeEach()
const { algod, testAccount } = fixture.context

Expand Down Expand Up @@ -628,6 +634,10 @@ describe.skip('Resource Packer: Mixed', () => {
await v8Client.create({ method: 'createApplication', methodArgs: [] })
})

afterAll(() => {
algokit.Config.configure({ populateAppCallResources: false })
})

test('same account', async () => {
const { algod, testAccount } = fixture.context
const acct = algosdk.generateAccount()
Expand Down
10 changes: 6 additions & 4 deletions src/transaction/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,11 @@ export const sendTransaction = async function (

let txnToSend = transaction

const populateResources = sendParams?.populateAppCallResources ?? Config.populateAppCallResources

// Populate resources if the transaction is an appcall and populateAppCallResources wasn't explicitly set to false
// NOTE: Temporary false by default until this algod bug is fixed: https://github.com/algorand/go-algorand/issues/5914
// if (txnToSend.type === algosdk.TransactionType.appl && sendParams?.populateAppCallResources !== false) {
if (txnToSend.type === algosdk.TransactionType.appl && sendParams?.populateAppCallResources === true) {
if (txnToSend.type === algosdk.TransactionType.appl && populateResources) {
const newAtc = new AtomicTransactionComposer()
newAtc.addTransaction({ txn: txnToSend, signer: getSenderTransactionSigner(from) })
const packed = await populateAppCallResources(newAtc, algod)
Expand Down Expand Up @@ -430,8 +431,9 @@ export const sendAtomicTransactionComposer = async function (atcSend: AtomicTran
try {
// If populateAppCallResources is true OR if populateAppCallResources is undefined and there are app calls, then populate resources
// NOTE: Temporary false by default until this algod bug is fixed: https://github.com/algorand/go-algorand/issues/5914
// if (sendParams?.populateAppCallResources || (sendParams?.populateAppCallResources === undefined && hasAppCalls())) {
if (sendParams?.populateAppCallResources) {
const populateResources = sendParams?.populateAppCallResources ?? Config.populateAppCallResources

if (populateResources) {
atc = await populateAppCallResources(givenAtc, algod)
}

Expand Down
Loading

0 comments on commit 2145566

Please sign in to comment.