use of org.xel.http.APICall.Builder in project elastic-core-maven by OrdinaryDude.
the class PhasingOnlyTest method testExtraRestrictions.
@Test
public void testExtraRestrictions() throws Exception {
// all transactions must be approved either by BOB or CHUCK, total fees 5 NXT, min duration 4, max duration 100
setPhasingOnlyControl(VotingModel.ACCOUNT, null, 1L, null, null, new long[] { BOB.getId(), CHUCK.getId() }, 5 * Constants.ONE_NXT, 4, 100);
Builder builder = new ACTestUtils.Builder("sendMoney", ALICE.getSecretPhrase()).recipient(BOB.getId()).param("amountNQT", 1 * Constants.ONE_NXT).feeNQT(7 * Constants.ONE_NXT);
// fee too high
setTransactionPhasingParams(builder, 20, VotingModel.ACCOUNT, null, 1L, null, null, new long[] { BOB.getId(), CHUCK.getId() });
ACTestUtils.assertTransactionBlocked(builder);
// fee at the limit
builder.feeNQT(5 * Constants.ONE_NXT);
JSONObject response = ACTestUtils.assertTransactionSuccess(builder);
String fullHash = (String) response.get("fullHash");
generateBlock();
// not yet approved, another transaction at max fee should fail
ACTestUtils.assertTransactionBlocked(builder);
// approve
Builder approveBuilder = new ACTestUtils.Builder("approveTransaction", BOB.getSecretPhrase()).param("transactionFullHash", fullHash);
ACTestUtils.assertTransactionSuccess(approveBuilder);
generateBlock();
// now can submit next transaction
response = ACTestUtils.assertTransactionSuccess(builder);
fullHash = (String) response.get("fullHash");
generateBlock();
// approve
approveBuilder.param("transactionFullHash", fullHash);
ACTestUtils.assertTransactionSuccess(approveBuilder);
generateBlock();
// too long or too short periods should fail
builder.param("phasingFinishHeight", Nxt.getBlockchain().getHeight() + 200);
ACTestUtils.assertTransactionBlocked(builder);
builder.param("phasingFinishHeight", Nxt.getBlockchain().getHeight() + 3);
ACTestUtils.assertTransactionBlocked(builder);
builder.param("phasingFinishHeight", Nxt.getBlockchain().getHeight() + 4);
ACTestUtils.assertTransactionSuccess(builder);
}
use of org.xel.http.APICall.Builder in project elastic-core-maven by OrdinaryDude.
the class PhasingOnlyTest method testBalanceVoting.
@Test
public void testBalanceVoting() {
setPhasingOnlyControl(VotingModel.NQT, null, 100 * Constants.ONE_NXT, null, null, null, 0, 0, 0);
Builder builder = new ACTestUtils.Builder("sendMoney", ALICE.getSecretPhrase()).recipient(BOB.getId()).param("amountNQT", 1 * Constants.ONE_NXT);
// no phasing - block
ACTestUtils.assertTransactionBlocked(builder);
setTransactionPhasingParams(builder, 20, VotingModel.NQT, null, 100 * Constants.ONE_NXT, null, null, new long[] { DAVE.getId() });
ACTestUtils.assertTransactionBlocked(builder);
setTransactionPhasingParams(builder, 20, VotingModel.ACCOUNT, null, 1L, null, null, new long[] { BOB.getId(), CHUCK.getId() });
ACTestUtils.assertTransactionBlocked(builder);
setTransactionPhasingParams(builder, 20, VotingModel.NQT, null, 100 * Constants.ONE_NXT + 1, null, null, null);
ACTestUtils.assertTransactionBlocked(builder);
builder = new ACTestUtils.Builder("sendMoney", ALICE.getSecretPhrase()).recipient(BOB.getId()).param("amountNQT", 1 * Constants.ONE_NXT);
setTransactionPhasingParams(builder, 20, VotingModel.NQT, null, 100 * Constants.ONE_NXT, null, null, null);
ACTestUtils.assertTransactionSuccess(builder);
}
use of org.xel.http.APICall.Builder in project elastic-core-maven by OrdinaryDude.
the class PhasingOnlyTest method testAccountVoting.
@Test
public void testAccountVoting() throws Exception {
// all transactions must be approved either by BOB or CHUCK
setPhasingOnlyControl(VotingModel.ACCOUNT, null, 1L, null, null, new long[] { BOB.getId(), CHUCK.getId() }, 0, 0, 0);
Builder builder = new ACTestUtils.Builder("sendMoney", ALICE.getSecretPhrase()).recipient(BOB.getId()).param("amountNQT", 1 * Constants.ONE_NXT);
// no phasing - block
ACTestUtils.assertTransactionBlocked(builder);
// correct phasing
setTransactionPhasingParams(builder, 20, VotingModel.ACCOUNT, null, 1L, null, null, new long[] { BOB.getId(), CHUCK.getId() });
ACTestUtils.assertTransactionSuccess(builder);
// subset of the voters should also be blocked
setTransactionPhasingParams(builder, 20, VotingModel.ACCOUNT, null, 1L, null, null, new long[] { BOB.getId() });
ACTestUtils.assertTransactionBlocked(builder);
// incorrect quorum - even if more restrictive, should also be blocked
setTransactionPhasingParams(builder, 20, VotingModel.ACCOUNT, null, 2L, null, null, new long[] { BOB.getId(), CHUCK.getId() });
ACTestUtils.assertTransactionBlocked(builder);
// remove the phasing control
builder = new ACTestUtils.Builder("setPhasingOnlyControl", ALICE.getSecretPhrase());
setControlPhasingParams(builder, VotingModel.NONE, null, null, null, null, null, 0, 0, 0);
setTransactionPhasingParams(builder, 3, VotingModel.ACCOUNT, null, 1L, null, null, new long[] { BOB.getId(), CHUCK.getId() });
JSONObject removePhasingOnlyJSON = ACTestUtils.assertTransactionSuccess(builder);
generateBlock();
assertPhasingOnly(new PhasingParams(VotingModel.ACCOUNT.getCode(), 0L, 1L, 0L, (byte) 0, new long[] { BOB.getId(), CHUCK.getId() }), 0, 0, 0);
String fullHash = (String) removePhasingOnlyJSON.get("fullHash");
// approve the remove
builder = new ACTestUtils.Builder("approveTransaction", BOB.getSecretPhrase()).param("transactionFullHash", fullHash);
ACTestUtils.assertTransactionSuccess(builder);
generateBlock();
assertNoPhasingOnlyControl();
}
use of org.xel.http.APICall.Builder in project elastic-core-maven by OrdinaryDude.
the class PhasingOnlyTest method assertNoPhasingOnlyControl.
private void assertNoPhasingOnlyControl() {
Builder builder = new APICall.Builder("getPhasingOnlyControl").param("account", Long.toUnsignedString(ALICE.getId()));
JSONObject response = builder.build().invoke();
Assert.assertTrue(response.isEmpty());
}
use of org.xel.http.APICall.Builder in project elastic-core-maven by OrdinaryDude.
the class PhasingOnlyTest method assertPhasingOnly.
private void assertPhasingOnly(PhasingParams expected, long maxFees, int minDuration, int maxDuration) {
Builder builder = new APICall.Builder("getPhasingOnlyControl").param("account", Long.toUnsignedString(ALICE.getId()));
JSONObject response = builder.build().invoke();
Logger.logMessage("getPhasingOnlyControl response: " + response.toJSONString());
Assert.assertEquals(expected.getVoteWeighting().getVotingModel().getCode(), ((Long) response.get("votingModel")).byteValue());
Assert.assertEquals(expected.getQuorum(), Convert.parseLong(response.get("quorum")));
Assert.assertEquals(expected.getWhitelist().length, ((JSONArray) response.get("whitelist")).size());
Assert.assertEquals(expected.getVoteWeighting().getHoldingId(), Convert.parseUnsignedLong((String) response.get("holding")));
Assert.assertEquals(expected.getVoteWeighting().getMinBalance(), Convert.parseLong(response.get("minBalance")));
Assert.assertEquals(expected.getVoteWeighting().getMinBalanceModel().getCode(), ((Long) response.get("minBalanceModel")).byteValue());
Assert.assertEquals(maxFees, Convert.parseLong(response.get("maxFees")));
Assert.assertEquals(minDuration, ((Long) response.get("minDuration")).shortValue());
Assert.assertEquals(maxDuration, ((Long) response.get("maxDuration")).shortValue());
}
Aggregations