Search in sources :

Example 1 with StagingAffectedTransaction

use of com.quorum.tessera.data.staging.StagingAffectedTransaction in project tessera by ConsenSys.

the class StagingEntityDAOTest method createFixtures.

public Map<String, StagingTransaction> createFixtures() {
    final EntityManager entityManager = entityManagerFactory.createEntityManager();
    entityManager.getTransaction().begin();
    final String txnHash1 = Utils.createHashStr();
    final StagingTransaction stTransaction1 = new StagingTransaction();
    stTransaction1.setId(1L);
    stTransaction1.setHash(txnHash1);
    stTransaction1.setEncodedPayloadCodec(CODEC);
    entityManager.persist(stTransaction1);
    final String txnHash2 = Utils.createHashStr();
    final StagingTransaction stTransaction2a = new StagingTransaction();
    stTransaction2a.setId(21L);
    stTransaction2a.setHash(txnHash2);
    stTransaction2a.setEncodedPayloadCodec(CODEC);
    StagingAffectedTransaction stAffectedContractTransaction21a = new StagingAffectedTransaction();
    stAffectedContractTransaction21a.setHash(txnHash1);
    stAffectedContractTransaction21a.setSourceTransaction(stTransaction2a);
    stTransaction2a.getAffectedContractTransactions().add(stAffectedContractTransaction21a);
    entityManager.persist(stTransaction2a);
    // Another version of transaction 2
    final StagingTransaction stTransaction2b = new StagingTransaction();
    stTransaction2b.setId(22L);
    stTransaction2b.setHash(txnHash2);
    stTransaction2b.setEncodedPayloadCodec(CODEC);
    StagingAffectedTransaction stAffectedContractTransaction21b = new StagingAffectedTransaction();
    stAffectedContractTransaction21b.setHash(txnHash1);
    stAffectedContractTransaction21b.setSourceTransaction(stTransaction2b);
    stTransaction2b.getAffectedContractTransactions().add(stAffectedContractTransaction21b);
    entityManager.persist(stTransaction2b);
    final String txnHash4 = Utils.createHashStr();
    // we are storing a transaction TXN4 which depends on another transaction TXN3 (which has not
    // been received yet)
    final String txnHash3 = Utils.createHashStr();
    final StagingTransaction stTransaction4 = new StagingTransaction();
    stTransaction4.setId(4L);
    stTransaction4.setHash(txnHash4);
    stTransaction4.setEncodedPayloadCodec(CODEC);
    StagingAffectedTransaction stAffectedContractTransaction43 = new StagingAffectedTransaction();
    stAffectedContractTransaction43.setHash(txnHash3);
    stAffectedContractTransaction43.setSourceTransaction(stTransaction4);
    stTransaction4.getAffectedContractTransactions().add(stAffectedContractTransaction43);
    entityManager.persist(stTransaction4);
    final StagingTransaction stTransaction3 = new StagingTransaction();
    stTransaction3.setHash(txnHash3);
    stTransaction3.setId(3L);
    stTransaction3.setEncodedPayloadCodec(CODEC);
    StagingAffectedTransaction stAffectedContractTransaction31 = new StagingAffectedTransaction();
    stAffectedContractTransaction31.setHash(txnHash1);
    stAffectedContractTransaction31.setSourceTransaction(stTransaction3);
    stTransaction3.getAffectedContractTransactions().add(stAffectedContractTransaction31);
    entityManager.persist(stTransaction3);
    final String txnHash5 = Utils.createHashStr();
    // TXN5 is a unresolvable transaction as it depends on TXN6 which is never received
    final String txnHash6 = Utils.createHashStr();
    final StagingTransaction stTransaction5 = new StagingTransaction();
    stTransaction5.setHash(txnHash5);
    stTransaction5.setId(5L);
    stTransaction5.setEncodedPayloadCodec(CODEC);
    StagingAffectedTransaction stAffectedContractTransaction56 = new StagingAffectedTransaction();
    stAffectedContractTransaction56.setHash(txnHash6);
    stAffectedContractTransaction56.setSourceTransaction(stTransaction5);
    stTransaction5.getAffectedContractTransactions().add(stAffectedContractTransaction56);
    entityManager.persist(stTransaction5);
    final String txnHash7 = Utils.createHashStr();
    // TXN7 depends on TXN1 and TXN3
    final StagingTransaction stTransaction7 = new StagingTransaction();
    stTransaction7.setHash(txnHash7);
    stTransaction7.setId(7L);
    stTransaction7.setEncodedPayloadCodec(CODEC);
    StagingAffectedTransaction stAffectedContractTransaction71 = new StagingAffectedTransaction();
    stAffectedContractTransaction71.setHash(txnHash1);
    stAffectedContractTransaction71.setSourceTransaction(stTransaction7);
    stTransaction7.getAffectedContractTransactions().add(stAffectedContractTransaction71);
    StagingAffectedTransaction stAffectedContractTransaction74 = new StagingAffectedTransaction();
    stAffectedContractTransaction74.setHash(txnHash4);
    stAffectedContractTransaction74.setSourceTransaction(stTransaction7);
    stTransaction7.getAffectedContractTransactions().add(stAffectedContractTransaction74);
    entityManager.persist(stTransaction7);
    entityManager.getTransaction().commit();
    Map<String, StagingTransaction> transactions = new HashMap<>();
    transactions.put("TXN1", stTransaction1);
    transactions.put("TXN2A", stTransaction2a);
    transactions.put("TXN2B", stTransaction2b);
    transactions.put("TXN3", stTransaction3);
    transactions.put("TXN4", stTransaction4);
    transactions.put("TXN5", stTransaction5);
    transactions.put("TXN7", stTransaction7);
    return transactions;
}
Also used : StagingAffectedTransaction(com.quorum.tessera.data.staging.StagingAffectedTransaction) StagingTransaction(com.quorum.tessera.data.staging.StagingTransaction)

