Adding unit test case to for idempotent behaviour of importAccountWithStrategy idempotent (#15583)

feature/default_network_editable
Jyoti Puri 2 years ago committed by GitHub
parent 29e252e162
commit 637d4bcf2c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 60
      app/scripts/metamask-controller.actions.test.js

@ -32,6 +32,9 @@ const createLoggerMiddlewareMock = () => (req, res, next) => {
next();
};
const TEST_SEED =
'debris dizzy just program just float decrease vacant alarm reduce speak stadium';
const MetaMaskController = proxyquire('./metamask-controller', {
'./lib/createLoggerMiddleware': { default: createLoggerMiddlewareMock },
}).default;
@ -106,6 +109,63 @@ describe('MetaMaskController', function () {
});
});
describe('#importAccountWithStrategy', function () {
it('two sequential calls with same strategy give same result', async function () {
let keyringControllerState1;
let keyringControllerState2;
const importPrivkey =
'4cfd3e90fc78b0f86bf7524722150bb8da9c60cd532564d7ff43f5716514f553';
await metamaskController.createNewVaultAndKeychain('test@123');
await Promise.all([
metamaskController.importAccountWithStrategy('Private Key', [
importPrivkey,
]),
Promise.resolve(1).then(() => {
keyringControllerState1 = JSON.stringify(
metamaskController.keyringController.memStore.getState(),
);
metamaskController.importAccountWithStrategy('Private Key', [
importPrivkey,
]);
}),
Promise.resolve(2).then(() => {
keyringControllerState2 = JSON.stringify(
metamaskController.keyringController.memStore.getState(),
);
}),
]);
assert.deepEqual(keyringControllerState1, keyringControllerState2);
});
});
describe('#createNewVaultAndRestore', function () {
it('two successive calls with same inputs give same result', async function () {
const result1 = await metamaskController.createNewVaultAndRestore(
'test@123',
TEST_SEED,
);
const result2 = await metamaskController.createNewVaultAndRestore(
'test@123',
TEST_SEED,
);
assert.deepEqual(result1, result2);
});
});
describe('#createNewVaultAndKeychain', function () {
it('two successive calls with same inputs give same result', async function () {
const result1 = await metamaskController.createNewVaultAndKeychain(
'test@123',
);
const result2 = await metamaskController.createNewVaultAndKeychain(
'test@123',
);
assert.notEqual(result1, undefined);
assert.deepEqual(result1, result2);
});
});
describe('#addToken', function () {
const address = '0x514910771af9ca656af840dff83e8264ecf986ca';
const symbol = 'LINK';

Loading…
Cancel
Save