Search in sources :

Example 16 with APICall

use of org.xel.http.APICall in project elastic-core-maven by OrdinaryDude.

the class TestGetAccountPhasedTransactions method simpleOutgoingLookup.

@Test
public void simpleOutgoingLookup() {
    APICall apiCall = new TestCreateTwoPhased.TwoPhasedMoneyTransferBuilder().build();
    JSONObject transactionJSON = TestCreateTwoPhased.issueCreateTwoPhased(apiCall, false);
    generateBlock();
    JSONObject response = phasedTransactionsApiCall().invoke();
    Logger.logMessage("getAccountPhasedTransactionsResponse:" + response.toJSONString());
    JSONArray transactionsJson = (JSONArray) response.get("transactions");
    Assert.assertTrue(TwoPhasedSuite.searchForTransactionId(transactionsJson, (String) transactionJSON.get("transaction")));
    response = phasedTransactionsApiCall(CHUCK.getId()).invoke();
    Logger.logMessage("getAccountPhasedTransactionsResponse:" + response.toJSONString());
    transactionsJson = (JSONArray) response.get("transactions");
    Assert.assertFalse(TwoPhasedSuite.searchForTransactionId(transactionsJson, (String) transactionJSON.get("transaction")));
}
Also used : JSONObject(org.json.simple.JSONObject) APICall(org.xel.http.APICall) JSONArray(org.json.simple.JSONArray) Test(org.junit.Test) BlockchainTest(org.xel.BlockchainTest)

Example 17 with APICall

use of org.xel.http.APICall in project elastic-core-maven by OrdinaryDude.

the class TestGetAccountPhasedTransactions method multiple.

@Test
public void multiple() {
    JSONObject response = phasedTransactionsApiCall().invoke();
    Logger.logMessage("getAccountPhasedTransactionsResponse:" + response.toJSONString());
    JSONArray transactionsJson = (JSONArray) response.get("transactions");
    int transactionsSize0 = transactionsJson.size();
    APICall apiCall = new TestCreateTwoPhased.TwoPhasedMoneyTransferBuilder().build();
    JSONObject transactionJSON1 = TestCreateTwoPhased.issueCreateTwoPhased(apiCall, false);
    JSONObject transactionJSON2 = TestCreateTwoPhased.issueCreateTwoPhased(apiCall, false);
    generateBlock();
    response = phasedTransactionsApiCall().invoke();
    Logger.logMessage("getAccountPhasedTransactionsResponse:" + response.toJSONString());
    transactionsJson = (JSONArray) response.get("transactions");
    int transactionsSize = transactionsJson.size();
    Assert.assertTrue(transactionsSize - transactionsSize0 == 2);
    Assert.assertTrue(TwoPhasedSuite.searchForTransactionId(transactionsJson, (String) transactionJSON1.get("transaction")));
    Assert.assertTrue(TwoPhasedSuite.searchForTransactionId(transactionsJson, (String) transactionJSON2.get("transaction")));
}
Also used : JSONObject(org.json.simple.JSONObject) APICall(org.xel.http.APICall) JSONArray(org.json.simple.JSONArray) Test(org.junit.Test) BlockchainTest(org.xel.BlockchainTest)

Example 18 with APICall

use of org.xel.http.APICall in project elastic-core-maven by OrdinaryDude.

the class TestGetVoterPhasedTransactions method sorting.

@Test
public void sorting() {
    for (int i = 0; i < 15; i++) {
        APICall apiCall = new TestCreateTwoPhased.TwoPhasedMoneyTransferBuilder().build();
        TestCreateTwoPhased.issueCreateTwoPhased(apiCall, false);
    }
    JSONObject response = getVoterPhasedTransactions().invoke();
    Logger.logMessage("getVoterPhasedTransactionsResponse:" + response.toJSONString());
    JSONArray transactionsJson = (JSONArray) response.get("transactions");
    // sorting check
    int prevHeight = Integer.MAX_VALUE;
    for (Object transactionsJsonObj : transactionsJson) {
        JSONObject transactionObject = (JSONObject) transactionsJsonObj;
        int height = ((Long) transactionObject.get("height")).intValue();
        Assert.assertTrue(height <= prevHeight);
        prevHeight = height;
    }
}
Also used : TwoPhasedMoneyTransferBuilder(org.xel.http.twophased.TestCreateTwoPhased.TwoPhasedMoneyTransferBuilder) JSONObject(org.json.simple.JSONObject) APICall(org.xel.http.APICall) JSONArray(org.json.simple.JSONArray) JSONObject(org.json.simple.JSONObject) Test(org.junit.Test) BlockchainTest(org.xel.BlockchainTest)

