Skip to content

Commit a8e4d74

Browse files
committed
refactor: further tweaks to make things work with jest
1 parent aa386d4 commit a8e4d74

File tree

12 files changed

+120
-123
lines changed

12 files changed

+120
-123
lines changed

.tstoolkitrc.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ const config: TsToolkitConfig = {
1010
exports: {
1111
'.': 'index.ts',
1212
'./runtime-helpers': 'runtime-helpers.ts',
13-
'./internal': 'internal.ts',
14-
'./internal/arc4': 'internal-arc4.ts',
15-
'./internal/op': 'internal-op.ts',
13+
'./internal': 'internal/index.ts',
14+
'./internal/arc4': 'internal/arc4.ts',
15+
'./internal/op': 'internal/op.ts',
1616
'./vitest-transformer': 'test-transformer/vitest-transformer.ts',
1717
'./jest-transformer': 'test-transformer/jest-transformer.ts',
1818
},

examples/marketplace/contract.spec.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { arc4, Bytes } from '@algorandfoundation/algorand-typescript'
22
import { TestExecutionContext } from '@algorandfoundation/algorand-typescript-testing'
33
import { interpretAsArc4 } from '@algorandfoundation/algorand-typescript/arc4'
4-
import { afterEach } from 'node:test'
5-
import { describe, expect, test } from 'vitest'
4+
import { afterEach, describe, expect, test } from 'vitest'
65
import DigitalMarketplace, { ListingKey, ListingValue } from './contract.algo'
76

87
const TEST_DECIMALS = 6

examples/zk-whitelist/contract.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { arc4, Bytes } from '@algorandfoundation/algorand-typescript'
22
import { TestExecutionContext } from '@algorandfoundation/algorand-typescript-testing'
33
import { afterEach, describe, expect, it } from 'vitest'
4-
import { ABI_RETURN_VALUE_LOG_PREFIX } from '../../src/constants'
54
import ZkWhitelistContract from './contract.algo'
65

6+
const ABI_RETURN_VALUE_LOG_PREFIX = Bytes.fromHex('151F7C75')
7+
78
describe('ZK Whitelist', () => {
89
const ctx = new TestExecutionContext()
910

rollup.config.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ const config: RollupOptions = {
88
input: {
99
index: 'src/index.ts',
1010
'runtime-helpers': 'src/runtime-helpers.ts',
11-
'internal': 'src/internal.ts',
12-
'internal/arc4': 'src/internal-arc4.ts',
13-
'internal/op': 'src/internal-op.ts',
11+
'internal/index': 'src/internal/index.ts',
12+
'internal/arc4': 'src/internal/arc4.ts',
13+
'internal/op': 'src/internal/op.ts',
1414
'test-transformer/vitest-transformer': 'src/test-transformer/vitest-transformer.ts',
1515
'test-transformer/jest-transformer': 'src/test-transformer/jest-transformer.ts',
1616
},
Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
1-
import { AsyncLocalStorage } from 'node:async_hooks'
21
import type { TestExecutionContext } from '../test-execution-context'
32

43
export class ContextManager {
5-
private static asyncStore = new AsyncLocalStorage<TestExecutionContext>()
4+
private static _instance: TestExecutionContext | undefined
65

76
static set instance(ctx: TestExecutionContext) {
8-
const instance = this.asyncStore.getStore()
9-
if (instance !== undefined) throw new Error('Execution context has already been set')
10-
this.asyncStore.enterWith(ctx)
7+
if (this._instance !== undefined) throw new Error('Execution context has already been set')
8+
this._instance = ctx
119
}
1210
static get instance() {
13-
const instance = this.asyncStore.getStore()
14-
if (instance === undefined) throw new Error('No execution context has been set')
15-
return instance
11+
if (this._instance === undefined) throw new Error('No execution context has been set')
12+
return this._instance
1613
}
1714
static reset() {
18-
this.asyncStore.disable()
15+
this._instance = undefined
1916
}
2017
}

src/internal-arc4.ts

Lines changed: 0 additions & 2 deletions
This file was deleted.

src/internal-op.ts

Lines changed: 0 additions & 62 deletions
This file was deleted.

src/internal.ts

Lines changed: 0 additions & 38 deletions
This file was deleted.

src/internal/arc4.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from '@algorandfoundation/algorand-typescript/arc4'
2+
export { abimethod, Contract, methodSelector } from '../impl/contract'

src/internal/index.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
export * from '@algorandfoundation/algorand-typescript'
2+
export { BaseContract, contract } from '../impl/base-contract'
3+
export { compileImpl as compile } from '../impl/compiled'
4+
export { abimethod, Contract } from '../impl/contract'
5+
export { ensureBudgetImpl as ensureBudget } from '../impl/ensure-budget'
6+
export { Global } from '../impl/global'
7+
export { log } from '../impl/log'
8+
export { assertMatchImpl as assertMatch, matchImpl as match } from '../impl/match'
9+
export { BigUint, Bytes, Uint64 } from '../impl/primitives'
10+
export { Account, Application, Asset } from '../impl/reference'
11+
export { Box, BoxMap, BoxRef, GlobalState, LocalState } from '../impl/state'
12+
export { TemplateVarImpl as TemplateVar } from '../impl/template-var'
13+
export { Txn } from '../impl/txn'
14+
export { urangeImpl as urange } from '../impl/urange'
15+
export { assert, err } from '../util'
16+
export * as arc4 from './arc4'
17+
export * as op from './op'
18+
import { ApplicationTxn, AssetConfigTxn, AssetFreezeTxn, AssetTransferTxn, KeyRegistrationTxn, PaymentTxn, Transaction } from '../impl/gtxn'
19+
export const gtxn = {
20+
Transaction,
21+
PaymentTxn,
22+
KeyRegistrationTxn,
23+
AssetConfigTxn,
24+
AssetTransferTxn,
25+
AssetFreezeTxn,
26+
ApplicationTxn,
27+
}
28+
29+
import { applicationCall, assetConfig, assetFreeze, assetTransfer, keyRegistration, payment, submitGroup } from '../impl/inner-transactions'
30+
export const itxn = {
31+
submitGroup,
32+
payment,
33+
keyRegistration,
34+
assetConfig,
35+
assetTransfer,
36+
assetFreeze,
37+
applicationCall,
38+
}

0 commit comments

Comments
 (0)