Skip to content
Permalink
Browse files

jest setup for migration test

  • Loading branch information...
SebastienGllmt committed Oct 9, 2019
1 parent 97b7fa2 commit 6abc67353fa109111186549f6d9450d2a962141b
@@ -165,7 +165,7 @@ async function bip44Migration(
* This migrates to a new storage format to allow multiple wallets and different kinds of wallets
* see v2 storage spec for more details
*/
async function storagev2Migation(
export async function storagev2Migation(
persistentDb: lf$Database,
): Promise<boolean> {
// all information in the v1 indexdb can be inferred from the blockchain
@@ -179,7 +179,7 @@ async function storagev2Migation(
const settings = RustModule.Wallet.BlockchainSettings.from_json({
protocol_magic: protocolMagic
});
const migratedWallet = await migrateFromStorageV1({
await migrateFromStorageV1({
db: persistentDb,
accountPubKey: account.root_cached_key,
displayCutoff: lastReceiveIndex,
@@ -696,7 +696,7 @@ export class AddAdhocPublicDeriver {
PublicKeyId: keys.public,
PrivateKeyId: keys.private,
Parent: parentId,
Index: request.pathToPublic[request.pathToPublic.length].index,
Index: request.pathToPublic[request.pathToPublic.length - 1].index,
}),
levelInfo: id => ({
KeyDerivationId: id,
@@ -0,0 +1,79 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Migrate storage v1 to storage v2 1`] = `
Array [
Object {
"Bip44Account": Array [
Object {
"Bip44AccountId": 1,
"KeyDerivationId": 4,
},
],
},
Object {
"Bip44Chain": Array [
Object {
"Bip44ChainId": 1,
"DisplayCutoff": 142,
"KeyDerivationId": 5,
},
Object {
"Bip44ChainId": 2,
"DisplayCutoff": null,
"KeyDerivationId": 26,
},
],
},
Object {
"Bip44CoinType": Array [],
},
Object {
"Bip44Purpose": Array [
Object {
"Bip44PurposeId": 1,
"KeyDerivationId": 3,
},
],
},
Object {
"Bip44Root": Array [
Object {
"Bip44RootId": 1,
"KeyDerivationId": 1,
},
Object {
"Bip44RootId": 2,
"KeyDerivationId": 2,
},
],
},
Object {
"ConceptualWallet": Array [
Object {
"CoinType": 2147485463,
"ConceptualWalletId": 1,
"Name": "Wallet",
},
],
},
Object {
"HwWalletMeta": Array [],
},
Object {
"Key": Array [
Object {
"Hash": "a4f667dd7dd4e242fdc082540f24996a54227f6bbf0e77f735fc192fca4dbe8fcad69edddcd0ab1c5d1db62717c6b733fba5f19bcf4cda7a17770408342c4eb25373ab7e47678ab20ad428301a39324a0f789f10901ce41a128b466568f863b9b7baa989aaf09ec746615ea2400430dadec18ada015841107bd2133dc3b2af107ecea49c1b345bdb51ebda9fed6ebe6546efa20524d2dcc66c8a5605",
"IsEncrypted": true,
"KeyId": 1,
"PasswordLastUpdate": "2019-07-31T13:40:16+03:00",
},
Object {
"Hash": "b2938f29eb965952b03baaf010b0f5fe4a2c116a1e255274c9ace24deb72450ce1c045821c42ed11b33db3124b1551793e76b8ad187efb92b28969b92bb95964",
"IsEncrypted": false,
"KeyId": 2,
"PasswordLastUpdate": null,
},
],
},
]
`;
@@ -1,13 +1,39 @@
// @flow

import '../../test-config';
import { schema, } from 'lovefield';
import { setLocalItem } from '../../../../localStorage/primitives';
import oldStorage from '../../../../../../features/yoroi_snapshots/historical-versions/1_9_0/software/localStorage';
import { RustModule } from '../../cardanoCrypto/rustLoader';
import { loadLovefieldDB } from '../database/index';
import { storagev2Migation } from '../adaMigration';
import { mockDate, filterDbSnapshot } from '../bridge/tests/common';

beforeAll(async () => {
await RustModule.load();
});


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);

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

// TODO
const dump = (await db.export()).tables;
filterDbSnapshot(dump, keysForTest);
done();
});
@@ -0,0 +1,10 @@
{
"ACCOUNT": "{\"account\":0,\"root_cached_key\":\"b2938f29eb965952b03baaf010b0f5fe4a2c116a1e255274c9ace24deb72450ce1c045821c42ed11b33db3124b1551793e76b8ad187efb92b28969b92bb95964\",\"derivation_scheme\":\"V2\"}",
"WALLET": "{\"adaWallet\":{\"cwAmount\":{\"getCCoin\":\"4300447\"},\"cwId\":\"1\",\"cwMeta\":{\"cwAssurance\":\"CWANormal\",\"cwName\":\"Wallet\",\"cwUnit\":0},\"cwType\":\"CWTWeb\",\"cwPassphraseLU\":\"2019-07-31T13:40:16+03:00\"},\"masterKey\":\"a4f667dd7dd4e242fdc082540f24996a54227f6bbf0e77f735fc192fca4dbe8fcad69edddcd0ab1c5d1db62717c6b733fba5f19bcf4cda7a17770408342c4eb25373ab7e47678ab20ad428301a39324a0f789f10901ce41a128b466568f863b9b7baa989aaf09ec746615ea2400430dadec18ada015841107bd2133dc3b2af107ecea49c1b345bdb51ebda9fed6ebe6546efa20524d2dcc66c8a5605\",\"lastReceiveAddressIndex\":142}",
"test-LAST-LAUNCH-VER": "1.8.2",
"test-URI-SCHEME-ACCEPTANCE": "true",
"test-TERMS-OF-USE-ACCEPTANCE": "true",
"LAST_BLOCK_NUMBER": "2916793",
"test-USER-LOCALE": "en-US",
"openTabId": "1564569518648"
}

0 comments on commit 6abc673

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