Search in sources :

Example 1 with MobileCoinLedger

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

the class LedgerReconcileTest method single_spent_transaction_on_ledger.

@Test
public void single_spent_transaction_on_ledger() {
    MobileCoinLedger ledger = ledger(spentTxo(mob(10), keyImage(1), publicKey(2), block(1), block(2)));
    List<Payment> payments = reconcile(Collections.emptyList(), new MobileCoinLedgerWrapper(ledger));
    assertEquals(2, payments.size());
    Payment payment1 = payments.get(0);
    assertEquals(mob(10), payment1.getAmount());
    assertEquals(mob(-10), payment1.getAmountWithDirection());
    assertEquals(Direction.SENT, payment1.getDirection());
    assertEquals(mob(0), payment1.getFee());
    assertEquals(Payee.UNKNOWN, payment1.getPayee());
    assertEquals(State.SUCCESSFUL, payment1.getState());
    assertEquals(UuidUtil.UNKNOWN_UUID, payment1.getUuid());
    assertEquals("", payment1.getNote());
    Payment payment2 = payments.get(1);
    assertEquals(mob(10), payment2.getAmount());
    assertEquals(mob(10), payment2.getAmountWithDirection());
    assertEquals(Direction.RECEIVED, payment2.getDirection());
    assertEquals(mob(0), payment2.getFee());
    assertEquals(Payee.UNKNOWN, payment2.getPayee());
    assertEquals(State.SUCCESSFUL, payment2.getState());
    assertEquals(UuidUtil.UNKNOWN_UUID, payment2.getUuid());
    assertEquals("", payment2.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 2 with MobileCoinLedger

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

the class LedgerReconcileTest method one_received_and_one_spent_transaction_on_ledger_only_different_blocks.

@Test
public void one_received_and_one_spent_transaction_on_ledger_only_different_blocks() {
    MobileCoinLedger ledger = ledger(spentTxo(mob(2.5), keyImage(1), publicKey(2), block(1), block(2)), unspentTxo(mob(1), keyImage(3), publicKey(4), block(3)));
    List<Payment> payments = reconcile(Collections.emptyList(), new MobileCoinLedgerWrapper(ledger));
    assertEquals(3, payments.size());
    assertEquals(mob(1), payments.get(0).getAmountWithDirection());
    assertEquals(mob(-2.5), payments.get(1).getAmountWithDirection());
    assertEquals(mob(2.5), payments.get(2).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 3 with MobileCoinLedger

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

the class LedgerReconcileTest method unknown_payment_remains_in_place_behind_known_alternative_block_order.

@Test
public void unknown_payment_remains_in_place_behind_known_alternative_block_order() {
    List<Payment> localPayments = Arrays.asList(payment("matched payment", mob(10), keyImages(60), publicKeys(7)), payment("unmatched payment", mob(20), keyImages(16), publicKeys(12)));
    MobileCoinLedger ledger = ledger(spentTxo(mob(2.5), keyImage(5), publicKey(2), block(10), block(20)), unspentTxo(mob(10), keyImage(9), publicKey(7), block(15)));
    List<Payment> payments = reconcile(localPayments, new MobileCoinLedgerWrapper(ledger));
    assertEquals(Arrays.asList(20L, 15L, 0L, 10L), Stream.of(payments).map(Payment::getBlockIndex).toList());
    assertEquals(Arrays.asList(mob(-2.5), mob(10), mob(20), mob(2.5)), 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 4 with MobileCoinLedger

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

the class LedgerReconcileTest method one_received_and_one_spent_transaction_on_ledger_only_same_block_is_treated_as_change.

@Test
public void one_received_and_one_spent_transaction_on_ledger_only_same_block_is_treated_as_change() {
    MobileCoinLedger ledger = ledger(spentTxo(mob(2.5), keyImage(1), publicKey(2), block(1), block(2)), unspentTxo(mob(1), keyImage(3), publicKey(4), block(2)));
    List<Payment> payments = reconcile(Collections.emptyList(), 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 5 with MobileCoinLedger

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

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)

Aggregations

Test (org.junit.Test)11 MobileCoinLedgerWrapper (org.thoughtcrime.securesms.payments.MobileCoinLedgerWrapper)11 Payment (org.thoughtcrime.securesms.payments.Payment)11 MobileCoinLedger (org.thoughtcrime.securesms.payments.proto.MobileCoinLedger)11