CheckPrivateKeysSubmitAction extends MultiBitSubmitAction implements WalletBusyListener { @Override public void actionPerformed(ActionEvent event) { if (abort()) { return; } if (checkPrivateKeysPanel == null) { return; } CharSequence walletPassword = null; if (checkPrivateKeysPanel.getWalletPasswordField() != null) { walletPassword = CharBuffer.wrap(checkPrivateKeysPanel.getWalletPasswordField().getPassword()); if (bitcoinController.getModel().getActiveWallet().isEncrypted()) { if (walletPassword.length() == 0) { checkPrivateKeysPanel.setMessageText1(controller.getLocaliser().getString( "showExportPrivateKeysAction.youMustEnterTheWalletPassword")); checkPrivateKeysPanel.setMessageText2(" "); return; } if (!bitcoinController.getModel().getActiveWallet().checkPassword(walletPassword)) { checkPrivateKeysPanel.setMessageText1(controller.getLocaliser().getString( "createNewReceivingAddressSubmitAction.passwordIsIncorrect")); checkPrivateKeysPanel.setMessageText2(" "); return; } } } try { checkPrivateKeysMatchAddresses(bitcoinController.getModel().getActivePerWalletModelData(), walletPassword); } catch (PrivateKeysException pke) { pke.printStackTrace(); } } CheckPrivateKeysSubmitAction(BitcoinController bitcoinController,
                                      CheckPrivateKeysPanel checkPrivateKeysPanel, ImageIcon icon); @Override void actionPerformed(ActionEvent event); @Override void walletBusyChange(boolean newWalletIsBusy);  }
@Test public void testCheckPrivateKeysWithGoodEncryptedWallet() throws Exception { final CreateControllers.Controllers controllers = CreateControllers.createControllers(); BitcoinController controller = controllers.bitcoinController; ActionTestUtils.createNewActiveWallet(controller, "testCheckPrivateKeysWithEncryptedWallet", true, WALLET_PASSWORD); assertTrue("Wallet is not encrypted when it should be", controller.getModel().getActiveWallet().getEncryptionType() == EncryptionType.ENCRYPTED_SCRYPT_AES); FontSizer.INSTANCE.initialise(controller); CheckPrivateKeysPanel checkPanel = new CheckPrivateKeysPanel(controller); CheckPrivateKeysSubmitAction checkAction = checkPanel.getCheckPrivateKeysSubmitAction(); assertNotNull("checkAction was not created successfully", checkAction); assertEquals("Wrong number of keys at wallet creation", 1, controller.getModel().getActiveWallet().getKeychain().size()); assertTrue("Wallet password is not enabled when it should be", checkPanel.isWalletPasswordFieldEnabled()); checkAction.actionPerformed(null); assertEquals("Wrong message after execute with missing password", EXPECTED_ENTER_THE_WALLET_PASSWORD, checkPanel.getMessageText1()); checkPanel.setWalletPassword(WRONG_WALLET_PASSWORD); checkAction.actionPerformed(null); assertEquals("Wrong message after execute with wrong password", EXPECTED_WRONG_WALLET_PASSWORD, checkPanel.getMessageText1()); checkPanel.setWalletPassword(WALLET_PASSWORD); checkAction.actionPerformed(null); assertEquals("Wrong message after good private key check", EXPECTED_CHECKED_OK, checkPanel.getMessageText1()); }
@Test public void testCheckPrivateKeysWithBadEncryptedWallet() throws Exception { final CreateControllers.Controllers controllers = CreateControllers.createControllers(); BitcoinController controller = controllers.bitcoinController; File directory = new File("."); String currentPath = directory.getAbsolutePath(); String testDirectory = currentPath + File.separator + Constants.TESTDATA_DIRECTORY + File.separator + PrivateKeysHandlerTest.PRIVATE_KEYS_TESTDATA_DIRECTORY; String badWalletFile = testDirectory + File.separator + BAD_WALLET_FILE; FileHandler fileHandler = new FileHandler(controller); Wallet badWallet = fileHandler.loadFromFile(new File(badWalletFile)).getWallet(); assertNotNull(badWallet); FontSizer.INSTANCE.initialise(controller); CheckPrivateKeysPanel checkPanel = new CheckPrivateKeysPanel(controller); CheckPrivateKeysSubmitAction checkAction = checkPanel.getCheckPrivateKeysSubmitAction(); assertNotNull("checkAction was not created successfully", checkAction); assertEquals("Wrong number of keys at wallet creation", 6, controller.getModel().getActiveWallet().getKeychain().size()); assertTrue("Wallet password is not enabled when it should be", checkPanel.isWalletPasswordFieldEnabled()); checkPanel.setWalletPassword(BAD_WALLET_CORRECT_PASSWORD); checkAction.actionPerformed(null); assertEquals("Wrong message after failed private key check", EXPECTED_FAILED_CHECK, checkPanel.getMessageText1()); }