@Override public void run() { for (int tries = 3; tries > 0; tries--) { try { log.info("Polling status for deposit: {}", depositAddress); ShapeShiftTxStatus newStatus = shapeShift.getTxStatus(depositAddress); handler.sendMessage(handler.obtainMessage(UPDATE_SHAPESHIFT_STATUS, newStatus)); break; } catch (ShapeShiftException e) { log.warn("Error occurred while polling", e); handler.sendMessage(handler.obtainMessage(ERROR_MESSAGE, e.getMessage())); break; } catch (IOException e) { /* ignore and retry */ } } } }
@Test(expected = ShapeShiftException.class) public void testGetTxStatusFail() throws ShapeShiftException, AddressMalformedException, IOException { server.enqueue(new MockResponse().setBody(TX_STATUS_COMPLETE_JSON)); // Used an incorrect address, correct is 1NDQPAGamGePkSZXW2CYBzXJEefB7N4bTN shapeShift.getTxStatus(BTC.newAddress("18ETaXCYhJ8sxurh41vpKC3E6Tu7oJ94q8")); }
@Test(expected = ShapeShiftException.class) public void testEmailFail() throws ShapeShiftException, IOException, InterruptedException, JSONException, AddressMalformedException { server.enqueue(new MockResponse().setBody(TX_STATUS_NO_DEPOSIT_JSON)); ShapeShiftTxStatus txStatusReply = shapeShift .getTxStatus(BTC.newAddress("1NDQPAGamGePkSZXW2CYBzXJEefB7N4bTN")); // Bad status shapeShift.requestEmailReceipt("mail@example.com", txStatusReply); }
@Test public void testEmail() throws ShapeShiftException, IOException, InterruptedException, JSONException, AddressMalformedException { // Schedule some responses. server.enqueue(new MockResponse().setBody(TX_STATUS_COMPLETE_JSON)); server.enqueue(new MockResponse().setBody(EMAIL_JSON)); ShapeShiftTxStatus txStatusReply = shapeShift.getTxStatus(BTC.newAddress("1NDQPAGamGePkSZXW2CYBzXJEefB7N4bTN")); ShapeShiftEmail emailReply = shapeShift.requestEmailReceipt("mail@example.com", txStatusReply); assertFalse(emailReply.isError); assertEquals(ShapeShiftEmail.Status.SUCCESS, emailReply.status); assertEquals("Email receipt sent", emailReply.message); // Optional: confirm that your app made the HTTP requests you were expecting. RecordedRequest request = server.takeRequest(); assertEquals("/txStat/1NDQPAGamGePkSZXW2CYBzXJEefB7N4bTN", request.getPath()); request = server.takeRequest(); assertEquals("/mail", request.getPath()); JSONObject reqJson = new JSONObject(request.getBody().readUtf8()); assertEquals("mail@example.com", reqJson.getString("email")); assertEquals("66fa0b4c11227f9f05efa13d23e58c65b50acbd6395a126b5cd751064e6e79df", reqJson.getString("txid")); }
ShapeShiftTxStatus txStatusReply = shapeShift.getTxStatus(address); assertFalse(txStatusReply.isError); assertEquals(ShapeShiftTxStatus.Status.NO_DEPOSITS, txStatusReply.status); assertEquals(address, txStatusReply.address); txStatusReply = shapeShift.getTxStatus(address); assertFalse(txStatusReply.isError); assertEquals(ShapeShiftTxStatus.Status.RECEIVED, txStatusReply.status); assertEquals(BTC, txStatusReply.incomingValue.type); txStatusReply = shapeShift.getTxStatus(address); assertFalse(txStatusReply.isError); assertEquals(ShapeShiftTxStatus.Status.UNKNOWN, txStatusReply.status); txStatusReply = shapeShift.getTxStatus(address); assertFalse(txStatusReply.isError); assertEquals(ShapeShiftTxStatus.Status.COMPLETE, txStatusReply.status); txStatusReply.transactionId); txStatusReply = shapeShift.getTxStatus(address); assertTrue(txStatusReply.isError); assertEquals(ShapeShiftTxStatus.Status.FAILED, txStatusReply.status);