Search in sources :

Example 1 with PhasingParams

use of org.xel.PhasingParams 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();
}
Also used : JSONObject(org.json.simple.JSONObject) Builder(org.xel.http.APICall.Builder) PhasingParams(org.xel.PhasingParams) Test(org.junit.Test) BlockchainTest(org.xel.BlockchainTest)

Example 2 with PhasingParams

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

the class PhasingOnlyTest method testSetAndGet.

@Test
public void testSetAndGet() throws Exception {
    assertNoPhasingOnlyControl();
    setPhasingOnlyControl(VotingModel.ACCOUNT, null, 1L, null, null, new long[] { BOB.getId() }, 10 * Constants.ONE_NXT, 5, 1440);
    assertPhasingOnly(new PhasingParams(VotingModel.ACCOUNT.getCode(), 0L, 1L, 0L, (byte) 0, new long[] { BOB.getId() }), 10 * Constants.ONE_NXT, 5, 1440);
}
Also used : PhasingParams(org.xel.PhasingParams) Test(org.junit.Test) BlockchainTest(org.xel.BlockchainTest)

Example 3 with PhasingParams

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

the class SetPhasingOnlyControl method processRequest.

@Override
protected JSONStreamAware processRequest(HttpServletRequest request) throws NxtException {
    Account account = ParameterParser.getSenderAccount(request);
    PhasingParams phasingParams = parsePhasingParams(request, "control");
    long maxFees = ParameterParser.getLong(request, "controlMaxFees", 0, Constants.MAX_BALANCE_NQT, false);
    short minDuration = (short) ParameterParser.getInt(request, "controlMinDuration", 0, Constants.MAX_PHASING_DURATION - 1, false);
    short maxDuration = (short) ParameterParser.getInt(request, "controlMaxDuration", 0, Constants.MAX_PHASING_DURATION - 1, false);
    return createTransaction(request, account, new Attachment.SetPhasingOnly(phasingParams, maxFees, minDuration, maxDuration));
}
Also used : Account(org.xel.Account) PhasingParams(org.xel.PhasingParams) Attachment(org.xel.Attachment)

Aggregations

PhasingParams (org.xel.PhasingParams)3 Test (org.junit.Test)2 BlockchainTest (org.xel.BlockchainTest)2 JSONObject (org.json.simple.JSONObject)1 Account (org.xel.Account)1 Attachment (org.xel.Attachment)1 Builder (org.xel.http.APICall.Builder)1