Files
self/app/tests/utils/ethers.test.ts
Justin Hernandez fdb932eeba Feat: Lightweight e2e tests for iOS and Android (#840)
* Add Maestro e2e testing

* Run Maestro flows in parallel

* Fix mobile e2e workflow

* Fix e2e script flow path

* prettier

* fix

* prettier

* standardize yml files and new formatting commands

* fix ndk

* fix exclusions

* use double quotes for yml files

* feedback

* fixes

* fixes

* fix

* fix ios job

* unneeded

* fix workflows

* fix launch workflow

* fix

* fix pipeline

* workflow fixes

* install app to emulators

* better logging

* save current version of test script

* android works. ios wip. update locks

* fix pipelines

* cr feedback

* fix android e2e test

* Split mobile e2e workflow by platform (#842)

* Replace react-native-quick-crypto with @noble/hashes (#841)

* Add tests for ethers polyfills

* Add crypto utils

* Inline crypto polyfills into ethers util

* sort and update gemfile lock

* update lock

* chore: incrementing ios build number for version 2.6.3 [github action]

* android works. ios wip. update locks

* Specify Maestro platform

* Fix Android build step in e2e workflow

* fix android

* update ios

* add concurrency

* update Podfile.lock

* fix android

* prettier

* fix

* fix android pipeline

* try job again

* fix ios

* fix android

* fix ios

* fix command

* use android runner now that path is fixed

* fix android e2e test

* fix adb

* add caching

* fix build

* speed up build

* fix

* test emulator options

* updates

* fix pipeline

* fix

* fix script and move on

* add comment

---------

Co-authored-by: Self GitHub Actions <action@github.com>

* feedback

* fixes

* ignore for now

* ignore

* fix tests

* fix ios simulator booting

* fix ios test

* shutdown after run

* fix ios test

* better timing

* increase ios timeout

* fix both flows

* fix pipeline

* combine command

* fix ios

* break up build steps for better caching

* remove cache

* fix ios and android test pipelines

* update logic

---------

Co-authored-by: Self GitHub Actions <action@github.com>
2025-08-06 12:41:09 -07:00

57 lines
1.8 KiB
TypeScript

// SPDX-License-Identifier: BUSL-1.1; Copyright (c) 2025 Social Connect Labs, Inc.; Licensed under BUSL-1.1 (see LICENSE); Apache-2.0 from 2029-06-11
// Register crypto polyfills
// eslint-disable-next-line simple-import-sort/imports
import { ethers } from 'ethers';
import '../../src/utils/ethers';
describe('ethers crypto polyfills', () => {
it('randomBytes returns requested length and unique values', () => {
const a = ethers.randomBytes(16);
const b = ethers.randomBytes(16);
expect(a).toHaveLength(16);
expect(b).toHaveLength(16);
expect(ethers.hexlify(a)).not.toBe(ethers.hexlify(b));
});
it('computeHmac matches known vector', () => {
const result = ethers.computeHmac(
'sha256',
ethers.toUtf8Bytes('key'),
ethers.toUtf8Bytes('data'),
);
expect(ethers.hexlify(result)).toBe(
'0x5031fe3d989c6d1537a013fa6e739da23463fdaec3b70137d828e36ace221bd0',
);
});
it('pbkdf2 derives expected key', () => {
const derived = ethers.pbkdf2(
ethers.toUtf8Bytes('password'),
ethers.toUtf8Bytes('salt'),
1000,
32,
'sha256',
);
expect(ethers.hexlify(derived)).toBe(
'0x632c2812e46d4604102ba7618e9d6d7d2f8128f6266b4a03264d2a0460b7dcb3',
);
});
it('sha256 hashes data correctly', () => {
const digest = ethers.sha256(ethers.toUtf8Bytes('hello'));
expect(ethers.hexlify(digest)).toBe(
'0x2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824',
);
});
it('sha512 hashes data correctly', () => {
const digest = ethers.sha512(ethers.toUtf8Bytes('hello'));
expect(ethers.hexlify(digest)).toBe(
'0x9b71d224bd62f3785d96d46ad3ea3d73319bfbc2890caadae2dff72519673ca72323c3d99ba5c11d7c7acc6e14b8c5da0c4663475c2e5c3adef46f73bcdec043',
);
});
});