@Test public void loadAccounts_OldVersionData_DropOldData() throws Exception { FakeStore fakeStore = new FakeStore(); fakeStore.saveString(KeyStoreImpl.VERSION_KEY, "some_version"); fakeStore.saveString(KeyStoreImpl.STORE_KEY_ACCOUNTS, "{&quot;accounts&quot;:[{&quot;seed&quot;:&quot;{\\&quot;iv\\&quot;:\\&quot;nVGsoEHgjW4xw2gx\\\\n\\&quot;,\\&quot;cipher\\&quot;:\\&quot;kEC64vaQu\\\\\\/erpFvvnrY+sWm\\\\\\/o4GjmjPfgG31zQTwvp0taxo\\\\\\/04PoaisjfEQxrydRwBGFvG\\\\\\/nG345\\\\ntXMn+x2H0jnaPWWCznPA\\\\n\\&quot;}&quot;,&quot;public_key&quot;:&quot;GBYPGYWPWHWSVTQGTUCH2IICIP2PRLN3QYSUX5NOHHMNDQW26A4WK2IK&quot;}]}"); KeyStoreImpl keyStore = new KeyStoreImpl(fakeStore, new FakeBackupRestore()); keyStore.loadAccounts(); assertThat(fakeStore.getString(KeyStoreImpl.VERSION_KEY), equalTo(KeyStoreImpl.ENCRYPTION_VERSION_NAME)); assertThat(fakeStore.getString(KeyStoreImpl.STORE_KEY_ACCOUNTS), nullValue()); }
@NonNull @Override public List<KeyPair> loadAccounts() throws LoadAccountException { ArrayList<KeyPair> accounts = new ArrayList<>(); try { JSONArray jsonArray = loadJsonArray(); if (jsonArray != null) { for (int i = 0; i < jsonArray.length(); i++) { JSONObject accountJson = jsonArray.getJSONObject(i); String seed = accountJson.getString(JSON_KEY_ENCRYPTED_SEED); accounts.add(KeyPair.fromSecretSeed(seed)); } } } catch (JSONException e) { throw new LoadAccountException(e.getMessage(), e); } return accounts; }
KeyStoreImpl implements KeyStore { @NonNull @Override public List<KeyPair> loadAccounts() throws LoadAccountException { ArrayList<KeyPair> accounts = new ArrayList<>(); try { JSONArray jsonArray = loadJsonArray(); if (jsonArray != null) { for (int i = 0; i < jsonArray.length(); i++) { JSONObject accountJson = jsonArray.getJSONObject(i); String seed = accountJson.getString(JSON_KEY_ENCRYPTED_SEED); accounts.add(KeyPair.fromSecretSeed(seed)); } } } catch (JSONException e) { throw new LoadAccountException(e.getMessage(), e); } return accounts; } }
KeyStoreImpl implements KeyStore { @NonNull @Override public List<KeyPair> loadAccounts() throws LoadAccountException { ArrayList<KeyPair> accounts = new ArrayList<>(); try { JSONArray jsonArray = loadJsonArray(); if (jsonArray != null) { for (int i = 0; i < jsonArray.length(); i++) { JSONObject accountJson = jsonArray.getJSONObject(i); String seed = accountJson.getString(JSON_KEY_ENCRYPTED_SEED); accounts.add(KeyPair.fromSecretSeed(seed)); } } } catch (JSONException e) { throw new LoadAccountException(e.getMessage(), e); } return accounts; } KeyStoreImpl(@NonNull Store store, @NonNull BackupRestore backupRestore); }
KeyStoreImpl implements KeyStore { @NonNull @Override public List<KeyPair> loadAccounts() throws LoadAccountException { ArrayList<KeyPair> accounts = new ArrayList<>(); try { JSONArray jsonArray = loadJsonArray(); if (jsonArray != null) { for (int i = 0; i < jsonArray.length(); i++) { JSONObject accountJson = jsonArray.getJSONObject(i); String seed = accountJson.getString(JSON_KEY_ENCRYPTED_SEED); accounts.add(KeyPair.fromSecretSeed(seed)); } } } catch (JSONException e) { throw new LoadAccountException(e.getMessage(), e); } return accounts; } KeyStoreImpl(@NonNull Store store, @NonNull BackupRestore backupRestore); @NonNull @Override List<KeyPair> loadAccounts(); @Override void deleteAccount(String publicAddress); @Override KeyPair newAccount(); @Override KeyPair importAccount(@NonNull String json, @NonNull String passphrase); @Override void clearAllAccounts(); }
KeyStoreImpl implements KeyStore { @NonNull @Override public List<KeyPair> loadAccounts() throws LoadAccountException { ArrayList<KeyPair> accounts = new ArrayList<>(); try { JSONArray jsonArray = loadJsonArray(); if (jsonArray != null) { for (int i = 0; i < jsonArray.length(); i++) { JSONObject accountJson = jsonArray.getJSONObject(i); String seed = accountJson.getString(JSON_KEY_ENCRYPTED_SEED); accounts.add(KeyPair.fromSecretSeed(seed)); } } } catch (JSONException e) { throw new LoadAccountException(e.getMessage(), e); } return accounts; } KeyStoreImpl(@NonNull Store store, @NonNull BackupRestore backupRestore); @NonNull @Override List<KeyPair> loadAccounts(); @Override void deleteAccount(String publicAddress); @Override KeyPair newAccount(); @Override KeyPair importAccount(@NonNull String json, @NonNull String passphrase); @Override void clearAllAccounts();  }