Skip to content

Commit 7582d6e

Browse files
committed
fix: tweak resource population code to handle supplied access references
1 parent f97ac64 commit 7582d6e

File tree

3 files changed

+139
-135
lines changed

3 files changed

+139
-135
lines changed

docs/code/modules/index.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ the estimated rate.
575575

576576
#### Defined in
577577

578-
[src/transaction/transaction.ts:1056](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction/transaction.ts#L1056)
578+
[src/transaction/transaction.ts:1078](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction/transaction.ts#L1078)
579579

580580
___
581581

@@ -639,7 +639,7 @@ Allows for control of fees on a `Transaction` or `SuggestedParams` object
639639

640640
#### Defined in
641641

642-
[src/transaction/transaction.ts:1083](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction/transaction.ts#L1083)
642+
[src/transaction/transaction.ts:1105](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction/transaction.ts#L1105)
643643

644644
___
645645

@@ -967,7 +967,7 @@ Converts `bigint`'s for Uint's < 64 to `number` for easier use.
967967

968968
#### Defined in
969969

970-
[src/transaction/transaction.ts:922](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction/transaction.ts#L922)
970+
[src/transaction/transaction.ts:944](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction/transaction.ts#L944)
971971

972972
___
973973

@@ -1943,7 +1943,7 @@ Returns the array of transactions currently present in the given `AtomicTransact
19431943

19441944
#### Defined in
19451945

1946-
[src/transaction/transaction.ts:1132](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction/transaction.ts#L1132)
1946+
[src/transaction/transaction.ts:1154](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction/transaction.ts#L1154)
19471947

19481948
___
19491949

@@ -2330,7 +2330,7 @@ Returns suggested transaction parameters from algod unless some are already prov
23302330

23312331
#### Defined in
23322332

2333-
[src/transaction/transaction.ts:1110](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction/transaction.ts#L1110)
2333+
[src/transaction/transaction.ts:1132](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction/transaction.ts#L1132)
23342334

23352335
___
23362336

@@ -2941,7 +2941,7 @@ An object with transaction IDs, transactions, group transaction ID (`groupTransa
29412941

29422942
#### Defined in
29432943

2944-
[src/transaction/transaction.ts:782](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction/transaction.ts#L782)
2944+
[src/transaction/transaction.ts:804](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction/transaction.ts#L804)
29452945

29462946
___
29472947

@@ -2970,7 +2970,7 @@ Signs and sends a group of [up to 16](https://dev.algorand.co/concepts/transacti
29702970

29712971
#### Defined in
29722972

2973-
[src/transaction/transaction.ts:955](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction/transaction.ts#L955)
2973+
[src/transaction/transaction.ts:977](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction/transaction.ts#L977)
29742974

29752975
___
29762976

@@ -3243,4 +3243,4 @@ Throws an error if the transaction is not confirmed or rejected in the next `tim
32433243

32443244
#### Defined in
32453245

3246-
[src/transaction/transaction.ts:999](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction/transaction.ts#L999)
3246+
[src/transaction/transaction.ts:1021](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction/transaction.ts#L1021)

src/transaction/transaction.spec.ts

Lines changed: 87 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -939,55 +939,101 @@ describe('Resource population: Mixed', () => {
939939
const v9Result = await v9AppFactory.send.create({ method: 'createApplication' })
940940
v8Client = v8Result.appClient
941941
v9Client = v9Result.appClient
942+
943+
await v8Client.fundAppAccount({ amount: (328500).microAlgo() })
944+
await v8Client.send.call({ method: 'bootstrap', staticFee: (3_000).microAlgo() })
945+
946+
await v9Client.fundAppAccount({ amount: (2334300).microAlgo() })
947+
await v9Client.send.call({ method: 'bootstrap', staticFee: (3_000).microAlgo() })
942948
})
943949

944950
afterAll(() => {
945951
Config.configure({ populateAppCallResources: false })
946952
})
947953

948-
test('same account', async () => {
949-
const { algorand, testAccount } = fixture.context
950-
const acct = algosdk.generateAccount()
954+
describe('mixed', () => {
955+
test('same account', async () => {
956+
const { algorand, testAccount } = fixture.context
957+
const acct = algosdk.generateAccount()
951958

952-
const rekeyedTo = algorand.account.random()
953-
await algorand.account.rekeyAccount(testAccount, rekeyedTo)
959+
const rekeyedTo = algorand.account.random()
960+
await algorand.account.rekeyAccount(testAccount, rekeyedTo)
954961

955-
const { transactions } = await algorand.send
956-
.newGroup()
957-
.addAppCallMethodCall(await v8Client.params.call({ method: 'addressBalance', args: [acct.addr.toString()], sender: testAccount }))
958-
.addAppCallMethodCall(await v9Client.params.call({ method: 'addressBalance', args: [acct.addr.toString()], sender: testAccount }))
959-
.send({ populateAppCallResources: true })
962+
const { transactions } = await algorand.send
963+
.newGroup()
964+
.addAppCallMethodCall(await v8Client.params.call({ method: 'addressBalance', args: [acct.addr.toString()], sender: testAccount }))
965+
.addAppCallMethodCall(await v9Client.params.call({ method: 'addressBalance', args: [acct.addr.toString()], sender: testAccount }))
966+
.send({ populateAppCallResources: true })
960967

961-
const v8CallAccts = transactions[0].applicationCall?.accounts ?? []
962-
const v9CallAccts = transactions[1].applicationCall?.accounts ?? []
968+
const v8CallAccts = transactions[0].applicationCall?.accounts ?? []
969+
const v9CallAccts = transactions[1].applicationCall?.accounts ?? []
963970

964-
expect(v8CallAccts.length + v9CallAccts.length).toBe(1)
965-
})
971+
expect(v8CallAccts.length + v9CallAccts.length).toBe(1)
972+
})
966973

967-
test('app account', async () => {
968-
const { algorand, testAccount } = fixture.context
974+
test('app account', async () => {
975+
const { algorand, testAccount } = fixture.context
976+
const externalAppID = (await v8Client.getGlobalState()).externalAppID!.value as bigint
969977

970-
await v8Client.fundAppAccount({ amount: (328500).microAlgo() })
971-
await v8Client.send.call({ method: 'bootstrap', staticFee: (3_000).microAlgo() })
978+
const { transactions } = await algorand.send
979+
.newGroup()
980+
.addAppCallMethodCall(
981+
await v8Client.params.call({ method: 'externalAppCall', staticFee: (2_000).microAlgo(), sender: testAccount }),
982+
)
983+
.addAppCallMethodCall(
984+
await v9Client.params.call({
985+
method: 'addressBalance',
986+
args: [algosdk.getApplicationAddress(externalAppID).toString()],
987+
sender: testAccount,
988+
}),
989+
)
990+
.send({ populateAppCallResources: true })
972991

973-
const externalAppID = (await v8Client.getGlobalState()).externalAppID!.value as bigint
992+
const v8CallApps = transactions[0].applicationCall?.foreignApps ?? []
993+
const v9CallAccts = transactions[1].applicationCall?.accounts ?? []
974994

975-
const { transactions } = await algorand.send
976-
.newGroup()
977-
.addAppCallMethodCall(await v8Client.params.call({ method: 'externalAppCall', staticFee: (2_000).microAlgo(), sender: testAccount }))
978-
.addAppCallMethodCall(
979-
await v9Client.params.call({
980-
method: 'addressBalance',
981-
args: [algosdk.getApplicationAddress(externalAppID).toString()],
982-
sender: testAccount,
983-
}),
984-
)
985-
.send({ populateAppCallResources: true })
995+
expect(v8CallApps!.length + v9CallAccts!.length).toBe(1)
996+
})
997+
})
986998

987-
const v8CallApps = transactions[0].applicationCall?.foreignApps ?? []
988-
const v9CallAccts = transactions[1].applicationCall?.accounts ?? []
999+
describe('accessReferences', () => {
1000+
test('fails to populate a transaction with access references', async () => {
1001+
const { testAccount } = fixture.context
1002+
const assetId = (await v9Client.getGlobalState()).asa.value as bigint
9891003

990-
expect(v8CallApps!.length + v9CallAccts!.length).toBe(1)
1004+
await expect(
1005+
async () =>
1006+
await v9Client.send.call({
1007+
method: 'hasAsset',
1008+
accessReferences: [{ assetId: assetId }],
1009+
args: [testAccount.toString()],
1010+
}),
1011+
).rejects.toThrow('No more transactions below reference limit. Add another app call to the group.')
1012+
})
1013+
1014+
test('successfully populates a transaction group including a transaction with access references', async () => {
1015+
const assetId = (await v9Client.getGlobalState()).asa.value as bigint
1016+
const { testAccount } = fixture.context
1017+
1018+
await v9Client.algorand
1019+
.newGroup()
1020+
.addAppCallMethodCall(
1021+
await v9Client.params.call({
1022+
method: 'hasAsset',
1023+
accessReferences: [{ assetId: assetId }],
1024+
args: [testAccount.toString()],
1025+
note: '1',
1026+
}),
1027+
)
1028+
.addAppCallMethodCall(
1029+
await v9Client.params.call({
1030+
method: 'hasAsset',
1031+
args: [testAccount.toString()],
1032+
note: '2',
1033+
}),
1034+
)
1035+
.send()
1036+
})
9911037
})
9921038
})
9931039

@@ -1189,22 +1235,7 @@ describe('access references', () => {
11891235
let externalClient: AppClient
11901236

11911237
let alice: algosdk.Address
1192-
let bob: algosdk.Address
1193-
let charlie: algosdk.Address
1194-
let dan: algosdk.Address
1195-
let eve: algosdk.Address
1196-
let frank: algosdk.Address
1197-
let grace: algosdk.Address
1198-
let heidi: algosdk.Address
1199-
let ivan: algosdk.Address
1200-
let judy: algosdk.Address
1201-
let mallory: algosdk.Address
1202-
let niaj: algosdk.Address
1203-
let oscar: algosdk.Address
1204-
let peggy: algosdk.Address
1205-
let quentin: algosdk.Address
1206-
let ruth: algosdk.Address
1207-
let dave: algosdk.Address
1238+
let getTestAccounts: (count: number) => Promise<algosdk.Address[]>
12081239

12091240
beforeEach(fixture.newScope)
12101241

@@ -1231,22 +1262,9 @@ describe('access references', () => {
12311262
})
12321263

12331264
alice = await fixture.context.generateAccount({ initialFunds: AlgoAmount.Algo(0.1) })
1234-
bob = await fixture.context.generateAccount({ initialFunds: AlgoAmount.Algo(0.1) })
1235-
charlie = await fixture.context.generateAccount({ initialFunds: AlgoAmount.Algo(0.1) })
1236-
dan = await fixture.context.generateAccount({ initialFunds: AlgoAmount.Algo(0.1) })
1237-
eve = await fixture.context.generateAccount({ initialFunds: AlgoAmount.Algo(0.1) })
1238-
frank = await fixture.context.generateAccount({ initialFunds: AlgoAmount.Algo(0.1) })
1239-
grace = await fixture.context.generateAccount({ initialFunds: AlgoAmount.Algo(0.1) })
1240-
heidi = await fixture.context.generateAccount({ initialFunds: AlgoAmount.Algo(0.1) })
1241-
ivan = await fixture.context.generateAccount({ initialFunds: AlgoAmount.Algo(0.1) })
1242-
judy = await fixture.context.generateAccount({ initialFunds: AlgoAmount.Algo(0.1) })
1243-
mallory = await fixture.context.generateAccount({ initialFunds: AlgoAmount.Algo(0.1) })
1244-
niaj = await fixture.context.generateAccount({ initialFunds: AlgoAmount.Algo(0.1) })
1245-
oscar = await fixture.context.generateAccount({ initialFunds: AlgoAmount.Algo(0.1) })
1246-
peggy = await fixture.context.generateAccount({ initialFunds: AlgoAmount.Algo(0.1) })
1247-
quentin = await fixture.context.generateAccount({ initialFunds: AlgoAmount.Algo(0.1) })
1248-
ruth = await fixture.context.generateAccount({ initialFunds: AlgoAmount.Algo(0.1) })
1249-
dave = await fixture.context.generateAccount({ initialFunds: AlgoAmount.Algo(1) })
1265+
getTestAccounts = async (count: number) => {
1266+
return await Promise.all(Array.from({ length: count }, () => fixture.context.generateAccount({ initialFunds: AlgoAmount.Algo(0.1) })))
1267+
}
12501268
}, 20_000) // Account generation and funding can be slow
12511269

12521270
test('address reference enables access', async () => {
@@ -1263,7 +1281,7 @@ describe('access references', () => {
12631281
method: 'addressBalance',
12641282
args: [alice],
12651283
populateAppCallResources: false,
1266-
accountReferences: [alice, bob, charlie, dan, eve, frank, grace, heidi],
1284+
accountReferences: [alice, ...(await getTestAccounts(7))],
12671285
})
12681286
})
12691287

@@ -1273,7 +1291,7 @@ describe('access references', () => {
12731291
method: 'addressBalance',
12741292
args: [alice],
12751293
populateAppCallResources: false,
1276-
accountReferences: [alice, bob, charlie, dan, eve, frank, grace, heidi, ivan],
1294+
accountReferences: [alice, ...(await getTestAccounts(8))],
12771295
}),
12781296
).rejects.toThrow(/max number of accounts is 8/)
12791297
})
@@ -1283,24 +1301,7 @@ describe('access references', () => {
12831301
method: 'addressBalance',
12841302
args: [alice],
12851303
populateAppCallResources: false,
1286-
accessReferences: [
1287-
{ address: alice },
1288-
{ address: bob },
1289-
{ address: charlie },
1290-
{ address: dan },
1291-
{ address: eve },
1292-
{ address: frank },
1293-
{ address: grace },
1294-
{ address: heidi },
1295-
{ address: ivan },
1296-
{ address: judy },
1297-
{ address: mallory },
1298-
{ address: niaj },
1299-
{ address: oscar },
1300-
{ address: peggy },
1301-
{ address: quentin },
1302-
{ address: ruth },
1303-
],
1304+
accessReferences: [{ address: alice }, ...(await getTestAccounts(15)).map((a) => ({ address: a }))],
13041305
})
13051306
})
13061307

@@ -1310,25 +1311,7 @@ describe('access references', () => {
13101311
method: 'addressBalance',
13111312
args: [alice],
13121313
populateAppCallResources: false,
1313-
accessReferences: [
1314-
{ address: alice },
1315-
{ address: bob },
1316-
{ address: charlie },
1317-
{ address: dan },
1318-
{ address: eve },
1319-
{ address: frank },
1320-
{ address: grace },
1321-
{ address: heidi },
1322-
{ address: ivan },
1323-
{ address: judy },
1324-
{ address: mallory },
1325-
{ address: niaj },
1326-
{ address: oscar },
1327-
{ address: peggy },
1328-
{ address: quentin },
1329-
{ address: ruth },
1330-
{ address: dave },
1331-
],
1314+
accessReferences: [{ address: alice }, ...(await getTestAccounts(16)).map((a) => ({ address: a }))],
13321315
}),
13331316
).rejects.toThrow(/max number of references is 16/)
13341317
})
@@ -1376,7 +1359,6 @@ describe('access references', () => {
13761359
test('locals reference enables access', async () => {
13771360
const alice = await fixture.context.generateAccount({ initialFunds: AlgoAmount.Algo(1) })
13781361

1379-
// Opt alice into the external app
13801362
await fixture.algorand.send.appCallMethodCall(await externalClient.params.optIn({ method: 'optInToApplication', sender: alice }))
13811363

13821364
await appClient.send.call({

0 commit comments

Comments
 (0)