From c75113e67b322e16f9d9306d29746c07ce174e0c Mon Sep 17 00:00:00 2001 From: Piotr Roslaniec Date: Wed, 27 Sep 2023 11:56:32 +0200 Subject: [PATCH] chore: fix vitest test config --- package.json | 5 +- packages/pre/package.json | 5 +- .../pre/test/acceptance/alice-grants.test.ts | 44 ++-- .../pre/test/acceptance/delay-enact.test.ts | 19 +- packages/pre/test/docs.test.ts | 27 ++- packages/pre/test/pre-strategy.test.ts | 20 +- packages/pre/test/pre.test.ts | 27 +-- packages/pre/test/test-utils.ts | 11 +- packages/pre/tsconfig.json | 9 +- packages/shared/package.json | 5 +- packages/shared/test/cohort.test.ts | 10 +- .../test/conditions/base/condition.test.ts | 12 +- .../test/conditions/base/contract.test.ts | 26 +-- .../shared/test/conditions/base/rpc.test.ts | 8 +- .../shared/test/conditions/base/time.test.ts | 8 +- .../conditions/compound-condition.test.ts | 29 ++- .../test/conditions/condition-expr.test.ts | 47 +++-- .../shared/test/conditions/context.test.ts | 33 +-- packages/taco/package.json | 5 +- packages/taco/test/cbd-strategy.test.ts | 189 ------------------ packages/taco/test/dkg-client.test.ts | 47 ++--- packages/taco/test/docs.test..ts | 126 ------------ packages/taco/test/ritual.test.ts | 3 +- packages/taco/test/taco.test.ts | 25 +-- packages/taco/test/test-utils.ts | 32 ++- packages/taco/tsconfig.json | 7 +- packages/test-utils/package.json | 21 +- packages/test-utils/src/utils.ts | 6 +- packages/test-utils/tsconfig.build.json | 13 -- packages/test-utils/tsconfig.cjs.json | 7 + packages/test-utils/tsconfig.es.json | 10 + pnpm-lock.yaml | 113 +++-------- tsconfig.prod.json | 5 +- vitest.config.ts | 2 +- 34 files changed, 295 insertions(+), 661 deletions(-) delete mode 100644 packages/taco/test/cbd-strategy.test.ts delete mode 100644 packages/taco/test/docs.test..ts delete mode 100644 packages/test-utils/tsconfig.build.json create mode 100644 packages/test-utils/tsconfig.cjs.json create mode 100644 packages/test-utils/tsconfig.es.json diff --git a/package.json b/package.json index 18b318221..701b8f278 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "type-check": "pnpm --parallel --aggregate-output --reporter append-only type-check", "build": "tsc --build --verbose ./tsconfig.prod.json", "watch": "tsc --build --verbose --watch ./tsconfig.prod.json", - "test": "vitest run", + "test": "pnpm build && vitest run", "package:check": "pnpm run --parallel --aggregate-output --reporter append-only --filter './packages/**' package-check", "packages:lint": "pnpm packages:sort --check", "packages:sort": "sort-package-json \"package.json\" \"examples/*/package.json\" \"packages/*/package.json\"", @@ -24,6 +24,9 @@ "ci:lint": "run-p lint type-check package:check packages:lint exports:lint", "check-examples": "pnpm run --parallel --aggregate-output --reporter append-only --filter './examples/**' check" }, + "dependencies": { + "@nucypher/nucypher-core": "0.13.0-alpha.1" + }, "devDependencies": { "@skypack/package-check": "^0.2.2", "@types/node": "^20.6.0", diff --git a/packages/pre/package.json b/packages/pre/package.json index b1af235b7..0d64dd5c4 100644 --- a/packages/pre/package.json +++ b/packages/pre/package.json @@ -38,11 +38,12 @@ "typedoc": "typedoc" }, "dependencies": { - "@nucypher/nucypher-core": "0.13.0-alpha.0", + "@nucypher/nucypher-core": "/home/piotr/Documents/projects/nucypher/nucypher-core/nucypher-core-wasm-bundler/dist", "@nucypher/shared": "workspace:*" }, "devDependencies": { - "@nucypher/test-utils": "workspace:*" + "@nucypher/test-utils": "workspace:*", + "vitest": "^0.34.4" }, "peerDependencies": { "ethers": "^5.7.2" diff --git a/packages/pre/test/acceptance/alice-grants.test.ts b/packages/pre/test/acceptance/alice-grants.test.ts index 324d6fc03..6c15b7358 100644 --- a/packages/pre/test/acceptance/alice-grants.test.ts +++ b/packages/pre/test/acceptance/alice-grants.test.ts @@ -5,35 +5,33 @@ import { PublicKey, VerifiedKeyFrag, } from '@nucypher/nucypher-core'; +import { ChecksumAddress, initialize, Ursula } from '@nucypher/shared'; import { bytesEqual, - fakeAlice, - fakeBob, fakePorterUri, fakeProvider, - fakeRemoteBob, fakeSigner, + fakeUrsulas, fromBytes, + mockGetUrsulas, + mockRetrieveCFragsRequest, +} from '@nucypher/test-utils'; +import { beforeEach, describe, expect, it } from 'vitest'; + +import { EnactedPolicy, toBytes } from '../../src'; +import { Enrico } from '../../src/characters'; +import { + fakeAlice, + fakeBob, + fakeRemoteBob, mockEncryptTreasureMap, mockGenerateKFrags, - mockGetUrsulas, mockMakeTreasureMap, mockPublishToBlockchain, - mockRetrieveCFragsRequest, reencryptKFrags, -} from '@nucypher/test-utils'; -import { beforeAll, expect, test } from 'vitest'; +} from '../test-utils'; -import { - ChecksumAddress, - EnactedPolicy, - Enrico, - initialize, - toBytes, - Ursula, -} from '../../src'; - -test('story: alice shares message with bob through policy', () => { +describe('story: alice shares message with bob through policy', () => { const message = 'secret-message-from-alice'; const threshold = 2; const shares = 3; @@ -52,12 +50,12 @@ test('story: alice shares message with bob through policy', () => { let aliceVerifyingKey: PublicKey; let policyEncryptingKey: PublicKey; - beforeAll(async () => { + beforeEach(async () => { await initialize(); }); - test('alice grants a new policy to bob', async () => { - const getUrsulasSpy = mockGetUrsulas(); + it('alice grants a new policy to bob', async () => { + const getUrsulasSpy = mockGetUrsulas(fakeUrsulas().slice(0, shares)); const generateKFragsSpy = mockGenerateKFrags(); const publishToBlockchainSpy = mockPublishToBlockchain(); const makeTreasureMapSpy = mockMakeTreasureMap(); @@ -105,14 +103,13 @@ test('story: alice shares message with bob through policy', () => { verifiedKFrags = makeTreasureMapSpy.mock.calls[0][1] as VerifiedKeyFrag[]; }); - test('enrico encrypts the message', () => { + it('enrico encrypts the message', () => { const enrico = new Enrico(policyEncryptingKey); encryptedMessage = enrico.encryptMessagePre(toBytes(message)); }); - test('bob retrieves and decrypts the message', async () => { + it('bob retrieves and decrypts the message', async () => { const bob = fakeBob(); - const getUrsulasSpy = mockGetUrsulas(); const retrieveCFragsSpy = mockRetrieveCFragsRequest( ursulaAddresses, verifiedKFrags, @@ -128,7 +125,6 @@ test('story: alice shares message with bob through policy', () => { ); const bobPlaintext = fromBytes(retrievedMessage[0]); - expect(getUrsulasSpy).toHaveBeenCalled(); expect(retrieveCFragsSpy).toHaveBeenCalled(); expect(bobPlaintext).toEqual(message); diff --git a/packages/pre/test/acceptance/delay-enact.test.ts b/packages/pre/test/acceptance/delay-enact.test.ts index 7c2ef6428..cafa6f518 100644 --- a/packages/pre/test/acceptance/delay-enact.test.ts +++ b/packages/pre/test/acceptance/delay-enact.test.ts @@ -1,18 +1,19 @@ import { bytesEqual, - fakeAlice, fakePorterUri, fakeProvider, - fakeRemoteBob, fakeSigner, - mockEncryptTreasureMap, - mockGenerateKFrags, mockGetUrsulas, - mockPublishToBlockchain, } from '@nucypher/test-utils'; -import { beforeAll, expect, test } from 'vitest'; +import { expect, test } from 'vitest'; -import { initialize } from '../../src'; +import { + fakeAlice, + fakeRemoteBob, + mockEncryptTreasureMap, + mockGenerateKFrags, + mockPublishToBlockchain, +} from '../test-utils'; test('story: alice creates a policy but someone else enacts it', () => { const threshold = 2; @@ -22,10 +23,6 @@ test('story: alice creates a policy but someone else enacts it', () => { const label = 'fake-data-label'; test('verifies capsule frags', async () => { - beforeAll(async () => { - await initialize(); - }); - test('alice generates a new policy', async () => { const provider = fakeProvider(); const getUrsulasSpy = mockGetUrsulas(); diff --git a/packages/pre/test/docs.test.ts b/packages/pre/test/docs.test.ts index 98af9386b..fd32cddb4 100644 --- a/packages/pre/test/docs.test.ts +++ b/packages/pre/test/docs.test.ts @@ -1,23 +1,21 @@ +import { + ConditionExpression, + ContractCondition, + ContractConditionProps, + ERC721Ownership, +} from '@nucypher/shared'; import { fakeProvider, fakeUrsulas, mockDetectEthereumProvider, - mockEncryptTreasureMap, - mockGenerateKFrags, mockGetUrsulas, - mockMakeTreasureMap, - mockPublishToBlockchain, mockRetrieveAndDecrypt, } from '@nucypher/test-utils'; import { providers } from 'ethers'; -import { beforeAll, expect, test, vi } from 'vitest'; +import { beforeAll, describe, expect, it, vi } from 'vitest'; import { Cohort, - ConditionExpression, - ContractCondition, - ContractConditionProps, - ERC721Ownership, getPorterUri, initialize, PreStrategy, @@ -25,12 +23,19 @@ import { toBytes, } from '../src'; -test('doc tests', async () => { +import { + mockEncryptTreasureMap, + mockGenerateKFrags, + mockMakeTreasureMap, + mockPublishToBlockchain, +} from './test-utils'; + +describe('doc tests', async () => { beforeAll(async () => { await initialize(); }); - test('runs get started example', async () => { + it('runs get started example', async () => { const detectEthereumProvider = mockDetectEthereumProvider(); const getUrsulasSpy = mockGetUrsulas(); const generateKFragsSpy = mockGenerateKFrags(); diff --git a/packages/pre/test/pre-strategy.test.ts b/packages/pre/test/pre-strategy.test.ts index 09af8e0c9..f5f1940f9 100644 --- a/packages/pre/test/pre-strategy.test.ts +++ b/packages/pre/test/pre-strategy.test.ts @@ -1,4 +1,5 @@ import { SecretKey, VerifiedKeyFrag } from '@nucypher/nucypher-core'; +import { Ursula } from '@nucypher/shared'; import { aliceSecretKeyBytes, bobSecretKeyBytes, @@ -6,25 +7,26 @@ import { fakeSigner, fakeUrsulas, makeCohort, - mockEncryptTreasureMap, - mockGenerateKFrags, mockGetUrsulas, - mockMakeTreasureMap, - mockPublishToBlockchain, mockRetrieveCFragsRequest, } from '@nucypher/test-utils'; -import { afterEach, beforeAll, expect, test, vi } from 'vitest'; +import { afterEach, expect, test, vi } from 'vitest'; import { conditions, DeployedPreStrategy, - initialize, PreDecrypter, PreStrategy, toBytes, - Ursula, } from '../src'; +import { + mockEncryptTreasureMap, + mockGenerateKFrags, + mockMakeTreasureMap, + mockPublishToBlockchain, +} from './test-utils'; + // Shared test variables const ownsNFT = new conditions.ERC721Ownership({ contractAddress: '0x1e988ba4692e52Bc50b375bcC8585b95c48AaD77', @@ -76,10 +78,6 @@ const makeDeployedPreStrategy = async () => { }; test('pre strategy', () => { - beforeAll(async () => { - await initialize(); - }); - test('PreStrategy', () => { afterEach(() => { vi.restoreAllMocks(); diff --git a/packages/pre/test/pre.test.ts b/packages/pre/test/pre.test.ts index 4b24873d9..79923486a 100644 --- a/packages/pre/test/pre.test.ts +++ b/packages/pre/test/pre.test.ts @@ -1,26 +1,18 @@ import { CapsuleFrag, reencrypt } from '@nucypher/nucypher-core'; import { - fakeAlice, - fakeBob, - fakeUrsulas, - reencryptKFrags, -} from '@nucypher/test-utils'; -import { beforeAll, expect, test } from 'vitest'; - -import { - Alice, - Bob, CompoundCondition, ConditionExpression, - Enrico, ERC721Ownership, - initialize, - MessageKit, - PolicyMessageKit, - RetrievalResult, - toBytes, zip, -} from '../src'; +} from '@nucypher/shared'; +import { fakeUrsulas } from '@nucypher/test-utils'; +import { beforeAll, expect, test } from 'vitest'; + +import { Alice, Bob, MessageKit, toBytes } from '../src'; +import { Enrico } from '../src/characters'; +import { PolicyMessageKit, RetrievalResult } from '../src/kits'; + +import { fakeAlice, fakeBob, reencryptKFrags } from './test-utils'; test('proxy reencryption', () => { let alice: Alice; @@ -32,7 +24,6 @@ test('proxy reencryption', () => { test('verifies capsule frags', async () => { beforeAll(async () => { - await initialize(); bob = fakeBob(); alice = fakeAlice(); }); diff --git a/packages/pre/test/test-utils.ts b/packages/pre/test/test-utils.ts index e957a500c..ca61faa94 100644 --- a/packages/pre/test/test-utils.ts +++ b/packages/pre/test/test-utils.ts @@ -14,14 +14,9 @@ import { } from '@nucypher/nucypher-core'; import { SpyInstance, vi } from 'vitest'; -import { - Alice, - BlockchainPolicy, - Bob, - PreEnactedPolicy, - RemoteBob, - toBytes, -} from '../src'; +import { Alice, Bob, toBytes } from '../src'; +import { RemoteBob } from '../src/characters'; +import { BlockchainPolicy, PreEnactedPolicy } from '../src/policy'; export const fakeBob = (): Bob => { const secretKey = SecretKey.fromBEBytes( diff --git a/packages/pre/tsconfig.json b/packages/pre/tsconfig.json index 8d2d7c3d7..935974c35 100644 --- a/packages/pre/tsconfig.json +++ b/packages/pre/tsconfig.json @@ -3,6 +3,11 @@ "include": ["src", "test"], "compilerOptions": { "esModuleInterop": true, - "skipLibCheck": true, - } + "skipLibCheck": true + }, + "references": [ + { + "path": "../test-utils/tsconfig.es.json" + } + ] } diff --git a/packages/shared/package.json b/packages/shared/package.json index 09f43034a..8c2bc58d3 100644 --- a/packages/shared/package.json +++ b/packages/shared/package.json @@ -44,7 +44,7 @@ "@ethersproject/abi": "^5.7.0", "@ethersproject/abstract-signer": "^5.7.0", "@ethersproject/providers": "^5.7.2", - "@nucypher/nucypher-core": "0.13.0-alpha.0", + "@nucypher/nucypher-core": "0.13.0-alpha.1", "axios": "^1.5.0", "deep-equal": "^2.2.1", "ethers": "^5.7.2", @@ -60,7 +60,8 @@ "@types/semver": "^7.5.0", "cz-conventional-changelog": "^3.0.1", "standard-version": "^9.0.0", - "typechain": "^8.3.1" + "typechain": "^8.3.1", + "vitest": "^0.34.4" }, "engines": { "node": ">=18", diff --git a/packages/shared/test/cohort.test.ts b/packages/shared/test/cohort.test.ts index 8be3f0e7b..8fff3b734 100644 --- a/packages/shared/test/cohort.test.ts +++ b/packages/shared/test/cohort.test.ts @@ -1,21 +1,21 @@ import { fakeUrsulas, makeCohort } from '@nucypher/test-utils'; -import { beforeAll, expect, test } from 'vitest'; +import { beforeAll, describe, expect, it } from 'vitest'; import { Cohort, initialize } from '../src'; -test('Cohort', () => { +describe('Cohort', () => { beforeAll(async () => { await initialize(); }); - test('creates a Cohort', async () => { + it('creates a Cohort', async () => { const ursulas = fakeUrsulas(); const cohort = await makeCohort(ursulas); const expectedUrsulas = ursulas.map((u) => u.checksumAddress); expect(cohort.ursulaAddresses).toEqual(expectedUrsulas); }); - test('serializes to a plain object', async () => { + it('serializes to a plain object', async () => { const ursulas = fakeUrsulas(); const cohort = await makeCohort(ursulas); const asObj = cohort.toObj(); @@ -23,7 +23,7 @@ test('Cohort', () => { expect(fromObj).toEqual(cohort); }); - test('serializes to JSON', async () => { + it('serializes to JSON', async () => { const ursulas = fakeUrsulas(); const cohort = await makeCohort(ursulas); const asJson = cohort.toJSON(); diff --git a/packages/shared/test/conditions/base/condition.test.ts b/packages/shared/test/conditions/base/condition.test.ts index 34b0da448..d03226a12 100644 --- a/packages/shared/test/conditions/base/condition.test.ts +++ b/packages/shared/test/conditions/base/condition.test.ts @@ -3,7 +3,7 @@ import { TEST_CONTRACT_ADDR, testContractConditionObj, } from '@nucypher/test-utils'; -import { expect, test } from 'vitest'; +import { describe, expect, it } from 'vitest'; import { Condition, @@ -12,28 +12,28 @@ import { ERC721Ownership, } from '../../../src'; -test('validation', () => { +describe('validation', () => { const condition = new ERC721Balance({ contractAddress: TEST_CONTRACT_ADDR, chain: TEST_CHAIN_ID, }); - test('accepts a correct schema', async () => { + it('accepts a correct schema', async () => { const result = Condition.validate(condition.schema, condition.value); expect(result.error).toBeUndefined(); expect(result.data.contractAddress).toEqual(TEST_CONTRACT_ADDR); }); }); -test('serialization', () => { - test('serializes to a plain object', () => { +describe('serialization', () => { + it('serializes to a plain object', () => { const contract = new ContractCondition(testContractConditionObj); expect(contract.toObj()).toEqual({ ...testContractConditionObj, }); }); - test('serializes predefined conditions', () => { + it('serializes predefined conditions', () => { const contract = new ERC721Ownership(testContractConditionObj); expect(contract.toObj()).toEqual({ ...testContractConditionObj, diff --git a/packages/shared/test/conditions/base/contract.test.ts b/packages/shared/test/conditions/base/contract.test.ts index 3037fbdb5..2feda5290 100644 --- a/packages/shared/test/conditions/base/contract.test.ts +++ b/packages/shared/test/conditions/base/contract.test.ts @@ -4,7 +4,7 @@ import { testContractConditionObj, testFunctionAbi, } from '@nucypher/test-utils'; -import { beforeAll, expect, test } from 'vitest'; +import { beforeAll, describe, expect, it } from 'vitest'; import { ConditionExpression, @@ -19,8 +19,8 @@ import { } from '../../../src/conditions/base/contract'; import { USER_ADDRESS_PARAM } from '../../../src/conditions/const'; -test('validation', () => { - test('accepts on a valid schema', () => { +describe('validation', () => { + it('accepts on a valid schema', () => { const result = ContractCondition.validate( contractConditionSchema, testContractConditionObj, @@ -30,7 +30,7 @@ test('validation', () => { expect(result.data).toEqual(testContractConditionObj); }); - test('rejects an invalid schema', () => { + it('rejects an invalid schema', () => { const badContractCondition = { ...testContractConditionObj, // Intentionally removing `contractAddress` @@ -51,7 +51,7 @@ test('validation', () => { }); }); -test('accepts either standardContractType or functionAbi but not both or none', () => { +describe('accepts either standardContractType or functionAbi but not both or none', () => { const standardContractType = 'ERC20'; const functionAbi = { inputs: [ @@ -73,7 +73,7 @@ test('accepts either standardContractType or functionAbi but not both or none', type: 'function', }; - test('accepts standardContractType', () => { + it('accepts standardContractType', () => { const conditionObj = { ...testContractConditionObj, standardContractType, @@ -88,7 +88,7 @@ test('accepts either standardContractType or functionAbi but not both or none', expect(result.data).toEqual(conditionObj); }); - test('accepts functionAbi', () => { + it('accepts functionAbi', () => { const conditionObj = { ...testContractConditionObj, functionAbi, @@ -103,7 +103,7 @@ test('accepts either standardContractType or functionAbi but not both or none', expect(result.data).toEqual(conditionObj); }); - test('rejects both', () => { + it('rejects both', () => { const conditionObj = { ...testContractConditionObj, standardContractType, @@ -123,7 +123,7 @@ test('accepts either standardContractType or functionAbi but not both or none', }); }); - test('rejects none', () => { + it('rejects none', () => { const conditionObj = { ...testContractConditionObj, standardContractType: undefined, @@ -144,7 +144,7 @@ test('accepts either standardContractType or functionAbi but not both or none', }); }); -test('supports custom function abi', () => { +describe('supports custom function abi', () => { const contractConditionObj: ContractConditionProps = { ...testContractConditionObj, standardContractType: undefined, @@ -167,7 +167,7 @@ test('supports custom function abi', () => { await initialize(); }); - test('accepts custom function abi with a custom parameter', async () => { + it('accepts custom function abi with a custom parameter', async () => { const asJson = await conditionExpr .buildContext(fakeProvider(), {}, fakeSigner()) .withCustomParams(customParams) @@ -178,7 +178,7 @@ test('supports custom function abi', () => { expect(asJson).toContain(myCustomParam); }); - test.each([ + it.each([ { method: 'balanceOf', functionAbi: { @@ -217,7 +217,7 @@ test('supports custom function abi', () => { expect(result.data?.functionAbi).toEqual(functionAbi); }); - test.each([ + it.each([ { method: '1234', badField: 'name', diff --git a/packages/shared/test/conditions/base/rpc.test.ts b/packages/shared/test/conditions/base/rpc.test.ts index aa5954611..89d782184 100644 --- a/packages/shared/test/conditions/base/rpc.test.ts +++ b/packages/shared/test/conditions/base/rpc.test.ts @@ -1,11 +1,11 @@ import { testRpcConditionObj } from '@nucypher/test-utils'; -import { expect, test } from 'vitest'; +import { describe, expect, it } from 'vitest'; import { RpcCondition } from '../../../src'; import { rpcConditionSchema } from '../../../src/conditions/base/rpc'; -test('validation', () => { - test('accepts on a valid schema', () => { +describe('validation', () => { + it('accepts on a valid schema', () => { const result = RpcCondition.validate( rpcConditionSchema, testRpcConditionObj, @@ -15,7 +15,7 @@ test('validation', () => { expect(result.data).toEqual(testRpcConditionObj); }); - test('rejects an invalid schema', () => { + it('rejects an invalid schema', () => { const badRpcObj = { ...testRpcConditionObj, // Intentionally replacing `method` with an invalid method diff --git a/packages/shared/test/conditions/base/time.test.ts b/packages/shared/test/conditions/base/time.test.ts index 1ea55bbe7..e0b434551 100644 --- a/packages/shared/test/conditions/base/time.test.ts +++ b/packages/shared/test/conditions/base/time.test.ts @@ -1,4 +1,4 @@ -import { expect, test } from 'vitest'; +import { describe, expect, it } from 'vitest'; import { ReturnValueTestProps, @@ -11,14 +11,14 @@ import { TimeConditionType, } from '../../../src/conditions/base/time'; -test('validation', () => { +describe('validation', () => { const returnValueTest: ReturnValueTestProps = { index: 0, comparator: '>', value: '100', }; - test('accepts a valid schema', () => { + it('accepts a valid schema', () => { const conditionObj: TimeConditionProps = { conditionType: TimeConditionType, returnValueTest, @@ -31,7 +31,7 @@ test('validation', () => { expect(result.data).toEqual(conditionObj); }); - test('rejects an invalid schema', () => { + it('rejects an invalid schema', () => { const badObj = { conditionType: TimeConditionType, // Intentionally replacing `returnValueTest` with an invalid test diff --git a/packages/shared/test/conditions/compound-condition.test.ts b/packages/shared/test/conditions/compound-condition.test.ts index 2535d88fc..8d5e8feea 100644 --- a/packages/shared/test/conditions/compound-condition.test.ts +++ b/packages/shared/test/conditions/compound-condition.test.ts @@ -3,16 +3,16 @@ import { testRpcConditionObj, testTimeConditionObj, } from '@nucypher/test-utils'; -import {describe, expect, test} from 'vitest'; +import { describe, expect, it } from 'vitest'; -import {CompoundCondition, Condition} from '../../src'; +import { CompoundCondition, Condition } from '../../src'; import { compoundConditionSchema, CompoundConditionType, } from '../../src/conditions/compound-condition'; describe('validation', () => { - test('accepts or operator', () => { + it('accepts or operator', () => { const conditionObj = { operator: 'or', operands: [testContractConditionObj, testTimeConditionObj], @@ -26,7 +26,7 @@ describe('validation', () => { }); }); - test('accepts and operator', () => { + it('accepts and operator', () => { const conditionObj = { operator: 'and', operands: [testContractConditionObj, testTimeConditionObj], @@ -43,7 +43,7 @@ describe('validation', () => { }); }); - test('rejects an invalid operator', () => { + it('rejects an invalid operator', () => { const result = CompoundCondition.validate(compoundConditionSchema, { operator: 'not-an-operator', operands: [testRpcConditionObj, testTimeConditionObj], @@ -60,7 +60,7 @@ describe('validation', () => { }); }); - test('rejects invalid number of operands = 0', () => { + it('rejects invalid number of operands = 0', () => { const result = CompoundCondition.validate(compoundConditionSchema, { operator: 'or', operands: [], @@ -75,7 +75,7 @@ describe('validation', () => { }); }); - test('rejects invalid number of operands = 1', () => { + it('rejects invalid number of operands = 1', () => { const result = CompoundCondition.validate(compoundConditionSchema, { operator: 'or', operands: [testRpcConditionObj], @@ -89,7 +89,7 @@ describe('validation', () => { }); }); - test('accepts recursive compound conditions', () => { + it('accepts recursive compound conditions', () => { const conditionObj = { operator: 'and', operands: [ @@ -126,14 +126,13 @@ describe('validation', () => { const multichainCondition = { conditionType: 'compound', operator: 'and', - operands: [1, 137, 5, 80001].map((chain) => ( - { - ...testRpcConditionObj, - chain, - })), + operands: [1, 137, 5, 80001].map((chain) => ({ + ...testRpcConditionObj, + chain, + })), }; - test('accepts on a valid multichain condition schema', () => { + it('accepts on a valid multichain condition schema', () => { const result = CompoundCondition.validate( compoundConditionSchema, multichainCondition, @@ -143,7 +142,7 @@ describe('validation', () => { expect(result.data).toEqual(multichainCondition); }); - test('rejects an invalid multichain condition schema', () => { + it('rejects an invalid multichain condition schema', () => { const badMultichainCondition = { ...multichainCondition, operands: [ diff --git a/packages/shared/test/conditions/condition-expr.test.ts b/packages/shared/test/conditions/condition-expr.test.ts index 018a5d603..101b1d024 100644 --- a/packages/shared/test/conditions/condition-expr.test.ts +++ b/packages/shared/test/conditions/condition-expr.test.ts @@ -8,7 +8,7 @@ import { testTimeConditionObj, } from '@nucypher/test-utils'; import { SemVer } from 'semver'; -import { expect, test } from 'vitest'; +import { beforeAll, describe, expect, it } from 'vitest'; import { CompoundCondition, @@ -16,6 +16,7 @@ import { ContractCondition, ContractConditionProps, ERC721Balance, + initialize, objectEquals, RpcCondition, RpcConditionType, @@ -25,7 +26,7 @@ import { } from '../../src'; import { USER_ADDRESS_PARAM } from '../../src/conditions/const'; -test('condition set', () => { +describe('condition set', () => { const erc721BalanceCondition = new ERC721Balance({ chain: TEST_CHAIN_ID, contractAddress: TEST_CONTRACT_ADDR, @@ -65,10 +66,14 @@ test('condition set', () => { ], }); - test('equality', () => { + beforeAll(async () => { + await initialize(); + }); + + describe('equality', () => { const conditionExprCurrentVersion = new ConditionExpression(rpcCondition); - test('same version and condition', () => { + it('same version and condition', () => { const conditionExprSameCurrentVersion = new ConditionExpression( rpcCondition, ConditionExpression.VERSION, @@ -78,7 +83,7 @@ test('condition set', () => { ).toBeTruthy(); }); - test('different minor/patch version but same condition', () => { + it('different minor/patch version but same condition', () => { const conditionExprOlderMinorVersion = new ConditionExpression( rpcCondition, '0.1.0', @@ -98,7 +103,7 @@ test('condition set', () => { ).not.toBeTruthy(); }); - test('minor/patch number greater than major; still older', () => { + it('minor/patch number greater than major; still older', () => { const conditionExprOlderMinorVersion = new ConditionExpression( rpcCondition, '0.9.0', @@ -135,7 +140,7 @@ test('condition set', () => { ).not.toBeTruthy(); }); - test.each([ + it.each([ erc721BalanceCondition, contractConditionNoAbi, contractConditionWithAbi, @@ -151,7 +156,7 @@ test('condition set', () => { ).not.toBeTruthy(); }); - test('same contract condition although using erc721 helper', () => { + it('same contract condition although using erc721 helper', () => { const erc721ConditionExpr = new ConditionExpression( erc721BalanceCondition, ); @@ -169,8 +174,8 @@ test('condition set', () => { }); }); - test('serialization / deserialization', () => { - test.each([ + describe('serialization / deserialization', () => { + it.each([ erc721BalanceCondition, contractConditionNoAbi, contractConditionWithAbi, @@ -198,14 +203,14 @@ test('condition set', () => { expect(fromWasmConditions.equals(conditionExprFromJson)).toBeTruthy(); }); - test('serializes to and from WASM conditions', () => { + it('serializes to and from WASM conditions', () => { const conditionExpr = new ConditionExpression(erc721BalanceCondition); const wasmConditions = conditionExpr.toWASMConditions(); const fromWasm = ConditionExpression.fromWASMConditions(wasmConditions); expect(conditionExpr.equals(fromWasm)).toBeTruthy(); }); - test('incompatible version', () => { + it('incompatible version', () => { const currentVersion = new SemVer(ConditionExpression.VERSION); const invalidVersion = currentVersion.inc('major'); expect(() => { @@ -218,7 +223,7 @@ test('condition set', () => { ); }); - test.each(['version', 'x.y', 'x.y.z', '-1,0.0', '1.0.0.0.0.0.0'])( + it.each(['version', 'x.y', 'x.y.z', '-1,0.0', '1.0.0.0.0.0.0'])( 'invalid versions', (invalidVersion) => { expect(() => { @@ -230,7 +235,7 @@ test('condition set', () => { }, ); - test.each(['_invalid_condition_type_', undefined as unknown as string])( + it.each(['_invalid_condition_type_', undefined as unknown as string])( 'rejects an invalid condition type', (invalidConditionType) => { const conditionObj = { @@ -246,7 +251,7 @@ test('condition set', () => { }, ); - test('rejects a mismatched condition type', () => { + it('rejects a mismatched condition type', () => { const conditionObj = { ...testTimeConditionObj, conditionType: RpcConditionType, @@ -259,7 +264,7 @@ test('condition set', () => { }).toThrow(/^Invalid condition/); }); - test('erc721 condition serialization', () => { + it('erc721 condition serialization', () => { const conditionExpr = new ConditionExpression(erc721BalanceCondition); const erc721BalanceConditionObj = erc721BalanceCondition.toObj(); @@ -287,7 +292,7 @@ test('condition set', () => { expect(conditionExprFromJson.condition).toBeInstanceOf(ContractCondition); }); - test('contract condition no abi serialization', () => { + it('contract condition no abi serialization', () => { const conditionExpr = new ConditionExpression(contractConditionNoAbi); const conditionExprJson = conditionExpr.toJson(); @@ -319,7 +324,7 @@ test('condition set', () => { expect(conditionExprFromJson.condition).toBeInstanceOf(ContractCondition); }); - test('contract condition with abi serialization', () => { + it('contract condition with abi serialization', () => { const conditionExpr = new ConditionExpression(contractConditionWithAbi); const conditionExprJson = conditionExpr.toJson(); @@ -352,7 +357,7 @@ test('condition set', () => { expect(conditionExprFromJson.condition).toBeInstanceOf(ContractCondition); }); - test('time condition serialization', () => { + it('time condition serialization', () => { const conditionExpr = new ConditionExpression(timeCondition); const conditionExprJson = conditionExpr.toJson(); @@ -375,7 +380,7 @@ test('condition set', () => { expect(conditionExprFromJson.condition).toBeInstanceOf(TimeCondition); }); - test('rpc condition serialization', () => { + it('rpc condition serialization', () => { const conditionExpr = new ConditionExpression(rpcCondition); const conditionExprJson = conditionExpr.toJson(); @@ -399,7 +404,7 @@ test('condition set', () => { expect(conditionExprFromJson.condition).toBeInstanceOf(RpcCondition); }); - test('compound condition serialization', () => { + it('compound condition serialization', () => { const conditionExpr = new ConditionExpression(compoundCondition); const compoundConditionObj = compoundCondition.toObj(); diff --git a/packages/shared/test/conditions/context.test.ts b/packages/shared/test/conditions/context.test.ts index 53352e874..b8ed8084a 100644 --- a/packages/shared/test/conditions/context.test.ts +++ b/packages/shared/test/conditions/context.test.ts @@ -7,7 +7,7 @@ import { testRpcConditionObj, } from '@nucypher/test-utils'; import { ethers } from 'ethers'; -import { beforeAll, expect, test } from 'vitest'; +import { beforeAll, describe, expect, it } from 'vitest'; import { ConditionExpression, @@ -19,7 +19,7 @@ import { import { USER_ADDRESS_PARAM } from '../../src/conditions/const'; import { RESERVED_CONTEXT_PARAMS } from '../../src/conditions/context/context'; -test('context', () => { +describe('context', () => { let provider: ethers.providers.Provider; let signer: ethers.Signer; @@ -29,8 +29,8 @@ test('context', () => { signer = fakeSigner(); }); - test('serialization', () => { - test('serializes to json', async () => { + describe('serialization', () => { + it('serializes to json', async () => { const rpcCondition = new RpcCondition({ ...testRpcConditionObj, parameters: [USER_ADDRESS_PARAM], @@ -44,12 +44,13 @@ test('context', () => { rpcCondition, ).buildContext(provider, {}, signer); const asJson = await conditionContext.toJson(); + expect(asJson).toBeDefined(); expect(asJson).toContain(USER_ADDRESS_PARAM); }); }); - test('context parameters', () => { + describe('context parameters', () => { const customParamKey = ':customParam'; const customParams: Record = {}; customParams[customParamKey] = 1234; @@ -65,8 +66,8 @@ test('context', () => { const conditionExpr = new ConditionExpression(contractCondition); const conditionContext = conditionExpr.buildContext(provider, {}, signer); - test('return value test', () => { - test('accepts on a custom context parameters', async () => { + describe('return value test', () => { + it('accepts on a custom context parameters', async () => { const asObj = await conditionContext .withCustomParams(customParams) .toObj(); @@ -74,14 +75,14 @@ test('context', () => { expect(asObj[customParamKey]).toEqual(1234); }); - test('rejects on a missing custom context parameter', async () => { + it('rejects on a missing custom context parameter', async () => { await expect(conditionContext.toObj()).rejects.toThrow( `Missing custom context parameter(s): ${customParamKey}`, ); }); }); - test('rejects on using reserved context parameter', () => { + it('rejects on using reserved context parameter', () => { const badCustomParams: Record = {}; RESERVED_CONTEXT_PARAMS.forEach((reservedParam) => { badCustomParams[reservedParam] = 'this-will-throw'; @@ -93,7 +94,7 @@ test('context', () => { }); }); - test('detects if a signer is required', () => { + it('detects if a signer is required', () => { const conditionObj = { ...testContractConditionObj, returnValueTest: { @@ -110,7 +111,7 @@ test('context', () => { ); }); - test('detects if a signer is not required', () => { + it('detects if a signer is not required', () => { const condition = new RpcCondition(testRpcConditionObj); const conditionExpr = new ConditionExpression(condition); expect( @@ -121,7 +122,7 @@ test('context', () => { expect(conditionExpr.buildContext(provider, {})).toBeDefined(); }); - test('rejects on a missing signer', () => { + it('rejects on a missing signer', () => { const conditionObj = { ...testContractConditionObj, returnValueTest: { @@ -137,7 +138,7 @@ test('context', () => { ); }); - test('rejects on a missing signer', () => { + it('rejects on a missing signer', () => { const conditionObj = { ...testContractConditionObj, returnValueTest: { @@ -153,7 +154,7 @@ test('context', () => { ); }); - test('custom method parameters', () => { + describe('custom method parameters', () => { const contractConditionObj = { ...testContractConditionObj, standardContractType: undefined, // We're going to use a custom function ABI @@ -165,7 +166,7 @@ test('context', () => { }, }; - test('rejects on a missing parameter ', async () => { + it('rejects on a missing parameter ', async () => { const customContractCondition = new ContractCondition({ ...contractConditionObj, parameters: [USER_ADDRESS_PARAM, customParamKey], @@ -179,7 +180,7 @@ test('context', () => { ); }); - test('accepts on a hard-coded parameter', async () => { + it('accepts on a hard-coded parameter', async () => { const customContractCondition = new ContractCondition({ ...contractConditionObj, parameters: [USER_ADDRESS_PARAM, 100], diff --git a/packages/taco/package.json b/packages/taco/package.json index a86b84f8b..2ca82fcd4 100644 --- a/packages/taco/package.json +++ b/packages/taco/package.json @@ -38,11 +38,12 @@ "typedoc": "typedoc" }, "dependencies": { - "@nucypher/nucypher-core": "0.13.0-alpha.0", + "@nucypher/nucypher-core": "0.13.0-alpha.1", "@nucypher/shared": "workspace:*" }, "devDependencies": { - "@nucypher/test-utils": "workspace:*" + "@nucypher/test-utils": "workspace:*", + "vitest": "^0.34.4" }, "peerDependencies": { "ethers": "^5.7.2" diff --git a/packages/taco/test/cbd-strategy.test.ts b/packages/taco/test/cbd-strategy.test.ts deleted file mode 100644 index d17033402..000000000 --- a/packages/taco/test/cbd-strategy.test.ts +++ /dev/null @@ -1,189 +0,0 @@ -import { - FerveoVariant, - SecretKey, - SessionStaticSecret, -} from '@nucypher/nucypher-core'; -import { - aliceSecretKeyBytes, - fakeDkgFlow, - fakeDkgRitual, - fakeProvider, - fakeSigner, - fakeTDecFlow, - fakeUrsulas, - makeCohort, - mockCbdDecrypt, - mockDkgParticipants, - mockGetParticipants, - mockGetRitual, - mockGetUrsulas, - mockRandomSessionStaticSecret, -} from '@nucypher/test-utils'; -import { ethers } from 'ethers'; -import { afterEach, beforeAll, expect, test, vi } from 'vitest'; - -import { - CbdStrategy, - conditions, - DeployedCbdStrategy, - initialize, - ThresholdDecrypter, - toBytes, -} from '../src'; - -// Shared test variables -const ownsNFT = new conditions.ERC721Ownership({ - contractAddress: '0x1e988ba4692e52Bc50b375bcC8585b95c48AaD77', - parameters: [3591], - chain: 5, -}); -const conditionExpr = new conditions.ConditionExpression(ownsNFT); -const ritualId = 0; - -const makeCbdStrategy = async () => { - const ursulas = fakeUrsulas(); - const cohort = await makeCohort(ursulas); - const strategy = CbdStrategy.create(cohort); - expect(strategy.cohort).toEqual(cohort); - return strategy; -}; - -async function makeDeployedCbdStrategy() { - const ursulas = fakeUrsulas(); - const provider = fakeProvider(); - const strategy = await makeCbdStrategy(); - const mockedDkg = fakeDkgFlow(FerveoVariant.precomputed, 0, 4, 4); - const mockedDkgRitual = fakeDkgRitual(mockedDkg); - const getUrsulasSpy = mockGetUrsulas(ursulas); - const getExistingRitualSpy = mockGetRitual(mockedDkgRitual); - - const deployedStrategy = await strategy.deploy(provider, ritualId); - - expect(getUrsulasSpy).toHaveBeenCalled(); - expect(getExistingRitualSpy).toHaveBeenCalled(); - - return { mockedDkg, deployedStrategy }; -} - -test('cbd strategy', () => { - let secretKey; - let provider: ethers.providers.Provider; - let signer: ethers.Signer; - - beforeAll(async () => { - await initialize(); - secretKey = SecretKey.fromBEBytes(aliceSecretKeyBytes); - provider = fakeProvider(secretKey.toBEBytes()); - signer = fakeSigner(secretKey.toBEBytes()); - }); - - test('CbdStrategy', () => { - afterEach(() => { - vi.restoreAllMocks(); - }); - - test('creates a strategy', async () => { - await makeCbdStrategy(); - }); - - test('can deploy and return a CbdDeployedStrategy', async () => { - await makeDeployedCbdStrategy(); - }); - - test('serialization', () => { - test('serializes to a plain object', async () => { - const strategy = await makeCbdStrategy(); - const asObj = strategy.toObj(); - const fromObj = CbdStrategy.fromObj(asObj); - expect(fromObj.equals(strategy)).toBeTruthy(); - }); - - test('serializes to a JSON', async () => { - const strategy = await makeCbdStrategy(); - const asJson = strategy.toJSON(); - const fromJson = CbdStrategy.fromJSON(asJson); - expect(fromJson.equals(strategy)).toBeTruthy(); - }); - }); - }); - - test('CbdDeployedStrategy', () => { - afterEach(() => { - vi.restoreAllMocks(); - }); - - test('can encrypt and decrypt', async () => { - const { mockedDkg, deployedStrategy } = await makeDeployedCbdStrategy(); - - const message = 'this is a secret'; - const thresholdMessageKit = deployedStrategy - .makeEncrypter(conditionExpr) - .encryptMessageCbd(message); - - // Setup mocks for `retrieveAndDecrypt` - const { decryptionShares } = fakeTDecFlow({ - ...mockedDkg, - message: toBytes(message), - dkgPublicKey: mockedDkg.dkg.publicKey(), - thresholdMessageKit, - }); - const { participantSecrets, participants } = mockDkgParticipants( - mockedDkg.ritualId, - ); - const requesterSessionKey = SessionStaticSecret.random(); - const decryptSpy = mockCbdDecrypt( - mockedDkg.ritualId, - decryptionShares, - participantSecrets, - requesterSessionKey.publicKey(), - ); - const getParticipantsSpy = mockGetParticipants(participants); - const getUrsulasSpy = mockGetUrsulas(); - const sessionKeySpy = mockRandomSessionStaticSecret(requesterSessionKey); - - const decryptedMessage = - await deployedStrategy.decrypter.retrieveAndDecrypt( - provider, - thresholdMessageKit, - signer, - ); - expect(getUrsulasSpy).toHaveBeenCalled(); - expect(getParticipantsSpy).toHaveBeenCalled(); - expect(sessionKeySpy).toHaveBeenCalled(); - expect(decryptSpy).toHaveBeenCalled(); - expect(decryptedMessage).toEqual(toBytes(message)); - }); - - test('serialization', () => { - test('serializes to a plaintext object', async () => { - const { deployedStrategy } = await makeDeployedCbdStrategy(); - const asJson = deployedStrategy.toJSON(); - const fromJson = DeployedCbdStrategy.fromJSON(asJson); - expect(fromJson.equals(deployedStrategy)).toBeTruthy(); - }); - - test('serializes to a JSON', async () => { - const { deployedStrategy } = await makeDeployedCbdStrategy(); - const asJson = deployedStrategy.toJSON(); - const fromJson = DeployedCbdStrategy.fromJSON(asJson); - expect(fromJson.equals(deployedStrategy)).toBeTruthy(); - }); - }); - }); - - test('ThresholdDecrypter', () => { - test('serializes to a plain object', async () => { - const { deployedStrategy } = await makeDeployedCbdStrategy(); - const configObj = deployedStrategy.decrypter.toObj(); - const fromObj = ThresholdDecrypter.fromObj(configObj); - expect(fromObj.equals(deployedStrategy.decrypter)).toBeTruthy(); - }); - - test('serializes to a JSON', async () => { - const { deployedStrategy } = await makeDeployedCbdStrategy(); - const configJSON = deployedStrategy.decrypter.toJSON(); - const fromJSON = ThresholdDecrypter.fromJSON(configJSON); - expect(fromJSON.equals(deployedStrategy.decrypter)).toBeTruthy(); - }); - }); -}); diff --git a/packages/taco/test/dkg-client.test.ts b/packages/taco/test/dkg-client.test.ts index ea8ee5a24..035e09d88 100644 --- a/packages/taco/test/dkg-client.test.ts +++ b/packages/taco/test/dkg-client.test.ts @@ -1,41 +1,32 @@ -import { - fakeProvider, - mockCoordinatorRitual, - mockDkgParticipants, - mockGetParticipants, - mockRitualId, -} from '@nucypher/test-utils'; -import { afterEach, expect, test, vi } from 'vitest'; +import { DkgCoordinatorAgent } from '@nucypher/shared'; +import { fakeProvider, mockGetParticipants } from '@nucypher/test-utils'; +import { beforeAll, describe, expect, it } from 'vitest'; -import { DkgCoordinatorAgent, SecretKey } from '../src'; +import { initialize } from '../src'; -vi.mock('../../src/contracts/agents/coordinator', () => ({ - DkgCoordinatorAgent: { - getRitual: () => Promise.resolve(mockCoordinatorRitual(mockRitualId)), - getParticipants: () => Promise.resolve(mockDkgParticipants(mockRitualId)), - }, -})); +import { fakeRitualId, mockDkgParticipants, mockGetRitual } from './test-utils'; -test('DkgCoordinatorAgent', () => { - afterEach(() => { - vi.restoreAllMocks(); +describe('DkgCoordinatorAgent', () => { + beforeAll(async () => { + await initialize(); }); - test('fetches transcripts from the coordinator', async () => { - const provider = fakeProvider(SecretKey.random().toBEBytes()); - const ritual = await DkgCoordinatorAgent.getRitual(provider, mockRitualId); + it('fetches transcripts from the coordinator', async () => { + const provider = fakeProvider(); + const getRitualSpy = mockGetRitual(); + const ritual = await DkgCoordinatorAgent.getRitual(provider, fakeRitualId); expect(ritual).toBeDefined(); + expect(getRitualSpy).toHaveBeenCalled(); }); - test('fetches participants from the coordinator', async () => { - const provider = fakeProvider(SecretKey.random().toBEBytes()); - const fakeParticipants = await mockDkgParticipants(mockRitualId); + it('fetches participants from the coordinator', async () => { + const provider = fakeProvider(); const getParticipantsSpy = mockGetParticipants( - fakeParticipants.participants, + mockDkgParticipants(fakeRitualId).participants, ); const participants = await DkgCoordinatorAgent.getParticipants( provider, - mockRitualId, + fakeRitualId, ); expect(getParticipantsSpy).toHaveBeenCalled(); expect(participants.length).toBeGreaterThan(0); @@ -43,8 +34,8 @@ test('DkgCoordinatorAgent', () => { }); // TODO: Fix this test after the DkgClient.verifyRitual() method is implemented -// test('DkgClient', () => { -// test('verifies the dkg ritual', async () => { +// describe('DkgClient', () => { +// it('verifies the dkg ritual', async () => { // const provider = fakeWeb3Provider(SecretKey.random().toBEBytes()); // // const dkgClient = new DkgClient(provider); diff --git a/packages/taco/test/docs.test..ts b/packages/taco/test/docs.test..ts deleted file mode 100644 index 26ecc0006..000000000 --- a/packages/taco/test/docs.test..ts +++ /dev/null @@ -1,126 +0,0 @@ -import { - fakeProvider, - fakeUrsulas, - mockDetectEthereumProvider, - mockEncryptTreasureMap, - mockGenerateKFrags, - mockGetUrsulas, - mockMakeTreasureMap, - mockPublishToBlockchain, - mockRetrieveAndDecrypt, -} from '@nucypher/test-utils'; -import { providers } from 'ethers'; -import { beforeAll, expect, test, vi } from 'vitest'; - -import { - CbdStrategy, - Cohort, - ConditionExpression, - ContractCondition, - ContractConditionProps, - ERC721Ownership, - getPorterUri, - initialize, - SecretKey, - toBytes, -} from '../src'; - -test('doc tests', async () => { - beforeAll(async () => { - await initialize(); - }); - - test('runs get started example', async () => { - const detectEthereumProvider = mockDetectEthereumProvider(); - const getUrsulasSpy = mockGetUrsulas(); - const generateKFragsSpy = mockGenerateKFrags(); - const publishToBlockchainSpy = mockPublishToBlockchain(); - const makeTreasureMapSpy = mockMakeTreasureMap(); - const encryptTreasureMapSpy = mockEncryptTreasureMap(); - - vi.spyOn(providers, 'Web3Provider').mockImplementation(() => - fakeProvider(SecretKey.random().toBEBytes()), - ); - - // - // Start of the code example - // - - // 2. Build a Cohort - const porterUri = getPorterUri('tapir'); - const numUrsulas = 5; - const newCohort = await Cohort.create(porterUri, numUrsulas); - - // 3. Specify default conditions - const NFTOwnership = new ERC721Ownership({ - contractAddress: '0xBC4CA0EdA7647A8aB7C2061c2E118A18a936f13D', - chain: 5, // Tapir network uses Görli testnet - parameters: [5954], - }); - - const conditions = new ConditionExpression( - NFTOwnership, - // Other conditions can be added here - ); - - // 4. Build a Strategy - const newStrategy = CbdStrategy.create(newCohort); - - const MMprovider = await detectEthereumProvider(); - const mumbai = providers.getNetwork(80001); - - const provider = new providers.Web3Provider(MMprovider, mumbai); - const signer = provider.getSigner(); - const newDeployed = await newStrategy.deploy(provider, signer, 'test'); - - // 5. Encrypt the plaintext & update conditions - const NFTBalanceConfig: ContractConditionProps = { - conditionType: 'contract', - contractAddress: '0xBC4CA0EdA7647A8aB7C2061c2E118A18a936f13D', - standardContractType: 'ERC721', - chain: 5, - method: 'balanceOf', - parameters: [':userAddress'], - returnValueTest: { - comparator: '>=', - value: 3, - }, - }; - const NFTBalance = new ContractCondition(NFTBalanceConfig); - const newConditions = new ConditionExpression(NFTBalance); - const plaintext = 'this is a secret'; - const encrypter = newDeployed.makeEncrypter(newConditions); - const encryptedMessageKit = encrypter.encryptMessagePre(plaintext); - - // Mocking - Not a part of any code example - const retrieveCFragsSpy = mockRetrieveAndDecrypt( - makeTreasureMapSpy, - encryptedMessageKit, - ); - - // 6. Request decryption rights - const decryptedMessage = await newDeployed.decrypter.retrieveAndDecrypt( - provider, - signer, - [encryptedMessageKit], - ); - - // - // End of the code example - // - - const expectedAddresses = fakeUrsulas().map((u) => u.checksumAddress); - const condObj = conditions.condition.toObj(); - expect(newCohort.ursulaAddresses).toEqual(expectedAddresses); - expect(condObj.parameters).toEqual([5954]); - expect(condObj.chain).toEqual(NFTBalanceConfig.chain); - expect(condObj.contractAddress).toEqual(NFTBalanceConfig.contractAddress); - expect(publishToBlockchainSpy).toHaveBeenCalled(); - expect(getUrsulasSpy).toHaveBeenCalledTimes(2); - expect(generateKFragsSpy).toHaveBeenCalled(); - expect(encryptTreasureMapSpy).toHaveBeenCalled(); - expect(makeTreasureMapSpy).toHaveBeenCalled(); - expect(retrieveCFragsSpy).toHaveBeenCalled(); - expect(decryptedMessage[0]).toEqual(toBytes(plaintext)); - }); -}); diff --git a/packages/taco/test/ritual.test.ts b/packages/taco/test/ritual.test.ts index 71fbb2109..572aa657c 100644 --- a/packages/taco/test/ritual.test.ts +++ b/packages/taco/test/ritual.test.ts @@ -1,8 +1,7 @@ import { DkgPublicKey } from '@nucypher/nucypher-core'; +import { fromHexString } from '@nucypher/shared'; import { expect, test } from 'vitest'; -import { fromHexString } from '../src'; - test('Ritual', () => { test('deserializes pre-made dkg ritual', async () => { const pkWord1 = fromHexString( diff --git a/packages/taco/test/taco.test.ts b/packages/taco/test/taco.test.ts index e72fe55e0..468c719b5 100644 --- a/packages/taco/test/taco.test.ts +++ b/packages/taco/test/taco.test.ts @@ -1,28 +1,27 @@ -import { - FerveoVariant, - initialize, - SessionStaticSecret, -} from '@nucypher/nucypher-core'; +import { FerveoVariant, SessionStaticSecret } from '@nucypher/nucypher-core'; import { aliceSecretKeyBytes, fakeDkgFlow, - fakeDkgRitual, fakePorterUri, fakeProvider, fakeSigner, fakeTDecFlow, mockCbdDecrypt, - mockDkgParticipants, - mockGetFinalizedRitualSpy, mockGetParticipants, mockGetRitualIdFromPublicKey, - mockRandomSessionStaticSecret, } from '@nucypher/test-utils'; -import { beforeAll, expect, test } from 'vitest'; +import { expect, test } from 'vitest'; import * as taco from '../src'; import { conditions, toBytes } from '../src'; +import { + fakeDkgRitual, + mockDkgParticipants, + mockGetFinalizedRitualSpy, + mockMakeSessionKey, +} from './test-utils'; + // Shared test variables const message = 'this is a secret'; const ownsNFT = new conditions.ERC721Ownership({ @@ -32,10 +31,6 @@ const ownsNFT = new conditions.ERC721Ownership({ }); test('taco', () => { - beforeAll(async () => { - await initialize(); - }); - test('encrypts and decrypts', async () => { const mockedDkg = fakeDkgFlow(FerveoVariant.precomputed, 0, 4, 4); const mockedDkgRitual = fakeDkgRitual(mockedDkg); @@ -68,7 +63,7 @@ test('taco', () => { requesterSessionKey.publicKey(), ); const getParticipantsSpy = mockGetParticipants(participants); - const sessionKeySpy = mockRandomSessionStaticSecret(requesterSessionKey); + const sessionKeySpy = mockMakeSessionKey(requesterSessionKey); const getRitualIdFromPublicKey = mockGetRitualIdFromPublicKey( mockedDkg.ritualId, ); diff --git a/packages/taco/test/test-utils.ts b/packages/taco/test/test-utils.ts index 563ff804c..742e9bb99 100644 --- a/packages/taco/test/test-utils.ts +++ b/packages/taco/test/test-utils.ts @@ -18,6 +18,7 @@ import { } from '@nucypher/nucypher-core'; import { ConditionExpression, + DkgCoordinatorAgent, DkgParticipant, DkgRitualState, toBytes, @@ -86,9 +87,9 @@ export const fakeDkgTDecFlowE2E: ( }; }; -export const mockCoordinatorRitual = async ( +export const fakeCoordinatorRitual = ( ritualId: number, -): Promise<{ +): { aggregationMismatch: boolean; initTimestamp: number; aggregatedTranscriptHash: string; @@ -100,8 +101,8 @@ export const mockCoordinatorRitual = async ( aggregatedTranscript: string; publicKeyHash: string; totalAggregations: number; -}> => { - const ritual = await fakeDkgTDecFlowE2E(); +} => { + const ritual = fakeDkgTDecFlowE2E(); const dkgPkBytes = ritual.dkg.publicKey().toBytes(); return { id: ritualId, @@ -152,7 +153,7 @@ export const mockDkgParticipants = ( return { participantSecrets, participants }; }; -export const mockRitualId = 0; +export const fakeRitualId = 0; export const fakeDkgRitual = (ritual: { dkg: Dkg; @@ -160,7 +161,7 @@ export const fakeDkgRitual = (ritual: { threshold: number; }) => { return new DkgRitual( - mockRitualId, + fakeRitualId, ritual.dkg.publicKey(), ritual.sharesNum, ritual.threshold, @@ -168,10 +169,15 @@ export const fakeDkgRitual = (ritual: { ); }; -export const mockGetRitual = (dkgRitual: DkgRitual): SpyInstance => { - return vi.spyOn(DkgClient, 'getRitual').mockImplementation(() => { - return Promise.resolve(dkgRitual); - }); +export const mockGetRitual = (dkgRitual?: DkgRitual): SpyInstance => { + const { dkg, threshold, sharesNum } = fakeDkgTDecFlowE2E(); + return vi + .spyOn(DkgCoordinatorAgent, 'getRitual') + .mockImplementation(async () => { + return Promise.resolve( + dkgRitual ?? fakeDkgRitual({ dkg, threshold, sharesNum }), + ); + }); }; export const mockGetFinalizedRitualSpy = ( @@ -181,3 +187,9 @@ export const mockGetFinalizedRitualSpy = ( return Promise.resolve(dkgRitual); }); }; + +export const mockMakeSessionKey = (secret: SessionStaticSecret) => { + return vi + .spyOn(SessionStaticSecret, 'random') + .mockImplementation(() => secret); +}; diff --git a/packages/taco/tsconfig.json b/packages/taco/tsconfig.json index 8d2d7c3d7..aacfbec2c 100644 --- a/packages/taco/tsconfig.json +++ b/packages/taco/tsconfig.json @@ -4,5 +4,10 @@ "compilerOptions": { "esModuleInterop": true, "skipLibCheck": true, - } + }, + "references": [ + { + "path": "../shared/tsconfig.es.json" + } + ] } diff --git a/packages/test-utils/package.json b/packages/test-utils/package.json index aa455b298..fa2dfe2e6 100644 --- a/packages/test-utils/package.json +++ b/packages/test-utils/package.json @@ -10,27 +10,30 @@ "author": "Piotr Roslaniec ", "exports": { ".": { - "import": "./dist/index.js", - "require": "./dist/index.js" + "import": "./dist/es/index.js", + "require": "./dist/cjs/index.js" } }, - "main": "./dist/index.js", - "module": "./dist/index.js", - "types": "./dist/index.d.ts", + "main": "./dist/cjs/index.js", + "module": "./dist/es/index.js", + "types": "./dist/cjs/index.d.ts", "files": [ - "dist/**/*" + "dist" ], "scripts": { - "build": "tsc --build ./tsconfig.build.json --verbose", + "build": "pnpm build:module && pnpm build:cjs", + "build:cjs": "tsc --build ./tsconfig.cjs.json --verbose", + "build:module": "tsc --build ./tsconfig.es.json --verbose", "exports:lint": "ts-unused-exports tsconfig.json --ignoreFiles src/index.ts", "lint": "eslint --ext .ts src", "lint:fix": "pnpm lint --fix" }, "dependencies": { - "@nucypher/nucypher-core": "0.13.0-alpha.0", + "@nucypher/nucypher-core": "0.13.0-alpha.1", "@nucypher/shared": "workspace:*", "axios": "^1.5.0", - "ethers": "^5.7.2" + "ethers": "^5.7.2", + "vitest": "^0.34.4" }, "devDependencies": { "@typechain/ethers-v5": "^11.1.1", diff --git a/packages/test-utils/src/utils.ts b/packages/test-utils/src/utils.ts index 48a919165..839756d00 100644 --- a/packages/test-utils/src/utils.ts +++ b/packages/test-utils/src/utils.ts @@ -112,9 +112,7 @@ export const fakeUrsulas = (n = 4): Ursula[] => uri: `https://example.${i}.com:9151`, })); -export const mockGetUrsulas = ( - ursulas: Ursula[] = fakeUrsulas(), -): SpyInstance => { +export const mockGetUrsulas = (ursulas: Ursula[] = fakeUrsulas()) => { const fakePorterUrsulas = ( mockUrsulas: readonly Ursula[], ): GetUrsulasResult => { @@ -353,7 +351,7 @@ export const makeCohort = async (ursulas: Ursula[] = fakeUrsulas()) => { return cohort; }; -const mockRetrieveAndDecrypt = ( +export const mockRetrieveAndDecrypt = ( makeTreasureMapSpy: SpyInstance, encryptedMessageKit: MessageKit, ) => { diff --git a/packages/test-utils/tsconfig.build.json b/packages/test-utils/tsconfig.build.json deleted file mode 100644 index dedc2a266..000000000 --- a/packages/test-utils/tsconfig.build.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "extends": "./tsconfig.json", - "include": ["src"], - "compilerOptions": { - "outDir": "dist", - "rootDir": "src" - }, - "references": [ - { - "path": "../shared/tsconfig.es.json" - } - ] -} diff --git a/packages/test-utils/tsconfig.cjs.json b/packages/test-utils/tsconfig.cjs.json new file mode 100644 index 000000000..035a2ab62 --- /dev/null +++ b/packages/test-utils/tsconfig.cjs.json @@ -0,0 +1,7 @@ +{ + "extends": "./tsconfig.es.json", + "compilerOptions": { + "outDir": "dist/cjs", + "module": "CommonJS", + } +} diff --git a/packages/test-utils/tsconfig.es.json b/packages/test-utils/tsconfig.es.json new file mode 100644 index 000000000..2ffa9192c --- /dev/null +++ b/packages/test-utils/tsconfig.es.json @@ -0,0 +1,10 @@ +{ + "extends": "./tsconfig.json", + "include": ["src"], + "compilerOptions": { + "outDir": "dist/es", + "rootDir": "src", + "module": "ES2022", + "target": "ES2022" + } +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 189ffa434..76603fe8d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -13,6 +13,10 @@ overrides: importers: .: + dependencies: + '@nucypher/nucypher-core': + specifier: 0.13.0-alpha.1 + version: 0.13.0-alpha.1 devDependencies: '@skypack/package-check': specifier: ^0.2.2 @@ -301,8 +305,8 @@ importers: packages/pre: dependencies: '@nucypher/nucypher-core': - specifier: 0.13.0-alpha.0 - version: 0.13.0-alpha.0 + specifier: /home/piotr/Documents/projects/nucypher/nucypher-core/nucypher-core-wasm-bundler/dist + version: link:../../../nucypher-core/nucypher-core-wasm-bundler/dist '@nucypher/shared': specifier: workspace:* version: link:../shared @@ -313,6 +317,9 @@ importers: '@nucypher/test-utils': specifier: workspace:* version: link:../test-utils + vitest: + specifier: ^0.34.4 + version: 0.34.4 packages/shared: dependencies: @@ -326,8 +333,8 @@ importers: specifier: ^5.7.2 version: 5.7.2 '@nucypher/nucypher-core': - specifier: 0.13.0-alpha.0 - version: 0.13.0-alpha.0 + specifier: 0.13.0-alpha.1 + version: 0.13.0-alpha.1 axios: specifier: ^1.5.0 version: 1.5.0 @@ -371,12 +378,15 @@ importers: typechain: specifier: ^8.3.1 version: 8.3.1(typescript@5.2.2) + vitest: + specifier: ^0.34.4 + version: 0.34.4 packages/taco: dependencies: '@nucypher/nucypher-core': - specifier: 0.13.0-alpha.0 - version: 0.13.0-alpha.0 + specifier: 0.13.0-alpha.1 + version: 0.13.0-alpha.1 '@nucypher/shared': specifier: workspace:* version: link:../shared @@ -387,12 +397,15 @@ importers: '@nucypher/test-utils': specifier: workspace:* version: link:../test-utils + vitest: + specifier: ^0.34.4 + version: 0.34.4 packages/test-utils: dependencies: '@nucypher/nucypher-core': - specifier: 0.13.0-alpha.0 - version: 0.13.0-alpha.0 + specifier: 0.13.0-alpha.1 + version: 0.13.0-alpha.1 '@nucypher/shared': specifier: workspace:* version: link:../shared @@ -402,6 +415,9 @@ importers: ethers: specifier: ^5.7.2 version: 5.7.2 + vitest: + specifier: ^0.34.4 + version: 0.34.4 devDependencies: '@typechain/ethers-v5': specifier: ^11.1.1 @@ -696,11 +712,6 @@ packages: engines: {node: '>=6.9.0'} dev: true - /@babel/helper-validator-identifier@7.22.15: - resolution: {integrity: sha512-4E/F9IIEi8WR94324mbDUMo074YTheJmd7eZF5vITTeYchqAi6sYXRLHUVsmkdmY4QjfKTcB2jB7dVP3NaBElQ==} - engines: {node: '>=6.9.0'} - dev: true - /@babel/helper-validator-identifier@7.22.20: resolution: {integrity: sha512-Y4OZ+ytlatR8AI+8KZfKuL5urKp7qey08ha31L8b3BwewJAoJamTzyvxPR/5D+KkdJCGPq/+8TukHBlY10FX9A==} engines: {node: '>=6.9.0'} @@ -735,7 +746,7 @@ packages: resolution: {integrity: sha512-C/BaXcnnvBCmHTpz/VGZ8jgtE2aYlW4hxDhseJAWZb7gqGM/qtCK6iZUb0TyKFf7BOUsBH7Q7fkRsDRhg1XklQ==} engines: {node: '>=6.9.0'} dependencies: - '@babel/helper-validator-identifier': 7.22.15 + '@babel/helper-validator-identifier': 7.22.20 chalk: 2.4.2 js-tokens: 4.0.0 dev: true @@ -2144,7 +2155,6 @@ packages: cpu: [arm64] os: [android] requiresBuild: true - dev: true optional: true /@esbuild/android-arm@0.16.17: @@ -2162,7 +2172,6 @@ packages: cpu: [arm] os: [android] requiresBuild: true - dev: true optional: true /@esbuild/android-x64@0.16.17: @@ -2180,7 +2189,6 @@ packages: cpu: [x64] os: [android] requiresBuild: true - dev: true optional: true /@esbuild/darwin-arm64@0.16.17: @@ -2198,7 +2206,6 @@ packages: cpu: [arm64] os: [darwin] requiresBuild: true - dev: true optional: true /@esbuild/darwin-x64@0.16.17: @@ -2216,7 +2223,6 @@ packages: cpu: [x64] os: [darwin] requiresBuild: true - dev: true optional: true /@esbuild/freebsd-arm64@0.16.17: @@ -2234,7 +2240,6 @@ packages: cpu: [arm64] os: [freebsd] requiresBuild: true - dev: true optional: true /@esbuild/freebsd-x64@0.16.17: @@ -2252,7 +2257,6 @@ packages: cpu: [x64] os: [freebsd] requiresBuild: true - dev: true optional: true /@esbuild/linux-arm64@0.16.17: @@ -2270,7 +2274,6 @@ packages: cpu: [arm64] os: [linux] requiresBuild: true - dev: true optional: true /@esbuild/linux-arm@0.16.17: @@ -2288,7 +2291,6 @@ packages: cpu: [arm] os: [linux] requiresBuild: true - dev: true optional: true /@esbuild/linux-ia32@0.16.17: @@ -2306,7 +2308,6 @@ packages: cpu: [ia32] os: [linux] requiresBuild: true - dev: true optional: true /@esbuild/linux-loong64@0.16.17: @@ -2324,7 +2325,6 @@ packages: cpu: [loong64] os: [linux] requiresBuild: true - dev: true optional: true /@esbuild/linux-mips64el@0.16.17: @@ -2342,7 +2342,6 @@ packages: cpu: [mips64el] os: [linux] requiresBuild: true - dev: true optional: true /@esbuild/linux-ppc64@0.16.17: @@ -2360,7 +2359,6 @@ packages: cpu: [ppc64] os: [linux] requiresBuild: true - dev: true optional: true /@esbuild/linux-riscv64@0.16.17: @@ -2378,7 +2376,6 @@ packages: cpu: [riscv64] os: [linux] requiresBuild: true - dev: true optional: true /@esbuild/linux-s390x@0.16.17: @@ -2396,7 +2393,6 @@ packages: cpu: [s390x] os: [linux] requiresBuild: true - dev: true optional: true /@esbuild/linux-x64@0.16.17: @@ -2414,7 +2410,6 @@ packages: cpu: [x64] os: [linux] requiresBuild: true - dev: true optional: true /@esbuild/netbsd-x64@0.16.17: @@ -2432,7 +2427,6 @@ packages: cpu: [x64] os: [netbsd] requiresBuild: true - dev: true optional: true /@esbuild/openbsd-x64@0.16.17: @@ -2450,7 +2444,6 @@ packages: cpu: [x64] os: [openbsd] requiresBuild: true - dev: true optional: true /@esbuild/sunos-x64@0.16.17: @@ -2468,7 +2461,6 @@ packages: cpu: [x64] os: [sunos] requiresBuild: true - dev: true optional: true /@esbuild/win32-arm64@0.16.17: @@ -2486,7 +2478,6 @@ packages: cpu: [arm64] os: [win32] requiresBuild: true - dev: true optional: true /@esbuild/win32-ia32@0.16.17: @@ -2504,7 +2495,6 @@ packages: cpu: [ia32] os: [win32] requiresBuild: true - dev: true optional: true /@esbuild/win32-x64@0.16.17: @@ -2522,7 +2512,6 @@ packages: cpu: [x64] os: [win32] requiresBuild: true - dev: true optional: true /@eslint-community/eslint-utils@4.4.0(eslint@8.49.0): @@ -3031,7 +3020,6 @@ packages: engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} dependencies: '@sinclair/typebox': 0.27.8 - dev: true /@jest/source-map@27.5.1: resolution: {integrity: sha512-y9NIHUYF3PJRlHk98NdC/N1gl88BL08aQQgu4k4ZopQkCw9t9cV8mtl3TV8b/YCB8XaVTFrmUTAJvjsntDireg==} @@ -3148,7 +3136,6 @@ packages: /@jridgewell/sourcemap-codec@1.4.15: resolution: {integrity: sha512-eF2rxCRulEKXHTRiDrDy6erMYWqNw4LPdQ8UQA4huuxaQsVeRPFl2oM8oDGxMFhJUWZf9McpLtJasDDZb/Bpeg==} - dev: true /@jridgewell/trace-mapping@0.3.19: resolution: {integrity: sha512-kf37QtfW+Hwx/buWGMPcR60iF9ziHa6r/CZJIHbmcm4+0qrXiVdxegAH0F6yddEVQ7zdkjcGCgCzUu+BcbhQxw==} @@ -3283,8 +3270,8 @@ packages: '@nodelib/fs.scandir': 2.1.5 fastq: 1.15.0 - /@nucypher/nucypher-core@0.13.0-alpha.0: - resolution: {integrity: sha512-Nk+BE1iUY4m/ZHtbKRLJkAidXLLpwFmIbXBgS9qJMT1601dYFee/VvP0W6QoiSP9CirtZ730qtltuYb+MIzOfg==} + /@nucypher/nucypher-core@0.13.0-alpha.1: + resolution: {integrity: sha512-uKu/YLTZ6mqkQ2kaQMJs/USUiw9EYFtaZU6FaD8zAN8XKLpHYuYD13BDfU7idR1nZIKjL/E5xIoVJFV3Dx0x2w==} dev: false /@pmmmwh/react-refresh-webpack-plugin@0.5.11(react-refresh@0.11.0)(webpack-dev-server@4.15.1)(webpack@5.88.2): @@ -3390,7 +3377,6 @@ packages: /@sinclair/typebox@0.27.8: resolution: {integrity: sha512-+Fj43pSMwJs4KRrH/938Uf+uAELIgVBmQzg/q1YG10djyfA3TnrU8N8XzqCh/okZdszqBQTZf96idMfE5lnwTA==} - dev: true /@sinonjs/commons@1.8.6: resolution: {integrity: sha512-Ky+XkAkqPZSm3NLBeUng77EBQl3cmeJhITaGHdYH8kjVB+aun3S4XBRti2zt17mtt0mIUDiNxYeoJm6drVvBJQ==} @@ -3629,11 +3615,9 @@ packages: resolution: {integrity: sha512-frBecisrNGz+F4T6bcc+NLeolfiojh5FxW2klu669+8BARtyQv2C/GkNW6FUodVe4BroGMP/wER/YDGc7rEllw==} dependencies: '@types/chai': 4.3.6 - dev: true /@types/chai@4.3.6: resolution: {integrity: sha512-VOVRLM1mBxIRxydiViqPcKn6MIxZytrbMpd6RJLIWKxUNr3zux8no0Oc7kJx0WAPIitgZ0gkrDS+btlqQpubpw==} - dev: true /@types/connect-history-api-fallback@1.5.1: resolution: {integrity: sha512-iaQslNbARe8fctL5Lk+DsmgWOM83lM+7FzP0eQUJs1jd3kBE8NWqBTIT2S8SqQOJjxvt2eyIjpOuYeRXq2AdMw==} @@ -4181,7 +4165,6 @@ packages: '@vitest/spy': 0.34.4 '@vitest/utils': 0.34.4 chai: 4.3.8 - dev: true /@vitest/runner@0.34.4: resolution: {integrity: sha512-hwwdB1StERqUls8oV8YcpmTIpVeJMe4WgYuDongVzixl5hlYLT2G8afhcdADeDeqCaAmZcSgLTLtqkjPQF7x+w==} @@ -4189,7 +4172,6 @@ packages: '@vitest/utils': 0.34.4 p-limit: 4.0.0 pathe: 1.1.1 - dev: true /@vitest/snapshot@0.34.4: resolution: {integrity: sha512-GCsh4coc3YUSL/o+BPUo7lHQbzpdttTxL6f4q0jRx2qVGoYz/cyTRDJHbnwks6TILi6560bVWoBpYC10PuTLHw==} @@ -4197,13 +4179,11 @@ packages: magic-string: 0.30.3 pathe: 1.1.1 pretty-format: 29.7.0 - dev: true /@vitest/spy@0.34.4: resolution: {integrity: sha512-PNU+fd7DUPgA3Ya924b1qKuQkonAW6hL7YUjkON3wmBwSTIlhOSpy04SJ0NrRsEbrXgMMj6Morh04BMf8k+w0g==} dependencies: tinyspy: 2.1.1 - dev: true /@vitest/utils@0.34.4: resolution: {integrity: sha512-yR2+5CHhp/K4ySY0Qtd+CAL9f5Yh1aXrKfAT42bq6CtlGPh92jIDDDSg7ydlRow1CP+dys4TrOrbELOyNInHSg==} @@ -4211,7 +4191,6 @@ packages: diff-sequences: 29.6.3 loupe: 2.3.6 pretty-format: 29.7.0 - dev: true /@webassemblyjs/ast@1.11.6: resolution: {integrity: sha512-IN1xI7PwOvLPgjcf180gC1bqn3q/QaOCwYUahIOhbYUu8KA/3tw2RT/T0Gidi1l7Hhj5D/INhJxiICObqpMu4Q==} @@ -4409,7 +4388,6 @@ packages: /acorn-walk@8.2.0: resolution: {integrity: sha512-k+iyHEuPgSw6SbuDpGQM+06HQUa04DZ3o+F6CSzXMvvI5KMvnaEqXe+YVe555R9nn6GPt404fos4wcgpw12SDA==} engines: {node: '>=0.4.0'} - dev: true /acorn@7.4.1: resolution: {integrity: sha512-nQyp0o1/mNdbTO1PO6kHkwSrmgZ0MT/jCCpNiwbUjGoRN4dlBhqJtoQuCnEOKzgTVwg0ZWiCoQy6SxMebQVh8A==} @@ -4539,7 +4517,6 @@ packages: /ansi-styles@5.2.0: resolution: {integrity: sha512-Cxwpt2SfTzTtXcfOlzGEee8O+c+MmUgGrNiBcXnuWxuFJHe6a5Hz7qwhwe5OgaSYI0IJvkLqWX1ASG+cJOkEiA==} engines: {node: '>=10'} - dev: true /any-promise@1.3.0: resolution: {integrity: sha512-7UvmKalWRt1wgjL1RrGxoSJW/0QZFIegpeGvZG9kjp8vrRu55XTHbwnqq2GpXm9uLbcuhxm3IqX9OB4MZR1b2A==} @@ -4705,7 +4682,6 @@ packages: /assertion-error@1.1.0: resolution: {integrity: sha512-jgsaNduz+ndvGyFt3uSuWqvy4lCnIJiovtouQN5JZHOKCS2QuhEdbcQHFhVksz2N2U9hXJo8odG7ETyWlEeuDw==} - dev: true /ast-types-flow@0.0.7: resolution: {integrity: sha512-eBvWn1lvIApYMhzQMsu9ciLfkBY499mFZlNqG+/9WR7PVlroQw0vG30cOQQbaKz3sCEc44TAOu2ykzqXSNnwag==} @@ -5138,7 +5114,6 @@ packages: /cac@6.7.14: resolution: {integrity: sha512-b6Ilus+c3RrdDk+JhLKUAQfzzgLEPy6wcXqS7f/xe1EETvsDP6GORG7SFuOs6cID5YkqchW/LXZbX5bc8j7ZcQ==} engines: {node: '>=8'} - dev: true /cachedir@2.3.0: resolution: {integrity: sha512-A+Fezp4zxnit6FanDmv9EqXNAi3vt9DWp51/71UEhXukb7QUuvtv9344h91dyAxuTLoSYJFU299qzR3tzwPAhw==} @@ -5214,7 +5189,6 @@ packages: loupe: 2.3.6 pathval: 1.1.1 type-detect: 4.0.8 - dev: true /chalk@2.4.2: resolution: {integrity: sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==} @@ -5248,7 +5222,6 @@ packages: /check-error@1.0.2: resolution: {integrity: sha512-BrgHpW9NURQgzoNyjfq0Wu6VFO6D7IZEmJNdtgNqpzGG8RuNFHt2jQxWlAs4HMe119chBnv+34syEZtc6IhLtA==} - dev: true /check-types@11.2.3: resolution: {integrity: sha512-+67P1GkJRaxQD6PKK0Et9DhwQB+vGg3PM5+aavopCpZT1lj9jeqfvpgTLAWErNj8qApkkmXlu/Ug74kmhagkXg==} @@ -6169,7 +6142,6 @@ packages: engines: {node: '>=6'} dependencies: type-detect: 4.0.8 - dev: true /deep-equal@2.2.2: resolution: {integrity: sha512-xjVyBf0w5vH0I42jdAZzOKVldmPgSulmiyPRywoyq7HXC9qdgo17kxJE+rdnif5Tz6+pIrpJI8dCpMNLIGkUiA==} @@ -6316,7 +6288,6 @@ packages: /diff-sequences@29.6.3: resolution: {integrity: sha512-EjePK1srD3P08o2j4f0ExnylqRs5B9tJjcp9t1krH2qRi8CCdsYfwe9JgSLurFBWwq4uOlipzfk5fHNvwFKr8Q==} engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} - dev: true /diff@4.0.2: resolution: {integrity: sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==} @@ -6722,7 +6693,6 @@ packages: '@esbuild/win32-arm64': 0.18.20 '@esbuild/win32-ia32': 0.18.20 '@esbuild/win32-x64': 0.18.20 - dev: true /escalade@3.1.1: resolution: {integrity: sha512-k0er2gUkLf8O0zKJiAhmkTnJlTvINGv7ygDNPbeIsX/TJjGJZHuh9B2UxbsaEkmlEo9MfhrSzmhIlhRlI2GXnw==} @@ -7755,7 +7725,6 @@ packages: engines: {node: ^8.16.0 || ^10.6.0 || >=11.0.0} os: [darwin] requiresBuild: true - dev: true optional: true /function-bind@1.1.1: @@ -7785,7 +7754,6 @@ packages: /get-func-name@2.0.0: resolution: {integrity: sha512-Hm0ixYtaSZ/V7C8FJrtZIuBBI+iSgL+1Aq82zSu8VQNB4S3Gk8e7Qs3VwBDJAhmRZcFqkl3tQu36g/Foh5I5ig==} - dev: true /get-intrinsic@1.2.1: resolution: {integrity: sha512-2DcsyfABl+gVHEfCOaTrWgyt+tb6MSEGmKq+kI5HwLbIYgjgmMcV8KQ41uaKz1xxUcn9tJtgFbQUEVcEbd0FYw==} @@ -9459,7 +9427,6 @@ packages: /jsonc-parser@3.2.0: resolution: {integrity: sha512-gfFQZrcTc8CnKXp6Y4/CBT3fTc0OVuDofpre4aEeEpSBPV5X5v4+Vmx+8snU7RLPrNHPKSgLxGo9YuQzz20o+w==} - dev: true /jsonfile@4.0.0: resolution: {integrity: sha512-m6F1R3z8jjlf2imQHS2Qez5sjKWQzbuuhuJ/FKYFRZvPE3PuHcSMVZzfsLhGVOkfd20obL5SWEBew5ShlquNxg==} @@ -9603,7 +9570,6 @@ packages: /local-pkg@0.4.3: resolution: {integrity: sha512-SFppqq5p42fe2qcZQqqEOiVRXl+WCP1MdT6k7BDEW1j++sp5fIY+/fdRQitvKgB5BrBcmrs5m/L0v2FrU5MY1g==} engines: {node: '>=14'} - dev: true /locate-path@2.0.0: resolution: {integrity: sha512-NCI2kiDkyR7VeEKm27Kda/iQHyKJe1Bu0FlTbYp3CqJu+9IFe9bLyAjMxf5ZDDbEg+iMPzB5zYyUTSm8wVTKmA==} @@ -9709,7 +9675,6 @@ packages: resolution: {integrity: sha512-RaPMZKiMy8/JruncMU5Bt6na1eftNoo++R4Y+N2FrxkDVTrGvcyzFTsaGif4QTeKESheMGegbhw6iUAq+5A8zA==} dependencies: get-func-name: 2.0.0 - dev: true /lower-case@2.0.2: resolution: {integrity: sha512-7fm3l3NAF9WfN6W3JOmf5drwpVqX78JtoGJ3A6W0a6ZnldM41w2fV5D490psKFTpMds8TJse/eHLFFsNHHjHgg==} @@ -9744,7 +9709,6 @@ packages: engines: {node: '>=12'} dependencies: '@jridgewell/sourcemap-codec': 1.4.15 - dev: true /make-dir@3.1.0: resolution: {integrity: sha512-g3FeP20LNwhALb/6Cz6Dd4F2ngze0jz7tbzrD2wAV+o9FeNHe4rL+yK2md0J/fiSf1sa1ADhXqi5+oVwOM/eGw==} @@ -9953,7 +9917,6 @@ packages: pathe: 1.1.1 pkg-types: 1.0.3 ufo: 1.3.0 - dev: true /modify-values@1.0.1: resolution: {integrity: sha512-xV2bxeN6F7oYjZWTe/YPAy6MN2M+sL4u/Rlm2AHCIVGfo2p1yGmBHQ6vHehl4bRTZBdHu3TSkWdYgkwpYzAGSw==} @@ -10333,7 +10296,6 @@ packages: engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} dependencies: yocto-queue: 1.0.0 - dev: true /p-locate@2.0.0: resolution: {integrity: sha512-nQja7m7gSKuewoVRen45CtVfODR3crN3goVQ0DDZ9N3yHxgpkuBhZqsaiotSQRrADUrne346peY7kT3TSACykg==} @@ -10474,11 +10436,9 @@ packages: /pathe@1.1.1: resolution: {integrity: sha512-d+RQGp0MAYTIaDBIMmOfMwz3E+LOZnxx1HZd5R18mmCZY0QBlK0LDZfPc8FW8Ed2DlvsuE6PRjroDY+wg4+j/Q==} - dev: true /pathval@1.1.1: resolution: {integrity: sha512-Dp6zGqpTdETdR63lehJYPeIOqpiNBNtc7BpWSLrOje7UaIsE5aY92r/AunQA7rsXvet3lrJ3JnZX29UPTKXyKQ==} - dev: true /performance-now@2.1.0: resolution: {integrity: sha512-7EAHlyLHI56VEIdK57uwHdHKIaAGbnXPiw0yWbarQZOKaKpvUIgW0jWRVLiatnM+XXlSwsanIBH/hzGMJulMow==} @@ -10541,7 +10501,6 @@ packages: jsonc-parser: 3.2.0 mlly: 1.4.2 pathe: 1.1.1 - dev: true /pkg-up@3.1.0: resolution: {integrity: sha512-nDywThFk1i4BQK4twPQ6TA4RT8bDY96yeuCVBWL3ePARCiEKDRSrNGbFIgUJpLp+XeIR65v8ra7WuJOFUBtkMA==} @@ -11335,7 +11294,6 @@ packages: nanoid: 3.3.6 picocolors: 1.0.0 source-map-js: 1.0.2 - dev: true /prelude-ls@1.1.2: resolution: {integrity: sha512-ESF23V4SKG6lVSGZgYNpbsiaAkdab6ZgOxe52p7+Kid3W3u3bxR4Vfd/o21dmN7jSt0IwgZ4v5MUd26FEtXE9w==} @@ -11415,7 +11373,6 @@ packages: '@jest/schemas': 29.6.3 ansi-styles: 5.2.0 react-is: 18.2.0 - dev: true /process-nextick-args@2.0.1: resolution: {integrity: sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==} @@ -11600,7 +11557,6 @@ packages: /react-is@18.2.0: resolution: {integrity: sha512-xWGDIW6x921xtzPkhiULtthJHoJvBbF3q26fzloPCK0hsvxtPVelvftw3zjbHWSkR2km9Z+4uxbDDK/6Zw9B8w==} - dev: true /react-refresh@0.11.0: resolution: {integrity: sha512-F27qZr8uUqwhWZboondsPx8tnC3Ct3SxZA3V5WyEvujRyyNv0VYPhoBg1gZ8/MV5tubQp76Trw8lTv9hzRBa+A==} @@ -12039,7 +11995,6 @@ packages: hasBin: true optionalDependencies: fsevents: 2.3.3 - dev: true /run-async@2.4.1: resolution: {integrity: sha512-tvVnVv01b8c1RrA6Ep7JkStj85Guv/YrMcwqYQnwjsAS2cTmmPGBBjAjpCW7RrSodNSoE2/qg9O4bceNvUuDgQ==} @@ -12324,7 +12279,6 @@ packages: /siginfo@2.0.0: resolution: {integrity: sha512-ybx0WO1/8bSBLEWXZvEd7gMW3Sn3JFlW3TvX1nREbDLRNQNaeNN8WK0meBwPdAaOI7TtRRRJn/Es1zhrrCHu7g==} - dev: true /signal-exit@3.0.7: resolution: {integrity: sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==} @@ -12495,7 +12449,6 @@ packages: /stackback@0.0.2: resolution: {integrity: sha512-1XMJE5fQo1jGH6Y/7ebnwPOBEkIEnT4QF32d5R1+VXdXveM0IBMJt8zfaxX1P3QhVwrYe+576+jkANtSS2mBbw==} - dev: true /stackframe@1.3.4: resolution: {integrity: sha512-oeVtt7eWQS+Na6F//S4kJ2K2VbRlS9D43mAlMyVpVWovy9o+jfgH8O9agzANzaiLjclA0oYzUXEM4PurhSUChw==} @@ -12540,7 +12493,6 @@ packages: /std-env@3.4.3: resolution: {integrity: sha512-f9aPhy8fYBuMN+sNfakZV18U39PbalgjXG3lLB9WkaYTxijru61wb57V9wxxNthXM5Sd88ETBWi29qLAsHO52Q==} - dev: true /stop-iteration-iterator@1.0.0: resolution: {integrity: sha512-iCGQj+0l0HOdZ2AEeBADlsRC+vsnDsZsbdSiH1yNSjcfKM7fdpCMfqAL/dwF5BLiw/XhRft/Wax6zQbhq2BcjQ==} @@ -12704,7 +12656,6 @@ packages: resolution: {integrity: sha512-PugKzOsyXpArk0yWmUwqOZecSO0GH0bPoctLcqNDH9J04pVW3lflYE0ujElBGTloevcxF5MofAOZ7C5l2b+wLg==} dependencies: acorn: 8.10.0 - dev: true /strip-outer@1.0.1: resolution: {integrity: sha512-k55yxKHwaXnpYGsOzg4Vl8+tDrWylxDEpknGjhTiZB8dFRU5rTo9CAzeycivxV3s+zlTKwrs6WxMxR95n26kwg==} @@ -13004,17 +12955,14 @@ packages: /tinybench@2.5.1: resolution: {integrity: sha512-65NKvSuAVDP/n4CqH+a9w2kTlLReS9vhsAP06MWx+/89nMinJyB2icyl58RIcqCmIggpojIGeuJGhjU1aGMBSg==} - dev: true /tinypool@0.7.0: resolution: {integrity: sha512-zSYNUlYSMhJ6Zdou4cJwo/p7w5nmAH17GRfU/ui3ctvjXFErXXkruT4MWW6poDeXgCaIBlGLrfU6TbTXxyGMww==} engines: {node: '>=14.0.0'} - dev: true /tinyspy@2.1.1: resolution: {integrity: sha512-XPJL2uSzcOyBMky6OFrusqWlzfFrXtE0hPuMgW8A2HmaqrPo4ZQHRN/V0QXN3FSjKxpsbRrFc5LI7KOwBsT1/w==} engines: {node: '>=14.0.0'} - dev: true /tmp@0.0.33: resolution: {integrity: sha512-jRCJlojKnZ3addtTOjdIqoRuPEKBvNXcGYqzO6zWZX8KfKEpnGY5jfggJQ3EjKuu8D4bJRr0y+cYJFmYbImXGw==} @@ -13215,7 +13163,6 @@ packages: /type-detect@4.0.8: resolution: {integrity: sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==} engines: {node: '>=4'} - dev: true /type-fest@0.16.0: resolution: {integrity: sha512-eaBzG6MxNzEn9kiwvtre90cXaNLkmadMWa1zQMs3XORCXNbsH/OewwbxC5ia9dCxIxnTAsSxXJaa/p5y8DlvJg==} @@ -13381,7 +13328,6 @@ packages: /ufo@1.3.0: resolution: {integrity: sha512-bRn3CsoojyNStCZe0BG0Mt4Nr/4KF+rhFlnNXybgqt5pXHNFRlqinSoQaTrGyzE4X8aHplSb+TorH+COin9Yxw==} - dev: true /uglify-js@3.17.4: resolution: {integrity: sha512-T9q82TJI9e/C1TAxYvfb16xO120tMVFZrGA3f9/P4424DNu6ypK103y0GPFVa17yotwSyZW5iYXgjYHkGrJW/g==} @@ -13566,7 +13512,6 @@ packages: - sugarss - supports-color - terser - dev: true /vite@4.4.9(@types/node@20.6.3): resolution: {integrity: sha512-2mbUn2LlUmNASWwSCNSJ/EG2HuSRTnVNaydp6vMCm5VIqJsjMfbIWtbH2kDuwUVW5mMUKKZvGPX/rqeqVvv1XA==} @@ -13602,7 +13547,6 @@ packages: rollup: 3.29.1 optionalDependencies: fsevents: 2.3.3 - dev: true /vitest@0.34.4: resolution: {integrity: sha512-SE/laOsB6995QlbSE6BtkpXDeVNLJc1u2LHRG/OpnN4RsRzM3GQm4nm3PQCK5OBtrsUqnhzLdnT7se3aeNGdlw==} @@ -13667,7 +13611,6 @@ packages: - sugarss - supports-color - terser - dev: true /vscode-oniguruma@1.7.0: resolution: {integrity: sha512-L9WMGRfrjOhgHSdOYgCt/yRMsXzLDJSL7BPrOZt73gU0iWO4mpqzqQzOz5srxqTvMBaR0XZTSrVWo4j55Rc6cA==} @@ -14022,7 +13965,6 @@ packages: dependencies: siginfo: 2.0.0 stackback: 0.0.2 - dev: true /wildcard@2.0.1: resolution: {integrity: sha512-CC1bOL87PIWSBhDcTrdeLo6eGT7mCFtrg0uIJtqJUFyK+eJnzl8A1niH56uu7KMa5XFrtiV+AQuHO3n7DsHnLQ==} @@ -14320,7 +14262,6 @@ packages: /yocto-queue@1.0.0: resolution: {integrity: sha512-9bnSc/HEW2uRy67wc+T8UwauLuPJVn28jb+GtJY16iiKWyvmYJRXVT4UamsAEGQfPohgr2q4Tq0sQbQlxTfi1g==} engines: {node: '>=12.20'} - dev: true /yup@0.32.11: resolution: {integrity: sha512-Z2Fe1bn+eLstG8DRR6FTavGD+MeAwyfmouhHsIUgaADz8jvFKbO/fXc2trJKZg+5EBjh4gGm3iU/t3onKlXHIg==} diff --git a/tsconfig.prod.json b/tsconfig.prod.json index e24d55b62..c54331bde 100644 --- a/tsconfig.prod.json +++ b/tsconfig.prod.json @@ -32,7 +32,10 @@ "path": "./packages/taco/tsconfig.cjs.json" }, { - "path": "./packages/test-utils/tsconfig.build.json" + "path": "./packages/test-utils/tsconfig.es.json" + }, + { + "path": "./packages/test-utils/tsconfig.cjs.json" } ] } diff --git a/vitest.config.ts b/vitest.config.ts index 99356159d..2b146dac4 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -3,7 +3,7 @@ import { defineConfig } from 'vitest/config'; export default defineConfig({ test: { root: __dirname, - environment: 'node', + environment: 'jsdom', coverage: { enabled: true, reporter: ['text', 'html', 'lcov', 'clover'],