Example 19 with APICall

use of org.xel.http.APICall in project elastic-core-maven by OrdinaryDude.

the class TestGetVoterPhasedTransactions method simpleTransactionLookup.

@Test
public void simpleTransactionLookup() {
    APICall apiCall = new TwoPhasedMoneyTransferBuilder().build();
    JSONObject transactionJSON = TestCreateTwoPhased.issueCreateTwoPhased(apiCall, false);
    String transactionId = (String) transactionJSON.get("transaction");
    generateBlock();
    JSONObject response = getVoterPhasedTransactions().invoke();
    Logger.logMessage("getVoterPhasedTransactionsResponse:" + response.toJSONString());
    JSONArray transactionsJson = (JSONArray) response.get("transactions");
    Assert.assertTrue(TwoPhasedSuite.searchForTransactionId(transactionsJson, transactionId));
}
Also used : TwoPhasedMoneyTransferBuilder(org.xel.http.twophased.TestCreateTwoPhased.TwoPhasedMoneyTransferBuilder) JSONObject(org.json.simple.JSONObject) APICall(org.xel.http.APICall) JSONArray(org.json.simple.JSONArray) Test(org.junit.Test) BlockchainTest(org.xel.BlockchainTest)

Example 20 with APICall

use of org.xel.http.APICall in project elastic-core-maven by OrdinaryDude.

the class TestGetPolls method accountPollsIncrease.

@Test
public void accountPollsIncrease() {
    APICall apiCall = new APICall.Builder("getPolls").param("includeVoters", "false").param("account", Long.toUnsignedString(DAVE.getId())).param("firstIndex", 0).param("lastIndex", 100).build();
    JSONObject jsonResponse = apiCall.invoke();
    Logger.logMessage("getPollsResponse:" + jsonResponse.toJSONString());
    JSONArray polls = (JSONArray) jsonResponse.get("polls");
    int initialSize = polls.size();
    APICall createPollApiCall = new TestCreatePoll.CreatePollBuilder().secretPhrase(DAVE.getSecretPhrase()).build();
    String poll = TestCreatePoll.issueCreatePoll(createPollApiCall, false);
    generateBlock();
    jsonResponse = apiCall.invoke();
    Logger.logMessage("getPollsResponse:" + jsonResponse.toJSONString());
    polls = (JSONArray) jsonResponse.get("polls");
    int size = polls.size();
    JSONObject lastPoll = (JSONObject) polls.get(0);
    Assert.assertEquals(poll, lastPoll.get("poll"));
    Assert.assertEquals(size, initialSize + 1);
}
Also used : JSONObject(org.json.simple.JSONObject) APICall(org.xel.http.APICall) JSONArray(org.json.simple.JSONArray) Test(org.junit.Test) BlockchainTest(org.xel.BlockchainTest)

Aggregations

APICall (org.xel.http.APICall)20 Test (org.junit.Test)18 BlockchainTest (org.xel.BlockchainTest)18 JSONObject (org.json.simple.JSONObject)16 JSONArray (org.json.simple.JSONArray)10 TwoPhasedMoneyTransferBuilder (org.xel.http.twophased.TestCreateTwoPhased.TwoPhasedMoneyTransferBuilder)5 CreatePollBuilder (org.xel.http.votingsystem.TestCreatePoll.CreatePollBuilder)2 ArrayList (java.util.ArrayList)1 Builder (org.xel.http.APICall.Builder)1