org.spongycastle.pqc.math.linearalgebra.ByteUtils Java Examples

The following examples show how to use org.spongycastle.pqc.math.linearalgebra.ByteUtils. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TxPoolV1Test.java    From aion with MIT License 6 votes vote down vote up
private List<PooledTransaction> getMockTransaction(long energyConsumed) {
    AionTransaction tx =
            AionTransaction.create(
                    key.get(0),
                    ByteUtils.fromHexString("0000000000000001"),
                    AddressUtils.wrapAddress(
                            "0000000000000000000000000000000000000000000000000000000000000001"),
                    ByteUtils.fromHexString("1"),
                    ByteUtils.fromHexString("1"),
                    Constant.MIN_ENERGY_CONSUME,
                    1L,
                    TransactionTypes.DEFAULT,
                    null);

    return Collections.singletonList(new PooledTransaction(tx, energyConsumed));
}
 
Example #2
Source File: TxPoolV1Test.java    From aion with MIT License 6 votes vote down vote up
private PooledTransaction genTransactionWithTimestamp(
    byte[] nonce, ECKey key, byte[] timeStamp) {
    AionTransaction tx =
            AionTransaction.createGivenTimestamp(
                    key,
                    nonce,
                    AddressUtils.wrapAddress(
                            "0000000000000000000000000000000000000000000000000000000000000001"),
                    ByteUtils.fromHexString("1"),
                    ByteUtils.fromHexString("1"),
                    Constant.MIN_ENERGY_CONSUME,
                    1L,
                    TransactionTypes.DEFAULT,
                    timeStamp,
                    null);
    return new PooledTransaction(tx, Constant.MIN_ENERGY_CONSUME);
}
 
Example #3
Source File: TxPoolV1Test.java    From aion with MIT License 6 votes vote down vote up
private PooledTransaction genTransactionRandomPrice(
        byte[] nonce, ECKey key, long energyConsumed) {
    AionTransaction tx =
            AionTransaction.create(
                    key,
                    nonce,
                    AddressUtils.wrapAddress(
                            "0000000000000000000000000000000000000000000000000000000000000001"),
                    ByteUtils.fromHexString("1"),
                    ByteUtils.fromHexString("1"),
                    Constant.MIN_ENERGY_CONSUME,
                    1 + r.nextInt(1000),
                    TransactionTypes.DEFAULT,
                    null);
    return new PooledTransaction(tx, energyConsumed);
}
 
Example #4
Source File: TxnPoolTest.java    From aion with MIT License 6 votes vote down vote up
@Test
public void addRepeatedTxn() {
    Properties config = new Properties();
    config.put(TxPoolA0.PROP_TX_TIMEOUT, "10");

    ITxPool tp = new TxPoolA0(config);
    AionTransaction txn =
            AionTransaction.create(
                    key.get(0),
                    ByteUtils.fromHexString("0000000000000001"),
                    new AionAddress(key.get(0).getAddress()),
                    ByteUtils.fromHexString("1"),
                    ByteUtils.fromHexString("1"),
                MIN_ENERGY_CONSUME,
                    1L,
                    TransactionTypes.DEFAULT, null);

    PooledTransaction pooledTx = new PooledTransaction(txn, 0);

    List<PooledTransaction> txnl = new ArrayList<>();
    txnl.add(pooledTx);
    txnl.add(pooledTx);
    tp.add(txnl);

    Assert.assertEquals(1, tp.size());
}
 
Example #5
Source File: BinaryEnricherTest.java    From openkeepass with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldAddAttachmentDataAndMaintainBinaryId() {
    int attachmentId = 5;
    String attachmentKey = "test.txt";
    byte[] attachmentData = ByteUtils.fromHexString("FF00EE");

    Binary binary = new BinaryBuilder().id(attachmentId).isCompressed(false).data(attachmentData).build();

    ArrayList<Binary> binaryList = new ArrayList<Binary>();
    binaryList.add(binary);

    Binaries binaries = new BinariesBuilder().binaries(binaryList).build();

    Meta meta = new MetaBuilder("binaryTest").binaries(binaries).build();

    Entry entry1 = new EntryBuilder("1").addAttachment(attachmentKey, attachmentId).build();

    Group groupA = new GroupBuilder("A").addEntry(entry1).build();

    KeePassFile keePassFile = new KeePassFileBuilder(meta).addTopGroups(groupA).build();
    BinaryEnricher enricher = new BinaryEnricher();
    KeePassFile enrichedKeePassFile = enricher.enrichNodesWithBinaryData(keePassFile);

    Attachment attachment =
            enrichedKeePassFile.getRoot().getGroups().get(0).getEntries().get(0).getAttachments().get(0);

    assertThat(attachment.getRef(), is(attachmentId));
    assertThat(attachment.getKey(), is(attachmentKey));
    assertThat(attachment.getData(), is(attachmentData));
}
 