Example 2 with StagingAffectedTransaction

use of com.quorum.tessera.data.staging.StagingAffectedTransaction in project tessera by ConsenSys.

the class StagingEntityDAOTest method testSave.

@Test
public void testSave() {
    String txHash = Utils.createHashStr();
    final StagingTransaction stagingTransaction = new StagingTransaction();
    stagingTransaction.setHash(txHash);
    stagingTransaction.setPrivacyMode(PrivacyMode.STANDARD_PRIVATE);
    stagingTransaction.setEncodedPayloadCodec(CODEC);
    stagingTransaction.setPayload(payloadData);
    final StagingAffectedTransaction affected1 = new StagingAffectedTransaction();
    affected1.setSourceTransaction(stagingTransaction);
    affected1.setHash("affected1");
    final StagingAffectedTransaction affected2 = new StagingAffectedTransaction();
    affected2.setId(123L);
    affected2.setSourceTransaction(stagingTransaction);
    affected2.setHash("affected2");
    stagingTransaction.setAffectedContractTransactions(Stream.of(affected1, affected2).collect(Collectors.toSet()));
    stagingEntityDAO.save(stagingTransaction);
    assertThat(stagingEntityDAO.retrieveByHash(txHash)).isPresent();
    final StagingTransaction retrieved = stagingEntityDAO.retrieveByHash(txHash).get();
    assertThat(retrieved).isEqualTo(stagingTransaction);
    assertThat(retrieved.getValidationStage()).isNull();
    assertThat(retrieved.getPrivacyMode()).isEqualTo(PrivacyMode.STANDARD_PRIVATE);
    assertThat(retrieved.getAffectedContractTransactions()).containsExactlyInAnyOrder(affected1, affected2);
    retrieved.getAffectedContractTransactions().forEach(a -> assertThat(a.getId()).isNotNull());
}
Also used : StagingAffectedTransaction(com.quorum.tessera.data.staging.StagingAffectedTransaction) StagingTransaction(com.quorum.tessera.data.staging.StagingTransaction) Test(org.junit.Test)

Aggregations

StagingAffectedTransaction (com.quorum.tessera.data.staging.StagingAffectedTransaction)2 StagingTransaction (com.quorum.tessera.data.staging.StagingTransaction)2 Test (org.junit.Test)1