Skip to content

Commit

Permalink
add more complex test
Browse files Browse the repository at this point in the history
  • Loading branch information
Kukks committed Nov 17, 2023
1 parent a009d19 commit 94d9a85
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
30 changes: 28 additions & 2 deletions NBXplorer.Tests/UnitTest1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4488,7 +4488,7 @@ public async Task CanAssociateIndependentScripts(Backend backend)
var parentWallet = Guid.NewGuid().ToString();
var parentWalletTS = new WalletTrackedSource(parentWallet);


#if SUPPORT_DBTRIE
//this should create both wallets
if (backend == Backend.DBTrie)
{
Expand All @@ -4507,7 +4507,7 @@ await Assert.ThrowsAsync<NBXplorerException>(async () =>await tester.Client.Gene
await Assert.ThrowsAsync<HttpRequestException>(async () =>await tester.Client.ImportUTXOs(parentWalletTS, Array.Empty<ImportUTXORequest>()));
return;
}

#endif
await tester.Client.TrackAsync(wallet1TS, new TrackWalletRequest()
{
ParentWallet = parentWalletTS
Expand Down Expand Up @@ -4580,6 +4580,32 @@ await Eventually(async () =>
scriptBagUtxos = await tester.Client.GetUTXOsAsync(wallet1TS);
Assert.Equal(2, scriptBagUtxos.GetUnspentUTXOs().Length);
});

//create wallet A
//create wallet b using generate and make it child of A
// create address using unused on B
// creat wallet C tracking address from B, make it child of A, B
var walletA = new WalletTrackedSource(Guid.NewGuid().ToString());
await tester.Client.TrackAsync(walletA);
var generatResponse = await tester.Client.GenerateWalletAsync(new GenerateWalletRequest()
{
ParentWallet = walletA
});
var walletB = TrackedSource.Create(generatResponse.DerivationScheme);
var addressA = await tester.Client.GetUnusedAsync(generatResponse.DerivationScheme, DerivationFeature.Deposit, 0, true);
var walletC = AddressTrackedSource.Create(addressA.Address);
await tester.Client.TrackAsync(walletC, new TrackWalletRequest()
{
ParentWallet = walletB
});
await tester.Client.TrackAsync(walletC, new TrackWalletRequest()
{
ParentWallet = walletA
});

var kpi = await tester.Client.GetKeyInformationsAsync(addressA.ScriptPubKey, CancellationToken.None);
var tss = kpi.Select(information => information.TrackedSource);
Assert.True(tss.Distinct().Count() == tss.Count(), "The result should only distinct tracked source matches. While this endpoint is marked obsolete, the same logic is used to trigger events, which means there will be duplicated events when the script is matched against");
}
}
}
5 changes: 5 additions & 0 deletions NBXplorer/Controllers/MainController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,11 @@ public async Task<IActionResult> TrackWallet(
(trackedSourceContext.TrackedSource is WalletTrackedSource ||
request?.ParentWallet is not null))
{
if (request?.ParentWallet == trackedSourceContext.TrackedSource)
{
throw new NBXplorerException(new NBXplorerError(400, "parent-wallet-same-as-tracked-source",
"Parent wallets cannot be the same as the tracked source"));
}
await postgresRepository.EnsureWalletCreated(trackedSourceContext.TrackedSource, request?.ParentWallet is null? null: new []{request?.ParentWallet });
}
if (repo is not PostgresRepository && request.ParentWallet is not null)
Expand Down

0 comments on commit 94d9a85

Please sign in to comment.