Skip to content

Commit 7d8f820

Browse files
authored
Merge pull request #91 from algorandfoundation/feat/feedback-features
feat: add stub implementations for additional 1.0 features
2 parents 59e7963 + 4edce80 commit 7d8f820

35 files changed

+306
-110
lines changed

README.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,19 @@ After the setup, the examples provided using `vitest` can be converted to work w
169169
#### Contract Definition
170170

171171
```typescript
172-
import { arc4, assert, Bytes, GlobalState, gtxn, LocalState, op, Txn, uint64, Uint64 } from '@algorandfoundation/algorand-typescript'
172+
import {
173+
arc4,
174+
assert,
175+
Bytes,
176+
GlobalState,
177+
gtxn,
178+
LocalState,
179+
op,
180+
readonly,
181+
Txn,
182+
uint64,
183+
Uint64,
184+
} from '@algorandfoundation/algorand-typescript'
173185

174186
export default class VotingContract extends arc4.Contract {
175187
topic = GlobalState({ initialValue: 'default_topic', key: Bytes('topic') })
@@ -195,7 +207,7 @@ export default class VotingContract extends arc4.Contract {
195207
return true
196208
}
197209

198-
@arc4.abimethod({ readonly: true })
210+
@readonly
199211
public getVotes(): uint64 {
200212
return this.votes.value
201213
}
@@ -262,7 +274,7 @@ This example demonstrates key aspects of testing with `algorand-typescript-testi
262274

263275
- Use of `arc4.Contract` as the base class for the contract.
264276
- ABI methods defined using the `@arc4.abimethod` decorator.
265-
- Readonly method annotation with `@arc4.abimethod({readonly: true})`.
277+
- Readonly method annotation with `@arc4.abimethod({readonly: true})` or `@readonly`.
266278

267279
2. Testing ARC4 Contracts:
268280

docs/coverage.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ See which `algorand-typescript` stubs are implemented by the `algorand-typescrip
3434
| Txn | Emulated |
3535
| Uint64 | Native |
3636
| abiCall | Mockable |
37-
| arc4EncodedLength | Native |
37+
| sizeOf | Native |
3838
| compile | Mockable |
3939
| compileArc4 | Mockable |
4040
| decodeArc4 | Native |
@@ -72,6 +72,7 @@ See which `algorand-typescript` stubs are implemented by the `algorand-typescrip
7272
| arc4.abimethod | Emulated |
7373
| arc4.methodSelector | Native |
7474
| arc4.baremethod | Emulated |
75+
| arc4.readonly | Emulated |
7576
| gtxn.ApplicationCallTxn | Emulated |
7677
| gtxn.AssetConfigTxn | Emulated |
7778
| gtxn.AssetFreezeTxn | Emulated |

docs/readme.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,19 @@ After the setup, the examples provided using `vitest` can be converted to work w
167167
#### Contract Definition
168168

169169
```typescript
170-
import { arc4, assert, Bytes, GlobalState, gtxn, LocalState, op, Txn, uint64, Uint64 } from '@algorandfoundation/algorand-typescript'
170+
import {
171+
arc4,
172+
assert,
173+
Bytes,
174+
GlobalState,
175+
gtxn,
176+
LocalState,
177+
op,
178+
readonly,
179+
Txn,
180+
uint64,
181+
Uint64,
182+
} from '@algorandfoundation/algorand-typescript'
171183

172184
export default class VotingContract extends arc4.Contract {
173185
topic = GlobalState({ initialValue: 'default_topic', key: Bytes('topic') })
@@ -193,7 +205,7 @@ export default class VotingContract extends arc4.Contract {
193205
return true
194206
}
195207

196-
@arc4.abimethod({ readonly: true })
208+
@readonly
197209
public getVotes(): uint64 {
198210
return this.votes.value
199211
}
@@ -260,7 +272,7 @@ This example demonstrates key aspects of testing with `algorand-typescript-testi
260272

261273
- Use of `arc4.Contract` as the base class for the contract.
262274
- ABI methods defined using the `@arc4.abimethod` decorator.
263-
- Readonly method annotation with `@arc4.abimethod({readonly: true})`.
275+
- Readonly method annotation with `@arc4.abimethod({readonly: true})` or `@readonly`.
264276

265277
2. Testing ARC4 Contracts:
266278