Example #6
Source File: PendingStateTest.java    From aion with MIT License 5 votes vote down vote up
@Test
public void invalidEnergyLimit() {
    AionTransaction tx =
            AionTransaction.create(
                    deployerKey,
                    BigInteger.ZERO.toByteArray(),
                    new AionAddress(new byte[32]),
                    ByteUtils.fromHexString("1"),
                    ByteUtils.fromHexString("1"),
                    10L,
                    energyPrice,
                    TransactionTypes.DEFAULT, null);

    assertEquals(pendingState.addTransactionFromApiServer(tx), TxResponse.INVALID_TX_NRG_LIMIT);
}
 
Example #7
Source File: TxnPoolTest.java    From aion with MIT License 5 votes vote down vote up
@Test
public void testSnapshotAll2() {
    ECKeyFac.setType(ECKeyFac.ECKeyType.ED25519);
    ECKey key = ECKeyFac.inst().create();

    List<PooledTransaction> txs = new ArrayList<>();
    for (int i = 0; i < 17; i++) {
        AionTransaction tx =
                AionTransaction.create(
                        key,
                        BigInteger.valueOf(i).toByteArray(),
                        AddressUtils.wrapAddress(
                                "0000000000000000000000000000000000000000000000000000000000000001"),
                        ByteUtils.fromHexString("1"),
                        ByteUtils.fromHexString("1"),
                    MIN_ENERGY_CONSUME,
                        1L,
                        TransactionTypes.DEFAULT, null);
        PooledTransaction pooledTx = new PooledTransaction(tx, MIN_ENERGY_CONSUME);
        txs.add(pooledTx);
    }

    Properties config = new Properties();
    ITxPool tp = new TxPoolA0(config);

    tp.add(txs.subList(0, 17));
    assertEquals(17, tp.snapshot().size());
    assertEquals(17, tp.snapshotAll().size());
}
 
Example #8
Source File: TxnPoolTest.java    From aion with MIT License 5 votes vote down vote up
@Test
public void testSnapshotAll() {
    ECKeyFac.setType(ECKeyFac.ECKeyType.ED25519);
    ECKey key = ECKeyFac.inst().create();

    List<PooledTransaction> txs = new ArrayList<>();
    for (int i = 0; i < 1000; i++) {
        AionTransaction tx =
                AionTransaction.create(
                        key,
                        BigInteger.valueOf(i).toByteArray(),
                        AddressUtils.wrapAddress(
                                "0000000000000000000000000000000000000000000000000000000000000001"),
                        ByteUtils.fromHexString("1"),
                        ByteUtils.fromHexString("1"),
                    MIN_ENERGY_CONSUME,
                        1L,
                        TransactionTypes.DEFAULT, null);
        PooledTransaction pooledTx = new PooledTransaction(tx, MIN_ENERGY_CONSUME);
        txs.add(pooledTx);
    }

    Properties config = new Properties();
    ITxPool tp = new TxPoolA0(config);

    tp.add(txs.subList(0, 476));
    assertEquals(476, tp.snapshot().size());
    assertEquals(476, tp.snapshotAll().size());

    tp.remove(txs.subList(0, 100));
    assertEquals(376, tp.snapshot().size());
    assertEquals(376, tp.snapshotAll().size());
}
 
Example #9
Source File: TxnPoolTest.java    From aion with MIT License 5 votes vote down vote up
private PooledTransaction genTransactionRandomPrice(byte[] nonce, ECKey key, long energyConsumed) {
    AionTransaction tx =
            AionTransaction.create(
                    key,
                    nonce,
                    AddressUtils.wrapAddress(
                            "0000000000000000000000000000000000000000000000000000000000000001"),
                    ByteUtils.fromHexString("1"),
                    ByteUtils.fromHexString("1"),
                    MIN_ENERGY_CONSUME,
                    1 + r.nextInt(1000),
                    TransactionTypes.DEFAULT,
                    null);
    return new PooledTransaction(tx, energyConsumed);
}
 
