Skip to content
Permalink
Browse files

fix migration for HW wallets

  • Loading branch information...
SebastienGllmt committed Oct 10, 2019
1 parent 1c11b6f commit a498ba51326dfd77123b1b59f09c3cf879977337
@@ -704,7 +704,7 @@ export class AddAdhocPublicDeriver {
...request.pathToPublic[request.pathToPublic.length - 1].insert,
}),
},
level: request.pathToPublic.length,
level: request.pathStartLevel + request.pathToPublic.length - 1,
addPublicDeriverRequest: request.publicDeriverInsert
}
);
@@ -715,7 +715,7 @@ export class AddAdhocPublicDeriver {
derivationId: publicDeriver.publicDeriverResult.KeyDerivationId,
children: request.initialDerivations,
},
request.pathToPublic.length,
request.pathStartLevel + request.pathToPublic.length - 1,
);

const hwWalletMeta = request.hwWalletMetaInsert == null
@@ -1,6 +1,104 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Migrate storage v1 to storage v2 1`] = `
exports[`Migrate ledger storage v1 to storage v2 1`] = `
Array [
Object {
"Bip44Account": Array [
Object {
"Bip44AccountId": 1,
"KeyDerivationId": 4,
},
],
},
Object {
"Bip44Chain": Array [
Object {
"Bip44ChainId": 1,
"DisplayCutoff": 77,
"KeyDerivationId": 5,
},
Object {
"Bip44ChainId": 2,
"DisplayCutoff": null,
"KeyDerivationId": 26,
},
],
},
Object {
"Bip44CoinType": Array [
Object {
"Bip44CoinTypeId": 1,
"KeyDerivationId": 3,
},
],
},
Object {
"Bip44Purpose": Array [
Object {
"Bip44PurposeId": 1,
"KeyDerivationId": 2,
},
],
},
Object {
"Bip44Root": Array [
Object {
"Bip44RootId": 1,
"KeyDerivationId": 1,
},
],
},
Object {
"Bip44Wrapper": Array [
Object {
"Bip44WrapperId": 1,
"ConceptualWalletId": 1,
"IsBundled": false,
"PublicDeriverLevel": 3,
"SignerLevel": 0,
"Version": 2,
},
],
},
Object {
"ConceptualWallet": Array [
Object {
"CoinType": 2147485463,
"ConceptualWalletId": 1,
"Name": "Yoroi-Ledger",
},
],
},
Object {
"HwWalletMeta": Array [
Object {
"ConceptualWalletId": 1,
"DeviceId": "",
"HwWalletMetaId": 1,
"Label": "",
"Language": "",
"MajorVersion": 1,
"MinorVersion": 0,
"Model": "NanoS",
"PatchVersion": 0,
"Vendor": "ledger.com",
},
],
},
Object {
"Key": Array [
Object {
"Hash": "76bca341ea86128125b49999ea1799fcd0d005a64b9150c33ed4648a3c11b20c26ea85882a1616bbf4ffae3fae6debe77169a3b299ec226409e2def1bffd35a9",
"IsEncrypted": false,
"KeyId": 1,
"PasswordLastUpdate": null,
},
],
},
]
`;

exports[`Migrate memory storage v1 to storage v2 1`] = `
Array [
Object {
"Bip44Account": Array [
@@ -90,3 +188,101 @@ Array [
},
]
`;

