Search in sources :

Example 1 with APICall

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

the class TestCreateTwoPhased method invalidMoneyTransfer.

@Test
public void invalidMoneyTransfer() {
    int height = Nxt.getBlockchain().getHeight();
    APICall apiCall = new TwoPhasedMoneyTransferBuilder().finishHeight(height).build();
    issueCreateTwoPhased(apiCall, true);
    apiCall = new TwoPhasedMoneyTransferBuilder().finishHeight(height + 100000).build();
    issueCreateTwoPhased(apiCall, true);
    apiCall = new TwoPhasedMoneyTransferBuilder().quorum(0).build();
    issueCreateTwoPhased(apiCall, true);
    apiCall = new TwoPhasedMoneyTransferBuilder().noWhitelist().build();
    issueCreateTwoPhased(apiCall, true);
    apiCall = new TwoPhasedMoneyTransferBuilder().whitelisted(0).build();
    issueCreateTwoPhased(apiCall, true);
/*apiCall = new TwoPhasedMoneyTransferBuilder().votingModel(VoteWeighting.VotingModel.ASSET.getCode()).build();
        issueCreateTwoPhased(apiCall, true);

        apiCall = new TwoPhasedMoneyTransferBuilder().votingModel(VoteWeighting.VotingModel.ASSET.getCode())
                .minBalance(50, VoteWeighting.MinBalanceModel.ASSET.getCode())
                .build();
        issueCreateTwoPhased(apiCall, true);*/
}
Also used : APICall(org.xel.http.APICall) Test(org.junit.Test) BlockchainTest(org.xel.BlockchainTest)

Example 2 with APICall

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

the class TestCreateTwoPhased method unconfirmed.

@Test
public void unconfirmed() {
    List<String> transactionIds = new ArrayList<>(10);
    for (int i = 0; i < 10; i++) {
        APICall apiCall = new TwoPhasedMoneyTransferBuilder().build();
        JSONObject transactionJSON = issueCreateTwoPhased(apiCall, false);
        String idString = (String) transactionJSON.get("transaction");
        transactionIds.add(idString);
    }
    APICall apiCall = new TwoPhasedMoneyTransferBuilder().build();
    apiCall.invoke();
    JSONObject response = TestGetAccountPhasedTransactions.phasedTransactionsApiCall().invoke();
    Logger.logMessage("getAccountPhasedTransactionsResponse:" + response.toJSONString());
    JSONArray transactionsJson = (JSONArray) response.get("transactions");
    for (String idString : transactionIds) {
        Assert.assertTrue(TwoPhasedSuite.searchForTransactionId(transactionsJson, idString));
    }
}
Also used : JSONObject(org.json.simple.JSONObject) APICall(org.xel.http.APICall) ArrayList(java.util.ArrayList) JSONArray(org.json.simple.JSONArray) Test(org.junit.Test) BlockchainTest(org.xel.BlockchainTest)

Example 3 with APICall

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

the class TestGetPhasingPoll method transactionVotes.

@Test
public void transactionVotes() {
    APICall apiCall = new TestCreateTwoPhased.TwoPhasedMoneyTransferBuilder().quorum(1).build();
    JSONObject transactionJSON = TestCreateTwoPhased.issueCreateTwoPhased(apiCall, false);
    String fullHash = (String) transactionJSON.get("fullHash");
    String transactionId = (String) transactionJSON.get("transaction");
    generateBlock();
    long fee = Constants.ONE_NXT;
    apiCall = new APICall.Builder("approveTransaction").param("secretPhrase", CHUCK.getSecretPhrase()).param("transactionFullHash", fullHash).param("feeNQT", fee).build();
    JSONObject response = apiCall.invoke();
    Logger.logMessage("approveTransactionResponse:" + response.toJSONString());
    generateBlock();
    apiCall = new APICall.Builder("getPhasingPoll").param("transaction", transactionId).param("countVotes", "true").build();
    response = apiCall.invoke();
    Logger.logMessage("getPhasingPollResponse:" + response.toJSONString());
    Assert.assertNull(response.get("errorCode"));
    Assert.assertEquals(1, Integer.parseInt((String) response.get("result")));
}
Also used : JSONObject(org.json.simple.JSONObject) APICall(org.xel.http.APICall) Test(org.junit.Test) BlockchainTest(org.xel.BlockchainTest)

Example 4 with APICall

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

the class TestGetAccountPhasedTransactions method simpleIngoingLookup.

@Test
public void simpleIngoingLookup() {
    APICall apiCall = new TestCreateTwoPhased.TwoPhasedMoneyTransferBuilder().build();
    JSONObject transactionJSON = TestCreateTwoPhased.issueCreateTwoPhased(apiCall, false);
    generateBlock();
    JSONObject response = phasedTransactionsApiCall(BOB.getId()).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 5 with APICall

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

the class TestGetAccountPhasedTransactions 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 = phasedTransactionsApiCall().invoke();
    Logger.logMessage("getAccountPhasedTransactionsResponse:" + 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 : 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)

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