Example #10
Source File: TxnPoolTest.java    From aion with MIT License 5 votes vote down vote up
private PooledTransaction genTransactionWithTimestamp(byte[] nonce, ECKey key, byte[] timeStamp, long energyConsumed) {
    AionTransaction tx = AionTransaction.createGivenTimestamp(
            key,
            nonce,
            AddressUtils.wrapAddress("0000000000000000000000000000000000000000000000000000000000000001"),
            ByteUtils.fromHexString("1"),
            ByteUtils.fromHexString("1"),
        MIN_ENERGY_CONSUME,
            1L,
            TransactionTypes.DEFAULT,
            timeStamp, null);
    return new PooledTransaction(tx, energyConsumed);
}
 
Example #11
Source File: TxnPoolTest.java    From aion with MIT License 5 votes vote down vote up
private PooledTransaction genTransaction(byte[] nonce, int _index, long energyConsumed) {
    AionTransaction tx =
            AionTransaction.create(
                    key.get(_index),
                    nonce,
                    AddressUtils.wrapAddress(
                            "0000000000000000000000000000000000000000000000000000000000000001"),
                    ByteUtils.fromHexString("1"),
                    ByteUtils.fromHexString("1"),
                MIN_ENERGY_CONSUME,
                    1L,
                    TransactionTypes.DEFAULT, null);
    return new PooledTransaction(tx, energyConsumed);
}
 
Example #12
Source File: TxnPoolTest.java    From aion with MIT License 5 votes vote down vote up
private PooledTransaction genTransaction(byte[] nonce, long energyConsumed) {
    AionTransaction tx =
            AionTransaction.create(
                    key.get(0),
                    nonce,
                    AddressUtils.wrapAddress(
                            "0000000000000000000000000000000000000000000000000000000000000001"),
                    ByteUtils.fromHexString("1"),
                    ByteUtils.fromHexString("1"),
                MIN_ENERGY_CONSUME,
                    1L,
                    TransactionTypes.DEFAULT, null);
    return new PooledTransaction(tx, energyConsumed);
}
 
Example #13
Source File: TxnPoolTest.java    From aion with MIT License 5 votes vote down vote up
private List<PooledTransaction> getMockTransaction(long energyConsumed) {
    AionTransaction tx =
            AionTransaction.create(
                    key.get(0),
                    ByteUtils.fromHexString("0000000000000001"),
                    AddressUtils.wrapAddress(
                        "0000000000000000000000000000000000000000000000000000000000000001"),
                    ByteUtils.fromHexString("1"),
                    ByteUtils.fromHexString("1"),
                MIN_ENERGY_CONSUME,
                    1L,
                    TransactionTypes.DEFAULT, null);

    return Collections.singletonList(new PooledTransaction(tx, energyConsumed));
}
 
Example #14
Source File: TxPoolV1Test.java    From aion with MIT License 5 votes vote down vote up
@Test
public void updatePoolTransactionTest() {
    List<PooledTransaction> txs = new ArrayList<>();
    AionTransaction tx =
        AionTransaction.create(
            key.get(0),
            BigInteger.valueOf(0).toByteArray(),
            AddressUtils.wrapAddress(
                "0000000000000000000000000000000000000000000000000000000000000001"),
            ByteUtils.fromHexString("1"),
            ByteUtils.fromHexString("1"),
            Constant.MIN_ENERGY_CONSUME,
            1L,
            TransactionTypes.DEFAULT,
            null);
    PooledTransaction pooledTx = new PooledTransaction(tx, Constant.MIN_ENERGY_CONSUME);
    txs.add(pooledTx);

    Properties config = new Properties();
    config.put(TXPOOL_PROPERTY.PROP_POOL_SIZE_MAX, String.valueOf(Constant.TXPOOL_SIZE_MIN));
    TxPoolV1 tp = new TxPoolV1(config);

    PooledTransaction pTx = tp.add(txs).get(0);
    assertNotNull(pTx);
    assertEquals(tx, pTx.tx);

    PooledTransaction newPtx = new PooledTransaction(tx, Constant.MIN_ENERGY_CONSUME+1);
    tp.updatePoolTransaction(newPtx);

    PooledTransaction ptx = tp.getPoolTx(new AionAddress(key.get(0).getAddress()), BigInteger.ZERO);
    assertNotNull(ptx);
    assertEquals(newPtx, ptx);
    assertEquals(tx, ptx.tx);
}
 
