private static void RepositoryCanTrackAddresses(RepositoryTester tester) { var keyInfo = tester.Repository.GetKeyInformation(pubKey.GetLineFor(DerivationFeature.Deposit).Derive(0).ScriptPubKey); Assert.NotNull(keyInfo); Assert.Equal(new KeyPath("0/0"), keyInfo.KeyPath); Assert.Equal(keyInfo.DerivationStrategy.ToString(), pubKey.ToString()); keyInfo = tester.Repository.GetKeyInformation(pubKey.GetLineFor(DerivationFeature.Deposit).Derive(1).ScriptPubKey); Assert.NotNull(keyInfo); Assert.Equal(new KeyPath("0/1"), keyInfo.KeyPath); Assert.Equal(keyInfo.DerivationStrategy.ToString(), pubKey.ToString()); keyInfo = tester.Repository.GetKeyInformation(pubKey.GetLineFor(DerivationFeature.Deposit).Derive(29).ScriptPubKey); Assert.NotNull(keyInfo); Assert.Equal(new KeyPath("0/29"), keyInfo.KeyPath); Assert.Equal(keyInfo.DerivationStrategy.ToString(), pubKey.ToString()); keyInfo = tester.Repository.GetKeyInformation(pubKey.GetLineFor(DerivationFeature.Change).Derive(29).ScriptPubKey); Assert.NotNull(keyInfo); Assert.Equal(new KeyPath("1/29"), keyInfo.KeyPath); Assert.Equal(keyInfo.DerivationStrategy.ToString(), pubKey.ToString()); keyInfo = tester.Repository.GetKeyInformation(pubKey.GetLineFor(DerivationFeature.Deposit).Derive(30).ScriptPubKey); Assert.Null(keyInfo); keyInfo = tester.Repository.GetKeyInformation(pubKey.GetLineFor(DerivationFeature.Change).Derive(30).ScriptPubKey); Assert.Null(keyInfo); tester.Repository.MarkAsUsed(CreateKeyPathInformation(pubKey, new KeyPath("1/5"))); keyInfo = tester.Repository.GetKeyInformation(pubKey.GetLineFor(DerivationFeature.Change).Derive(25).ScriptPubKey); Assert.NotNull(keyInfo); Assert.Equal(new KeyPath("1/25"), keyInfo.KeyPath); Assert.Equal(keyInfo.DerivationStrategy, pubKey); keyInfo = tester.Repository.GetKeyInformation(pubKey.GetLineFor(DerivationFeature.Change).Derive(36).ScriptPubKey); Assert.Null(keyInfo); keyInfo = tester.Repository.GetKeyInformation(pubKey.GetLineFor(DerivationFeature.Deposit).Derive(30).ScriptPubKey); Assert.Null(keyInfo); for (int i = 0; i < 10; i++) { tester.Repository.MarkAsUsed(CreateKeyPathInformation(pubKey, new KeyPath("1/" + i))); } keyInfo = tester.Repository.GetKeyInformation(pubKey.GetLineFor(DerivationFeature.Deposit).Derive(30).ScriptPubKey); Assert.Null(keyInfo); tester.Repository.MarkAsUsed(CreateKeyPathInformation(pubKey, new KeyPath("1/10"))); keyInfo = tester.Repository.GetKeyInformation(pubKey.GetLineFor(DerivationFeature.Deposit).Derive(30).ScriptPubKey); Assert.NotNull(keyInfo); keyInfo = tester.Repository.GetKeyInformation(pubKey.GetLineFor(DerivationFeature.Deposit).Derive(39).ScriptPubKey); Assert.NotNull(keyInfo); keyInfo = tester.Repository.GetKeyInformation(pubKey.GetLineFor(DerivationFeature.Deposit).Derive(41).ScriptPubKey); Assert.Null(keyInfo); //No op tester.Repository.MarkAsUsed(CreateKeyPathInformation(pubKey, new KeyPath("1/6"))); keyInfo = tester.Repository.GetKeyInformation(pubKey.GetLineFor(DerivationFeature.Change).Derive(29).ScriptPubKey); Assert.NotNull(keyInfo); Assert.Equal(new KeyPath("1/29"), keyInfo.KeyPath); Assert.Equal(keyInfo.DerivationStrategy.ToString(), pubKey.ToString()); keyInfo = tester.Repository.GetKeyInformation(pubKey.GetLineFor(DerivationFeature.Change).Derive(30).ScriptPubKey); Assert.Null(keyInfo); }
private static DirectDerivationStrategy CreateDerivationStrategy(ExtPubKey pubKey = null) { pubKey = pubKey ?? new ExtKey().Neuter(); return((DirectDerivationStrategy) new DerivationStrategyFactory(Network.RegTest).Parse($"{pubKey.ToString(Network.RegTest)}-[legacy]")); }