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;
}
}
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();
}
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();
}
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());
}
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());
}
Aggregations