Example #15
Source File: TxPoolV1Test.java    From aion with MIT License 5 votes vote down vote up
@Test
public void isContainedTest() {
    List<PooledTransaction> txs = new ArrayList<>();
    AionTransaction tx =
        AionTransaction.create(
            key.get(0),
            BigInteger.valueOf(0).toByteArray(),
            AddressUtils.wrapAddress(
                "0000000000000000000000000000000000000000000000000000000000000001"),
            ByteUtils.fromHexString("1"),
            ByteUtils.fromHexString("1"),
            Constant.MIN_ENERGY_CONSUME,
            1L,
            TransactionTypes.DEFAULT,
            null);
    PooledTransaction pooledTx = new PooledTransaction(tx, Constant.MIN_ENERGY_CONSUME);
    txs.add(pooledTx);

    Properties config = new Properties();
    config.put(TXPOOL_PROPERTY.PROP_POOL_SIZE_MAX, String.valueOf(Constant.TXPOOL_SIZE_MIN));
    TxPoolV1 tp = new TxPoolV1(config);

    assertThat(tp.isContained(new AionAddress(key.get(0).getAddress()), BigInteger.ZERO)).isFalse();
    tp.add(txs);
    assertThat(tp.isContained(new AionAddress(key.get(0).getAddress()), BigInteger.ZERO)).isTrue();
    assertThat(tp.isContained(new AionAddress(key.get(0).getAddress()), BigInteger.ONE)).isFalse();
}
 
Example #16
Source File: TxPoolV1Test.java    From aion with MIT License 5 votes vote down vote up
@Test
public void getPoolTxTest() {

    List<PooledTransaction> txs = new ArrayList<>();
    AionTransaction tx =
        AionTransaction.create(
            key.get(0),
            BigInteger.valueOf(0).toByteArray(),
            AddressUtils.wrapAddress(
                "0000000000000000000000000000000000000000000000000000000000000001"),
            ByteUtils.fromHexString("1"),
            ByteUtils.fromHexString("1"),
            Constant.MIN_ENERGY_CONSUME,
            1L,
            TransactionTypes.DEFAULT,
            null);
    PooledTransaction pooledTx = new PooledTransaction(tx, Constant.MIN_ENERGY_CONSUME);
    txs.add(pooledTx);

    Properties config = new Properties();
    config.put(TXPOOL_PROPERTY.PROP_POOL_SIZE_MAX, String.valueOf(Constant.TXPOOL_SIZE_MIN));
    TxPoolV1 tp = new TxPoolV1(config);

    List<PooledTransaction> pooledTransactions = tp.add(txs);

    assertNull(tp.getPoolTx(new AionAddress(key.get(1).getAddress()), BigInteger.ZERO));
    assertNull(tp.getPoolTx(new AionAddress(key.get(0).getAddress()), BigInteger.ONE));
    PooledTransaction pTx = tp.getPoolTx(new AionAddress(key.get(0).getAddress()), BigInteger.ZERO);
    assertNotNull(pTx);
    assertEquals(tx, pTx.tx);
}
 
Example #17
Source File: TxPoolV1Test.java    From aion with MIT License 5 votes vote down vote up
@Test
public void addRepeatedTxn() {
    Properties config = new Properties();
    config.put(TXPOOL_PROPERTY.PROP_TX_TIMEOUT, "10");

    TxPoolV1 tp = new TxPoolV1(config);
    AionTransaction txn =
            AionTransaction.create(
                    key.get(0),
                    ByteUtils.fromHexString("0000000000000001"),
                    new AionAddress(key.get(0).getAddress()),
                    ByteUtils.fromHexString("1"),
                    ByteUtils.fromHexString("1"),
                    Constant.MIN_ENERGY_CONSUME,
                    1L,
                    TransactionTypes.DEFAULT,
                    null);

    PooledTransaction pooledTx = new PooledTransaction(txn, 0);

    List<PooledTransaction> txnl = new ArrayList<>();
    txnl.add(pooledTx);
    txnl.add(pooledTx);
    tp.add(txnl);

    Assert.assertEquals(1, tp.size());
}
 
