Skip to content

Commit

Permalink
Refactor how group transactions are implemented in testing
Browse files Browse the repository at this point in the history
  • Loading branch information
tristanmenzel committed Sep 25, 2024
1 parent ab8b347 commit 24e2179
Show file tree
Hide file tree
Showing 7 changed files with 321 additions and 241 deletions.
15 changes: 7 additions & 8 deletions examples/hello-world-abi/contract.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import type { gtxn } from '@algorandfoundation/algo-ts'
import { TransactionType } from '@algorandfoundation/algo-ts'
import { TestExecutionContext } from '@algorandfoundation/algo-ts-testing'
import { afterEach, describe, expect, it } from 'vitest'
import { invariant } from '../../src/util'
import HelloWorldContract from './contract.algo'
import { TestExecutionContext } from '@algorandfoundation/algo-ts-testing'

describe('HelloWorldContract', () => {
const ctx = new TestExecutionContext()
Expand All @@ -11,19 +12,17 @@ describe('HelloWorldContract', () => {
it('logs the returned value when sayBananas is called', async () => {
const contract = ctx.contract.create(HelloWorldContract)
const result = contract.sayBananas()

const application = (ctx.txn.lastActive as gtxn.ApplicationTxn).appId
invariant(ctx.txn.lastActive.type === TransactionType.ApplicationCall, 'Last txn must be app')

expect(result).toBe('Bananas')
expect(ctx.exportLogs(application.id, 's')).toStrictEqual([result])
expect(ctx.exportLogs(ctx.txn.lastActive.appId.id, 's')).toStrictEqual([result])
})
it('logs the returned value when sayHello is called', async () => {
const contract = ctx.contract.create(HelloWorldContract)
const result = contract.sayHello('John', 'Doe')

const application = (ctx.txn.lastActive as gtxn.ApplicationTxn).appId
invariant(ctx.txn.lastActive.type === TransactionType.ApplicationCall, 'Last txn must be app')

expect(result).toBe('Hello John Doe')
expect(ctx.exportLogs(application.id, 's')).toStrictEqual([result])
expect(ctx.exportLogs(ctx.txn.lastActive.appId.id, 's')).toStrictEqual([result])
})
})
Loading

0 comments on commit 24e2179

Please sign in to comment.