@Test(expected = ShapeShiftException.class) public void testInvalidTxStatus() throws ShapeShiftException { new ShapeShiftTime(new JSONObject()); } }
@Test(expected = ShapeShiftException.class) public void testInvalidTime() throws ShapeShiftException { new ShapeShiftTime(new JSONObject()); }
/** * Time Remaining on Fixed Amount Transaction * * When a transaction is created with a fixed amount requested there is a 10 minute window for * the deposit. After the 10 minute window if the deposit has not been received the transaction * expires and a new one must be created. This api call returns how many seconds are left before * the transaction expires. */ public ShapeShiftTime getTime(AbstractAddress address) throws ShapeShiftException, IOException { String apiUrl = getApiUrl(String.format(TIME_REMAINING_API, address.toString())); Request request = new Request.Builder().url(apiUrl).build(); return new ShapeShiftTime(getMakeApiCall(request)); }
@Test public void testTime2() throws JSONException, ShapeShiftException { JSONObject json = new JSONObject( "{" + "status: \"expired\"," + "seconds_remaining: \"0\"" + "}"); ShapeShiftTime time = new ShapeShiftTime(json); assertNotNull(time); assertFalse(time.isError); assertEquals(ShapeShiftTime.Status.EXPIRED, time.status); assertEquals(0, time.secondsRemaining); }
@Test public void testTime() throws JSONException, ShapeShiftException { JSONObject json = new JSONObject( "{" + "status: \"pending\"," + "seconds_remaining: \"100\"" + "}"); ShapeShiftTime time = new ShapeShiftTime(json); assertNotNull(time); assertFalse(time.isError); assertEquals(ShapeShiftTime.Status.PENDING, time.status); assertEquals(100, time.secondsRemaining); }
@Test public void testTimeError() throws JSONException, ShapeShiftException { JSONObject json = new JSONObject("{ error: \"error\" }"); ShapeShiftTime time = new ShapeShiftTime(json); assertNotNull(time); assertTrue(time.isError); assertEquals("error", time.errorMessage); assertNull(time.status); assertEquals(-1, time.secondsRemaining); }