Skip to content

Commit

Permalink
Merge main into release
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] authored Aug 9, 2024
2 parents 5c04490 + 138ae68 commit f306ade
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 3 deletions.
4 changes: 2 additions & 2 deletions docs/code/modules/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2466,7 +2466,7 @@ The information about the compiled code

#### Defined in

[src/app-deploy.ts:616](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/app-deploy.ts#L616)
[src/app-deploy.ts:625](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/app-deploy.ts#L625)

___

Expand Down Expand Up @@ -2823,7 +2823,7 @@ The TEAL without comments

#### Defined in

[src/app-deploy.ts:639](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/app-deploy.ts#L639)
[src/app-deploy.ts:648](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/app-deploy.ts#L648)

___

Expand Down
21 changes: 21 additions & 0 deletions src/app-deploy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,27 @@ test('Can substitute template variable with multiple underscores', async () => {
`)
})

test('Can substitue both bytes and int uint64', async () => {
const test_teal = `
int TMPL_SOME_VALUE
pushint TMPL_SOME_VALUE
bytes TMPL_SOME_VALUE
pushbytes TMPL_SOME_VALUE
return
`
const test_params = {
SOME_VALUE: 123,
}
const substituted = algokit.performTemplateSubstitution(test_teal, test_params)
expect(substituted).toBe(`
int 123
pushint 123
bytes 0x000000000000007b
pushbytes 0x000000000000007b
return
`)
})

function getMetadata(overrides?: Partial<AppDeployMetadata>): AppDeployMetadata {
return {
name: 'test',
Expand Down
9 changes: 9 additions & 0 deletions src/app-deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,15 @@ export function performTemplateSubstitution(tealCode: string, templateParams?: T
for (const key in templateParams) {
const value = templateParams[key]
const token = `TMPL_${key.replace(/^TMPL_/, '')}`

// If this is a number, first replace any byte representations of the number
// These may appear in the TEAL in order to circumvent int compression and preserve PC values
if (typeof value === 'number' || typeof value === 'boolean') {
tealCode = tealCode.replace(new RegExp(`(?<=bytes )${token}`, 'g'), `0x${value.toString(16).padStart(16, '0')}`)

// We could probably return here since mixing pushint and pushbytes is likely not going to happen, but might as well do both
}

tealCode = tealCode.replace(
new RegExp(token, 'g'),
typeof value === 'string'
Expand Down
2 changes: 1 addition & 1 deletion src/types/account-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ export class AccountManager {
return {
assetId: BigInt(assetId),
balance: BigInt(info['asset-holding']['amount']),
frozen: info['asset-holding']['is-frozen'] === 'true',
frozen: info['asset-holding']['is-frozen'] === true,
round: BigInt(info['round']),
}
}
Expand Down

0 comments on commit f306ade

Please sign in to comment.