1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-01 21:57:06 +01:00
metamask-extension/app/scripts/migrations/028.test.js
Mark Stacey f47cfbbb3e
Use strict assertion mode everywhere (#11012)
The `assert` module has two modes: "Legacy" and "strict". When using
strict mode, the "strict" version of each assertion method is implied.
Whereas in legacy mode, by default it will use the deprecated, "loose"
version of each assertion.

We now use strict mode everywhere. A few tests required updates where
they were asserting the wrong thing, and it was passing beforehand due
to the loose matching.
2021-05-07 17:08:24 -02:30

82 lines
2.2 KiB
JavaScript

import { strict as assert } from 'assert';
import firstTimeState from '../first-time-state';
import migration28 from './028';
const oldStorage = {
meta: {},
data: {
PreferencesController: {
tokens: [
{ address: '0xa', symbol: 'A', decimals: 4 },
{ address: '0xb', symbol: 'B', decimals: 4 },
],
identities: {
'0x6d14': {},
'0x3695': {},
},
},
},
};
describe('migration #28', function () {
it('should add corresponding tokens to accountTokens', function (done) {
migration28
.migrate(oldStorage)
.then((newStorage) => {
const newTokens = newStorage.data.PreferencesController.tokens;
const newAccountTokens =
newStorage.data.PreferencesController.accountTokens;
const testTokens = [
{ address: '0xa', symbol: 'A', decimals: 4 },
{ address: '0xb', symbol: 'B', decimals: 4 },
];
assert.equal(
newTokens.length,
0,
'tokens is expected to have the length of 0',
);
assert.equal(
newAccountTokens['0x6d14'].mainnet.length,
2,
'tokens for address is expected to have the length of 2',
);
assert.equal(
newAccountTokens['0x3695'].mainnet.length,
2,
'tokens for address is expected to have the length of 2',
);
assert.equal(
Object.keys(newAccountTokens).length,
2,
'account tokens should be created for all identities',
);
assert.deepEqual(
newAccountTokens['0x6d14'].mainnet,
testTokens,
'tokens for address should be the same than before',
);
assert.deepEqual(
newAccountTokens['0x3695'].mainnet,
testTokens,
'tokens for address should be the same than before',
);
done();
})
.catch(done);
});
it('should successfully migrate first time state', function (done) {
migration28
.migrate({
meta: {},
data: firstTimeState,
})
.then((migratedData) => {
assert.equal(migratedData.meta.version, migration28.version);
done();
})
.catch(done);
});
});