Example #18
Source File: TxPoolV1Test.java    From aion with MIT License 5 votes vote down vote up
private PooledTransaction genTransaction(byte[] nonce, long energyConsumed) {
    AionTransaction tx =
            AionTransaction.create(
                    key.get(0),
                    nonce,
                    AddressUtils.wrapAddress(
                            "0000000000000000000000000000000000000000000000000000000000000001"),
                    ByteUtils.fromHexString("1"),
                    ByteUtils.fromHexString("1"),
                    Constant.MIN_ENERGY_CONSUME,
                    1L,
                    TransactionTypes.DEFAULT,
                    null);
    return new PooledTransaction(tx, energyConsumed);
}
 
Example #19
Source File: TxPoolV1Test.java    From aion with MIT License 5 votes vote down vote up
private PooledTransaction genTransactionWithEnergyPrice(byte[] nonce, long energyPrice) {
    AionTransaction tx =
            AionTransaction.create(
                    key.get(0),
                    nonce,
                    AddressUtils.wrapAddress(
                            "0000000000000000000000000000000000000000000000000000000000000001"),
                    ByteUtils.fromHexString("1"),
                    ByteUtils.fromHexString("1"),
                    Constant.MIN_ENERGY_CONSUME,
                    energyPrice,
                    TransactionTypes.DEFAULT,
                    null);
    return new PooledTransaction(tx, Constant.MIN_ENERGY_CONSUME);
}
 
Example #20
Source File: TxPoolV1Test.java    From aion with MIT License 5 votes vote down vote up
private PooledTransaction genTransaction(byte[] nonce, int _index) {
    AionTransaction tx =
            AionTransaction.create(
                    key.get(_index),
                    nonce,
                    AddressUtils.wrapAddress(
                            "0000000000000000000000000000000000000000000000000000000000000001"),
                    ByteUtils.fromHexString("1"),
                    ByteUtils.fromHexString("1"),
                    Constant.MIN_ENERGY_CONSUME,
                    1L,
                    TransactionTypes.DEFAULT,
                    null);
    return new PooledTransaction(tx, Constant.MIN_ENERGY_CONSUME);
}
 
Example #21
Source File: TxPoolV1Test.java    From aion with MIT License 5 votes vote down vote up
@Test
public void poolFullTest() {
    List<PooledTransaction> txs = new ArrayList<>();
    for (int i = 0; i < Constant.TXPOOL_SIZE_MIN + 1; i++) {
        AionTransaction tx =
            AionTransaction.create(
                key.get(0),
                BigInteger.valueOf(i).toByteArray(),
                AddressUtils.wrapAddress(
                    "0000000000000000000000000000000000000000000000000000000000000001"),
                ByteUtils.fromHexString("1"),
                ByteUtils.fromHexString("1"),
                Constant.MIN_ENERGY_CONSUME,
                1L,
                TransactionTypes.DEFAULT,
                null);
        PooledTransaction pooledTx = new PooledTransaction(tx, Constant.MIN_ENERGY_CONSUME);
        txs.add(pooledTx);
    }

    Properties config = new Properties();
    config.put(TXPOOL_PROPERTY.PROP_POOL_SIZE_MAX, String.valueOf(Constant.TXPOOL_SIZE_MIN));
    TxPoolV1 tp = new TxPoolV1(config);

    List<PooledTransaction> pooledTransactions = tp.add(txs);
    assertThat(tp.isFull()).isTrue();
    assertEquals(Constant.TXPOOL_SIZE_MIN, pooledTransactions.size());
}
 
Example #22
Source File: TxPoolV1Test.java    From aion with MIT License 5 votes vote down vote up
@Test
public void testSnapshotAll() {

    List<PooledTransaction> txs = new ArrayList<>();
    for (int i = 0; i < 1000; i++) {
        AionTransaction tx =
                AionTransaction.create(
                        key.get(0),
                        BigInteger.valueOf(i).toByteArray(),
                        AddressUtils.wrapAddress(
                                "0000000000000000000000000000000000000000000000000000000000000001"),
                        ByteUtils.fromHexString("1"),
                        ByteUtils.fromHexString("1"),
                        Constant.MIN_ENERGY_CONSUME,
                        1L,
                        TransactionTypes.DEFAULT,
                        null);
        PooledTransaction pooledTx = new PooledTransaction(tx, Constant.MIN_ENERGY_CONSUME);
        txs.add(pooledTx);
    }

    Properties config = new Properties();
    TxPoolV1 tp = new TxPoolV1(config);

    tp.add(txs.subList(0, 476));
    assertEquals(476, tp.snapshot().size());
    assertEquals(476, tp.snapshotAll().size());

    tp.remove(txs.subList(0, 100));
    assertEquals(376, tp.snapshot().size());
    assertEquals(376, tp.snapshotAll().size());
}
 
