Skip to content

Commit ab53bd3

Browse files
committed
feat: update langspec to v4.3.0
1 parent 9495cc9 commit ab53bd3

File tree

10 files changed

+155
-15
lines changed

10 files changed

+155
-15
lines changed

package-lock.json

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@
6868
"vitest": "3.2.4"
6969
},
7070
"dependencies": {
71-
"@algorandfoundation/algorand-typescript": "1.0.0-alpha.83",
72-
"@algorandfoundation/puya-ts": "1.0.0-alpha.83",
71+
"@algorandfoundation/algorand-typescript": "1.0.0-alpha.84",
72+
"@algorandfoundation/puya-ts": "1.0.0-alpha.84",
7373
"elliptic": "^6.6.1",
7474
"js-sha256": "^0.11.0",
7575
"js-sha3": "^0.9.3",

src/impl/app-params.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,8 @@ export const AppParams: typeof op.AppParams = {
7171
const app = getApp(a)
7272
return app === undefined ? [Account(), false] : [app.address, true]
7373
},
74+
appVersion: function (a: ApplicationType | uint64): readonly [uint64, boolean] {
75+
const app = getApp(a)
76+
return app === undefined ? [Uint64(0), false] : [app.version, true]
77+
},
7478
}

src/impl/gtxn.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ export const GTxn: typeof op.GTxn = {
197197
lastLog(t: StubUint64Compat): bytes {
198198
return lazyContext.activeGroup.getApplicationCallTransaction(asUint64(t)).lastLog
199199
},
200-
stateProofPk(t: StubUint64Compat): bytes {
200+
stateProofPk(t: StubUint64Compat): bytes<64> {
201201
return lazyContext.activeGroup.getKeyRegistrationTransaction(asUint64(t)).stateProofKey
202202
},
203203
approvalProgramPages(a: StubUint64Compat, b: StubUint64Compat): bytes {
@@ -212,6 +212,9 @@ export const GTxn: typeof op.GTxn = {
212212
numClearStateProgramPages(t: StubUint64Compat): uint64 {
213213
return lazyContext.activeGroup.getApplicationCallTransaction(asUint64(t)).numClearStateProgramPages
214214
},
215+
rejectVersion: function (a: uint64): uint64 {
216+
return lazyContext.activeGroup.getApplicationCallTransaction(asUint64(a)).rejectVersion
217+
},
215218
}
216219

217220
/** @internal */

src/impl/itxn.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ export const GITxn: typeof op.GITxn = {
243243
lastLog: function (t: StubUint64Compat): bytes {
244244
return getApplicationCallInnerTxn(t).lastLog
245245
},
246-
stateProofPk: function (t: StubUint64Compat): bytes {
246+
stateProofPk: function (t: StubUint64Compat): bytes<64> {
247247
return getKeyRegistrationInnerTxn(t).stateProofKey
248248
},
249249
approvalProgramPages: function (t: StubUint64Compat, a: StubUint64Compat): bytes {
@@ -258,6 +258,9 @@ export const GITxn: typeof op.GITxn = {
258258
numClearStateProgramPages: function (t: StubUint64Compat): uint64 {
259259
return getApplicationCallInnerTxn(t).numClearStateProgramPages
260260
},
261+
rejectVersion: function (t: StubUint64Compat): uint64 {
262+
return getApplicationCallInnerTxn(t).rejectVersion
263+
},
261264
}
262265
/** @internal */
263266
export const ITxn: typeof op.ITxn = {
@@ -643,7 +646,7 @@ export const ITxn: typeof op.ITxn = {
643646
/**
644647
* 64 byte state proof public key
645648
*/
646-
get stateProofPk(): bytes {
649+
get stateProofPk(): bytes<64> {
647650
return lazyContext.activeGroup.getItxnGroup().getKeyRegistrationInnerTxn().stateProofKey
648651
},
649652
/**
@@ -670,6 +673,9 @@ export const ITxn: typeof op.ITxn = {
670673
get numClearStateProgramPages(): uint64 {
671674
return lazyContext.activeGroup.getItxnGroup().getApplicationCallInnerTxn().numClearStateProgramPages
672675
},
676+
get rejectVersion(): uint64 {
677+
return lazyContext.activeGroup.getItxnGroup().getApplicationCallInnerTxn().rejectVersion
678+
},
673679
}
674680

675681
const setConstructingItxnField = (fields: Partial<InnerTxnFields>): void => {
@@ -862,6 +868,9 @@ export const ITxnCreate: typeof op.ITxnCreate = {
862868
pages.push(asBytes(a))
863869
setConstructingItxnField({ clearStateProgram: pages })
864870
},
871+
setRejectVersion: function (a: StubUint64Compat): void {
872+
setConstructingItxnField({ rejectVersion: asUint64(a) })
873+
},
865874
next: function (): void {
866875
lazyContext.activeGroup.appendInnerTransactionGroup()
867876
},

src/impl/reference.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ export class ApplicationData {
168168
localStateMaps: new BytesMap(),
169169
boxes: new BytesMap(),
170170
materialisedBoxes: new BytesMap(),
171+
version: 0,
171172
}
172173
}
173174
}
@@ -221,6 +222,9 @@ export class ApplicationCls extends Uint64BackedCls implements ApplicationType {
221222
}
222223
return result
223224
}
225+
get version(): uint64 {
226+
return this.data.application.version
227+
}
224228
}
225229

226230
export type AssetData = Mutable<Omit<AssetType, 'id' | 'balance' | 'frozen'>>

src/impl/transactions.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ export class ApplicationCallTransaction extends TransactionBase implements gtxn.
253253
#clearStateProgramPages: Array<bytes>
254254
#appLogs: Array<bytes>
255255
#appId: ApplicationType
256+
#rejectVersion: uint64
256257

257258
/** @internal */
258259
protected constructor(fields: ApplicationCallTransactionFields) {
@@ -272,6 +273,7 @@ export class ApplicationCallTransaction extends TransactionBase implements gtxn.
272273
this.#apps = fields.apps ?? []
273274
this.#approvalProgramPages = fields.approvalProgramPages ?? (fields.approvalProgram ? [fields.approvalProgram] : [])
274275
this.#clearStateProgramPages = fields.clearStateProgramPages ?? (fields.clearStateProgram ? [fields.clearStateProgram] : [])
276+
this.#rejectVersion = fields.rejectVersion ?? Uint64(0)
275277
Object.entries(fields.scratchSpace ?? {}).forEach(([k, v]) => this.setScratchSlot(Number(k), v))
276278
}
277279

@@ -335,6 +337,9 @@ export class ApplicationCallTransaction extends TransactionBase implements gtxn.
335337
get apfa() {
336338
return this.#apps
337339
}
340+
get rejectVersion() {
341+
return this.#rejectVersion
342+
}
338343
appArgs(index: Uint64Compat): bytes {
339344
return toBytes(this.args[asNumber(index)])
340345
}

src/impl/txn.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ export const Txn: typeof op.Txn = {
462462
/**
463463
* 64 byte state proof public key
464464
*/
465-
get stateProofPk(): bytes {
465+
get stateProofPk(): bytes<64> {
466466
return lazyContext.activeGroup.getKeyRegistrationTransaction().stateProofKey
467467
},
468468

@@ -493,4 +493,7 @@ export const Txn: typeof op.Txn = {
493493
get numClearStateProgramPages(): uint64 {
494494
return lazyContext.activeGroup.getApplicationCallTransaction().numClearStateProgramPages
495495
},
496+
get rejectVersion(): uint64 {
497+
return lazyContext.activeGroup.getApplicationCallTransaction().rejectVersion
498+
},
496499
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import {
2+
abimethod,
3+
arc4,
4+
assert,
5+
Bytes,
6+
contract,
7+
Contract,
8+
itxn,
9+
OnCompleteAction,
10+
op,
11+
Txn,
12+
} from '@algorandfoundation/algorand-typescript'
13+
14+
@contract({ avmVersion: 12 })
15+
export class Avm12Contract extends Contract {
16+
testFalconVerify() {
17+
assert(!op.falconVerify(Bytes(), Bytes(), op.bzero(1793).toFixed({ length: 1793 })))
18+
}
19+
20+
testRejectVersion() {
21+
const compiledV0 = arc4.compileArc4(ContractV0)
22+
const v0Txn = compiledV0.bareCreate()
23+
const app = v0Txn.createdApp
24+
assert(app.version === 0, 'should be version 0')
25+
26+
const compiledV1 = arc4.compileArc4(ContractV1)
27+
28+
const v1Txn = compiledV0.call.update({
29+
rejectVersion: 1,
30+
appId: app,
31+
onCompletion: OnCompleteAction.UpdateApplication,
32+
approvalProgram: compiledV1.approvalProgram,
33+
clearStateProgram: compiledV1.clearStateProgram,
34+
extraProgramPages: compiledV1.extraProgramPages,
35+
})
36+
assert(v1Txn.itxn.appId.version === 1, 'should be version 1')
37+
38+
itxn
39+
.applicationCall({
40+
appArgs: [arc4.methodSelector(ContractV1.prototype.delete)],
41+
onCompletion: OnCompleteAction.DeleteApplication,
42+
appId: app,
43+
rejectVersion: 2,
44+
})
45+
.submit()
46+
}
47+
}
48+
49+
@contract({ avmVersion: 12 })
50+
export class ContractV0 extends Contract {
51+
@abimethod({ allowActions: 'UpdateApplication' })
52+
update() {
53+
assert(Txn.rejectVersion === 1, 'can only update if caller expects this to be currently be v0')
54+
}
55+
}
56+
57+
@contract({ avmVersion: 12 })
58+
export class ContractV1 extends Contract {
59+
@abimethod({ allowActions: 'DeleteApplication' })
60+
delete() {
61+
assert(Txn.rejectVersion === 2, 'can only update if caller expects this to be currently be v1')
62+
}
63+
}

tests/avm12.algo.spec.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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

Comments
 (0)