Skip to content

Commit 86f82a2

Browse files
committed
spike: remove algorandClient getter from app client and app factory
1 parent 920e018 commit 86f82a2

File tree

6 files changed

+37
-32
lines changed

6 files changed

+37
-32
lines changed

src/transaction/transaction.spec.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ describe('transaction', () => {
315315
note: 'txn2',
316316
} satisfies Parameters<(typeof appClient1)['send']['call']>[0]
317317

318-
const result = await appClient1.algorand
318+
const result = await appClient1
319319
.newGroup()
320320
.addAppCallMethodCall(await appClient1.params.call(txn1Params))
321321
.addAppCallMethodCall(await appClient1.params.call(txn2Params))
@@ -406,7 +406,7 @@ describe('transaction', () => {
406406
const { testAccount } = localnet.context
407407
const expectedFee = 8000n
408408

409-
const result = await appClient1.algorand
409+
const result = await appClient1
410410
.newGroup()
411411
.addPayment({
412412
sender: testAccount.addr,
@@ -432,7 +432,7 @@ describe('transaction', () => {
432432

433433
test('alters fee, allocating surplus fees to the most fee constrained transaction first', async () => {
434434
const { testAccount } = localnet.context
435-
const result = await appClient1.algorand
435+
const result = await appClient1
436436
.newGroup()
437437
.addAppCallMethodCall(
438438
await appClient1.params.call({
@@ -520,7 +520,7 @@ describe('transaction', () => {
520520
test('throws when maxFee is below the calculated fee', async () => {
521521
await expect(
522522
async () =>
523-
await appClient1.algorand
523+
await appClient1
524524
.newGroup()
525525
.addAppCallMethodCall(
526526
await appClient1.params.call({
@@ -581,7 +581,7 @@ describe('transaction', () => {
581581
test('throws when staticFee is below the calculated fee', async () => {
582582
await expect(
583583
async () =>
584-
await appClient1.algorand
584+
await appClient1
585585
.newGroup()
586586
.addAppCallMethodCall(
587587
await appClient1.params.call({
@@ -607,7 +607,7 @@ describe('transaction', () => {
607607
const { testAccount } = localnet.context
608608
await expect(
609609
async () =>
610-
await appClient1.algorand
610+
await appClient1
611611
.newGroup()
612612
.addAppCallMethodCall(
613613
await appClient1.params.call({
@@ -787,12 +787,12 @@ const resourcePopulationTests = (version: 8 | 9) => () => {
787787
let alice: Address & Account
788788

789789
describe('accounts', () => {
790-
test('addressBalance: invalid Account reference', async () => {
790+
test('addressBalance: unavailable Account', async () => {
791791
const { testAccount } = fixture.context
792792
alice = testAccount
793793
await expect(
794794
appClient.send.call({ method: 'addressBalance', args: [testAccount.toString()], populateAppCallResources: false }),
795-
).rejects.toThrow('invalid Account reference')
795+
).rejects.toThrow('unavailable Account')
796796
})
797797

798798
test('addressBalance', async () => {
@@ -846,7 +846,7 @@ const resourcePopulationTests = (version: 8 | 9) => () => {
846846
})
847847

848848
describe('cross-product references', () => {
849-
const hasAssetErrorMsg = version === 8 ? 'invalid Account reference' : 'unavailable Account'
849+
const hasAssetErrorMsg = 'unavailable Account'
850850

851851
test(`hasAsset: ${hasAssetErrorMsg}`, async () => {
852852
const { testAccount } = fixture.context
@@ -885,14 +885,14 @@ const resourcePopulationTests = (version: 8 | 9) => () => {
885885
})
886886

887887
describe('sendTransaction', () => {
888-
test('addressBalance: invalid Account reference', async () => {
888+
test('addressBalance: unavailable Account', async () => {
889889
await expect(
890890
appClient.send.call({
891891
method: 'addressBalance',
892892
args: [algosdk.generateAccount().addr.toString()],
893893
populateAppCallResources: false,
894894
}),
895-
).rejects.toThrow('invalid Account reference')
895+
).rejects.toThrow('unavailable Account')
896896
})
897897

898898
test('addressBalance', async () => {

src/types/app-client.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -957,14 +957,14 @@ describe('app-client', () => {
957957
args: ['test'],
958958
}
959959

960-
const simulateResult = await appClient.algorand
960+
const simulateResult = await appClient
961961
.newGroup()
962962
.addAppCallMethodCall(appCall1Params)
963963
.addPayment(paymentParams)
964964
.addAppCallMethodCall(appCall2Params)
965965
.simulate({ skipSignatures: true })
966966

967-
const sendResult = await appClient.algorand
967+
const sendResult = await appClient
968968
.newGroup()
969969
.addAppCallMethodCall(appCall1Params)
970970
.addPayment(paymentParams)

src/types/app-client.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,14 @@ import {
4646
ABIStruct,
4747
Arc56Contract,
4848
Arc56Method,
49+
ProgramSourceInfo,
50+
StorageKey,
51+
StorageMap,
4952
getABIDecodedValue,
5053
getABIEncodedValue,
5154
getABITupleFromABIStruct,
5255
getArc56Method,
5356
getArc56ReturnValue,
54-
ProgramSourceInfo,
55-
StorageKey,
56-
StorageMap,
5757
} from './app-arc56'
5858
import { AppLookup } from './app-deployer'
5959
import { AppManager, BoxIdentifier } from './app-manager'
@@ -69,6 +69,7 @@ import {
6969
AppUpdateParams,
7070
CommonAppCallParams,
7171
PaymentParams,
72+
TransactionComposer,
7273
} from './composer'
7374
import { Expand } from './expand'
7475
import { EventType } from './lifecycle-events'
@@ -343,6 +344,7 @@ export interface AppClientParams {
343344
approvalSourceMap?: SourceMap
344345
/** Optional source map for the clear state program */
345346
clearSourceMap?: SourceMap
347+
newGroup: () => TransactionComposer
346348
}
347349

348350
/** Parameters to clone an app client */
@@ -502,6 +504,7 @@ export class AppClient {
502504
}
503505
private _lastCompiled: { clear?: Uint8Array; approval?: Uint8Array }
504506

507+
private _newGroup: () => TransactionComposer
505508
/**
506509
* Create a new app client.
507510
* @param params The parameters to create the app client
@@ -557,6 +560,7 @@ export class AppClient {
557560
/** Send bare (raw) transactions to the current app */
558561
bare: this.getBareSendMethods(),
559562
}
563+
this._newGroup = params.newGroup
560564
}
561565

562566
/**
@@ -579,6 +583,7 @@ export class AppClient {
579583
defaultSigner: this._defaultSigner,
580584
approvalSourceMap: this._approvalSourceMap,
581585
clearSourceMap: this._clearSourceMap,
586+
newGroup: this._newGroup,
582587
...params,
583588
})
584589
}
@@ -680,11 +685,6 @@ export class AppClient {
680685
return this._appSpec
681686
}
682687

683-
/** A reference to the underlying `AlgorandClient` this app client is using. */
684-
public get algorand(): AlgorandClient {
685-
return this._algorand
686-
}
687-
688688
/** Get parameters to create transactions for the current app.
689689
*
690690
* A good mental model for this is that these parameters represent a deferred transaction creation.
@@ -714,6 +714,10 @@ export class AppClient {
714714
return this._sendMethods
715715
}
716716

717+
public get newGroup() {
718+
return this._newGroup
719+
}
720+
717721
/** Get state (local, global, box) from the current app */
718722
public get state() {
719723
return {

src/types/app-factory-and-client.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ import { afterEach, beforeAll, beforeEach, describe, expect, it, test } from 'vi
44
import * as algokit from '..'
55
import arc56Json from '../../tests/example-contracts/arc56_templates/artifacts/Templates.arc56_draft.json'
66
import byteArraysAr56Json from '../../tests/example-contracts/byte_arrays/artifacts/ByteArrays.arc56.json'
7+
import deployErrorAppArc56Json from '../../tests/example-contracts/deploy_error/artifacts/DeployError.arc56.json'
78
import largeAppArc56Json from '../../tests/example-contracts/extra-pages/large.arc56.json'
89
import smallAppArc56Json from '../../tests/example-contracts/extra-pages/small.arc56.json'
910
import errorInnerAppArc56Json from '../../tests/example-contracts/inner_error/artifacts/InnerApp.arc56.json'
1011
import errorMiddleAppArc56Json from '../../tests/example-contracts/inner_error/artifacts/MiddleApp.arc56.json'
1112
import errorOuterAppArc56Json from '../../tests/example-contracts/inner_error/artifacts/OuterApp.arc56.json'
12-
import deployErrorAppArc56Json from '../../tests/example-contracts/deploy_error/artifacts/DeployError.arc56.json'
1313
import nestedStruct from '../../tests/example-contracts/nested_struct/artifacts/NestedStruct.arc56.json'
1414
import { getTestingAppContract } from '../../tests/example-contracts/testing-app/contract'
1515
import { algoKitLogCaptureFixture, algorandFixture } from '../testing'
@@ -832,7 +832,7 @@ describe('ARC56: app-factory-and-app-client', () => {
832832

833833
try {
834834
// Don't use the app client to call, but since we've instantiated one the error transformer should be registered
835-
await appClient.algorand
835+
await appClient
836836
.newGroup()
837837
.addAppCallMethodCall({ appId: appClient.appId, method: appClient.getABIMethod('throwError')!, sender: testAccount })
838838
.send()

src/types/app-factory.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -217,11 +217,6 @@ export class AppFactory {
217217
return this._appSpec
218218
}
219219

220-
/** Return the algorand client this factory is using. */
221-
get algorand() {
222-
return this._algorand
223-
}
224-
225220
/** Get parameters to create transactions (create and deploy related calls) for the current app.
226221
*
227222
* A good mental model for this is that these parameters represent a deferred transaction creation.
@@ -293,6 +288,7 @@ export class AppFactory {
293288
return {
294289
appClient: this.getAppClientById({
295290
appId: result.appId,
291+
newGroup: () => this._algorand.newGroup(),
296292
}),
297293
result: {
298294
...result,
@@ -324,6 +320,7 @@ export class AppFactory {
324320
return {
325321
appClient: this.getAppClientById({
326322
appId: result.appId,
323+
newGroup: () => this._algorand.newGroup(),
327324
}),
328325
result: {
329326
...result,
@@ -376,7 +373,10 @@ export class AppFactory {
376373

377374
// Compile using a appID 0 AppClient so we can register the error handler and use the programs
378375
// to identify the app within the error handler (because we can't use app ID 0)
379-
const tempAppClient = this.getAppClientById({ appId: 0n })
376+
const tempAppClient = this.getAppClientById({
377+
appId: 0n,
378+
newGroup: this._algorand.newGroup,
379+
})
380380
const compiled = await tempAppClient.compile({ deployTimeParams, updatable, deletable })
381381

382382
const deployResult = await this._algorand.appDeployer.deploy({
@@ -402,6 +402,7 @@ export class AppFactory {
402402
const appClient = this.getAppClientById({
403403
appId: deployResult.appId,
404404
appName: params.appName,
405+
newGroup: () => this._algorand.newGroup(),
405406
})
406407
const result = {
407408
...deployResult,

src/types/client-manager.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export type ClientAppFactoryParams = Expand<Omit<AppFactoryParams, 'algorand'>>
2727
export type ClientResolveAppClientByCreatorAndNameParams = Expand<Omit<ResolveAppClientByCreatorAndName, 'algorand'>>
2828

2929
/** Params to get an app client by ID from `ClientManager`. */
30-
export type ClientAppClientParams = Expand<Omit<AppClientParams, 'algorand'>>
30+
export type ClientAppClientParams = Expand<Omit<AppClientParams, 'algorand' | 'newGroup'>>
3131

3232
/** Params to get an app client by network from `ClientManager`. */
3333
export type ClientAppClientByNetworkParams = Expand<Omit<AppClientParams, 'algorand' | 'appId'>>
@@ -308,7 +308,7 @@ export class ClientManager {
308308
if (!this._algorand) {
309309
throw new Error('Attempt to get app client from a ClientManager without an Algorand client')
310310
}
311-
return new AppClient({ ...params, algorand: this._algorand })
311+
return new AppClient({ ...params, algorand: this._algorand, newGroup: () => this._algorand!.newGroup() })
312312
}
313313

314314
/**
@@ -413,7 +413,7 @@ export class ClientManager {
413413
throw new Error('Attempt to get app client from a ClientManager without an Algorand client')
414414
}
415415

416-
return typedClient.fromNetwork({ ...params, algorand: this._algorand })
416+
return typedClient.fromNetwork({ ...params, algorand: this._algorand, newGroup: () => this._algorand!.newGroup() })
417417
}
418418

419419
/**

0 commit comments

Comments
 (0)