Example #23
Source File: TxPoolV1Test.java    From aion with MIT License 5 votes vote down vote up
@Test
public void testSnapshotAll2() {

    List<PooledTransaction> txs = new ArrayList<>();
    for (int i = 0; i < 17; i++) {
        AionTransaction tx =
                AionTransaction.create(
                        key.get(0),
                        BigInteger.valueOf(i).toByteArray(),
                        AddressUtils.wrapAddress(
                                "0000000000000000000000000000000000000000000000000000000000000001"),
                        ByteUtils.fromHexString("1"),
                        ByteUtils.fromHexString("1"),
                        Constant.MIN_ENERGY_CONSUME,
                        1L,
                        TransactionTypes.DEFAULT,
                        null);
        PooledTransaction pooledTx = new PooledTransaction(tx, Constant.MIN_ENERGY_CONSUME);
        txs.add(pooledTx);
    }

    Properties config = new Properties();
    TxPoolV1 tp = new TxPoolV1(config);

    tp.add(txs.subList(0, 17));
    assertEquals(17, tp.snapshot().size());
    assertEquals(17, tp.snapshotAll().size());
}
 
Example #24
Source File: TxPoolV1Test.java    From aion with MIT License 5 votes vote down vote up
@Test
public void isFullTest() {

    List<PooledTransaction> txs = new ArrayList<>();
    for (int i = 0; i < Constant.TXPOOL_SIZE_MIN; i++) {
        AionTransaction tx =
            AionTransaction.create(
                key.get(0),
                BigInteger.valueOf(i).toByteArray(),
                AddressUtils.wrapAddress(
                    "0000000000000000000000000000000000000000000000000000000000000001"),
                ByteUtils.fromHexString("1"),
                ByteUtils.fromHexString("1"),
                Constant.MIN_ENERGY_CONSUME,
                1L,
                TransactionTypes.DEFAULT,
                null);
        PooledTransaction pooledTx = new PooledTransaction(tx, Constant.MIN_ENERGY_CONSUME);
        txs.add(pooledTx);
    }

    Properties config = new Properties();
    config.put(TXPOOL_PROPERTY.PROP_POOL_SIZE_MAX, String.valueOf(Constant.TXPOOL_SIZE_MIN));
    TxPoolV1 tp = new TxPoolV1(config);

    assertThat(tp.isFull()).isFalse();

    tp.add(txs);
    assertThat(tp.isFull()).isTrue();
}
 
Example #25
Source File: TxnPoolTest.java    From aion with MIT License 4 votes vote down vote up
@Test
public void feemapTest() {
    Properties config = new Properties();
    config.put(TxPoolA0.PROP_TX_TIMEOUT, "10");

    TxPoolA0 tp = new TxPoolA0(config);

    List<PooledTransaction> txnl = new ArrayList<>();
    int cnt = 100;
    byte[] nonce = new byte[Long.BYTES];
    for (int i = 0; i < cnt; i++) {
        nonce[Long.BYTES - 1] = (byte) i;

        AionTransaction txn =
                AionTransaction.create(
                        key2.get(i),
                        nonce,
                        AddressUtils.wrapAddress(
                                "0000000000000000000000000000000000000000000000000000000000000001"),
                        ByteUtils.fromHexString("1"),
                        ByteUtils.fromHexString("1"),
                    MIN_ENERGY_CONSUME,
                        1L,
                        TransactionTypes.DEFAULT, null);
        PooledTransaction pooledTx = new PooledTransaction(txn, i + MIN_ENERGY_CONSUME + 1);
        txnl.add(pooledTx);
    }
    tp.add(txnl);

    Assert.assertEquals(tp.size(), cnt);

    // sort the inserted txs
    tp.snapshot();

    List<BigInteger> nl = tp.getFeeList();

    long val = 100;
    for (int i = 0; i < cnt; i++) {
        Assert.assertEquals(0, nl.get(i).compareTo(BigInteger.valueOf(MIN_ENERGY_CONSUME + val--)));
    }
}
 
Example #26
Source File: CallTransaction.java    From BlockchainWallet-Crypto with GNU General Public License v3.0 4 votes vote down vote up
public Object[] decode(byte[] encoded) {
    //import static org.apache.commons.lang3.ArrayUtils.subarray;
    //return decode(subarray(encoded, 4, encoded.length), inputs);
    return decode(ByteUtils.subArray(encoded, 4, encoded.length), inputs);
}
 
