Search in sources :

Example 11 with MobileCoinLedgerWrapper

use of org.thoughtcrime.securesms.payments.MobileCoinLedgerWrapper in project Signal-Android by signalapp.

the class LedgerReconcileTest method unmatched_payment_remains_in_place_behind_matched.

@Test
public void unmatched_payment_remains_in_place_behind_matched() {
    List<Payment> localPayments = Arrays.asList(payment("matched payment", mob(10), keyImages(6), publicKeys(2)), payment("unmatched payment", mob(20), keyImages(16), publicKeys(12)));
    MobileCoinLedger ledger = ledger(spentTxo(mob(2.5), keyImage(5), publicKey(2), block(1), block(2)), unspentTxo(mob(1.5), keyImage(7), publicKey(8), block(3)));
    List<Payment> payments = reconcile(localPayments, new MobileCoinLedgerWrapper(ledger));
    assertEquals(Arrays.asList(mob(1.5), mob(-2.5), mob(10), mob(20)), Stream.of(payments).map(Payment::getAmountWithDirection).toList());
}
Also used : Payment(org.thoughtcrime.securesms.payments.Payment) MobileCoinLedger(org.thoughtcrime.securesms.payments.proto.MobileCoinLedger) MobileCoinLedgerWrapper(org.thoughtcrime.securesms.payments.MobileCoinLedgerWrapper) Test(org.junit.Test)

Example 12 with MobileCoinLedgerWrapper

use of org.thoughtcrime.securesms.payments.MobileCoinLedgerWrapper in project Signal-Android by signalapp.

the class LedgerReconcileTest method single_spend_payment_that_can_be_found_on_ledger_reconstructed_receipt.

@Test
public void single_spend_payment_that_can_be_found_on_ledger_reconstructed_receipt() {
    List<Payment> localPayments = Collections.singletonList(payment("sent", mob(-1.5), keyImages(5), publicKeys(4)));
    MobileCoinLedger ledger = ledger(spentTxo(mob(2.5), keyImage(5), publicKey(2), block(1), block(2)), unspentTxo(mob(1), keyImage(3), publicKey(4), block(2)));
    List<Payment> payments = reconcile(localPayments, new MobileCoinLedgerWrapper(ledger));
    assertEquals(2, payments.size());
    assertEquals(mob(-1.5), payments.get(0).getAmountWithDirection());
    assertEquals(mob(2.5), payments.get(1).getAmountWithDirection());
}
Also used : Payment(org.thoughtcrime.securesms.payments.Payment) MobileCoinLedger(org.thoughtcrime.securesms.payments.proto.MobileCoinLedger) MobileCoinLedgerWrapper(org.thoughtcrime.securesms.payments.MobileCoinLedgerWrapper) Test(org.junit.Test)

Example 13 with MobileCoinLedgerWrapper

use of org.thoughtcrime.securesms.payments.MobileCoinLedgerWrapper in project Signal-Android by signalapp.

the class LedgerReconcileTest method single_receipt_payment_that_can_be_found_on_ledger_reconstructed_spend.

@Test
public void single_receipt_payment_that_can_be_found_on_ledger_reconstructed_spend() {
    List<Payment> localPayments = Collections.singletonList(payment("received", mob(2.5), keyImages(6), publicKeys(2)));
    MobileCoinLedger ledger = ledger(spentTxo(mob(2.5), keyImage(5), publicKey(2), block(1), block(2)));
    List<Payment> payments = reconcile(localPayments, new MobileCoinLedgerWrapper(ledger));
    assertEquals(2, payments.size());
    assertEquals(mob(-2.5), payments.get(0).getAmountWithDirection());
    assertEquals(mob(2.5), payments.get(1).getAmountWithDirection());
    assertEquals(2, payments.get(0).getBlockIndex());
    assertEquals("received", payments.get(1).getNote());
    assertEquals(1, payments.get(1).getBlockIndex());
}
Also used : Payment(org.thoughtcrime.securesms.payments.Payment) MobileCoinLedger(org.thoughtcrime.securesms.payments.proto.MobileCoinLedger) MobileCoinLedgerWrapper(org.thoughtcrime.securesms.payments.MobileCoinLedgerWrapper) Test(org.junit.Test)

Example 14 with MobileCoinLedgerWrapper

use of org.thoughtcrime.securesms.payments.MobileCoinLedgerWrapper in project Signal-Android by signalapp.

the class LedgerReconcileTest method single_unspent_transaction_on_ledger_only.

@Test
public void single_unspent_transaction_on_ledger_only() {
    MobileCoinLedger ledger = ledger(unspentTxo(mob(2.5), keyImage(2), publicKey(3), block(2)));
    List<Payment> payments = reconcile(Collections.emptyList(), new MobileCoinLedgerWrapper(ledger));
    assertEquals(1, payments.size());
    Payment payment = payments.get(0);
    assertEquals(mob(2.5), payment.getAmount());
    assertEquals(mob(2.5), payment.getAmountWithDirection());
    assertEquals(Direction.RECEIVED, payment.getDirection());
    assertEquals(mob(0), payment.getFee());
    assertEquals(Payee.UNKNOWN, payment.getPayee());
    assertEquals(State.SUCCESSFUL, payment.getState());
    assertEquals(UuidUtil.UNKNOWN_UUID, payment.getUuid());
    assertEquals("", payment.getNote());
}
Also used : Payment(org.thoughtcrime.securesms.payments.Payment) MobileCoinLedger(org.thoughtcrime.securesms.payments.proto.MobileCoinLedger) MobileCoinLedgerWrapper(org.thoughtcrime.securesms.payments.MobileCoinLedgerWrapper) Test(org.junit.Test)

Example 15 with MobileCoinLedgerWrapper

use of org.thoughtcrime.securesms.payments.MobileCoinLedgerWrapper in project Signal-Android by WhisperSystems.

the class LedgerReconcileTest method single_unspent_transaction_on_ledger_only.

@Test
public void single_unspent_transaction_on_ledger_only() {
    MobileCoinLedger ledger = ledger(unspentTxo(mob(2.5), keyImage(2), publicKey(3), block(2)));
    List<Payment> payments = reconcile(Collections.emptyList(), new MobileCoinLedgerWrapper(ledger));
    assertEquals(1, payments.size());
    Payment payment = payments.get(0);
    assertEquals(mob(2.5), payment.getAmount());
    assertEquals(mob(2.5), payment.getAmountWithDirection());
    assertEquals(Direction.RECEIVED, payment.getDirection());
    assertEquals(mob(0), payment.getFee());
    assertEquals(Payee.UNKNOWN, payment.getPayee());
    assertEquals(State.SUCCESSFUL, payment.getState());
    assertEquals(UuidUtil.UNKNOWN_UUID, payment.getUuid());
    assertEquals("", payment.getNote());
}
Also used : Payment(org.thoughtcrime.securesms.payments.Payment) MobileCoinLedger(org.thoughtcrime.securesms.payments.proto.MobileCoinLedger) MobileCoinLedgerWrapper(org.thoughtcrime.securesms.payments.MobileCoinLedgerWrapper) Test(org.junit.Test)

Aggregations

MobileCoinLedgerWrapper (org.thoughtcrime.securesms.payments.MobileCoinLedgerWrapper)26 Test (org.junit.Test)24 Payment (org.thoughtcrime.securesms.payments.Payment)24 MobileCoinLedger (org.thoughtcrime.securesms.payments.proto.MobileCoinLedger)22 PaymentDatabase (org.thoughtcrime.securesms.database.PaymentDatabase)2 RetryLaterException (org.thoughtcrime.securesms.transport.RetryLaterException)2