Skip to content

Commit

Permalink
Merge pull request #26 from algorandfoundation/fix/support-asset-type
Browse files Browse the repository at this point in the history
fix: support abi methods with parameters of type asset
  • Loading branch information
tristanmenzel authored Jun 13, 2023
2 parents 7bc052f + b6cb005 commit 795da41
Show file tree
Hide file tree
Showing 6 changed files with 131 additions and 7 deletions.
27 changes: 22 additions & 5 deletions examples/helloworld/client.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ import { algorandFixture } from '@algorandfoundation/algokit-utils/testing'
import { beforeEach, describe, expect, test } from '@jest/globals'
import { HelloWorldAppClient } from './client'
import { AtomicTransactionComposer } from 'algosdk'
import { microAlgos } from '@algorandfoundation/algokit-utils'

describe('hello world typed client', () => {
const localnet = algorandFixture()
const localnet = algorandFixture({
testAccountFunding: microAlgos(1_000_000),
})
beforeEach(localnet.beforeEach, 10_000)

test('Calls hello', async () => {
Expand Down Expand Up @@ -45,13 +48,27 @@ describe('hello world typed client', () => {

const atc = new AtomicTransactionComposer()
await client.helloWorldCheck({ name: 'World' }, { sendParams: { atc, skipSending: true } })
const [trans] = atc.buildGroup()
const [transactionWithSigner] = atc.buildGroup()

const { transaction: rawTransaction } = await client.hello({ name: 'Bananas' }, { sendParams: { skipSending: true } })

// Add a transaction in the middle of the method calls and check that it doesn't mess up the return values
const result = await client.compose().hello(['World']).addTransaction(trans).hello({ name: 'World!' }).execute()
// Add a transactions in the middle of the method calls and check that it doesn't mess up the return values
const result = await client
.compose()
.hello(['World'])
.addTransaction(transactionWithSigner)
.addTransaction(rawTransaction)
.addTransaction(
client.appClient.fundAppAccount({
amount: microAlgos(100_000),
sendParams: { skipSending: true },
}),
)
.hello({ name: 'World!' })
.execute()

expect(result.returns[0]).toBe('Hello, World')
expect(result.returns[1]).toBe('Hello, World!')
expect(result.txIds.length).toBe(3)
expect(result.txIds.length).toBe(5)
})
})
19 changes: 18 additions & 1 deletion examples/state/application.json

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions examples/state/client.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,23 @@ describe('state typed client', () => {

expect(localState.local_bytes1?.asString()).toBe('default value')
})

test('ABI methods which take assets can be called', async () => {
const { algod, indexer, testAccount } = localnet.context
const client = new StateAppClient(
{
resolveBy: 'creatorAndName',
sender: testAccount,
creatorAddress: testAccount.addr,
findExistingUsing: indexer,
},
algod,
)
await client.deploy({ deployTimeParams: { VALUE: 1 } })

// Call with number
await client.callWithAsset({ asset: 1234 })
// Call with bigint
await client.callWithAsset({ asset: 1234n })
})
})
65 changes: 64 additions & 1 deletion examples/state/client.ts

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions examples/state/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ def call_abi_txn(txn: pt.abi.PaymentTransaction, value: pt.abi.String, *, output
)
)

@app.external()
def call_with_asset(asset: pt.abi.Asset, *, output: pt.abi.Uint64) -> pt.Expr:
return pt.Seq(
pt.Assert(asset.asset_id(), comment="asset not provided"),
output.set(asset.asset_id()),
)

@app.external()
def set_global(
Expand Down
2 changes: 2 additions & 0 deletions src/client/helpers/get-equivalent-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export function getEquivalentType(abiTypeStr: string, ioType: 'input' | 'output'
switch (abiTypeStr) {
case 'void':
return 'void'
case 'asset':
return 'number | bigint'
case 'txn':
case 'pay':
case 'keyreg':
Expand Down

0 comments on commit 795da41

Please sign in to comment.