exports[`Migrate trezor storage v1 to storage v2 1`] = `
Array [
Object {
"Bip44Account": Array [
Object {
"Bip44AccountId": 1,
"KeyDerivationId": 4,
},
],
},
Object {
"Bip44Chain": Array [
Object {
"Bip44ChainId": 1,
"DisplayCutoff": 61,
"KeyDerivationId": 5,
},
Object {
"Bip44ChainId": 2,
"DisplayCutoff": null,
"KeyDerivationId": 26,
},
],
},
Object {
"Bip44CoinType": Array [
Object {
"Bip44CoinTypeId": 1,
"KeyDerivationId": 3,
},
],
},
Object {
"Bip44Purpose": Array [
Object {
"Bip44PurposeId": 1,
"KeyDerivationId": 2,
},
],
},
Object {
"Bip44Root": Array [
Object {
"Bip44RootId": 1,
"KeyDerivationId": 1,
},
],
},
Object {
"Bip44Wrapper": Array [
Object {
"Bip44WrapperId": 1,
"ConceptualWalletId": 1,
"IsBundled": false,
"PublicDeriverLevel": 3,
"SignerLevel": 0,
"Version": 2,
},
],
},
Object {
"ConceptualWallet": Array [
Object {
"CoinType": 2147485463,
"ConceptualWalletId": 1,
"Name": "Trezorro",
},
],
},
Object {
"HwWalletMeta": Array [
Object {
"ConceptualWalletId": 1,
"DeviceId": "Trezorro",
"HwWalletMetaId": 1,
"Label": "C875BA9D0C571FF4B8718FAA",
"Language": "english",
"MajorVersion": 2,
"MinorVersion": 1,
"Model": "T",
"PatchVersion": 1,
"Vendor": "trezor.io",
},
],
},
Object {
"Key": Array [
Object {
"Hash": "bc772da2ba5a37bad47f51d6a4476b236aa6734b5cd79c81706d5018d3203f6c05d510314991bfd73c2a3e9da72d2e1205b54cf6342f588a4fbbaaa98e58211b",
"IsEncrypted": false,
"KeyId": 1,
"PasswordLastUpdate": null,
},
],
},
]
`;
@@ -2,8 +2,11 @@

import '../../test-config';
import { schema, } from 'lovefield';
import type { lf$Database } from 'lovefield';
import { setLocalItem } from '../../../../localStorage/primitives';
import oldStorage from '../../../../../../features/yoroi_snapshots/historical-versions/1_9_0/software/localStorage';
import oldStorageMemory from '../../../../../../features/yoroi_snapshots/historical-versions/1_9_0/software/localStorage';
import oldStorageTrezor from '../../../../../../features/yoroi_snapshots/historical-versions/1_9_0/trezor/localStorage';
import oldStorageLedger from '../../../../../../features/yoroi_snapshots/historical-versions/1_9_0/ledger/localStorage';
import { RustModule } from '../../cardanoCrypto/rustLoader';
import { loadLovefieldDB } from '../database/index';
import { storagev2Migation } from '../adaMigration';
@@ -17,27 +20,53 @@ beforeEach(() => {
mockDate();
});

