Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(utils): remove duplicates #1239

Merged
merged 4 commits into from
Nov 14, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 5 additions & 24 deletions packages/utils/test/crypto/ec-utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ describe('Utils/EcUtils', () => {
describe('getAddressFromPrivateKey', () => {
it('can get Address From PrivateKey', () => {
const identity = getAddressFromPrivateKey(rawId.privateKey);
// 'getAddressFromPrivateKey() error'
expect(identity).toBe(rawId.address);
Copy link
Member Author

@alexandre-abrioux alexandre-abrioux Nov 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those comments were messages displayed in case of a failure back when we were still using mocha instead of jest, they were placed as the second argument in the expect, see #283. They can be removed, at least for happy-path tests, they can be confusing.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed them for failure tests too, see #1239 (comment)

});
it('cannot get Address From PrivateKey if the private key is wrong', () => {
Expand All @@ -48,7 +47,6 @@ describe('Utils/EcUtils', () => {
describe('getAddressFromPublicKey', () => {
it('can get Address From Public Key', () => {
const identity = getAddressFromPublicKey(rawId.publicKey);
// 'getAddressFromPublicKey() error'
expect(identity).toBe(rawId.address);
});
it('cannot get Address From Public Key if the Public key is wrong', () => {
Expand All @@ -65,7 +63,6 @@ describe('Utils/EcUtils', () => {
rawId.privateKey,
'0xfd6201dabdd4d7177f7c3baba47c5533b12f0a8127ab5d8c71d831fa4df2b19f',
);
// 'sign() error'
expect(signature).toBe(
'0xdf4d49c7c01e00a970378e5a400dd4168aed6c43a1c510b124026467c78a3566048549c6ab5e0f618e2939c518e9fbe52e07836d4cb07fa44186fa3ffe3b3b981b',
);
Expand All @@ -84,7 +81,6 @@ describe('Utils/EcUtils', () => {
'0xdf4d49c7c01e00a970378e5a400dd4168aed6c43a1c510b124026467c78a3566048549c6ab5e0f618e2939c518e9fbe52e07836d4cb07fa44186fa3ffe3b3b981b',
'0xfd6201dabdd4d7177f7c3baba47c5533b12f0a8127ab5d8c71d831fa4df2b19f',
);
// 'recover() error'
expect(id).toEqual(rawId.address);
});
it('cannot recover address from signature if signature is not well formatted', () => {
Expand All @@ -98,9 +94,7 @@ describe('Utils/EcUtils', () => {
describe('encrypt', () => {
it('can encrypt', async () => {
const encryptedData = await ecEncrypt(rawId.publicKey, anyData);
// 'encrypt() error'
expect(encryptedData.length).toBe(226);
// 'decrypt() error'
expect(await ecDecrypt(rawId.privateKey, encryptedData)).toBe(anyData);
});

Expand All @@ -113,6 +107,7 @@ describe('Utils/EcUtils', () => {
});

it('cannot encrypt data with a wrong public key', async () => {
// 'encrypt() error'
await expect(ecEncrypt('cf4a', anyData)).rejects.toThrowError(
'The public key must be a string representing 64 bytes',
);
Expand All @@ -125,11 +120,11 @@ describe('Utils/EcUtils', () => {
rawId.privateKey,
'307bac038efaa5bf8a0ac8db53fd4de8024a0c0baf37283a9e6671589eba18edc12b3915ff0df66e6ffad862440228a65ead99e3320e50aa90008961e3d68acc35b314e98020e3280bf4ce4258419dbb775185e60b43e7b88038a776a9322ff7cb3e886b2d92060cff2951ef3beedcc70a',
);
// 'decrypt() error'
expect(data).toBe(anyData);
});

it('cannot decrypt data with a wrong private key', async () => {
// 'decrypt() error'
await expect(
ecDecrypt(
'0xaa',
Expand All @@ -139,12 +134,14 @@ describe('Utils/EcUtils', () => {
});

it('cannot decrypt data with a wrong encrypted data: public key too short', async () => {
// 'decrypt() error'
await expect(ecDecrypt(rawId.privateKey, 'aa')).rejects.toThrowError(
'The encrypted data is not well formatted',
);
});

it('cannot decrypt data with a wrong encrypted data: public key not parsable', async () => {
// 'decrypt() error'
await expect(
ecDecrypt(
rawId.privateKey,
Expand All @@ -154,6 +151,7 @@ describe('Utils/EcUtils', () => {
});

it('cannot decrypt data with a wrong encrypted data: bad MAC', async () => {
// 'decrypt() error'
await expect(
ecDecrypt(
rawId.privateKey,
Expand All @@ -173,21 +171,4 @@ describe('Utils/EcUtils', () => {
}
});
});

it('can encrypt()', async () => {
const encryptedData = await ecEncrypt(rawId.publicKey, anyData);
// 'encrypt() error'
expect(encryptedData.length).toBe(226);
// 'decrypt() error'
expect(await ecDecrypt(rawId.privateKey, encryptedData)).toBe(anyData);
});

it('can decrypt()', async () => {
const data = await ecDecrypt(
rawId.privateKey,
'307bac038efaa5bf8a0ac8db53fd4de8024a0c0baf37283a9e6671589eba18edc12b3915ff0df66e6ffad862440228a65ead99e3320e50aa90008961e3d68acc35b314e98020e3280bf4ce4258419dbb775185e60b43e7b88038a776a9322ff7cb3e886b2d92060cff2951ef3beedcc70a',
);
// 'decrypt() error'
expect(data).toBe(anyData);
});
Comment on lines -177 to -192
Copy link
Member Author

@alexandre-abrioux alexandre-abrioux Nov 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those two tests are duplicates see above lines 95 and 118 (from the new line numbers)

});
Loading