docs/tg-application-spy.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ spy.onAbiCall(methodSelector('greet(string)string'), (itxnContext) => {
170170
**3. Strongly typed ABI calls**
171171

172172
```ts
173-
const result = abiCall(Hello.prototype.greet, {
173+
const result = abiCall<typeof Hello.prototype.greet>({
174174
appId: app,
175175
args: ['abi'],
176176
}).returnValue

docs/tg-contract-testing.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class SimpleVotingContract extends arc4.Contract {
4747
return this.votes.value
4848
}
4949

50-
@arc4.abimethod({ readonly: true })
50+
@readonly
5151
getVotes(): uint64 {
5252
return this.votes.value
5353
}

docs/tg-transactions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ export class Hello extends Contract {
376376

377377
export class HelloFactoryTyped extends Contract {
378378
test_compile_contract(app: Application) {
379-
const result2 = abiCall(Hello.prototype.greet, {
379+
const result2 = abiCall<typeof Hello.prototype.greet>({
380380
appId: app,
381381
args: ['abi'],
382382
}).returnValue

examples/arc4-simple-voting/contract.algo.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { gtxn, uint64 } from '@algorandfoundation/algorand-typescript'
2-
import { arc4, assert, Bytes, GlobalState, LocalState, op, Txn, Uint64 } from '@algorandfoundation/algorand-typescript'
2+
import { arc4, assert, Bytes, GlobalState, LocalState, op, readonly, Txn, Uint64 } from '@algorandfoundation/algorand-typescript'
33

44
export default class VotingContract extends arc4.Contract {
55
topic = GlobalState({ initialValue: Bytes('default_topic'), key: Bytes('topic') })
@@ -25,7 +25,7 @@ export default class VotingContract extends arc4.Contract {
2525
return new arc4.Bool(true)
2626
}
2727

28-
@arc4.abimethod({ readonly: true })
28+
@readonly
2929
public getVotes(): arc4.Uint64 {
3030
return new arc4.Uint64(this.votes.value)
3131
}

examples/local-storage/contract.algo.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { Account, bytes, uint64 } from '@algorandfoundation/algorand-typescript'
2-
import { Bytes, Global, LocalState, Txn, arc4, assert, contract } from '@algorandfoundation/algorand-typescript'
2+
import { Bytes, Global, LocalState, Txn, arc4, assert, contract, readonly } from '@algorandfoundation/algorand-typescript'
33

44
/**
55
* A contract demonstrating local storage functionality.
@@ -55,7 +55,7 @@ export default class LocalStorage extends arc4.Contract {
5555
* - [4] boolean: The value of localBool
5656
* - [5] Address: The value of localAccount converted to Address type
5757
*/
58-
@arc4.abimethod({ readonly: true })
58+
@readonly
5959
public readLocalState(): [uint64, uint64, bytes, string, boolean, arc4.Address] {
6060
const sender = Txn.sender
6161
// Convert Account reference type to native Address type for return value

examples/marketplace/contract.algo.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { Asset, gtxn, uint64 } from '@algorandfoundation/algorand-typescript'
2-
import { arc4, assert, BoxMap, clone, Global, itxn, op, Txn } from '@algorandfoundation/algorand-typescript'
2+
import { arc4, assert, BoxMap, clone, Global, itxn, op, readonly, Txn } from '@algorandfoundation/algorand-typescript'
33

44
export class ListingKey extends arc4.Struct<{
55
owner: arc4.Address
@@ -52,7 +52,7 @@ export default class DigitalMarketplace extends arc4.Contract {
5252
return amountToBePaid
5353
}
5454

55-
@arc4.abimethod({ readonly: true })
55+
@readonly
5656
getListingsMbr(): uint64 {
5757
return this.listingsBoxMbr()
5858
}

examples/precompiled/precompiled-typed.algo.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { assert, Contract, Global, itxn, Txn } from '@algorandfoundation/algoran
22
import { abiCall, compileArc4, methodSelector } from '@algorandfoundation/algorand-typescript/arc4'
33
import {
44
Hello,
5-
HelloStubbed,
5+
type HelloStubbed,
66
HelloTemplate,
77
HelloTemplateCustomPrefix,
88
LargeProgram,
@@ -24,14 +24,15 @@ export class HelloFactoryTyped extends Contract {
2424
}).returnValue
2525
assert(result === 'hello world')
2626

27-
const result2 = abiCall(Hello.prototype.greet, {
27+
const result2 = abiCall({
28+
method: Hello.prototype.greet,
2829
appId: app,
2930
args: ['abi'],
3031
}).returnValue
3132

3233
assert(result2 === 'hello abi')
3334

34-
const result3 = abiCall(HelloStubbed.prototype.greet, {
35+
const result3 = abiCall<typeof HelloStubbed.prototype.greet>({
3536
appId: app,
3637
args: ['stubbed'],
3738
}).returnValue

0 commit comments

Comments
 (0)