Skip to content

Commit 5e23672

Browse files
committed
chore: pr feedback
1 parent d12b5f5 commit 5e23672

File tree

2 files changed

+96
-28
lines changed

2 files changed

+96
-28
lines changed

docs/capabilities/app.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,7 @@ When interacting with apps (creating, updating, deleting, calling), there are so
382382
- `appReferences?: bigint[]` - The ID of any apps to load to the [foreign apps array](https://dev.algorand.co/concepts/smart-contracts/resource-usage#what-are-reference-arrays).
383383
- `assetReferences?: bigint[]` - The ID of any assets to load to the [foreign assets array](https://dev.algorand.co/concepts/smart-contracts/resource-usage#what-are-reference-arrays).
384384
- `boxReferences?: (BoxReference | BoxIdentifier)[]` - Any [boxes](#box-references) to load to the [boxes array](https://dev.algorand.co/concepts/smart-contracts/resource-usage#what-are-reference-arrays)
385+
- `accessReference?: AccessReference[]` - Unifies `accountReferences`, `appReferences`, `assetReferences`, and `boxReferences` under a single list. If non-empty, these other reference lists must be empty. If access is empty, those other reference lists may be non-empty.
385386

386387
When making an ABI call, the `args` parameter is replaced with a different type and there is also a `method` parameter per the [`AppMethodCall`](../code/modules/types_composer.md#appmethodcall) type:
387388

@@ -428,6 +429,15 @@ export interface BoxReference {
428429
}
429430
```
430431

432+
## Access References
433+
434+
Access references provide a unified way to specify all types of resource references (accounts, apps, assets, boxes, asset holdings, and app locals) that need to be accessible during smart contract execution. They are an alternative to using the separate `accountReferences`, `appReferences`, `assetReferences`, and `boxReferences` parameters.
435+
436+
In using this unified field, you are able to use a total of 16 individual references, however cross references which enable smart contract access to local state and account asset balance information must be explicitly defined using `locals` and `holdings` fields respectively.
437+
When using the seperate reference arrays, you are constraints to a collective total of 8.
438+
439+
The separate reference arrays (`accountReferences`, `appReferences`, etc.) remain fully supported, however when using `accessReferences`, you cannot also use `accountReferences`, `appReferences`, `assetReferences` or `boxReferences`.
440+
431441
## Compilation
432442

433443
The [`AppManager`](#appmanager) class allows you to compile TEAL code with caching semantics that allows you to avoid duplicate compilation and keep track of source maps from compiled code.

src/transaction/transaction.spec.ts

Lines changed: 86 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1189,6 +1189,24 @@ describe('access references', () => {
11891189
let appClient: AppClient
11901190
let externalClient: AppClient
11911191

1192+
let alice: algosdk.Address
1193+
let bob: algosdk.Address
1194+
let charlie: algosdk.Address
1195+
let dan: algosdk.Address
1196+
let eve: algosdk.Address
1197+
let frank: algosdk.Address
1198+
let grace: algosdk.Address
1199+
let heidi: algosdk.Address
1200+
let ivan: algosdk.Address
1201+
let judy: algosdk.Address
1202+
let mallory: algosdk.Address
1203+
let niaj: algosdk.Address
1204+
let oscar: algosdk.Address
1205+
let peggy: algosdk.Address
1206+
let quentin: algosdk.Address
1207+
let ruth: algosdk.Address
1208+
let dave: algosdk.Address
1209+
11921210
beforeEach(fixture.newScope)
11931211

11941212
beforeAll(async () => {
@@ -1212,7 +1230,25 @@ describe('access references', () => {
12121230
appId: (await appClient.getGlobalState()).externalAppID.value as bigint,
12131231
defaultSender: testAccount,
12141232
})
1215-
})
1233+
1234+
alice = await fixture.context.generateAccount({ initialFunds: AlgoAmount.Algo(0.1) })
1235+
bob = await fixture.context.generateAccount({ initialFunds: AlgoAmount.Algo(0.1) })
1236+
charlie = await fixture.context.generateAccount({ initialFunds: AlgoAmount.Algo(0.1) })
1237+
dan = await fixture.context.generateAccount({ initialFunds: AlgoAmount.Algo(0.1) })
1238+
eve = await fixture.context.generateAccount({ initialFunds: AlgoAmount.Algo(0.1) })
1239+
frank = await fixture.context.generateAccount({ initialFunds: AlgoAmount.Algo(0.1) })
1240+
grace = await fixture.context.generateAccount({ initialFunds: AlgoAmount.Algo(0.1) })
1241+
heidi = await fixture.context.generateAccount({ initialFunds: AlgoAmount.Algo(0.1) })
1242+
ivan = await fixture.context.generateAccount({ initialFunds: AlgoAmount.Algo(0.1) })
1243+
judy = await fixture.context.generateAccount({ initialFunds: AlgoAmount.Algo(0.1) })
1244+
mallory = await fixture.context.generateAccount({ initialFunds: AlgoAmount.Algo(0.1) })
1245+
niaj = await fixture.context.generateAccount({ initialFunds: AlgoAmount.Algo(0.1) })
1246+
oscar = await fixture.context.generateAccount({ initialFunds: AlgoAmount.Algo(0.1) })
1247+
peggy = await fixture.context.generateAccount({ initialFunds: AlgoAmount.Algo(0.1) })
1248+
quentin = await fixture.context.generateAccount({ initialFunds: AlgoAmount.Algo(0.1) })
1249+
ruth = await fixture.context.generateAccount({ initialFunds: AlgoAmount.Algo(0.1) })
1250+
dave = await fixture.context.generateAccount({ initialFunds: AlgoAmount.Algo(1) })
1251+
}, 20_000) // Account generation and funding can be slow
12161252

12171253
test('address reference enables access', async () => {
12181254
const alice = await fixture.context.generateAccount({ initialFunds: AlgoAmount.Algo(0.1) })
@@ -1225,16 +1261,7 @@ describe('access references', () => {
12251261
await appClient.send.bare.call({ args: [method, aliceAddr], populateAppCallResources: false, accessReferences: [{ address: alice }] })
12261262
})
12271263

1228-
test('only 8 non access reference accounts can be supplied', async () => {
1229-
const alice = await fixture.context.generateAccount({ initialFunds: AlgoAmount.Algo(0.1) })
1230-
const bob = await fixture.context.generateAccount({ initialFunds: AlgoAmount.Algo(0.1) })
1231-
const charlie = await fixture.context.generateAccount({ initialFunds: AlgoAmount.Algo(0.1) })
1232-
const dan = await fixture.context.generateAccount({ initialFunds: AlgoAmount.Algo(0.1) })
1233-
const eve = await fixture.context.generateAccount({ initialFunds: AlgoAmount.Algo(0.1) })
1234-
const frank = await fixture.context.generateAccount({ initialFunds: AlgoAmount.Algo(0.1) })
1235-
const grace = await fixture.context.generateAccount({ initialFunds: AlgoAmount.Algo(0.1) })
1236-
const heidi = await fixture.context.generateAccount({ initialFunds: AlgoAmount.Algo(0.1) })
1237-
1264+
test('up to 8 non access reference accounts can be used', async () => {
12381265
const method = appClient.getABIMethod('addressBalance').getSelector()
12391266

12401267
const addressType = new ABIAddressType()
@@ -1247,24 +1274,22 @@ describe('access references', () => {
12471274
})
12481275
})
12491276

1250-
test('only 16 access addresses can be supplied', async () => {
1251-
const alice = await fixture.context.generateAccount({ initialFunds: AlgoAmount.Algo(0.1) })
1252-
const bob = await fixture.context.generateAccount({ initialFunds: AlgoAmount.Algo(0.1) })
1253-
const charlie = await fixture.context.generateAccount({ initialFunds: AlgoAmount.Algo(0.1) })
1254-
const dan = await fixture.context.generateAccount({ initialFunds: AlgoAmount.Algo(0.1) })
1255-
const eve = await fixture.context.generateAccount({ initialFunds: AlgoAmount.Algo(0.1) })
1256-
const frank = await fixture.context.generateAccount({ initialFunds: AlgoAmount.Algo(0.1) })
1257-
const grace = await fixture.context.generateAccount({ initialFunds: AlgoAmount.Algo(0.1) })
1258-
const heidi = await fixture.context.generateAccount({ initialFunds: AlgoAmount.Algo(0.1) })
1259-
const ivan = await fixture.context.generateAccount({ initialFunds: AlgoAmount.Algo(0.1) })
1260-
const judy = await fixture.context.generateAccount({ initialFunds: AlgoAmount.Algo(0.1) })
1261-
const mallory = await fixture.context.generateAccount({ initialFunds: AlgoAmount.Algo(0.1) })
1262-
const niaj = await fixture.context.generateAccount({ initialFunds: AlgoAmount.Algo(0.1) })
1263-
const oscar = await fixture.context.generateAccount({ initialFunds: AlgoAmount.Algo(0.1) })
1264-
const peggy = await fixture.context.generateAccount({ initialFunds: AlgoAmount.Algo(0.1) })
1265-
const quentin = await fixture.context.generateAccount({ initialFunds: AlgoAmount.Algo(0.1) })
1266-
const ruth = await fixture.context.generateAccount({ initialFunds: AlgoAmount.Algo(0.1) })
1277+
test('throws when more than 8 non access reference accounts are supplied', async () => {
1278+
const method = appClient.getABIMethod('addressBalance').getSelector()
1279+
1280+
const addressType = new ABIAddressType()
1281+
const aliceAddr = addressType.encode(alice)
12671282

1283+
await expect(
1284+
appClient.send.bare.call({
1285+
args: [method, aliceAddr],
1286+
populateAppCallResources: false,
1287+
accountReferences: [alice, bob, charlie, dan, eve, frank, grace, heidi, ivan],
1288+
}),
1289+
).rejects.toThrow(/max number of accounts is 8/)
1290+
})
1291+
1292+
test('up to 16 access addresses can be used', async () => {
12681293
const method = appClient.getABIMethod('addressBalance').getSelector()
12691294

12701295
const addressType = new ABIAddressType()
@@ -1294,6 +1319,39 @@ describe('access references', () => {
12941319
})
12951320
})
12961321

1322+
test('throws when more than 16 access addresses are supplied', async () => {
1323+
const method = appClient.getABIMethod('addressBalance').getSelector()
1324+
1325+
const addressType = new ABIAddressType()
1326+
const aliceAddr = addressType.encode(alice)
1327+
1328+
await expect(
1329+
appClient.send.bare.call({
1330+
args: [method, aliceAddr],
1331+
populateAppCallResources: false,
1332+
accessReferences: [
1333+
{ address: alice },
1334+
{ address: bob },
1335+
{ address: charlie },
1336+
{ address: dan },
1337+
{ address: eve },
1338+
{ address: frank },
1339+
{ address: grace },
1340+
{ address: heidi },
1341+
{ address: ivan },
1342+
{ address: judy },
1343+
{ address: mallory },
1344+
{ address: niaj },
1345+
{ address: oscar },
1346+
{ address: peggy },
1347+
{ address: quentin },
1348+
{ address: ruth },
1349+
{ address: dave },
1350+
],
1351+
}),
1352+
).rejects.toThrow(/max number of references is 16/)
1353+
})
1354+
12971355
test('app reference enables access', async () => {
12981356
const method = appClient.getABIMethod('externalAppCall').getSelector()
12991357

0 commit comments

Comments
 (0)