Skip to content

Commit

Permalink
Merge pull request #97 from algorandfoundation/app-create-transaction
Browse files Browse the repository at this point in the history
bug: fix the transform logic for app call transaction
  • Loading branch information
PatrickDinh authored Sep 4, 2024
2 parents 73a701c + 10aa268 commit 3765fb1
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 5 deletions.
8 changes: 4 additions & 4 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 src/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ export function getIndexerTransactionFromAlgodTransaction(
...(transaction.type === TransactionType.appl
? {
'application-transaction': {
'application-id': transaction.appIndex,
'application-id': transaction.appIndex ?? 0,
'approval-program':
transaction.appApprovalProgram && transaction.appApprovalProgram.length > 0
? Buffer.from(transaction.appApprovalProgram).toString('base64')
Expand Down
62 changes: 62 additions & 0 deletions tests/scenarios/app-call-transactions.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { algorandFixture } from '@algorandfoundation/algokit-utils/testing'
import { Account } from 'algosdk'
import { afterEach, beforeEach, describe, expect, test, vitest } from 'vitest'
import { TestingAppClient } from '../contract/client'
import { GetSubscribedTransactions, SendXTransactions } from '../transactions'

describe('App call transactions', () => {
const localnet = algorandFixture()
beforeEach(localnet.beforeEach, 10e6)
afterEach(() => {
vitest.clearAllMocks()
})

describe('Can have an app create transaction subscribed correctly from algod', () => {
const app = async (config: { create: boolean }, creator: Account) => {
const app = new TestingAppClient(
{
resolveBy: 'id',
id: 0,
},
localnet.context.algod,
)
const creation = await app.create.bare({
sender: creator,
sendParams: {
skipSending: !config.create,
},
})

return {
app,
creation,
}
}

test('Works for app create', async () => {
const { testAccount } = localnet.context
const app1 = await app({ create: true }, testAccount)

// Ensure there is another transaction so algod subscription can process something
await SendXTransactions(1, testAccount, localnet.context.algod)
// Wait for indexer to catch up
await localnet.context.waitForIndexer()

const [algod] = await Promise.all([
GetSubscribedTransactions(
{
roundsToSync: 1,
syncBehaviour: 'sync-oldest',
watermark: Number(app1.creation.confirmation?.confirmedRound) - 1,
currentRound: Number(app1.creation.confirmation?.confirmedRound),
filters: { appCreate: true },
},
localnet.context.algod,
),
])

expect(algod.subscribedTransactions.length).toBe(1)
expect(algod.subscribedTransactions[0]['application-transaction']?.['application-id']).toBe(0)
})
})
})

0 comments on commit 3765fb1

Please sign in to comment.