@algorandfoundation/algorand-typescript-testing 1.0.0-alpha.5 → 1.0.0-alpha.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,2 @@
1
+ import { internal } from '@algorandfoundation/algorand-typescript';
2
+ export declare const AppLocal: internal.opTypes.AppLocalType;
@@ -1,13 +1,13 @@
1
- import { Account, Application, bytes, uint64 } from '@algorandfoundation/algorand-typescript';
1
+ import { Account, Application, bytes, LocalState, uint64 } from '@algorandfoundation/algorand-typescript';
2
2
  import { BytesMap } from '../collections/custom-key-map';
3
3
  import { Mutable } from '../typescript-helpers';
4
4
  import { Uint64BackedCls } from './base';
5
- import { GlobalStateCls, LocalStateMapCls } from './state';
5
+ import { GlobalStateCls } from './state';
6
6
  export declare class ApplicationData {
7
7
  application: Mutable<Omit<Application, 'id' | 'address'>> & {
8
8
  appLogs: bytes[];
9
9
  globalStates: BytesMap<GlobalStateCls<unknown>>;
10
- localStates: BytesMap<LocalStateMapCls<unknown>>;
10
+ localStates: BytesMap<LocalState<unknown>>;
11
11
  };
12
12
  isCreating: boolean;
13
13
  get appLogs(): bytes[];
package/impl/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export { AcctParams, balance, minBalance } from './acct-params';
2
2
  export { AppGlobal } from './app-global';
3
+ export { AppLocal } from './app-local';
3
4
  export { AppParams } from './app-params';
4
5
  export { AssetHolding } from './asset-holding';
5
6
  export { AssetParams } from './asset-params';
package/index.mjs CHANGED
@@ -226,6 +226,51 @@ const AppGlobal = {
226
226
  },
227
227
  };
228
228
 
229
+ const AppLocal = {
230
+ delete: function (a, b) {
231
+ const app = lazyContext.activeApplication;
232
+ const account = getAccount(a);
233
+ lazyContext.ledger.setLocalState(app, account, b, undefined);
234
+ },
235
+ getBytes: function (a, b) {
236
+ const account = getAccount(a);
237
+ return this.getExBytes(account, 0, asBytes(b))[0];
238
+ },
239
+ getUint64: function (a, b) {
240
+ const account = getAccount(a);
241
+ return this.getExUint64(account, 0, asBytes(b))[0];
242
+ },
243
+ getExBytes: function (a, b, c) {
244
+ const app = getApp(b);
245
+ const account = getAccount(a);
246
+ if (app === undefined || account === undefined) {
247
+ return [Bytes(), false];
248
+ }
249
+ const [state, exists] = lazyContext.ledger.getLocalState(app, account, c);
250
+ if (!exists) {
251
+ return [Bytes(), false];
252
+ }
253
+ return [state.value, exists];
254
+ },
255
+ getExUint64: function (a, b, c) {
256
+ const app = getApp(b);
257
+ const account = getAccount(a);
258
+ if (app === undefined || account === undefined) {
259
+ return [Uint64(0), false];
260
+ }
261
+ const [state, exists] = lazyContext.ledger.getLocalState(app, account, c);
262
+ if (!exists) {
263
+ return [Uint64(0), false];
264
+ }
265
+ return [state.value, exists];
266
+ },
267
+ put: function (a, b, c) {
268
+ const app = lazyContext.activeApplication;
269
+ const account = getAccount(a);
270
+ lazyContext.ledger.setLocalState(app, account, b, c);
271
+ },
272
+ };
273
+
229
274
  const resolveAssetIndex = (assetIdOrIndex) => {
230
275
  const input = asUint64(assetIdOrIndex);
231
276
  if (input >= 1001) {
@@ -2347,6 +2392,7 @@ var ops = /*#__PURE__*/Object.freeze({
2347
2392
  __proto__: null,
2348
2393
  AcctParams: AcctParams,
2349
2394
  AppGlobal: AppGlobal,
2395
+ AppLocal: AppLocal,
2350
2396
  AppParams: AppParams,
2351
2397
  AssetHolding: AssetHolding$1,
2352
2398
  AssetParams: AssetParams,
@@ -3213,13 +3259,12 @@ class LocalStateCls {
3213
3259
  }
3214
3260
  }
3215
3261
  class LocalStateMapCls {
3216
- #value = new Map();
3262
+ #value = new AccountMap();
3217
3263
  getValue(account) {
3218
- const accountString = asBytesCls(account.bytes).valueOf();
3219
- if (!this.#value.has(accountString)) {
3220
- this.#value.set(accountString, new LocalStateCls());
3264
+ if (!this.#value.has(account)) {
3265
+ this.#value.set(account, new LocalStateCls());
3221
3266
  }
3222
- return this.#value.get(accountString);
3267
+ return this.#value.getOrFail(account);
3223
3268
  }
3224
3269
  }
3225
3270
  function createGlobalState(options) {
@@ -3459,6 +3504,25 @@ class LedgerContext {
3459
3504
  globalState.value = asMaybeUint64Cls(value) ?? asMaybeBytesCls(value);
3460
3505
  }
3461
3506
  }
3507
+ getLocalState(app, account, key) {
3508
+ const appData = this.applicationDataMap.get(app.id);
3509
+ if (!appData?.application.localStates.has(key)) {
3510
+ return [undefined, false];
3511
+ }
3512
+ const localState = appData.application.localStates.getOrFail(key);
3513
+ return [localState(account), true];
3514
+ }
3515
+ setLocalState(app, account, key, value) {
3516
+ const appData = this.applicationDataMap.getOrFail(app.id);
3517
+ const localState = appData.application.localStates.getOrFail(key);
3518
+ const accountLocalState = localState(account);
3519
+ if (value === undefined) {
3520
+ accountLocalState.delete();
3521
+ }
3522
+ else {
3523
+ accountLocalState.value = asMaybeUint64Cls(value) ?? asMaybeBytesCls(value);
3524
+ }
3525
+ }
3462
3526
  }
3463
3527
 
3464
3528
  function decodeLogs(logs, decoding) {