-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
99 additions
and
3 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
src/background/services/secrets/utils/getAccountPrivateKeyFromMnemonic.test.ts
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { getAccountPrivateKeyFromMnemonic } from './getAccountPrivateKeyFromMnemonic'; | ||
import { | ||
DerivationPath, | ||
getWalletFromMnemonic, | ||
} from '@avalabs/core-wallets-sdk'; | ||
|
||
jest.mock('@avalabs/core-wallets-sdk', () => ({ | ||
...jest.requireActual('@avalabs/core-wallets-sdk'), | ||
getWalletFromMnemonic: jest.fn(() => ({ path: 'path', privateKey: '0xASD' })), | ||
})); | ||
describe('getAccountPrivateKeyFromMnemonic(', () => { | ||
it('should throw an error because the signer is falsy', async () => { | ||
(getWalletFromMnemonic as jest.Mock).mockReturnValueOnce(undefined); | ||
try { | ||
getAccountPrivateKeyFromMnemonic('random', 0, DerivationPath.BIP44); | ||
} catch (e) { | ||
expect(e).toEqual(new Error('The requested path is missing')); | ||
} | ||
}); | ||
it('should return with a privateKey', () => { | ||
const privateKey = getAccountPrivateKeyFromMnemonic( | ||
'random', | ||
0, | ||
DerivationPath.BIP44, | ||
); | ||
expect(privateKey).toBe('0xASD'); | ||
}); | ||
}); |
21 changes: 21 additions & 0 deletions
21
src/background/services/secrets/utils/getAddressForHvm.test.ts
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { addressBytesFromPubKey, getAddressForHvm } from './getAddressForHvm'; | ||
|
||
jest.mock('@noble/hashes/sha256', () => ({ | ||
sha256: jest.fn(() => new Uint8Array(1)), | ||
})); | ||
jest.mock('@noble/curves/ed25519', () => ({ | ||
ed25519: { getPublicKey: jest.fn(() => new Uint8Array(1)) }, | ||
})); | ||
|
||
describe('getAddressForHvm()', () => { | ||
it('should get the address bytes from publick key', () => { | ||
const result = addressBytesFromPubKey(new Uint8Array(1)); | ||
expect(JSON.stringify(result)).toEqual( | ||
JSON.stringify(new Uint8Array([0x00, ...new Uint8Array(1)])), | ||
); | ||
}); | ||
it('should get the address', () => { | ||
const address = getAddressForHvm('0xASD'); | ||
expect(address).toBe('0x000000'); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { DerivationPath } from '@avalabs/core-wallets-sdk'; | ||
import { HVMWallet } from './HVMWallet'; | ||
import { TransactionPayload, VMABI } from 'hypersdk-client'; | ||
const returnedPublickKey = new Uint8Array(1); | ||
const returnedSign = new Uint8Array(2); | ||
|
||
jest.mock('@avalabs/core-wallets-sdk', () => ({ | ||
...jest.requireActual('@avalabs/core-wallets-sdk'), | ||
getWalletFromMnemonic: jest.fn(() => ({ path: 'path', privateKey: '0xASD' })), | ||
})); | ||
jest.mock('@noble/curves/ed25519', () => ({ | ||
ed25519: { | ||
getPublicKey: jest.fn(() => returnedPublickKey), | ||
sign: jest.fn(() => returnedSign), | ||
}, | ||
})); | ||
jest.mock('hypersdk-client/dist/Marshaler', () => ({ | ||
Marshaler: jest.fn(() => ({ | ||
encodeTransaction: jest.fn(() => 'asd'), | ||
})), | ||
})); | ||
describe('HVMWallet', () => { | ||
it('should return the wallet from mnemonic', () => { | ||
const wallet = HVMWallet.fromMnemonic('mnemonic', 0, DerivationPath.BIP44); | ||
expect(wallet).toBeInstanceOf(HVMWallet); | ||
}); | ||
it('should get the public key', () => { | ||
const wallet = HVMWallet.fromMnemonic('mnemonic', 0, DerivationPath.BIP44); | ||
const pubKey = wallet.getPublicKey(); | ||
expect(JSON.stringify(pubKey)).toBe(JSON.stringify(returnedPublickKey)); | ||
}); | ||
it('should get the sign with `signEd25519`', async () => { | ||
const wallet = HVMWallet.fromMnemonic('mnemonic', 0, DerivationPath.BIP44); | ||
const sign = await wallet.signEd25519( | ||
{} as TransactionPayload, | ||
{} as VMABI, | ||
); | ||
expect(sign).toBe('1111111'); | ||
}); | ||
}); |
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