test('Migrate storage v1 to storage v2', async (done) => {
const db = await loadLovefieldDB(schema.DataStoreType.MEMORY);
for (const key of Object.keys(oldStorage)) {
await setLocalItem(key, oldStorage[key]);
}

const migrationResult = await storagev2Migation(db);
async function baseTest(
db: lf$Database,
): Promise<void> {
await storagev2Migation(db);

const keysForTest = [
'ConceptualWallet',
'Key',
'Bip44Wrapper',
'Bip44Root', // why two roots?
'Bip44Root',
'Bip44Purpose',
'Bip44CoinType', // TODO: why is this missing?
'Bip44CoinType',
'Bip44Account',
'Bip44Chain',
'HwWalletMeta', // TODO: another test that makes use of this
'HwWalletMeta',
];

const dump = (await db.export()).tables;
filterDbSnapshot(dump, keysForTest);
}

test('Migrate memory storage v1 to storage v2', async (done) => {
const db = await loadLovefieldDB(schema.DataStoreType.MEMORY);
for (const key of Object.keys(oldStorageMemory)) {
await setLocalItem(key, oldStorageMemory[key]);
}

await baseTest(db);
done();
});

test('Migrate trezor storage v1 to storage v2', async (done) => {
const db = await loadLovefieldDB(schema.DataStoreType.MEMORY);
for (const key of Object.keys(oldStorageTrezor)) {
await setLocalItem(key, oldStorageTrezor[key]);
}

await baseTest(db);
done();
});

test('Migrate ledger storage v1 to storage v2', async (done) => {
const db = await loadLovefieldDB(schema.DataStoreType.MEMORY);
for (const key of Object.keys(oldStorageLedger)) {
await setLocalItem(key, oldStorageLedger[key]);
}

await baseTest(db);
done();
});
@@ -0,0 +1,10 @@
{
"ACCOUNT": "{\"account\":0,\"root_cached_key\":\"76bca341ea86128125b49999ea1799fcd0d005a64b9150c33ed4648a3c11b20c26ea85882a1616bbf4ffae3fae6debe77169a3b299ec226409e2def1bffd35a9\",\"derivation_scheme\":\"V2\"}",
"WALLET": "{\"adaWallet\":{\"cwAmount\":{\"getCCoin\":\"3084182\"},\"cwId\":\"1\",\"cwMeta\":{\"cwAssurance\":\"CWANormal\",\"cwName\":\"Yoroi-Ledger\",\"cwUnit\":0},\"cwType\":\"CWTHardware\",\"cwPassphraseLU\":\"2019-07-31T13:29:06+03:00\",\"cwHardwareInfo\":{\"publicMasterKey\":\"76bca341ea86128125b49999ea1799fcd0d005a64b9150c33ed4648a3c11b20c26ea85882a1616bbf4ffae3fae6debe77169a3b299ec226409e2def1bffd35a9\",\"vendor\":\"ledger.com\",\"model\":\"NanoS\",\"deviceId\":\"\",\"label\":\"\",\"majorVersion\":1,\"minorVersion\":0,\"patchVersion\":0,\"language\":\"\"}},\"lastReceiveAddressIndex\":77}",
"test-LAST-LAUNCH-VER": "1.8.2",
"test-URI-SCHEME-ACCEPTANCE": "true",
"test-TERMS-OF-USE-ACCEPTANCE": "true",
"LAST_BLOCK_NUMBER": "2916766",
"test-USER-LOCALE": "en-US",
"openTabId": "1564568923240"
}
@@ -0,0 +1,10 @@
{
"ACCOUNT": "{\"account\":0,\"root_cached_key\":\"bc772da2ba5a37bad47f51d6a4476b236aa6734b5cd79c81706d5018d3203f6c05d510314991bfd73c2a3e9da72d2e1205b54cf6342f588a4fbbaaa98e58211b\",\"derivation_scheme\":\"V2\"}",
"WALLET": "{\"adaWallet\":{\"cwAmount\":{\"getCCoin\":\"9677490\"},\"cwId\":\"1\",\"cwMeta\":{\"cwAssurance\":\"CWANormal\",\"cwName\":\"Trezorro\",\"cwUnit\":0},\"cwType\":\"CWTHardware\",\"cwPassphraseLU\":\"2019-07-31T13:34:00+03:00\",\"cwHardwareInfo\":{\"publicMasterKey\":\"bc772da2ba5a37bad47f51d6a4476b236aa6734b5cd79c81706d5018d3203f6c05d510314991bfd73c2a3e9da72d2e1205b54cf6342f588a4fbbaaa98e58211b\",\"vendor\":\"trezor.io\",\"model\":\"T\",\"deviceId\":\"C875BA9D0C571FF4B8718FAA\",\"label\":\"Trezorro\",\"majorVersion\":2,\"minorVersion\":1,\"patchVersion\":1,\"language\":\"english\"}},\"lastReceiveAddressIndex\":61}",
"test-LAST-LAUNCH-VER": "1.8.2",
"test-URI-SCHEME-ACCEPTANCE": "true",
"test-TERMS-OF-USE-ACCEPTANCE": "true",
"LAST_BLOCK_NUMBER": "2916784",
"test-USER-LOCALE": "en-US",
"openTabId": "1564569169129"
}

0 comments on commit a498ba5

Please sign in to comment.
You can’t perform that action at this time.