diff --git a/backend/models/src/main/java/de/cotto/bitbook/backend/model/Transaction.java b/backend/models/src/main/java/de/cotto/bitbook/backend/model/Transaction.java index 3f331925..2192409c 100644 --- a/backend/models/src/main/java/de/cotto/bitbook/backend/model/Transaction.java +++ b/backend/models/src/main/java/de/cotto/bitbook/backend/model/Transaction.java @@ -41,7 +41,7 @@ public Transaction( this.time = time.withNano(0); this.fees = fees; this.inputs = inputs.stream().filter(input -> input.getValue().satoshis() > 0).collect(toList()); - this.outputs = outputs.stream().filter(output -> output.getValue().satoshis() > 0).collect(toList()); + this.outputs = new ArrayList<>(outputs); this.chain = chain; validateCoinsSum(hash, fees, inputs, outputs); } diff --git a/backend/models/src/test/java/de/cotto/bitbook/backend/model/TransactionTest.java b/backend/models/src/test/java/de/cotto/bitbook/backend/model/TransactionTest.java index af31316f..cdde10d7 100644 --- a/backend/models/src/test/java/de/cotto/bitbook/backend/model/TransactionTest.java +++ b/backend/models/src/test/java/de/cotto/bitbook/backend/model/TransactionTest.java @@ -68,7 +68,7 @@ void forCoinbase() { List.of(OUTPUT_1, OUTPUT_2, new Output(Coins.NONE, new Address("xxx"))), BTC ); - assertThat(coinbaseTransaction.getOutputs()).hasSize(2); + assertThat(coinbaseTransaction.getOutputs()).hasSize(3); } @Test @@ -259,7 +259,9 @@ void getOutputs() { } @Test - void ignoresEmptyOutputs() { + void includes_empty_outputs() { + // Even though outputs not spending anything, they count when considering the output index. + // As the output index is used to identify lightning network channels, empty outputs must not be ignored. List outputs = List.of( Output.EMPTY, new Output(Coins.NONE, new Address("xx")), @@ -268,7 +270,9 @@ void ignoresEmptyOutputs() { ); Transaction transaction = new Transaction(TRANSACTION_HASH, BLOCK_HEIGHT, DATE_TIME, FEES, TRANSACTION.getInputs(), outputs, BTC); - assertThat(transaction.getOutputs()).isEqualTo(TRANSACTION.getOutputs()); + assertThat(transaction.getOutputs()) + .containsAll(TRANSACTION.getOutputs()) + .hasSize(4); } @Test @@ -345,4 +349,4 @@ private Transaction getTransaction(Coins inFromAddress, Coins outToAddress2) { BTC ); } -} \ No newline at end of file +} diff --git a/backend/provider/blockchair/src/test/java/de/cotto/bitbook/backend/transaction/blockchair/BlockchairTransactionDtoTest.java b/backend/provider/blockchair/src/test/java/de/cotto/bitbook/backend/transaction/blockchair/BlockchairTransactionDtoTest.java index 226eec6b..008aa33a 100644 --- a/backend/provider/blockchair/src/test/java/de/cotto/bitbook/backend/transaction/blockchair/BlockchairTransactionDtoTest.java +++ b/backend/provider/blockchair/src/test/java/de/cotto/bitbook/backend/transaction/blockchair/BlockchairTransactionDtoTest.java @@ -192,6 +192,6 @@ void deserialization_zero_output_with_d_address() throws Exception { }"""; BlockchairTransactionDto blockchairTransactionDto = objectMapper.readValue(json, BlockchairTransactionDto.class); - assertThat(blockchairTransactionDto.toModel(BTC).getOutputs()).isEmpty(); + assertThat(blockchairTransactionDto.toModel(BTC).getOutputs()).hasSize(1); } -} \ No newline at end of file +} diff --git a/backend/provider/btccom/src/test/java/de/cotto/bitbook/backend/transaction/btccom/BtcComTransactionDtoTest.java b/backend/provider/btccom/src/test/java/de/cotto/bitbook/backend/transaction/btccom/BtcComTransactionDtoTest.java index 4fee4146..568d592a 100644 --- a/backend/provider/btccom/src/test/java/de/cotto/bitbook/backend/transaction/btccom/BtcComTransactionDtoTest.java +++ b/backend/provider/btccom/src/test/java/de/cotto/bitbook/backend/transaction/btccom/BtcComTransactionDtoTest.java @@ -354,6 +354,6 @@ void deserialization_zero_output_with_null_data() throws Exception { }"""; BtcComTransactionDto btcComTransactionDto = objectMapper.readValue(json, BtcComTransactionDto.class); - assertThat(btcComTransactionDto.toModel(BTC).getOutputs()).isEmpty(); + assertThat(btcComTransactionDto.toModel(BTC).getOutputs()).hasSize(1); } -} \ No newline at end of file +}