|
| 1 | +import { algos } from '@algorandfoundation/algokit-utils' |
| 2 | +import { ApplicationSpy, TestExecutionContext } from '@algorandfoundation/algorand-typescript-testing' |
| 3 | +import { afterEach, beforeAll, describe, expect } from 'vitest' |
| 4 | +import { Avm12Contract, ContractV0, ContractV1 } from './artifacts/avm12/contract.algo' |
| 5 | +import { createArc4TestFixture } from './test-fixture' |
| 6 | + |
| 7 | +describe('avm12', () => { |
| 8 | + const [test, localnetFixture] = createArc4TestFixture('tests/artifacts/avm12/contract.algo.ts', { |
| 9 | + Avm12Contract: { funding: algos(1) }, |
| 10 | + }) |
| 11 | + |
| 12 | + const ctx = new TestExecutionContext() |
| 13 | + beforeAll(async () => { |
| 14 | + await localnetFixture.newScope() |
| 15 | + }) |
| 16 | + afterEach(() => { |
| 17 | + ctx.reset() |
| 18 | + }) |
| 19 | + |
| 20 | + test('reject wrong app version', async ({ appClientAvm12Contract }) => { |
| 21 | + await appClientAvm12Contract.send.call({ method: 'testRejectVersion', args: [], extraFee: algos(1) }) |
| 22 | + const itxnComposeAlgoContract = ctx.contract.create(Avm12Contract) |
| 23 | + |
| 24 | + const contractV0App = ctx.any.application({ |
| 25 | + approvalProgram: ctx.any.bytes(), |
| 26 | + }) |
| 27 | + ctx.setCompiledApp(ContractV0, contractV0App.id) |
| 28 | + |
| 29 | + const spyV0 = new ApplicationSpy(ContractV0) |
| 30 | + spyV0.onBareCall((itxnContext) => { |
| 31 | + if (itxnContext.approvalProgram === contractV0App.approvalProgram) { |
| 32 | + itxnContext.createdApp = contractV0App |
| 33 | + } |
| 34 | + }) |
| 35 | + spyV0.on.update((itxnContext) => { |
| 36 | + if (itxnContext.appId === contractV0App) { |
| 37 | + ctx.ledger.patchApplicationData(itxnContext.appId, { application: { version: 1 } }) |
| 38 | + } |
| 39 | + }) |
| 40 | + |
| 41 | + const spyV1 = new ApplicationSpy(ContractV1) |
| 42 | + spyV1.on.delete((itxnContext) => { |
| 43 | + expect(itxnContext.rejectVersion).toEqual(2) |
| 44 | + }) |
| 45 | + ctx.addApplicationSpy(spyV0) |
| 46 | + ctx.addApplicationSpy(spyV1) |
| 47 | + itxnComposeAlgoContract.testRejectVersion() |
| 48 | + }) |
| 49 | +}) |
0 commit comments