Skip to content

Commit

Permalink
chore: fix vitest test config
Browse files Browse the repository at this point in the history
  • Loading branch information
piotr-roslaniec committed Sep 28, 2023
1 parent e5db5f3 commit b4e1570
Show file tree
Hide file tree
Showing 34 changed files with 285 additions and 690 deletions.
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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\"",
Expand All @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion packages/pre/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"typedoc": "typedoc"
},
"dependencies": {
"@nucypher/nucypher-core": "0.13.0-alpha.0",
"@nucypher/nucypher-core": "0.13.0-alpha.1",
"@nucypher/shared": "workspace:*"
},
"devDependencies": {
Expand Down
44 changes: 20 additions & 24 deletions packages/pre/test/acceptance/alice-grants.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down Expand Up @@ -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,
Expand All @@ -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);

Expand Down
19 changes: 8 additions & 11 deletions packages/pre/test/acceptance/delay-enact.test.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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();
Expand Down
27 changes: 16 additions & 11 deletions packages/pre/test/docs.test.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,41 @@
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,
SecretKey,
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();
Expand Down
20 changes: 9 additions & 11 deletions packages/pre/test/pre-strategy.test.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,32 @@
import { SecretKey, VerifiedKeyFrag } from '@nucypher/nucypher-core';
import { Ursula } from '@nucypher/shared';
import {
aliceSecretKeyBytes,
bobSecretKeyBytes,
fakeProvider,
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',
Expand Down Expand Up @@ -76,10 +78,6 @@ const makeDeployedPreStrategy = async () => {
};

test('pre strategy', () => {
beforeAll(async () => {
await initialize();
});

test('PreStrategy', () => {
afterEach(() => {
vi.restoreAllMocks();
Expand Down
27 changes: 9 additions & 18 deletions packages/pre/test/pre.test.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -32,7 +24,6 @@ test('proxy reencryption', () => {

test('verifies capsule frags', async () => {
beforeAll(async () => {
await initialize();
bob = fakeBob();
alice = fakeAlice();
});
Expand Down
11 changes: 3 additions & 8 deletions packages/pre/test/test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
9 changes: 7 additions & 2 deletions packages/pre/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
"include": ["src", "test"],
"compilerOptions": {
"esModuleInterop": true,
"skipLibCheck": true,
}
"skipLibCheck": true
},
"references": [
{
"path": "../test-utils/tsconfig.es.json"
}
]
}
5 changes: 3 additions & 2 deletions packages/shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
10 changes: 5 additions & 5 deletions packages/shared/test/cohort.test.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
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();
const fromObj = Cohort.fromObj(asObj);
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();
Expand Down
Loading

0 comments on commit b4e1570

Please sign in to comment.