-
Notifications
You must be signed in to change notification settings - Fork 29
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
Improve Test Coverage for packages/web3-wallet/src #464
Open
NueloSE
wants to merge
5
commits into
alephium:master
Choose a base branch
from
NueloSE:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b2c774e
Improve Test Coverage for packages/web3-wallet/src
NueloSE f2d034a
fix
NueloSE dad3095
Merge branch 'alephium:master' into master
NueloSE fccf620
Update password-crypto.test.ts
NueloSE 1652f39
Update privatekey-wallet.test.ts
NueloSE 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
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 |
---|---|---|
|
@@ -19,12 +19,77 @@ along with the library. If not, see <http://www.gnu.org/licenses/>. | |
import { web3 } from '@alephium/web3' | ||
import { PrivateKeyWallet } from './privatekey-wallet' | ||
|
||
describe('privatekey wallet', () => { | ||
it('test the length of private key', () => { | ||
describe('PrivateKeyWallet', () => { | ||
beforeAll(() => { | ||
// Set the node provider before running the tests | ||
web3.setCurrentNodeProvider('http://127.0.0.1:22973') | ||
}) | ||
|
||
it('should generate a private key of correct length', () => { | ||
for (let i = 0; i < 100; i++) { | ||
const wallet = PrivateKeyWallet.Random() | ||
expect(wallet.privateKey.length).toEqual(64) | ||
} | ||
}) | ||
|
||
it('should generate unique private keys', () => { | ||
const wallets = new Set<string>() | ||
for (let i = 0; i < 100; i++) { | ||
const wallet = PrivateKeyWallet.Random() | ||
wallets.add(wallet.privateKey) | ||
} | ||
expect(wallets.size).toEqual(100) | ||
}) | ||
|
||
it('should generate a wallet with valid address and public key', () => { | ||
const wallet = PrivateKeyWallet.Random() | ||
expect(wallet.address).toBeDefined() | ||
expect(wallet.publicKey).toBeDefined() | ||
expect(wallet.address.length).toBeGreaterThan(0) | ||
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. Lets verify the exact length of |
||
expect(wallet.publicKey.length).toBeGreaterThan(0) | ||
}) | ||
|
||
it('should correctly sign raw data', async () => { | ||
const wallet = PrivateKeyWallet.Random() | ||
const hexString = 'deadbeef' | ||
const signature = await wallet.signRaw(wallet.address, hexString) | ||
|
||
expect(signature).toBeDefined() | ||
expect(typeof signature).toBe('string') | ||
// Optionally add more checks to validate the signature | ||
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. Please verify if the signature is valid, we can use the |
||
}) | ||
|
||
it('should throw an error if signing with an incorrect address', async () => { | ||
const wallet = PrivateKeyWallet.Random() | ||
const hexString = 'deadbeef' | ||
|
||
await expect(wallet.signRaw('invalid-address', hexString)).rejects.toThrow('Unmatched signer address') | ||
}) | ||
|
||
it('should create a wallet from a mnemonic', () => { | ||
const mnemonic = 'test test test test test test test test test test test junk' | ||
const wallet = PrivateKeyWallet.FromMnemonic({ mnemonic }) | ||
|
||
expect(wallet.privateKey).toBeDefined() | ||
expect(wallet.publicKey).toBeDefined() | ||
expect(wallet.address).toBeDefined() | ||
}) | ||
|
||
it('should create a wallet with a specific group from a mnemonic', () => { | ||
const mnemonic = 'test test test test test test test test test test test junk' | ||
const targetGroup = 1 | ||
const wallet = PrivateKeyWallet.FromMnemonicWithGroup(mnemonic, targetGroup) | ||
|
||
expect(wallet.group).toEqual(targetGroup) | ||
expect(wallet.privateKey).toBeDefined() | ||
expect(wallet.publicKey).toBeDefined() | ||
expect(wallet.address).toBeDefined() | ||
}) | ||
|
||
it('should generate a wallet with the correct target group', () => { | ||
const targetGroup = 3 | ||
const wallet = PrivateKeyWallet.Random(targetGroup) | ||
|
||
expect(wallet.group).toEqual(targetGroup) | ||
}) | ||
}) |
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.
I'd be happy with
500_000
since this single test takes 700ms (on CI it could be twice as much) and it would add up a lot in the big picture, I guess that supporting 0.5MB messages is enough