Example #27
Source File: TxnPoolBenchmarkTest.java    From aion with MIT License 4 votes vote down vote up
@Test
/* 100K new transactions in pool around 350ms (cold-call)

  the second time snapshot is around 35ms
*/
public void benchmarkSnapshot5() {
    Properties config = new Properties();
    config.put("tx-timeout", "100");

    TxPoolA0 tp = new TxPoolA0(config);

    List<PooledTransaction> txnl = new ArrayList<>();
    int cnt = 10000;
    for (ECKey aKey1 : key) {
        for (int i = 0; i < cnt; i++) {
            AionTransaction txn =
                    AionTransaction.create(
                            aKey1,
                            BigInteger.valueOf(i).toByteArray(),
                            AddressUtils.wrapAddress(
                                    "0000000000000000000000000000000000000000000000000000000000000001"),
                            ByteUtils.fromHexString("1"),
                            ByteUtils.fromHexString("1"),
                        MIN_ENERGY_CONSUME,
                            1L,
                            TransactionTypes.DEFAULT, null);
            PooledTransaction pooledTx = new PooledTransaction(txn, MIN_ENERGY_CONSUME);
            txnl.add(pooledTx);
        }
    }

    tp.add(txnl);
    Assert.assertEquals(tp.size(), cnt * key.size());

    // sort the inserted txs
    System.out.println("1st time snapshot...");
    long start = System.currentTimeMillis();
    tp.snapshot();
    System.out.println("1st time spent: " + (System.currentTimeMillis() - start) + " ms.");

    System.out.println("2nd time snapshot...");
    start = System.currentTimeMillis();
    tp.snapshot();
    System.out.println("2nd time spent: " + (System.currentTimeMillis() - start) + " ms.");

    for (ECKey aKey : key) {
        List<BigInteger> nl = tp.getNonceList(new AionAddress(aKey.getAddress()));
        for (int i = 0; i < cnt; i++) {
            Assert.assertEquals(nl.get(i), BigInteger.valueOf(i));
        }
    }
}
 
Example #28
Source File: TxnPoolBenchmarkTest.java    From aion with MIT License 4 votes vote down vote up
@Test
/* 100K new transactions in pool around 350ms (cold-call)
 */
public void benchmarkSnapshot4() {
    Properties config = new Properties();
    config.put("tx-timeout", "100");

    TxPoolA0 tp = new TxPoolA0(config);

    List<PooledTransaction> txnl = new ArrayList<>();
    List<PooledTransaction> txnlrm = new ArrayList<>();
    int cnt = 100000;
    int rmCnt = 10;
    System.out.println("gen new transactions...");
    long start = System.currentTimeMillis();
    for (int i = 0; i < cnt; i++) {
        AionTransaction txn =
                AionTransaction.create(
                        key.get(0),
                        BigInteger.valueOf(i).toByteArray(),
                        AddressUtils.wrapAddress(
                                "0000000000000000000000000000000000000000000000000000000000000001"),
                        ByteUtils.fromHexString("1"),
                        ByteUtils.fromHexString("1"),
                    MIN_ENERGY_CONSUME,
                        1L,
                        TransactionTypes.DEFAULT, null);
        PooledTransaction pooledTx = new PooledTransaction(txn, MIN_ENERGY_CONSUME);
        txnl.add(pooledTx);

        if (i < rmCnt) {
            txnlrm.add(pooledTx);
        }
    }
    System.out.println("time spent: " + (System.currentTimeMillis() - start) + " ms.");

    System.out.println("Inserting txns...");
    start = System.currentTimeMillis();
    tp.add(txnl);
    System.out.println("time spent: " + (System.currentTimeMillis() - start) + " ms.");
    Assert.assertEquals(tp.size(), cnt);

    // sort the inserted txs
    System.out.println("Snapshoting...");
    start = System.currentTimeMillis();
    tp.snapshot();
    System.out.println("time spent: " + (System.currentTimeMillis() - start) + " ms.");

    System.out.println("Removing the first 10 txns...");
    start = System.currentTimeMillis();
    List rm = tp.remove(txnlrm);
    System.out.println("time spent: " + (System.currentTimeMillis() - start) + " ms.");
    Assert.assertEquals(rm.size(), rmCnt);
    Assert.assertEquals(tp.size(), cnt - rmCnt);

    System.out.println("Re-Snapshot after some txns was been removed...");
    start = System.currentTimeMillis();
    tp.snapshot();
    System.out.println("time spent: " + (System.currentTimeMillis() - start) + " ms.");

    List<BigInteger> nl = tp.getNonceList(new AionAddress(key.get(0).getAddress()));
    for (int i = 0; i < nl.size(); i++) {
        Assert.assertEquals(nl.get(i), BigInteger.valueOf(i).add(BigInteger.valueOf(rmCnt)));
    }
}
 
