Skip to content

Commit 32b0078

Browse files
authored
Merge pull request #101 from algorandfoundation/refactor/tests
refactor: create new scope in beforeAll | beforeEach as part of creating TestFixture
2 parents acfb4f1 + 5d28f00 commit 32b0078

24 files changed

+192
-178
lines changed

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/arc4/bool.algo.spec.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
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', {
12-
Arc4PrimitiveOpsContract: { deployParams: { createParams: { extraProgramPages: undefined } } },
11+
const test = createArc4TestFixture({
12+
path: 'tests/artifacts/arc4-primitive-ops/contract.algo.ts',
13+
contracts: {
14+
Arc4PrimitiveOpsContract: { deployParams: { createParams: { extraProgramPages: undefined } } },
15+
},
1316
})
1417
const ctx = new TestExecutionContext()
1518

16-
beforeAll(async () => {
17-
await localnetFixture.newScope()
18-
})
19-
2019
afterEach(() => {
2120
ctx.reset()
2221
})

tests/arc4/byte.algo.spec.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,23 @@ 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', {
15-
Arc4PrimitiveOpsContract: { deployParams: { createParams: { extraProgramPages: undefined } } },
14+
const test = createArc4TestFixture({
15+
path: 'tests/artifacts/arc4-primitive-ops/contract.algo.ts',
16+
contracts: {
17+
Arc4PrimitiveOpsContract: { deployParams: { createParams: { extraProgramPages: undefined } } },
18+
},
1619
})
1720

1821
const ctx = new TestExecutionContext()
1922

20-
beforeAll(async () => {
21-
await localnetFixture.newScope()
22-
})
2323
afterEach(() => {
2424
ctx.reset()
2525
})

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

Lines changed: 7 additions & 8 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,13 +9,12 @@ import { createArc4TestFixture } from '../test-fixture'
99

1010
describe('circular reference', () => {
1111
const ctx = new TestExecutionContext()
12-
const [test, localnetFixture] = createArc4TestFixture('tests/artifacts/circurlar-reference', {
13-
ContractOne: { funding: algo(1) },
14-
ContractTwo: { funding: algo(1) },
15-
})
16-
17-
beforeAll(async () => {
18-
await localnetFixture.newScope()
12+
const test = createArc4TestFixture({
13+
path: 'tests/artifacts/circurlar-reference',
14+
contracts: {
15+
ContractOne: { funding: algo(1) },
16+
ContractTwo: { funding: algo(1) },
17+
},
1918
})
2019

2120
afterEach(() => {

tests/arc4/emit.algo.spec.ts

Lines changed: 6 additions & 7 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,14 @@ 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', {
45-
Arc4PrimitiveOpsContract: { deployParams: { createParams: { extraProgramPages: undefined } } },
44+
const test = createArc4TestFixture({
45+
path: 'tests/artifacts/arc4-primitive-ops/contract.algo.ts',
46+
contracts: {
47+
Arc4PrimitiveOpsContract: { deployParams: { createParams: { extraProgramPages: undefined } } },
48+
},
4649
})
4750
const ctx = new TestExecutionContext()
4851

49-
beforeAll(async () => {
50-
await localnetFixture.newScope()
51-
})
52-
5352
afterEach(() => {
5453
ctx.reset()
5554
})

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

Lines changed: 8 additions & 9 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,16 @@ 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', {
19-
SignaturesContract: {
20-
deployParams: { createParams: { extraProgramPages: undefined, method: 'create' } },
21-
funding: new AlgoAmount({ microAlgos: Global.minBalance + _FUNDED_ACCOUNT_SPENDING }),
18+
const test = createArc4TestFixture({
19+
path: 'tests/artifacts/arc4-abi-method/contract.algo.ts',
20+
contracts: {
21+
SignaturesContract: {
22+
deployParams: { createParams: { extraProgramPages: undefined, method: 'create' } },
23+
funding: new AlgoAmount({ microAlgos: Global.minBalance + _FUNDED_ACCOUNT_SPENDING }),
24+
},
2225
},
2326
})
2427

25-
beforeAll(async () => {
26-
await localnetFixture.newScope()
27-
})
28-
2928
afterEach(() => {
3029
ctx.reset()
3130
})

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

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
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', {
9-
ByIndex: {},
10-
ByValue: {},
11-
C2C: { funding: algo(1) },
12-
})
13-
14-
beforeAll(async () => {
15-
await localnetFixture.newScope()
8+
const test = createArc4TestFixture({
9+
path: 'tests/artifacts/resource-encoding/contract.algo.ts',
10+
contracts: {
11+
ByIndex: {},
12+
ByValue: {},
13+
C2C: { funding: algo(1) },
14+
},
1615
})
1716

1817
afterEach(() => {

tests/arc4/str.algo.spec.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@ 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', {
13-
Arc4PrimitiveOpsContract: { deployParams: { createParams: { extraProgramPages: undefined } } },
12+
const test = createArc4TestFixture({
13+
path: 'tests/artifacts/arc4-primitive-ops/contract.algo.ts',
14+
contracts: {
15+
Arc4PrimitiveOpsContract: { deployParams: { createParams: { extraProgramPages: undefined } } },
16+
},
1417
})
1518
const ctx = new TestExecutionContext()
1619

17-
beforeAll(async () => {
18-
await localnetFixture.newScope()
19-
})
2020
afterEach(() => {
2121
ctx.reset()
2222
})

tests/arc4/ufixednxm.algo.spec.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,22 @@ 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', {
15-
Arc4PrimitiveOpsContract: { deployParams: { createParams: { extraProgramPages: undefined } } },
14+
const test = createArc4TestFixture({
15+
path: 'tests/artifacts/arc4-primitive-ops/contract.algo.ts',
16+
contracts: {
17+
Arc4PrimitiveOpsContract: { deployParams: { createParams: { extraProgramPages: undefined } } },
18+
},
1619
})
1720
const ctx = new TestExecutionContext()
1821

19-
beforeAll(async () => {
20-
await localnetFixture.newScope()
21-
})
2222
afterEach(() => {
2323
ctx.reset()
2424
})

tests/arc4/uintn.algo.spec.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,22 @@ 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', {
16-
Arc4PrimitiveOpsContract: { deployParams: { createParams: { extraProgramPages: undefined } } },
15+
const test = createArc4TestFixture({
16+
path: 'tests/artifacts/arc4-primitive-ops/contract.algo.ts',
17+
contracts: {
18+
Arc4PrimitiveOpsContract: { deployParams: { createParams: { extraProgramPages: undefined } } },
19+
},
1720
})
1821
const ctx = new TestExecutionContext()
1922

20-
beforeAll(async () => {
21-
await localnetFixture.newScope()
22-
})
2323
afterEach(() => {
2424
ctx.reset()
2525
})

0 commit comments

Comments
 (0)