Search in sources :

Example 1 with CreatePollBuilder

use of org.xel.http.votingsystem.TestCreatePoll.CreatePollBuilder in project elastic-core-maven by OrdinaryDude.

the class TestCastVote method validVoteCasting.

@Test
public void validVoteCasting() {
    APICall apiCall = new CreatePollBuilder().build();
    String poll = TestCreatePoll.issueCreatePoll(apiCall, false);
    generateBlock();
    apiCall = new APICall.Builder("castVote").param("secretPhrase", ALICE.getSecretPhrase()).param("poll", poll).param("vote00", 1).param("vote01", 0).param("feeNQT", Constants.ONE_NXT).build();
    JSONObject response = apiCall.invoke();
    Logger.logMessage("voteCasting:" + response.toJSONString());
    Assert.assertNull(response.get("error"));
    generateBlock();
    apiCall = new APICall.Builder("getPollResult").param("poll", poll).build();
    JSONObject getPollResponse = apiCall.invoke();
    Logger.logMessage("getPollResultResponse:" + getPollResponse.toJSONString());
    JSONArray results = (JSONArray) getPollResponse.get("results");
    long ringoResult = Long.parseLong(getResult(results, 0));
    Assert.assertEquals(1, ringoResult);
    long paulResult = Long.parseLong(getResult(results, 1));
    Assert.assertEquals(0, paulResult);
    // John's result is empty by spec
    Assert.assertEquals("", getResult(results, 2));
}
Also used : CreatePollBuilder(org.xel.http.votingsystem.TestCreatePoll.CreatePollBuilder) JSONObject(org.json.simple.JSONObject) APICall(org.xel.http.APICall) JSONArray(org.json.simple.JSONArray) Test(org.junit.Test) BlockchainTest(org.xel.BlockchainTest)

Example 2 with CreatePollBuilder

use of org.xel.http.votingsystem.TestCreatePoll.CreatePollBuilder in project elastic-core-maven by OrdinaryDude.

the class TestCastVote method invalidVoteCasting.

@Test
public void invalidVoteCasting() {
    APICall apiCall = new CreatePollBuilder().build();
    String poll = TestCreatePoll.issueCreatePoll(apiCall, false);
    generateBlock();
    apiCall = new APICall.Builder("castVote").param("secretPhrase", ALICE.getSecretPhrase()).param("poll", poll).param("vote1", 1).param("vote2", 1).param("vote3", 1).param("feeNQT", Constants.ONE_NXT).build();
    JSONObject response = apiCall.invoke();
    Logger.logMessage("voteCasting:" + response.toJSONString());
    Assert.assertNotNull(response.get("error"));
}
Also used : CreatePollBuilder(org.xel.http.votingsystem.TestCreatePoll.CreatePollBuilder) JSONObject(org.json.simple.JSONObject) APICall(org.xel.http.APICall) CreatePollBuilder(org.xel.http.votingsystem.TestCreatePoll.CreatePollBuilder) Test(org.junit.Test) BlockchainTest(org.xel.BlockchainTest)

Aggregations

JSONObject (org.json.simple.JSONObject)2 Test (org.junit.Test)2 BlockchainTest (org.xel.BlockchainTest)2 APICall (org.xel.http.APICall)2 CreatePollBuilder (org.xel.http.votingsystem.TestCreatePoll.CreatePollBuilder)2 JSONArray (org.json.simple.JSONArray)1