Example #29
Source File: TxnPoolBenchmarkTest.java    From aion with MIT License 4 votes vote down vote up
@Test
@Ignore
/* 1M new transactions with 10000 accounts (100 txs per account)in pool snapshot around 10s (cold-call)
  gen new txns 55s (spent a lot of time to sign tx)
  put txns into pool 2.5s
  snapshot txn 5s
*/
public void benchmarkSnapshot3() {
    Properties config = new Properties();
    config.put("tx-timeout", "100");

    TxPoolA0 tp = new TxPoolA0(config);

    List<PooledTransaction> txnl = new ArrayList<>();
    int cnt = 100;
    System.out.println("Gen new transactions --");
    long start = System.currentTimeMillis();
    for (ECKey aKey21 : key2) {
        for (int i = 0; i < cnt; i++) {
            AionTransaction txn =
                    AionTransaction.create(
                            aKey21,
                            BigInteger.valueOf(i).toByteArray(),
                            AddressUtils.wrapAddress(
                                    "0000000000000000000000000000000000000000000000000000000000000001"),
                            ByteUtils.fromHexString("1"),
                            ByteUtils.fromHexString("1"),
                        MIN_ENERGY_CONSUME,
                            1L,
                            TransactionTypes.DEFAULT, null);
            PooledTransaction pooledTx = new PooledTransaction(txn, MIN_ENERGY_CONSUME);
            txnl.add(pooledTx);
        }
    }
    System.out.println("time spent: " + (System.currentTimeMillis() - start) + " ms.");

    System.out.println("Adding transactions into pool--");
    start = System.currentTimeMillis();
    tp.add(txnl);
    System.out.println("time spent: " + (System.currentTimeMillis() - start) + " ms.");

    Assert.assertEquals(tp.size(), cnt * key2.size());

    // sort the inserted txs
    System.out.println("Snapshoting --");
    start = System.currentTimeMillis();
    tp.snapshot();
    System.out.println("time spent: " + (System.currentTimeMillis() - start) + " ms.");

    for (ECKey aKey2 : key2) {
        List<BigInteger> nl = tp.getNonceList(new AionAddress(aKey2.getAddress()));
        for (int i = 0; i < cnt; i++) {
            Assert.assertEquals(nl.get(i), BigInteger.valueOf(i));
        }
    }
}
 
Example #30
Source File: TxnPoolBenchmarkTest.java    From aion with MIT License 4 votes vote down vote up
@Test
public void benchmarkSnapshot() {
    Properties config = new Properties();
    config.put("tx-timeout", "100");

    TxPoolA0 tp = new TxPoolA0(config);

    List<PooledTransaction> txnl = new ArrayList<>();
    int cnt = 10000;
    for (ECKey aKey1 : key) {
        for (int i = 0; i < cnt; i++) {
            AionTransaction txn =
                    AionTransaction.create(
                            aKey1,
                            BigInteger.valueOf(i).toByteArray(),
                            AddressUtils.wrapAddress(
                                    "0000000000000000000000000000000000000000000000000000000000000001"),
                            ByteUtils.fromHexString("1"),
                            ByteUtils.fromHexString("1"),
                        MIN_ENERGY_CONSUME,
                            1L,
                            TransactionTypes.DEFAULT, null);
            PooledTransaction pooledTx = new PooledTransaction(txn, MIN_ENERGY_CONSUME);
            txnl.add(pooledTx);
        }
    }

    tp.add(txnl);
    Assert.assertEquals(tp.size(), cnt * key.size());

    // sort the inserted txs
    long start = System.currentTimeMillis();
    tp.snapshot();
    System.out.println("time spent: " + (System.currentTimeMillis() - start) + " ms.");

    for (ECKey aKey : key) {
        List<BigInteger> nl = tp.getNonceList(new AionAddress(aKey.getAddress()));
        for (int i = 0; i < cnt; i++) {
            Assert.assertEquals(nl.get(i), BigInteger.valueOf(i));
        }
    }
}