Test with real data
MODIFY
WalletWasabi.Tests/UnitTests/BitcoinCore/IndexBuilderServiceTests.cs
WalletWasabi.Tests/UnitTests/BitcoinCore/IndexBuilderServiceTests.cs
@@ -4,6 +4,7 @@ using NBitcoin.Crypto;
using NBitcoin.RPC;
using System;
using System.Collections.Generic;
+using System.IO;
using System.Linq;
using System.Threading.Tasks;
using WalletWasabi.BitcoinCore.Rpc;
@@ -129,24 +130,22 @@ namespace WalletWasabi.Tests.UnitTests.BitcoinCore
[Fact]
public void IncludeTaprootScriptInFilters()
{
- var block = GenerateBlockchain().First();
+ var getBlockRpcRawResponse = File.ReadAllText("./UnitTests/Data/VerboseBlock.json");
+
+ var block = RpcParser.ParseVerboseBlockResponse(getBlockRpcRawResponse);
var filter = IndexBuilderService.BuildFilterForBlock(block);
- var firstTaprootScript = block
- .Transactions.First()
- .Outputs.Where(x => x.PubkeyType == RpcPubkeyType.TxWitnessV1Taproot)
- .Select(x => x.ScriptPubKey)
- .First();
+ var txOutputs = block.Transactions.SelectMany(x => x.Outputs);
+ var prevTxOutputs = block.Transactions.SelectMany(x => x.Inputs.Where(y => y.PrevOutput is { }).Select(y => y.PrevOutput));
+ var allOutputs = txOutputs.Concat(prevTxOutputs);
- var firstTaprootScript2 = block
- .Transactions.First()
- .Outputs.Where(x => x.PubkeyType == RpcPubkeyType.TxWitnessV1Taproot)
- .Select(x => x.ScriptPubKey)
- .First();
+ var indexableOutputs = allOutputs.Where(x => x.PubkeyType is RpcPubkeyType.TxWitnessV0Keyhash or RpcPubkeyType.TxWitnessV1Taproot);
+ var nonIndexableOutputs = allOutputs.Except(indexableOutputs);
static byte[] ComputeKey(uint256 blockId) => blockId.ToBytes()[0..16];
- Assert.True(filter.Match(firstTaprootScript.ToCompressedBytes(), ComputeKey(block.Hash)));
+ Assert.All(indexableOutputs, x => Assert.True(filter.Match(x.ScriptPubKey.ToCompressedBytes(), ComputeKey(block.Hash))));
+ Assert.All(nonIndexableOutputs, x => Assert.False(filter.Match(x.ScriptPubKey.ToCompressedBytes(), ComputeKey(block.Hash))));
}
private IEnumerable<VerboseBlockInfo> GenerateBlockchain() =>

MODIFY
WalletWasabi.Tests/WalletWasabi.Tests.csproj
WalletWasabi.Tests/WalletWasabi.Tests.csproj
<None Update="./UnitTests/Data/MempoolInfoWithHistogram.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
+ <None Update="./UnitTests/Data/VerboseBlock.json">
+ <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+ </None>
</ItemGroup>
<ItemGroup>

Test with real data