Skip to content

Commit

Permalink
Merge pull request #36 from algorandfoundation/fix-reference-types
Browse files Browse the repository at this point in the history
fix: use correct types for account reference arguments
  • Loading branch information
robdmoore authored Jun 23, 2023
2 parents c350439 + 49e1189 commit 7dc1947
Show file tree
Hide file tree
Showing 9 changed files with 958 additions and 947 deletions.
1 change: 1 addition & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ jobs:
with:
run-commit-lint: true
run-build: true
audit-script: npm run audit
pre-test-script: |
pipx install algokit
algokit localnet start
7 changes: 7 additions & 0 deletions .nsprc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"GHSA-c2qf-rxjj-qqgw": {
"active": true,
"notes": "Ignored while dependencies are patching",
"expiry": "2023-06-30"
}
}
14 changes: 11 additions & 3 deletions examples/state/application.json

Large diffs are not rendered by default.

10 changes: 6 additions & 4 deletions examples/state/client.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ describe('state typed client', () => {
expect(localState.local_bytes1?.asString()).toBe('default value')
})

test('ABI methods which take assets can be called', async () => {
test('ABI methods which take references can be called', async () => {
const { algod, indexer, testAccount } = localnet.context
const client = new StateAppClient(
{
Expand All @@ -154,8 +154,10 @@ describe('state typed client', () => {
await client.deploy({ deployTimeParams: { VALUE: 1 } })

// Call with number
await client.callWithAsset({ asset: 1234 })
// Call with bigint
await client.callWithAsset({ asset: 1234n })
await client.callWithReferences({
asset: 1234,
account: testAccount.addr,
application: (await client.appClient.getAppReference()).appId,
})
})
})
42 changes: 26 additions & 16 deletions examples/state/client.ts

Large diffs are not rendered by default.

12 changes: 10 additions & 2 deletions examples/state/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,18 @@ 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:
def call_with_references(
asset: pt.abi.Asset,
account: pt.abi.Account,
application: pt.abi.Application,
*,
output: pt.abi.Uint64
) -> pt.Expr:
return pt.Seq(
pt.Assert(asset.asset_id(), comment="asset not provided"),
output.set(asset.asset_id()),
pt.Assert(pt.Len(account.address()), comment="account not provided"),
pt.Assert(application.application_id(), comment="application not provided"),
output.set(pt.Int(1)),
)

@app.external()
Expand Down
1,810 changes: 890 additions & 920 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"main": "src/index.js",
"private": false,
"scripts": {
"audit": "better-npm-audit audit",
"dev": "run-s dev:*",
"dev:helloworld": "ts-node --transpile-only src/index.ts generate -a ./examples/helloworld/application.json -o ./examples/helloworld/client.generated.ts",
"dev:lifecycle": "ts-node --transpile-only src/index.ts generate -a ./examples/lifecycle/application.json -o ./examples/lifecycle/client.generated.ts",
Expand Down Expand Up @@ -50,6 +51,7 @@
"@noble/ed25519": "1.7.3",
"@types/jest": "^29.5.2",
"algosdk": "^2.3.0",
"better-npm-audit": "^3.7.3",
"conventional-changelog-conventionalcommits": "^5.0.0",
"copyfiles": "^2.4.1",
"eslint": "8.42.0",
Expand Down
7 changes: 5 additions & 2 deletions src/client/helpers/get-equivalent-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import {
ABIArrayStaticType,
ABIBoolType,
ABIByteType,
ABIReferenceType,
ABIStringType,
ABITupleType,
ABIType,
ABIUfixedType,
ABIUintType,
abiTypeIsReference,
abiTypeIsTransaction,
} from 'algosdk'

Expand All @@ -20,7 +20,10 @@ export function getEquivalentType(abiTypeStr: string, ioType: 'input' | 'output'
if (abiTypeIsTransaction(abiTypeStr)) {
return 'TransactionToSign | Transaction | Promise<SendTransactionResult>'
}
if (abiTypeIsReference(abiTypeStr)) {
if (abiTypeStr == ABIReferenceType.account) {
return 'string | Uint8Array'
}
if (abiTypeStr == ABIReferenceType.application || abiTypeStr == ABIReferenceType.asset) {
return 'number | bigint'
}

Expand Down

0 comments on commit 7dc1947

Please sign in to comment.