From 158c9604b889611d4d9b40aaa08a7b5ecb008fb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius?= Date: Fri, 21 Jul 2017 13:27:23 -0300 Subject: [PATCH] Fix GetLimitOrders listener and add GetLimitOrders and GetTradeHistory API tests --- .../graphenej/api/GetLimitOrders.java | 8 +- .../api/android/NodeConnectionTest.java | 91 +++++++++++++++++++ 2 files changed, 95 insertions(+), 4 deletions(-) diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/api/GetLimitOrders.java b/graphenej/src/main/java/de/bitsharesmunich/graphenej/api/GetLimitOrders.java index 9fa7236..3327ff7 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/api/GetLimitOrders.java +++ b/graphenej/src/main/java/de/bitsharesmunich/graphenej/api/GetLimitOrders.java @@ -44,9 +44,9 @@ public class GetLimitOrders extends BaseGrapheneHandler { /** * Default Constructor * - * @param a id of asset being sold - * @param b id of asset being purchased - * @param limit maximum number of orders to retrieve + * @param a id of asset being sold + * @param b id of asset being purchased + * @param limit maximum number of orders to retrieve * @param oneTime boolean value indicating if WebSocket must be closed (true) or not * (false) after the response * @param listener A class implementing the WitnessResponseListener interface. This should @@ -59,7 +59,7 @@ public class GetLimitOrders extends BaseGrapheneHandler { this.b = b; this.limit = limit; this.mOneTime = oneTime; - this.mListener = mListener; + this.mListener = listener; } /** diff --git a/graphenej/src/test/java/de/bitsharesmunich/graphenej/api/android/NodeConnectionTest.java b/graphenej/src/test/java/de/bitsharesmunich/graphenej/api/android/NodeConnectionTest.java index e232636..0111738 100644 --- a/graphenej/src/test/java/de/bitsharesmunich/graphenej/api/android/NodeConnectionTest.java +++ b/graphenej/src/test/java/de/bitsharesmunich/graphenej/api/android/NodeConnectionTest.java @@ -18,6 +18,7 @@ import de.bitsharesmunich.graphenej.api.GetBlockHeader; import de.bitsharesmunich.graphenej.api.GetKeyReferences; import de.bitsharesmunich.graphenej.api.GetLimitOrders; import de.bitsharesmunich.graphenej.api.GetRequiredFees; +import de.bitsharesmunich.graphenej.api.GetTradeHistory; import de.bitsharesmunich.graphenej.errors.RepeatedRequestIdException; import de.bitsharesmunich.graphenej.errors.MalformedAddressException; import de.bitsharesmunich.graphenej.interfaces.WitnessResponseListener; @@ -42,6 +43,7 @@ public class NodeConnectionTest { private String ACCOUNT_NAME = System.getenv("ACCOUNT_NAME"); private long BlOCK_TEST_NUMBER = Long.parseLong(System.getenv("BlOCK_TEST_NUMBER")); private Asset BTS = new Asset("1.3.0"); + private Asset BLOCKPAY = new Asset("1.3.1072"); private Asset BITDOLAR = new Asset("1.3.121"); //USD Smartcoin private Asset BITEURO = new Asset("1.3.120"); //EUR Smartcoin private NodeConnection nodeConnection; @@ -450,6 +452,49 @@ public class NodeConnectionTest { } } + /** + * Test for GetLimitOrders Handler. + * + * Request for a limit orders between two assets + */ + @Test + public void testGetLimitOrdersRequest(){ + nodeConnection = NodeConnection.getInstance(); + nodeConnection.addNodeUrl(NODE_URL_1); + nodeConnection.connect("", "", false, mErrorListener); + + String asset_sold_id = BLOCKPAY.getBitassetId(); + String asset_purchased_id = BTS.getBitassetId(); + int limit = 10; + + System.out.println("Adding GetLimitOrders request"); + try{ + nodeConnection.addRequestHandler(new GetLimitOrders(asset_sold_id, asset_purchased_id, limit, true, new WitnessResponseListener(){ + @Override + public void onSuccess(WitnessResponse response) { + System.out.println("GetLimitOrders.onSuccess"); + } + + @Override + public void onError(BaseResponse.Error error) { + System.out.println("GetLimitOrders.onError. Msg: "+ error.message); + } + })); + }catch(RepeatedRequestIdException e){ + System.out.println("RepeatedRequestIdException. Msg: "+e.getMessage()); + } + + + try{ + // Holding this thread while we get update notifications + synchronized (this){ + wait(); + } + }catch(InterruptedException e){ + System.out.println("InterruptedException. Msg: "+e.getMessage()); + } + } + /** * Test for GetMarketHistory Handler. * @@ -542,6 +587,52 @@ public class NodeConnectionTest { } } + /** + * Test for GetRequiredFees Handler. + * + */ + @Test + public void testGetTradeHistoryRequest(){ + nodeConnection = NodeConnection.getInstance(); + nodeConnection.addNodeUrl(NODE_URL_1); + nodeConnection.connect("", "", false, mErrorListener); + + UserAccount userAccount_from = new UserAccount(ACCOUNT_ID_1); + UserAccount userAccount_to = new UserAccount(ACCOUNT_ID_2); + + + String asset_sold_id = BLOCKPAY.getBitassetId(); + String asset_purchased_id = BTS.getBitassetId(); + int limit = 10; + + System.out.println("Adding GetRequiredFees request"); + try{ + nodeConnection.addRequestHandler(new GetTradeHistory(asset_sold_id, asset_purchased_id, "", "", limit, true, new WitnessResponseListener(){ + @Override + public void onSuccess(WitnessResponse response) { + System.out.println("GetRequiredFees.onSuccess"); + } + + @Override + public void onError(BaseResponse.Error error) { + System.out.println("GetRequiredFees.onError. Msg: "+ error.message); + } + })); + }catch(RepeatedRequestIdException e){ + System.out.println("RepeatedRequestIdException. Msg: "+e.getMessage()); + } + + + try{ + // Holding this thread while we get update notifications + synchronized (this){ + wait(); + } + }catch(InterruptedException e){ + System.out.println("InterruptedException. Msg: "+e.getMessage()); + } + } + private WitnessResponseListener mErrorListener = new WitnessResponseListener() {