Search in sources :

Example 11 with APICall

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

the class TestCreatePoll method issueCreatePoll.

static String issueCreatePoll(APICall apiCall, boolean shouldFail) {
    JSONObject createPollResponse = apiCall.invoke();
    Logger.logMessage("createPollResponse: " + createPollResponse.toJSONString());
    if (!shouldFail) {
        Assert.assertNull(createPollResponse.get("errorCode"));
    }
    generateBlock();
    try {
        String pollId = (String) createPollResponse.get("transaction");
        if (!shouldFail && pollId == null)
            Assert.fail();
        apiCall = new APICall.Builder("getPoll").param("poll", pollId).build();
        JSONObject getPollResponse = apiCall.invoke();
        Logger.logMessage("getPollResponse:" + getPollResponse.toJSONString());
        Assert.assertEquals(pollId, getPollResponse.get("poll"));
        return pollId;
    } catch (Throwable t) {
        if (!shouldFail)
            Assert.fail(t.getMessage());
        return null;
    }
}
Also used : JSONObject(org.json.simple.JSONObject) APICall(org.xel.http.APICall)

Example 12 with APICall

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

the class TestCreatePoll method createValidPoll.

@Test
public void createValidPoll() {
    APICall apiCall = new CreatePollBuilder().build();
    issueCreatePoll(apiCall, false);
    generateBlock();
    apiCall = new CreatePollBuilder().votingModel(VoteWeighting.VotingModel.NQT.getCode()).build();
    issueCreatePoll(apiCall, false);
    generateBlock();
}
Also used : APICall(org.xel.http.APICall) Test(org.junit.Test) BlockchainTest(org.xel.BlockchainTest)

Example 13 with APICall

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

the class TestCreatePoll method createInvalidPoll.

@Test
public void createInvalidPoll() {
    APICall apiCall = new CreatePollBuilder().minBalance(-Constants.ONE_NXT).build();
    issueCreatePoll(apiCall, true);
    generateBlock();
    apiCall = new CreatePollBuilder().minBalance(0).build();
    issueCreatePoll(apiCall, true);
    generateBlock();
}
Also used : APICall(org.xel.http.APICall) Test(org.junit.Test) BlockchainTest(org.xel.BlockchainTest)

Example 14 with APICall

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

the class TestApproveTransaction method invalidVoteCasting.

@Test
public void invalidVoteCasting() {
    int duration = 10;
    APICall apiCall = new TwoPhasedMoneyTransferBuilder().finishHeight(Nxt.getBlockchain().getHeight() + duration).build();
    JSONObject transactionJSON = TestCreateTwoPhased.issueCreateTwoPhased(apiCall, false);
    generateBlock();
    apiCall = new APICall.Builder("approveTransaction").param("secretPhrase", DAVE.getSecretPhrase()).param("transactionFullHash", (String) transactionJSON.get("fullHash")).param("feeNQT", Constants.ONE_NXT).build();
    JSONObject response = apiCall.invoke();
    Assert.assertNotNull(response.get("error"));
    generateBlock();
    Assert.assertEquals("ALICE balance: ", -2 * Constants.ONE_NXT, ALICE.getBalanceDiff());
    Assert.assertEquals("BOB balance: ", 0, BOB.getBalanceDiff());
    Assert.assertEquals("CHUCK balance: ", 0, CHUCK.getBalanceDiff());
    Assert.assertEquals("DAVE balance: ", 0, DAVE.getBalanceDiff());
    generateBlocks(duration);
    Assert.assertEquals("ALICE balance: ", -2 * Constants.ONE_NXT, ALICE.getBalanceDiff());
    Assert.assertEquals("BOB balance: ", 0, BOB.getBalanceDiff());
    Assert.assertEquals("CHUCK balance: ", 0, CHUCK.getBalanceDiff());
    Assert.assertEquals("DAVE balance: ", 0, DAVE.getBalanceDiff());
}
Also used : TwoPhasedMoneyTransferBuilder(org.xel.http.twophased.TestCreateTwoPhased.TwoPhasedMoneyTransferBuilder) JSONObject(org.json.simple.JSONObject) APICall(org.xel.http.APICall) Test(org.junit.Test) BlockchainTest(org.xel.BlockchainTest)

Example 15 with APICall

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

the class TestApproveTransaction method validVoteCasting.

@Test
public void validVoteCasting() {
    int duration = 10;
    APICall apiCall = new TwoPhasedMoneyTransferBuilder().finishHeight(Nxt.getBlockchain().getHeight() + duration).build();
    JSONObject transactionJSON = TestCreateTwoPhased.issueCreateTwoPhased(apiCall, false);
    generateBlock();
    apiCall = new APICall.Builder("approveTransaction").param("secretPhrase", CHUCK.getSecretPhrase()).param("transactionFullHash", (String) transactionJSON.get("fullHash")).param("feeNQT", Constants.ONE_NXT).build();
    JSONObject response = apiCall.invoke();
    Logger.logMessage("approvePhasedTransactionResponse:" + response.toJSONString());
    Assert.assertNotNull(response.get("transaction"));
    generateBlocks(duration);
    Assert.assertEquals(-50 * Constants.ONE_NXT - 2 * Constants.ONE_NXT, ALICE.getBalanceDiff());
    Assert.assertEquals(50 * Constants.ONE_NXT, BOB.getBalanceDiff());
    Assert.assertEquals(-Constants.ONE_NXT, CHUCK.getBalanceDiff());
}
Also used : TwoPhasedMoneyTransferBuilder(org.xel.http.twophased.TestCreateTwoPhased.TwoPhasedMoneyTransferBuilder) JSONObject(org.json.simple.JSONObject) APICall(org.xel.http.APICall) 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