Search in sources :

Example 21 with Payment

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

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 22 with Payment

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

the class LedgerReconcileTest method single_receipt_payment_that_can_be_found_on_ledger_reconstructed_spend_with_change.

@Test
public void single_receipt_payment_that_can_be_found_on_ledger_reconstructed_spend_with_change() {
    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)), unspentTxo(mob(1.5), keyImage(7), publicKey(8), block(2)));
    List<Payment> payments = reconcile(localPayments, new MobileCoinLedgerWrapper(ledger));
    assertEquals(Arrays.asList(mob(-1), mob(2.5)), Stream.of(payments).map(Payment::getAmountWithDirection).toList());
    assertEquals("received", payments.get(1).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 23 with Payment

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

the class LedgerReconcileTest method payment.

private static Payment payment(String note, Money.MobileCoin valueAndDirection, Set<ByteString> keyImages, Set<ByteString> publicKeys) {
    UUID uuid = UUID.randomUUID();
    PaymentMetaData.MobileCoinTxoIdentification.Builder builderForValue = PaymentMetaData.MobileCoinTxoIdentification.newBuilder();
    builderForValue.addAllKeyImages(keyImages);
    builderForValue.addAllPublicKey(publicKeys);
    PaymentMetaData paymentMetaData = PaymentMetaData.newBuilder().setMobileCoinTxoIdentification(builderForValue).build();
    return new Payment() {

        @Override
        @NonNull
        public UUID getUuid() {
            return uuid;
        }

        @Override
        @NonNull
        public Payee getPayee() {
            return new Payee(RecipientId.from(1));
        }

        @Override
        public long getBlockIndex() {
            return 0;
        }

        @Override
        public long getBlockTimestamp() {
            return 0;
        }

        @Override
        public long getTimestamp() {
            return 0;
        }

        @Override
        @NonNull
        public Direction getDirection() {
            return valueAndDirection.isNegative() ? Direction.SENT : Direction.RECEIVED;
        }

        @Override
        @NonNull
        public State getState() {
            return State.SUCCESSFUL;
        }

        @Override
        @Nullable
        public FailureReason getFailureReason() {
            return null;
        }

        @Override
        @NonNull
        public String getNote() {
            return note;
        }

        @Override
        @NonNull
        public Money getAmount() {
            return valueAndDirection.abs();
        }

        @Override
        @NonNull
        public Money getFee() {
            return getAmount().toZero();
        }

        @Override
        @NonNull
        public PaymentMetaData getPaymentMetaData() {
            return paymentMetaData;
        }

        @Override
        public boolean isSeen() {
            return true;
        }
    };
}
Also used : Payment(org.thoughtcrime.securesms.payments.Payment) PaymentMetaData(org.thoughtcrime.securesms.payments.proto.PaymentMetaData) UUID(java.util.UUID) Payee(org.thoughtcrime.securesms.payments.Payee)

Example 24 with Payment

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

the class LedgerReconcileTest method unknown_payment_is_first_in_list.

@Test
public void unknown_payment_is_first_in_list() {
    List<Payment> localPayments = Collections.singletonList(payment("received", mob(2.5), 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(2.5), mob(1.5), mob(-2.5), mob(2.5)), Stream.of(payments).map(Payment::getAmountWithDirection).toList());
    assertEquals("received", payments.get(0).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 25 with Payment

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

the class LedgerReconcileTest method single_receipt_payment_that_can_be_found_on_ledger_reconstructed_spend_but_not_with_change_due_to_block.

@Test
public void single_receipt_payment_that_can_be_found_on_ledger_reconstructed_spend_but_not_with_change_due_to_block() {
    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)), 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(2.5)), Stream.of(payments).map(Payment::getAmountWithDirection).toList());
    assertEquals("received", payments.get(2).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

Payment (org.thoughtcrime.securesms.payments.Payment)34 MobileCoinLedgerWrapper (org.thoughtcrime.securesms.payments.MobileCoinLedgerWrapper)28 Test (org.junit.Test)24 MobileCoinLedger (org.thoughtcrime.securesms.payments.proto.MobileCoinLedger)22 ByteString (com.google.protobuf.ByteString)4 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 ReconstructedPayment (org.thoughtcrime.securesms.payments.ReconstructedPayment)4 PaymentMetaData (org.thoughtcrime.securesms.payments.proto.PaymentMetaData)4 SpannableString (android.text.SpannableString)2 View (android.view.View)2 TextView (android.widget.TextView)2 NonNull (androidx.annotation.NonNull)2 WorkerThread (androidx.annotation.WorkerThread)2 Toolbar (androidx.appcompat.widget.Toolbar)2 Group (androidx.constraintlayout.widget.Group)2 FragmentActivity (androidx.fragment.app.FragmentActivity)2 Collectors (com.annimon.stream.Collectors)2 ComparatorCompat (com.annimon.stream.ComparatorCompat)2 Stream (com.annimon.stream.Stream)2