-
Notifications
You must be signed in to change notification settings - Fork 81
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
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
}); | ||
it('cannot get Address From PrivateKey if the private key is wrong', () => { | ||
|
@@ -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', () => { | ||
|
@@ -65,7 +63,6 @@ describe('Utils/EcUtils', () => { | |
rawId.privateKey, | ||
'0xfd6201dabdd4d7177f7c3baba47c5533b12f0a8127ab5d8c71d831fa4df2b19f', | ||
); | ||
// 'sign() error' | ||
expect(signature).toBe( | ||
'0xdf4d49c7c01e00a970378e5a400dd4168aed6c43a1c510b124026467c78a3566048549c6ab5e0f618e2939c518e9fbe52e07836d4cb07fa44186fa3ffe3b3b981b', | ||
); | ||
|
@@ -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', () => { | ||
|
@@ -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); | ||
}); | ||
|
||
|
@@ -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', | ||
); | ||
|
@@ -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', | ||
|
@@ -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, | ||
|
@@ -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, | ||
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) |
||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.There was a problem hiding this comment.
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)