Skip to content

Commit ff6188f

Browse files
committed
refactor: create new scope in beforeAll | beforeEach as part of creating TestFixture
to be consistent with puya-ts and to reduce boilerplate code
1 parent acfb4f1 commit ff6188f

23 files changed

+72
-137
lines changed

tests/arc4/bool.algo.spec.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,18 @@
11
import { Bytes } from '@algorandfoundation/algorand-typescript'
22
import { TestExecutionContext } from '@algorandfoundation/algorand-typescript-testing'
33
import { Bool, convertBytes } from '@algorandfoundation/algorand-typescript/arc4'
4-
import { afterEach, beforeAll, describe, expect } from 'vitest'
4+
import { afterEach, describe, expect } from 'vitest'
55
import { ABI_RETURN_VALUE_LOG_PREFIX } from '../../src/constants'
66
import { asUint8Array } from '../../src/util'
77
import { getAvmResult } from '../avm-invoker'
88
import { createArc4TestFixture } from '../test-fixture'
99

1010
describe('arc4.Bool', async () => {
11-
const [test, localnetFixture] = createArc4TestFixture('tests/artifacts/arc4-primitive-ops/contract.algo.ts', {
11+
const test = createArc4TestFixture('tests/artifacts/arc4-primitive-ops/contract.algo.ts', {
1212
Arc4PrimitiveOpsContract: { deployParams: { createParams: { extraProgramPages: undefined } } },
1313
})
1414
const ctx = new TestExecutionContext()
1515

16-
beforeAll(async () => {
17-
await localnetFixture.newScope()
18-
})
19-
2016
afterEach(() => {
2117
ctx.reset()
2218
})

tests/arc4/byte.algo.spec.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,20 @@ import { Bytes } from '@algorandfoundation/algorand-typescript'
33
import { TestExecutionContext } from '@algorandfoundation/algorand-typescript-testing'
44
import { Byte, convertBytes } from '@algorandfoundation/algorand-typescript/arc4'
55
import { encodingUtil } from '@algorandfoundation/puya-ts'
6-
import { afterEach, beforeAll, describe, expect } from 'vitest'
6+
import { afterEach, describe, expect } from 'vitest'
77
import { ABI_RETURN_VALUE_LOG_PREFIX, MAX_UINT64 } from '../../src/constants'
88
import { asBigUintCls, asUint8Array } from '../../src/util'
99
import { getAvmResult } from '../avm-invoker'
1010
import { createArc4TestFixture } from '../test-fixture'
1111

1212
const invalidBytesLengthError = 'byte string must be 1 byte long'
1313
describe('arc4.Byte', async () => {
14-
const [test, localnetFixture] = createArc4TestFixture('tests/artifacts/arc4-primitive-ops/contract.algo.ts', {
14+
const test = createArc4TestFixture('tests/artifacts/arc4-primitive-ops/contract.algo.ts', {
1515
Arc4PrimitiveOpsContract: { deployParams: { createParams: { extraProgramPages: undefined } } },
1616
})
1717

1818
const ctx = new TestExecutionContext()
1919

20-
beforeAll(async () => {
21-
await localnetFixture.newScope()
22-
})
2320
afterEach(() => {
2421
ctx.reset()
2522
})

tests/arc4/circular-reference.algo.spec.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { algo } from '@algorandfoundation/algokit-utils'
22
import { methodSelector } from '@algorandfoundation/algorand-typescript/arc4'
3-
import { afterEach, beforeAll, describe, expect } from 'vitest'
3+
import { afterEach, describe, expect } from 'vitest'
44
import { ApplicationSpy } from '../../src/application-spy'
55
import { TestExecutionContext } from '../../src/test-execution-context'
66
import { ContractTwo } from '../artifacts/circurlar-reference/circular-reference-2.algo'
@@ -9,15 +9,11 @@ import { createArc4TestFixture } from '../test-fixture'
99

1010
describe('circular reference', () => {
1111
const ctx = new TestExecutionContext()
12-
const [test, localnetFixture] = createArc4TestFixture('tests/artifacts/circurlar-reference', {
12+
const test = createArc4TestFixture('tests/artifacts/circurlar-reference', {
1313
ContractOne: { funding: algo(1) },
1414
ContractTwo: { funding: algo(1) },
1515
})
1616

17-
beforeAll(async () => {
18-
await localnetFixture.newScope()
19-
})
20-
2117
afterEach(() => {
2218
ctx.reset()
2319
})

tests/arc4/emit.algo.spec.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { biguint, bytes, uint64 } from '@algorandfoundation/algorand-typescript'
22
import { arc4, BigUint, Bytes, emit, Uint64 } from '@algorandfoundation/algorand-typescript'
33
import { TestExecutionContext } from '@algorandfoundation/algorand-typescript-testing'
4-
import { afterEach, beforeAll, describe, expect } from 'vitest'
4+
import { afterEach, describe, expect } from 'vitest'
55
import { MAX_UINT512, MAX_UINT64 } from '../../src/constants'
66
import { getAvmResultLog } from '../avm-invoker'
77

@@ -41,15 +41,11 @@ class SwappedArc4 extends arc4.Struct<{
4141
}> {}
4242

4343
describe('arc4.emit', async () => {
44-
const [test, localnetFixture] = createArc4TestFixture('tests/artifacts/arc4-primitive-ops/contract.algo.ts', {
44+
const test = createArc4TestFixture('tests/artifacts/arc4-primitive-ops/contract.algo.ts', {
4545
Arc4PrimitiveOpsContract: { deployParams: { createParams: { extraProgramPages: undefined } } },
4646
})
4747
const ctx = new TestExecutionContext()
4848

49-
beforeAll(async () => {
50-
await localnetFixture.newScope()
51-
})
52-
5349
afterEach(() => {
5450
ctx.reset()
5551
})

tests/arc4/method-selector.algo.spec.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { arc4, Bytes, Global, Uint64 } from '@algorandfoundation/algorand-typesc
44
import { TestExecutionContext } from '@algorandfoundation/algorand-typescript-testing'
55
import { DynamicArray, methodSelector } from '@algorandfoundation/algorand-typescript/arc4'
66
import { encodingUtil } from '@algorandfoundation/puya-ts'
7-
import { afterEach, beforeAll, describe, expect } from 'vitest'
7+
import { afterEach, describe, expect } from 'vitest'
88
import { toBytes } from '../../src/impl/encoded-types/encoded-types'
99
import { encodeAddress } from '../../src/impl/reference'
1010
import { AnotherStruct, MyStruct, SignaturesContract } from '../artifacts/arc4-abi-method/contract.algo'
@@ -15,17 +15,13 @@ const _FUNDED_ACCOUNT_SPENDING = Uint64(1234)
1515

1616
describe('methodSelector', async () => {
1717
const ctx = new TestExecutionContext()
18-
const [test, localnetFixture] = createArc4TestFixture('tests/artifacts/arc4-abi-method/contract.algo.ts', {
18+
const test = createArc4TestFixture('tests/artifacts/arc4-abi-method/contract.algo.ts', {
1919
SignaturesContract: {
2020
deployParams: { createParams: { extraProgramPages: undefined, method: 'create' } },
2121
funding: new AlgoAmount({ microAlgos: Global.minBalance + _FUNDED_ACCOUNT_SPENDING }),
2222
},
2323
})
2424

25-
beforeAll(async () => {
26-
await localnetFixture.newScope()
27-
})
28-
2925
afterEach(() => {
3026
ctx.reset()
3127
})

tests/arc4/resource-encoding.algo.spec.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
11
import { algo } from '@algorandfoundation/algokit-utils'
2-
import { afterEach, beforeAll, describe, expect } from 'vitest'
2+
import { afterEach, describe, expect } from 'vitest'
33
import { TestExecutionContext } from '../../src/test-execution-context'
44
import { createArc4TestFixture } from '../test-fixture'
55

66
describe('resource encoding', () => {
77
const ctx = new TestExecutionContext()
8-
const [test, localnetFixture] = createArc4TestFixture('tests/artifacts/resource-encoding/contract.algo.ts', {
8+
const test = createArc4TestFixture('tests/artifacts/resource-encoding/contract.algo.ts', {
99
ByIndex: {},
1010
ByValue: {},
1111
C2C: { funding: algo(1) },
1212
})
1313

14-
beforeAll(async () => {
15-
await localnetFixture.newScope()
16-
})
17-
1814
afterEach(() => {
1915
ctx.reset()
2016
})

tests/arc4/str.algo.spec.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,18 @@ import { Bytes } from '@algorandfoundation/algorand-typescript'
22
import { TestExecutionContext } from '@algorandfoundation/algorand-typescript-testing'
33
import { convertBytes, Str } from '@algorandfoundation/algorand-typescript/arc4'
44
import { encodingUtil } from '@algorandfoundation/puya-ts'
5-
import { afterEach, beforeAll, describe, expect } from 'vitest'
5+
import { afterEach, describe, expect } from 'vitest'
66
import { ABI_RETURN_VALUE_LOG_PREFIX, MAX_LOG_SIZE } from '../../src/constants'
77
import { asUint8Array } from '../../src/util'
88
import { getAvmResult } from '../avm-invoker'
99
import { createArc4TestFixture } from '../test-fixture'
1010

1111
describe('arc4.Str', async () => {
12-
const [test, localnetFixture] = createArc4TestFixture('tests/artifacts/arc4-primitive-ops/contract.algo.ts', {
12+
const test = createArc4TestFixture('tests/artifacts/arc4-primitive-ops/contract.algo.ts', {
1313
Arc4PrimitiveOpsContract: { deployParams: { createParams: { extraProgramPages: undefined } } },
1414
})
1515
const ctx = new TestExecutionContext()
1616

17-
beforeAll(async () => {
18-
await localnetFixture.newScope()
19-
})
2017
afterEach(() => {
2118
ctx.reset()
2219
})

tests/arc4/ufixednxm.algo.spec.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,19 @@ import { Bytes } from '@algorandfoundation/algorand-typescript'
33
import { TestExecutionContext } from '@algorandfoundation/algorand-typescript-testing'
44
import { convertBytes, UFixed } from '@algorandfoundation/algorand-typescript/arc4'
55
import { encodingUtil } from '@algorandfoundation/puya-ts'
6-
import { afterEach, beforeAll, describe, expect } from 'vitest'
6+
import { afterEach, describe, expect } from 'vitest'
77
import { ABI_RETURN_VALUE_LOG_PREFIX } from '../../src/constants'
88
import { asBigUint, asUint8Array } from '../../src/util'
99
import { getAvmResult } from '../avm-invoker'
1010
import { createArc4TestFixture } from '../test-fixture'
1111

1212
const invalidBytesLengthError = (length: number) => `byte string must correspond to a ufixed${length}`
1313
describe('arc4.UFixed', async () => {
14-
const [test, localnetFixture] = createArc4TestFixture('tests/artifacts/arc4-primitive-ops/contract.algo.ts', {
14+
const test = createArc4TestFixture('tests/artifacts/arc4-primitive-ops/contract.algo.ts', {
1515
Arc4PrimitiveOpsContract: { deployParams: { createParams: { extraProgramPages: undefined } } },
1616
})
1717
const ctx = new TestExecutionContext()
1818

19-
beforeAll(async () => {
20-
await localnetFixture.newScope()
21-
})
2219
afterEach(() => {
2320
ctx.reset()
2421
})

tests/arc4/uintn.algo.spec.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,19 @@ import { TestExecutionContext } from '@algorandfoundation/algorand-typescript-te
44
import type { BitSize } from '@algorandfoundation/algorand-typescript/arc4'
55
import { convertBytes, Uint, Uint16, Uint256, Uint32, Uint8 } from '@algorandfoundation/algorand-typescript/arc4'
66
import { encodingUtil } from '@algorandfoundation/puya-ts'
7-
import { afterEach, beforeAll, describe, expect } from 'vitest'
7+
import { afterEach, describe, expect } from 'vitest'
88
import { ABI_RETURN_VALUE_LOG_PREFIX, MAX_UINT512, MAX_UINT64 } from '../../src/constants'
99
import { asBigUintCls, asUint8Array } from '../../src/util'
1010
import { getAvmResult } from '../avm-invoker'
1111
import { createArc4TestFixture } from '../test-fixture'
1212

1313
const invalidBytesLengthError = (length: number) => `byte string must correspond to a uint${length}`
1414
describe('arc4.Uint', async () => {
15-
const [test, localnetFixture] = createArc4TestFixture('tests/artifacts/arc4-primitive-ops/contract.algo.ts', {
15+
const test = createArc4TestFixture('tests/artifacts/arc4-primitive-ops/contract.algo.ts', {
1616
Arc4PrimitiveOpsContract: { deployParams: { createParams: { extraProgramPages: undefined } } },
1717
})
1818
const ctx = new TestExecutionContext()
1919

20-
beforeAll(async () => {
21-
await localnetFixture.newScope()
22-
})
2320
afterEach(() => {
2421
ctx.reset()
2522
})

tests/avm12.algo.spec.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
import { algos } from '@algorandfoundation/algokit-utils'
22
import { ApplicationSpy, TestExecutionContext } from '@algorandfoundation/algorand-typescript-testing'
3-
import { afterEach, beforeAll, describe, expect } from 'vitest'
3+
import { afterEach, describe, expect } from 'vitest'
44
import { Avm12Contract, ContractV0, ContractV1 } from './artifacts/avm12/contract.algo'
55
import { createArc4TestFixture } from './test-fixture'
66

77
describe('avm12', () => {
8-
const [test, localnetFixture] = createArc4TestFixture('tests/artifacts/avm12/contract.algo.ts', {
8+
const test = createArc4TestFixture('tests/artifacts/avm12/contract.algo.ts', {
99
Avm12Contract: { funding: algos(1) },
1010
})
1111

1212
const ctx = new TestExecutionContext()
13-
beforeAll(async () => {
14-
await localnetFixture.newScope()
15-
})
13+
1614
afterEach(() => {
1715
ctx.reset()
1816
})

0 commit comments

Comments
 (0)