diff --git a/Helpers/ApiCalls.cs b/Helpers/ApiCalls.cs index b7867ccc9b6..036a721d0e0 100644 --- a/Helpers/ApiCalls.cs +++ b/Helpers/ApiCalls.cs @@ -7,7 +7,6 @@ using Newtonsoft.Json; using Stratis.Bitcoin.Features.Wallet.Models; using Stratis.Bitcoin.Utilities.JsonErrors; -using Stratis.FederatedPeg.Features.MainchainGeneratorServices.Models; namespace Stratis.FederatedPeg.IntegrationTests { @@ -22,33 +21,33 @@ public JsonContent(object obj) : } } - public static async Task InitSidechain(string sidechainName, int apiPortForMainchain, int apiPortForSidechain, int multiSigN, int multiSigM, string folderFedMemberKey) - { - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); - - var initSidechainRequest = new InitSidechainRequest(); - initSidechainRequest.SidechainName = sidechainName; - initSidechainRequest.ApiPortForSidechain = apiPortForSidechain; - initSidechainRequest.MultiSigN = multiSigN; - initSidechainRequest.MultiSigM = multiSigM; - initSidechainRequest.FolderFedMemberKeys = folderFedMemberKey; - - var uri = new Uri($"http://localhost:{apiPortForMainchain}/api/MainchainGeneratorServices/init-sidechain"); - var request = new JsonContent(initSidechainRequest); - var httpResponseMessage = await client.PostAsync(uri, request); - - if (!httpResponseMessage.IsSuccessStatusCode) - { - string content = await httpResponseMessage.Content.ReadAsStringAsync(); - var result = JsonConvert.DeserializeObject(content); - string message = result.Errors[0].Message; - throw new Exception(message); - } - } - } + //public static async Task InitSidechain(string sidechainName, int apiPortForMainchain, int apiPortForSidechain, int multiSigN, int multiSigM, string folderFedMemberKey) + //{ + // using (var client = new HttpClient()) + // { + // client.DefaultRequestHeaders.Accept.Clear(); + // client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); + + // var initSidechainRequest = new InitSidechainRequest(); + // initSidechainRequest.SidechainName = sidechainName; + // initSidechainRequest.ApiPortForSidechain = apiPortForSidechain; + // initSidechainRequest.MultiSigN = multiSigN; + // initSidechainRequest.MultiSigM = multiSigM; + // initSidechainRequest.FolderFedMemberKeys = folderFedMemberKey; + + // var uri = new Uri($"http://localhost:{apiPortForMainchain}/api/MainchainGeneratorServices/init-sidechain"); + // var request = new JsonContent(initSidechainRequest); + // var httpResponseMessage = await client.PostAsync(uri, request); + + // if (!httpResponseMessage.IsSuccessStatusCode) + // { + // string content = await httpResponseMessage.Content.ReadAsStringAsync(); + // var result = JsonConvert.DeserializeObject(content); + // string message = result.Errors[0].Message; + // throw new Exception(message); + // } + // } + //} public static async Task Mnemonic(int apiPortForSidechain) { diff --git a/Helpers/IntegrationTestUtils.cs b/Helpers/IntegrationTestUtils.cs index 7f9df55499a..c9ddf6dbc03 100644 --- a/Helpers/IntegrationTestUtils.cs +++ b/Helpers/IntegrationTestUtils.cs @@ -1,144 +1,144 @@ -using System; -using System.Diagnostics; -using System.IO; -using System.Runtime.CompilerServices; -using System.Threading; -using System.Threading.Tasks; -using NBitcoin; -using Stratis.Bitcoin.Connection; -using Stratis.Bitcoin.Features.Wallet.Interfaces; -using Stratis.Bitcoin.IntegrationTests.Common.EnvironmentMockUpHelpers; -using Stratis.Bitcoin.P2P.Peer; -using Stratis.FederatedPeg.Features.FederationGateway.Interfaces; -using Stratis.FederatedPeg.Features.FederationGateway.Wallet; - -//using CoreNode = Stratis.Bitcoin. - -namespace Stratis.FederatedPeg.IntegrationTests.Helpers -{ - internal class IntegrationTestUtils - { - public static void RunFedKeyPairGen(string name, string passPhrase, string folder = null, [CallerMemberName] string caller = null) - { - if (folder == null) folder = $"Federations\\{caller}"; - - var process = new Process - { - StartInfo = new ProcessStartInfo - { - FileName = "dotnet", - Arguments = $"..\\..\\..\\..\\FedKeyPairGen\\bin\\Release\\PublishOutput\\FedKeyPairGen.dll -name={name} -pass={passPhrase} -folder={folder}", - UseShellExecute = true, - RedirectStandardOutput = false, - RedirectStandardError = false, - CreateNoWindow = true - } - }; - - //this call assumes you have used DotNet Publish to publish the FedKeyPairGen. - process.Start(); - } - - public static void DistributeKeys(string memberFolder) - { - var memberFolderManager = new MemberFolderManager(memberFolder); - var members = memberFolderManager.LoadMembers(); - - int memberFolderName = 1; - foreach (var member in members) - { - //create a folder for the member and copy his files there - //this represents the folder on a federation gateway where a member keeps his keys - //copy his public key - //copy his private key - //copy the multisig public address - //copy the multisig scriptpubkey - - //member photo - var mainchainDest = Directory.CreateDirectory($"{memberFolder}\\{memberFolderName}\\Mainchain"); - var sidechainDest = Directory.CreateDirectory($"{memberFolder}\\{memberFolderName}\\Sidechain"); - - File.Copy(Path.Combine(memberFolder, $"PUBLIC_mainchain_{member.Name}.txt"), Path.Combine(mainchainDest.FullName, $"PUBLIC_mainchain_{member.Name}.txt")); - File.Copy(Path.Combine(memberFolder, $"PUBLIC_sidechain_{member.Name}.txt"), Path.Combine(sidechainDest.FullName, $"PUBLIC_sidechain_{member.Name}.txt")); - - File.Copy(Path.Combine(memberFolder, $"PRIVATE_DO_NOT_SHARE_mainchain_{member.Name}.txt"), Path.Combine(mainchainDest.FullName, $"PRIVATE_DO_NOT_SHARE_mainchain_{member.Name}.txt")); - File.Copy(Path.Combine(memberFolder, $"PRIVATE_DO_NOT_SHARE_sidechain_{member.Name}.txt"), Path.Combine(sidechainDest.FullName, $"PRIVATE_DO_NOT_SHARE_sidechain_{member.Name}.txt")); - - File.Copy(Path.Combine(memberFolder, "Mainchain_ScriptPubKey.txt"), Path.Combine(mainchainDest.FullName, "Mainchain_ScriptPubKey.txt")); - File.Copy(Path.Combine(memberFolder, "Sidechain_ScriptPubKey.txt"), Path.Combine(sidechainDest.FullName, "Sidechain_ScriptPubKey.txt")); - - File.Copy(Path.Combine(memberFolder, "Mainchain_Address.txt"), Path.Combine(mainchainDest.FullName, "Mainchain_Address.txt")); - File.Copy(Path.Combine(memberFolder, "Sidechain_Address.txt"), Path.Combine(sidechainDest.FullName, "Sidechain_Address.txt")); - - ++memberFolderName; - } - } - - public static void CreateScriptAndAddress(string memberfolder, Network network) - { - var memberFolderManager = new MemberFolderManager(memberfolder); - var federation = memberFolderManager.LoadFederation(2, 3); - memberFolderManager.OutputScriptPubKeyAndAddress(federation, network); - memberFolderManager.OutputScriptPubKeyAndAddress(federation, network); - } - - public static async Task WaitLoop(Func act) - { - var cancel = new CancellationTokenSource(Debugger.IsAttached ? 15 * 60 * 1000 : 30 * 1000); - while (!act()) - { - cancel.Token.ThrowIfCancellationRequested(); - await Task.Delay(50); - } - } - - public static bool AreNodesSynced(CoreNode node1, CoreNode node2) - { - if (node1.FullNode.Chain.Tip.HashBlock != node2.FullNode.Chain.Tip.HashBlock) return false; - if (node1.FullNode.ChainBehaviorState.ConsensusTip.HashBlock != node2.FullNode.ChainBehaviorState.ConsensusTip.HashBlock) return false; - if (node1.FullNode.GetBlockStoreTip().HashBlock != node2.FullNode.GetBlockStoreTip().HashBlock) return false; - if (node1.FullNode.MempoolManager().InfoAll().Count != node2.FullNode.MempoolManager().InfoAll().Count) return false; - if (node1.FullNode.WalletManager().WalletTipHash != node2.FullNode.WalletManager().WalletTipHash) return false; - if (node1.CreateRPCClient().GetBestBlockHash() != node2.CreateRPCClient().GetBestBlockHash()) return false; - return true; - } - - private static IFederationWalletManager GetGeneralWalletManager(CoreNode node) - { - return node.FullNode.NodeService(); - } - - public static bool AreNodeGeneralWalletsSynced(CoreNode node1, CoreNode node2) - { - return IntegrationTestUtils.GetGeneralWalletManager(node1).WalletTipHash == IntegrationTestUtils.GetGeneralWalletManager(node2).WalletTipHash; - } - - public static void ResyncGeneralWallet(CoreNode node) - { - var federationWalletSyncManager = node.FullNode.NodeService(); - federationWalletSyncManager.SyncFromHeight(0); - } - - public static bool IsGeneralWalletSyncedToHeight(CoreNode node, int height) - { - var generalWalletManager = node.FullNode.NodeService() as FederationWalletManager; - return generalWalletManager.LastBlockHeight() >= height; - } - - //todo: duplication - public static void SaveGeneralWallet(CoreNode node, string walletName) - { - var generalWalletManager = node.FullNode.NodeService() as FederationWalletManager; - var wallet = generalWalletManager.GetWallet(); - generalWalletManager.SaveWallet(); - } - - public static bool AreConnected(CoreNode node1, CoreNode node2) - { - var connectionManager = node1.FullNode.NodeService(); - foreach (INetworkPeer peer in connectionManager.ConnectedPeers) - if (peer.PeerEndPoint.Port == node2.Endpoint.Port) return true; - return false; - } - } -} \ No newline at end of file +//using System; +//using System.Diagnostics; +//using System.IO; +//using System.Runtime.CompilerServices; +//using System.Threading; +//using System.Threading.Tasks; +//using NBitcoin; +//using Stratis.Bitcoin.Connection; +//using Stratis.Bitcoin.Features.Wallet.Interfaces; +//using Stratis.Bitcoin.IntegrationTests.Common.EnvironmentMockUpHelpers; +//using Stratis.Bitcoin.P2P.Peer; +//using Stratis.FederatedPeg.Features.FederationGateway.Interfaces; +//using Stratis.FederatedPeg.Features.FederationGateway.Wallet; + +////using CoreNode = Stratis.Bitcoin. + +//namespace Stratis.FederatedPeg.IntegrationTests.Helpers +//{ +// internal class IntegrationTestUtils +// { +// public static void RunFedKeyPairGen(string name, string passPhrase, string folder = null, [CallerMemberName] string caller = null) +// { +// if (folder == null) folder = $"Federations\\{caller}"; + +// var process = new Process +// { +// StartInfo = new ProcessStartInfo +// { +// FileName = "dotnet", +// Arguments = $"..\\..\\..\\..\\FedKeyPairGen\\bin\\Release\\PublishOutput\\FedKeyPairGen.dll -name={name} -pass={passPhrase} -folder={folder}", +// UseShellExecute = true, +// RedirectStandardOutput = false, +// RedirectStandardError = false, +// CreateNoWindow = true +// } +// }; + +// //this call assumes you have used DotNet Publish to publish the FedKeyPairGen. +// process.Start(); +// } + +// public static void DistributeKeys(string memberFolder) +// { +// var memberFolderManager = new MemberFolderManager(memberFolder); +// var members = memberFolderManager.LoadMembers(); + +// int memberFolderName = 1; +// foreach (var member in members) +// { +// //create a folder for the member and copy his files there +// //this represents the folder on a federation gateway where a member keeps his keys +// //copy his public key +// //copy his private key +// //copy the multisig public address +// //copy the multisig scriptpubkey + +// //member photo +// var mainchainDest = Directory.CreateDirectory($"{memberFolder}\\{memberFolderName}\\Mainchain"); +// var sidechainDest = Directory.CreateDirectory($"{memberFolder}\\{memberFolderName}\\Sidechain"); + +// File.Copy(Path.Combine(memberFolder, $"PUBLIC_mainchain_{member.Name}.txt"), Path.Combine(mainchainDest.FullName, $"PUBLIC_mainchain_{member.Name}.txt")); +// File.Copy(Path.Combine(memberFolder, $"PUBLIC_sidechain_{member.Name}.txt"), Path.Combine(sidechainDest.FullName, $"PUBLIC_sidechain_{member.Name}.txt")); + +// File.Copy(Path.Combine(memberFolder, $"PRIVATE_DO_NOT_SHARE_mainchain_{member.Name}.txt"), Path.Combine(mainchainDest.FullName, $"PRIVATE_DO_NOT_SHARE_mainchain_{member.Name}.txt")); +// File.Copy(Path.Combine(memberFolder, $"PRIVATE_DO_NOT_SHARE_sidechain_{member.Name}.txt"), Path.Combine(sidechainDest.FullName, $"PRIVATE_DO_NOT_SHARE_sidechain_{member.Name}.txt")); + +// File.Copy(Path.Combine(memberFolder, "Mainchain_ScriptPubKey.txt"), Path.Combine(mainchainDest.FullName, "Mainchain_ScriptPubKey.txt")); +// File.Copy(Path.Combine(memberFolder, "Sidechain_ScriptPubKey.txt"), Path.Combine(sidechainDest.FullName, "Sidechain_ScriptPubKey.txt")); + +// File.Copy(Path.Combine(memberFolder, "Mainchain_Address.txt"), Path.Combine(mainchainDest.FullName, "Mainchain_Address.txt")); +// File.Copy(Path.Combine(memberFolder, "Sidechain_Address.txt"), Path.Combine(sidechainDest.FullName, "Sidechain_Address.txt")); + +// ++memberFolderName; +// } +// } + +// public static void CreateScriptAndAddress(string memberfolder, Network network) +// { +// var memberFolderManager = new MemberFolderManager(memberfolder); +// var federation = memberFolderManager.LoadFederation(2, 3); +// memberFolderManager.OutputScriptPubKeyAndAddress(federation, network); +// memberFolderManager.OutputScriptPubKeyAndAddress(federation, network); +// } + +// public static async Task WaitLoop(Func act) +// { +// var cancel = new CancellationTokenSource(Debugger.IsAttached ? 15 * 60 * 1000 : 30 * 1000); +// while (!act()) +// { +// cancel.Token.ThrowIfCancellationRequested(); +// await Task.Delay(50); +// } +// } + +// public static bool AreNodesSynced(CoreNode node1, CoreNode node2) +// { +// if (node1.FullNode.Chain.Tip.HashBlock != node2.FullNode.Chain.Tip.HashBlock) return false; +// if (node1.FullNode.ChainBehaviorState.ConsensusTip.HashBlock != node2.FullNode.ChainBehaviorState.ConsensusTip.HashBlock) return false; +// if (node1.FullNode.GetBlockStoreTip().HashBlock != node2.FullNode.GetBlockStoreTip().HashBlock) return false; +// if (node1.FullNode.MempoolManager().InfoAll().Count != node2.FullNode.MempoolManager().InfoAll().Count) return false; +// if (node1.FullNode.WalletManager().WalletTipHash != node2.FullNode.WalletManager().WalletTipHash) return false; +// if (node1.CreateRPCClient().GetBestBlockHash() != node2.CreateRPCClient().GetBestBlockHash()) return false; +// return true; +// } + +// private static IFederationWalletManager GetGeneralWalletManager(CoreNode node) +// { +// return node.FullNode.NodeService(); +// } + +// public static bool AreNodeGeneralWalletsSynced(CoreNode node1, CoreNode node2) +// { +// return IntegrationTestUtils.GetGeneralWalletManager(node1).WalletTipHash == IntegrationTestUtils.GetGeneralWalletManager(node2).WalletTipHash; +// } + +// public static void ResyncGeneralWallet(CoreNode node) +// { +// var federationWalletSyncManager = node.FullNode.NodeService(); +// federationWalletSyncManager.SyncFromHeight(0); +// } + +// public static bool IsGeneralWalletSyncedToHeight(CoreNode node, int height) +// { +// var generalWalletManager = node.FullNode.NodeService() as FederationWalletManager; +// return generalWalletManager.LastBlockHeight() >= height; +// } + +// //todo: duplication +// public static void SaveGeneralWallet(CoreNode node, string walletName) +// { +// var generalWalletManager = node.FullNode.NodeService() as FederationWalletManager; +// var wallet = generalWalletManager.GetWallet(); +// generalWalletManager.SaveWallet(); +// } + +// public static bool AreConnected(CoreNode node1, CoreNode node2) +// { +// var connectionManager = node1.FullNode.NodeService(); +// foreach (INetworkPeer peer in connectionManager.ConnectedPeers) +// if (peer.PeerEndPoint.Port == node2.Endpoint.Port) return true; +// return false; +// } +// } +//} \ No newline at end of file diff --git a/Helpers/TestFederationFolder.cs b/Helpers/TestFederationFolder.cs index 6e3fc662ba8..5ab7e027ed7 100644 --- a/Helpers/TestFederationFolder.cs +++ b/Helpers/TestFederationFolder.cs @@ -1,102 +1,95 @@ -using System.IO; -using System.Linq; -using System.Runtime.CompilerServices; -using NBitcoin; -using Stratis.Bitcoin.Features.Wallet; -using Stratis.Bitcoin.Tests.Common;using Stratis.Bitcoin.IntegrationTests.Common; -using Stratis.Bitcoin.IntegrationTests.Common.EnvironmentMockUpHelpers; -using Stratis.FederatedPeg.Features.FederationGateway.Interfaces; -using Stratis.FederatedPeg.Features.FederationGateway.Wallet; +//using System.IO; +//using System.Linq; +//using System.Runtime.CompilerServices; +//using NBitcoin; +//using Stratis.Bitcoin.Features.Wallet; +//using Stratis.Bitcoin.Tests.Common;using Stratis.Bitcoin.IntegrationTests.Common; +//using Stratis.Bitcoin.IntegrationTests.Common.EnvironmentMockUpHelpers; +//using Stratis.FederatedPeg.Features.FederationGateway.Interfaces; +//using Stratis.FederatedPeg.Features.FederationGateway.Wallet; -namespace Stratis.FederatedPeg.IntegrationTests.Helpers -{ - internal class TestFederationFolder - { - //eg: Federations\deposit_funds_to_sidechain - public string Folder { get; } +//namespace Stratis.FederatedPeg.IntegrationTests.Helpers +//{ +// internal class TestFederationFolder +// { +// //eg: Federations\deposit_funds_to_sidechain +// public string Folder { get; } - public TestFederationFolder([CallerMemberName] string caller = null) - { - this.Folder = Path.Combine(Path.Combine(Directory.GetCurrentDirectory(), $"Federations\\{caller}")); - Directory.CreateDirectory(this.Folder); - TestBase.AssureEmptyDir(this.Folder); - } +// public TestFederationFolder([CallerMemberName] string caller = null) +// { +// this.Folder = Path.Combine(Path.Combine(Directory.GetCurrentDirectory(), $"Federations\\{caller}")); +// Directory.CreateDirectory(this.Folder); +// TestBase.AssureEmptyDir(this.Folder); +// } - public MemberFolderManager CreateMemberFolderManager() - { - return new MemberFolderManager(this.Folder); - } +// //public MemberFolderManager CreateMemberFolderManager() +// //{ +// // return null; +// //} - public void RunFedKeyPairGen(string name, string password) - { - string destination = $"{this.Folder}\\{name}"; - Directory.CreateDirectory(destination); - IntegrationTestUtils.RunFedKeyPairGen(name, password, destination); - } +// public void RunFedKeyPairGen(string name, string password) +// { +// string destination = $"{this.Folder}\\{name}"; +// Directory.CreateDirectory(destination); +// IntegrationTestUtils.RunFedKeyPairGen(name, password, destination); +// } - public void DistributeKeys(string[] folderNames) - { - foreach (string folder in folderNames) - { - var source = new DirectoryInfo($"{this.Folder}\\{folder}"); - var files = source.GetFiles("PUBLIC*"); - foreach (var file in files) - { - string dest = $"{file.Directory.Parent.FullName}\\{file.Name}"; - File.Copy(file.FullName, $"{file.Directory.Parent.FullName}\\{file.Name}"); - } - } - } +// public void DistributeKeys(string[] folderNames) +// { +// foreach (string folder in folderNames) +// { +// var source = new DirectoryInfo($"{this.Folder}\\{folder}"); +// var files = source.GetFiles("PUBLIC*"); +// foreach (var file in files) +// { +// string dest = $"{file.Directory.Parent.FullName}\\{file.Name}"; +// File.Copy(file.FullName, $"{file.Directory.Parent.FullName}\\{file.Name}"); +// } +// } +// } - public void DistributeScriptAndAddress(string[] folderNames) - { - foreach (string folder in folderNames) - { - string dest = Path.Combine(this.Folder, folder); - File.Copy( Path.Combine(this.Folder, "Mainchain_Address.txt"), Path.Combine(dest, "Mainchain_Address.txt")); - File.Copy( Path.Combine(this.Folder, "Sidechain_Address.txt"), Path.Combine(dest, "Sidechain_Address.txt")); - File.Copy( Path.Combine(this.Folder, "Mainchain_ScriptPubKey.txt"), Path.Combine(dest, "Mainchain_ScriptPubKey.txt")); - File.Copy( Path.Combine(this.Folder, "Sidechain_ScriptPubKey.txt"), Path.Combine(dest, "Sidechain_ScriptPubKey.txt")); - } - } +// public void DistributeScriptAndAddress(string[] folderNames) +// { +// foreach (string folder in folderNames) +// { +// string dest = Path.Combine(this.Folder, folder); +// File.Copy( Path.Combine(this.Folder, "Mainchain_Address.txt"), Path.Combine(dest, "Mainchain_Address.txt")); +// File.Copy( Path.Combine(this.Folder, "Sidechain_Address.txt"), Path.Combine(dest, "Sidechain_Address.txt")); +// File.Copy( Path.Combine(this.Folder, "Mainchain_ScriptPubKey.txt"), Path.Combine(dest, "Mainchain_ScriptPubKey.txt")); +// File.Copy( Path.Combine(this.Folder, "Sidechain_ScriptPubKey.txt"), Path.Combine(dest, "Sidechain_ScriptPubKey.txt")); +// } +// } - public void ImportPrivateKeyToWallet(CoreNode node, string walletName, string walletPassword, string memberName, - string memberPassword, int m, int n, Network network) - { - // Use the GeneralWalletManager and get the API created wallet. - var generalWalletManager = node.FullNode.NodeService() as FederationWalletManager; - var wallet = generalWalletManager.GetWallet(); +// public void ImportPrivateKeyToWallet(CoreNode node, string walletName, string walletPassword, string memberName, +// string memberPassword, int m, int n, Network network) +// { +// // Use the GeneralWalletManager and get the API created wallet. +// var generalWalletManager = node.FullNode.NodeService() as FederationWalletManager; +// var wallet = generalWalletManager.GetWallet(); - //Decrypt the private key - var chain = network.ToChain(); - string privateKeyEncrypted = File.ReadAllText(Path.Combine(this.Folder, $"{memberName}\\PRIVATE_DO_NOT_SHARE_{chain}_{memberName}.txt")); +// //Decrypt the private key +// var chain = network.ToChain(); +// string privateKeyEncrypted = File.ReadAllText(Path.Combine(this.Folder, $"{memberName}\\PRIVATE_DO_NOT_SHARE_{chain}_{memberName}.txt")); - var privateKeyDecryptString = HdOperations.DecryptSeed(privateKeyEncrypted, memberPassword, network); +// var privateKeyDecryptString = HdOperations.DecryptSeed(privateKeyEncrypted, memberPassword, network); - var multiSigAddress = new MultiSigAddress(); - - var memberFolderManager = new MemberFolderManager(this.Folder); - var federation = memberFolderManager.LoadFederation(m, n); - - var publicKeys = chain == Chain.Mainchain ? - (from f in federation.Members orderby f.PublicKeyMainChain.ToHex() select f.PublicKeyMainChain).ToArray() - : (from f in federation.Members orderby f.PublicKeySideChain.ToHex() select f.PublicKeySideChain).ToArray(); +// var multiSigAddress = new MultiSigAddress(); - // TODO: Change this to generate the requisite ExtKeys and ExtPubKeys instead - //multiSigAddress.Create(privateKeyDecryptString, publicKeys, m, network); +// // TODO: Change this to generate the requisite ExtKeys and ExtPubKeys instead +// //multiSigAddress.Create(privateKeyDecryptString, publicKeys, m, network); - //account.ImportMultiSigAddress(multiSigAddress); +// //account.ImportMultiSigAddress(multiSigAddress); - generalWalletManager.SaveWallet(); +// generalWalletManager.SaveWallet(); - // return account; - } +// // return account; +// } - public void SaveGeneralWallet(CoreNode node, string walletName) - { - var generalWalletManager = node.FullNode.NodeService() as FederationWalletManager; - var wallet = generalWalletManager.GetWallet(); - generalWalletManager.SaveWallet(); - } - } -} +// public void SaveGeneralWallet(CoreNode node, string walletName) +// { +// var generalWalletManager = node.FullNode.NodeService() as FederationWalletManager; +// var wallet = generalWalletManager.GetWallet(); +// generalWalletManager.SaveWallet(); +// } +// } +//} diff --git a/SidechainFunder_Can.cs b/SidechainFunder_Can.cs index f8b7be5d44d..8f056557b75 100644 --- a/SidechainFunder_Can.cs +++ b/SidechainFunder_Can.cs @@ -1,1008 +1,1006 @@ -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Threading.Tasks; -using FluentAssertions; -using NBitcoin; -using Stratis.Bitcoin.Features.Api; -using Stratis.Bitcoin.Features.BlockStore; -using Stratis.Bitcoin.Features.Consensus; -using Stratis.Bitcoin.Features.MemoryPool; -using Stratis.Bitcoin.Features.Miner; -using Stratis.Bitcoin.Features.Miner.Interfaces; -using Stratis.Bitcoin.Features.RPC; -using Stratis.Bitcoin.Features.Wallet; -using Stratis.Bitcoin.Features.Wallet.Controllers; -using Stratis.Bitcoin.Features.Wallet.Models; -using Stratis.Bitcoin.IntegrationTests.Common.EnvironmentMockUpHelpers; -using Stratis.Bitcoin.Tests.Common; -using Stratis.FederatedPeg.Features.FederationGateway; -using Stratis.FederatedPeg.Features.MainchainGeneratorServices; -using Stratis.FederatedPeg.Features.SidechainGeneratorServices; -using Stratis.FederatedPeg.IntegrationTests.Helpers; -using Xunit; -using WtTransactionBuildContext = Stratis.Bitcoin.Features.Wallet.TransactionBuildContext; -using System; -using Stratis.Bitcoin.Features.Notifications; -using Stratis.Bitcoin.IntegrationTests.Common; -using Stratis.Sidechains.Networks; - -//todo: this is pre-refactoring code -//todo: ensure no duplicate or fake withdrawal or deposit transactions are possible (current work underway) - -namespace Stratis.FederatedPeg.IntegrationTests -{ - public class FedMember - { - public string Name { get; set; } - - public Mnemonic Mnemonic { get; set; } - - public string Password { get; set; } - - public PubKey PubKey { get; set; } - } - - // Use Case references. (See documents in the requirements folder n the repo.) - // UCInit: Generate and Initialize Sidechain. - // UCGenF: Generate Federation Member Key Pairs. - // UCFund: Send Funds to Sidechain. - public class SidechainFunder_Can - { - private List members; - private readonly Network sidechainNetwork = ApexNetwork.Test; - private readonly Network mainchainNetwork = Network.StratisRegTest; - - public void CreateMembers() - { - int membersCount = 3; - int minSigneesCount = 2; - - // Create the members. - members = new List(); - for (int i = 0; i < membersCount; i++) - { - Mnemonic mnemonic = new Mnemonic(Wordlist.English, WordCount.Twelve); - var pubKey = mnemonic.DeriveExtKey().PrivateKey.PubKey; - - FedMember member = new FedMember - { - Name = $"member{i}", - Password = $"pass{i}", - Mnemonic = mnemonic, - PubKey = pubKey - }; - - members.Add(member); - } - - // Create the redeem script. - Script redeemScript = PayToMultiSigTemplate.Instance.GenerateScriptPubKey(minSigneesCount, members.Select(p => p.PubKey).ToArray()); - Console.WriteLine("Redeem script: " + redeemScript.ToString()); - - // Create the Apex sidechain multisig address. - BitcoinAddress sidechainMultisigAddress = redeemScript.Hash.GetAddress(ApexNetwork.Test); - Console.WriteLine("Sidechan P2SH: " + sidechainMultisigAddress.ScriptPubKey); - Console.WriteLine("Sidechain Multisig address: " + sidechainMultisigAddress); - - // Create the Stratis Test sidechain multisig address. - BitcoinAddress mainchainMultisigAddress = redeemScript.Hash.GetAddress(Network.StratisTest); - Console.WriteLine("Mainchain P2SH: " + mainchainMultisigAddress.ScriptPubKey); - Console.WriteLine("Mainchain Multisig address: " + mainchainMultisigAddress); - - - // Tests. - var destinations = redeemScript.GetDestinationPublicKeys(ApexNetwork.Test); - Assert.Equal(membersCount, destinations.Length); - } - [Fact(Skip = "Waiting for mining changes on the full node")] public async Task deposit_funds_to_sidechain() - { - CreateMembers(); - int addNodeDelay = 4000; - - TestBase.AssureEmptyDir("TestData\\deposit_funds_to_sidechain"); - TestBase.AssureEmptyDir("Federations\\deposit_funds_to_sidechain"); - - //check empty - Directory.Exists("TestData\\deposit_funds_to_sidechain").Should().BeFalse(); - Directory.Exists("Federations\\deposit_funds_to_sidechain").Should().BeFalse(); - - // UCInit: Precondition - Generate a Blockchain using the Stratis Blockchain Generation - // technology. (Not shown in this test. We have pre-prepared a chain called 'enigma'). - string sidechain_folder = @"..\..\..\..\..\assets"; - - using (var nodeBuilder = NodeBuilder.Create(this)) - // using (SidechainIdentifier.Create("enigma", sidechain_folder)) - { +//using System.Collections.Generic; +//using System.IO; +//using System.Linq; +//using System.Threading.Tasks; +//using FluentAssertions; +//using NBitcoin; +//using Stratis.Bitcoin.Features.Api; +//using Stratis.Bitcoin.Features.BlockStore; +//using Stratis.Bitcoin.Features.Consensus; +//using Stratis.Bitcoin.Features.MemoryPool; +//using Stratis.Bitcoin.Features.Miner; +//using Stratis.Bitcoin.Features.Miner.Interfaces; +//using Stratis.Bitcoin.Features.RPC; +//using Stratis.Bitcoin.Features.Wallet; +//using Stratis.Bitcoin.Features.Wallet.Controllers; +//using Stratis.Bitcoin.Features.Wallet.Models; +//using Stratis.Bitcoin.IntegrationTests.Common.EnvironmentMockUpHelpers; +//using Stratis.Bitcoin.Tests.Common; +//using Stratis.FederatedPeg.Features.FederationGateway; +//using Stratis.FederatedPeg.IntegrationTests.Helpers; +//using Xunit; +//using WtTransactionBuildContext = Stratis.Bitcoin.Features.Wallet.TransactionBuildContext; +//using System; +//using Stratis.Bitcoin.Features.Notifications; +//using Stratis.Bitcoin.IntegrationTests.Common; +//using Stratis.Sidechains.Networks; + +////todo: this is pre-refactoring code +////todo: ensure no duplicate or fake withdrawal or deposit transactions are possible (current work underway) + +//namespace Stratis.FederatedPeg.IntegrationTests +//{ +// public class FedMember +// { +// public string Name { get; set; } + +// public Mnemonic Mnemonic { get; set; } + +// public string Password { get; set; } + +// public PubKey PubKey { get; set; } +// } + +// // Use Case references. (See documents in the requirements folder n the repo.) +// // UCInit: Generate and Initialize Sidechain. +// // UCGenF: Generate Federation Member Key Pairs. +// // UCFund: Send Funds to Sidechain. +// public class SidechainFunder_Can +// { +// private List members; +// private readonly Network sidechainNetwork = ApexNetwork.Test; +// private readonly Network mainchainNetwork = Network.StratisRegTest; + +// public void CreateMembers() +// { +// int membersCount = 3; +// int minSigneesCount = 2; + +// // Create the members. +// members = new List(); +// for (int i = 0; i < membersCount; i++) +// { +// Mnemonic mnemonic = new Mnemonic(Wordlist.English, WordCount.Twelve); +// var pubKey = mnemonic.DeriveExtKey().PrivateKey.PubKey; + +// FedMember member = new FedMember +// { +// Name = $"member{i}", +// Password = $"pass{i}", +// Mnemonic = mnemonic, +// PubKey = pubKey +// }; + +// members.Add(member); +// } + +// // Create the redeem script. +// Script redeemScript = PayToMultiSigTemplate.Instance.GenerateScriptPubKey(minSigneesCount, members.Select(p => p.PubKey).ToArray()); +// Console.WriteLine("Redeem script: " + redeemScript.ToString()); + +// // Create the Apex sidechain multisig address. +// BitcoinAddress sidechainMultisigAddress = redeemScript.Hash.GetAddress(ApexNetwork.Test); +// Console.WriteLine("Sidechan P2SH: " + sidechainMultisigAddress.ScriptPubKey); +// Console.WriteLine("Sidechain Multisig address: " + sidechainMultisigAddress); + +// // Create the Stratis Test sidechain multisig address. +// BitcoinAddress mainchainMultisigAddress = redeemScript.Hash.GetAddress(Network.StratisTest); +// Console.WriteLine("Mainchain P2SH: " + mainchainMultisigAddress.ScriptPubKey); +// Console.WriteLine("Mainchain Multisig address: " + mainchainMultisigAddress); + + +// // Tests. +// var destinations = redeemScript.GetDestinationPublicKeys(ApexNetwork.Test); +// Assert.Equal(membersCount, destinations.Length); +// } +// [Fact(Skip = "Waiting for mining changes on the full node")] public async Task deposit_funds_to_sidechain() +// { +// CreateMembers(); +// int addNodeDelay = 4000; + +// TestBase.AssureEmptyDir("TestData\\deposit_funds_to_sidechain"); +// TestBase.AssureEmptyDir("Federations\\deposit_funds_to_sidechain"); + +// //check empty +// Directory.Exists("TestData\\deposit_funds_to_sidechain").Should().BeFalse(); +// Directory.Exists("Federations\\deposit_funds_to_sidechain").Should().BeFalse(); + +// // UCInit: Precondition - Generate a Blockchain using the Stratis Blockchain Generation +// // technology. (Not shown in this test. We have pre-prepared a chain called 'enigma'). +// string sidechain_folder = @"..\..\..\..\..\assets"; + +// using (var nodeBuilder = NodeBuilder.Create(this)) +// // using (SidechainIdentifier.Create("enigma", sidechain_folder)) +// { - //creates the federation folder - var fedFolder = new TestFederationFolder(); - - // - // Act as Sidechain Generator. - // - - // UCInit: The actor communicates with each Federation Member and they follow the process - // described in the Generate Federation Member Key Pairs use case. - - // - // Act as Federation Member(s). - // - // The actor communicates with each Federation Member and they follow the process described in - // the Generate Federation Member Key Pairs use case. - // This calls the command line console to generate the keys and send their public key to - // the SidechainGenerator. - - - - // UCGenF: The Federation Member actor navigates to an application and issues a command to - // Generate Federation Key Pairs. - // UCGenF: The actor enters their full name. - // UCGenF: The actor enters a Password and asked to confirm it. - // UCGenF: The actor is reminded to not forget or share his password. - // (Console app will output: "Keep this pass phrase safe.") - // UCGenF: The actor issues the generate command. Text files are produced and it is made - // absolutely clear once again that the user is not to lose his password and to - // take care of the files. - // (Console app output: "Two of the files are PRIVATE keys that you must keep secret. - // Do not distribute these private keys.") - - // The RunFedKeyPair creates a folder for each member to simulate what they create locally. - fedFolder.RunFedKeyPairGen("member1", "pass1"); - fedFolder.RunFedKeyPairGen("member2", "pass2"); - fedFolder.RunFedKeyPairGen("member3", "pass3"); - - // Give file operations a chance to complete. - await Task.Delay(2000); - - File.Exists(Path.Combine(fedFolder.Folder, "member1\\PRIVATE_DO_NOT_SHARE_Mainchain_member1.txt")).Should().BeTrue(); - File.Exists(Path.Combine(fedFolder.Folder, "member1\\PRIVATE_DO_NOT_SHARE_Sidechain_member1.txt")).Should().BeTrue(); - File.Exists(Path.Combine(fedFolder.Folder, "member1\\PUBLIC_Mainchain_member1.txt")).Should().BeTrue(); - File.Exists(Path.Combine(fedFolder.Folder, "member1\\PUBLIC_Sidechain_member1.txt")).Should().BeTrue(); - - File.Exists(Path.Combine(fedFolder.Folder, "member2\\PRIVATE_DO_NOT_SHARE_Mainchain_member2.txt")).Should().BeTrue(); - File.Exists(Path.Combine(fedFolder.Folder, "member2\\PRIVATE_DO_NOT_SHARE_Sidechain_member2.txt")).Should().BeTrue(); - File.Exists(Path.Combine(fedFolder.Folder, "member2\\PUBLIC_Mainchain_member2.txt")).Should().BeTrue(); - File.Exists(Path.Combine(fedFolder.Folder, "member2\\PUBLIC_Sidechain_member2.txt")).Should().BeTrue(); - - File.Exists(Path.Combine(fedFolder.Folder, "member3\\PRIVATE_DO_NOT_SHARE_Mainchain_member3.txt")).Should().BeTrue(); - File.Exists(Path.Combine(fedFolder.Folder, "member3\\PRIVATE_DO_NOT_SHARE_Sidechain_member3.txt")).Should().BeTrue(); - File.Exists(Path.Combine(fedFolder.Folder, "member3\\PUBLIC_Mainchain_member3.txt")).Should().BeTrue(); - File.Exists(Path.Combine(fedFolder.Folder, "member3\\PUBLIC_Sidechain_member3.txt")).Should().BeTrue(); - - // UCGenF: The actor communicates the public keys with the Sidechain Generator. - // DistributeKeys copies the public keys from each member to the parent folder in order - // to simulate the distribution of keys to the Sidechain Generator. - // UCInit: The actor receives all the public keys from the Federation Members. - fedFolder.DistributeKeys(new[] { "member1", "member2", "member3" }); - - File.Exists(Path.Combine(fedFolder.Folder, "PUBLIC_Mainchain_member1.txt")).Should().BeTrue(); - File.Exists(Path.Combine(fedFolder.Folder, "PUBLIC_Sidechain_member1.txt")).Should().BeTrue(); - - File.Exists(Path.Combine(fedFolder.Folder, "PUBLIC_Mainchain_member2.txt")).Should().BeTrue(); - File.Exists(Path.Combine(fedFolder.Folder, "PUBLIC_Sidechain_member2.txt")).Should().BeTrue(); - - File.Exists(Path.Combine(fedFolder.Folder, "PUBLIC_Mainchain_member3.txt")).Should().BeTrue(); - File.Exists(Path.Combine(fedFolder.Folder, "PUBLIC_Sidechain_member3.txt")).Should().BeTrue(); - - // Give file operations a chance to complete. - await Task.Delay(2000); - - // - // Act as Sidechain Generator - // - - // UCInit: The actor navigates to an initialize sidechain feature. He enters the multi-sig - // quorum parameters (eg 12 of 20) and enters the folder location (federation folder) - // where the collected public keys are located. - - // This part of the use case is realized on a by running a mainchain and a sidechain each with - // added Mainchain/Sidechain Generation Services. - - // Create mainchain with MainchainGeneratorServices. - var mainchainNode_GeneratorRole = nodeBuilder.CreateCustomNode(false, fullNodeBuilder => - { - // We will run 10+ nodes in this integration test. - // All these nodes will output to one console. - // We use the 'agent' to help identify nodes and - // their connections in the console. - fullNodeBuilder - .UseBlockStore() - .UsePosConsensus() - .UseMempool() - .UseWallet() - .AddPowPosMining() - .AddMainchainGeneratorServices() - .UseApi() - .AddRPC(); - }, this.mainchainNetwork, agent: "MainchainGeneratorRole "); - mainchainNode_GeneratorRole.Start(); - - await Task.Delay(3000); - - //Create sidechain with SidechainGeneratorServices. - var sidechainNode_GeneratorRole = nodeBuilder.CreateCustomNode(false, fullNodeBuilder => - { - fullNodeBuilder - .UseBlockStore() - .UsePosConsensus() - .UseMempool() - .UseWallet() - .AddPowPosMining() - .AddSidechainGeneratorServices() - .UseApi() - .AddRPC(); - }, - this.sidechainNetwork, - agent: "SidechainGeneratorRole " - ); - - //At the same time we create another sidechain node and connect it to the newly initialized Sidechain - //to create a new sidechain network. - var sidechainNode_Member1_Wallet = nodeBuilder.CreateCustomNode(false, fullNodeBuilder => - { - fullNodeBuilder - .UseBlockStore() - .UsePosConsensus() - .UseMempool() - .UseWallet() - .AddPowPosMining() - - // The multi-sigs will usually be monitored on the FederationGateway. - // However, that is not a requirement and any node can monitor the - // multi-sigs. In this case we will add the wallet to our FunderRole - // node and use the wallet to confirm the premine is generated into - // the multi-sig address. - // .UseGeneralPurposeWallet() - .UseApi() - .AddRPC(); - }, - this.sidechainNetwork, - agent: "SidechainMember1Wallet " - ); - - var sidechainNode_FunderRole = nodeBuilder.CreateCustomNode(false, fullNodeBuilder => - { - fullNodeBuilder - .UseBlockStore() - .UsePosConsensus() - .UseMempool() - .UseWallet() - .AddPowPosMining() - .UseApi() - .AddRPC(); - }, - this.sidechainNetwork, - agent: "SidechainFunderRole " - ); - - // Start the engines! - sidechainNode_GeneratorRole.Start(); - sidechainNode_Member1_Wallet.Start(); - sidechainNode_FunderRole.Start(); - - //give nodes startup time - await Task.Delay(10000); - - // Connect the sidechain nodes together. - var rpcClientGR = sidechainNode_GeneratorRole.CreateRPCClient(); - rpcClientGR.AddNode(sidechainNode_Member1_Wallet.Endpoint); - await Task.Delay(addNodeDelay); - rpcClientGR.AddNode(sidechainNode_FunderRole.Endpoint); - await Task.Delay(addNodeDelay); - - var rpcClientMW = sidechainNode_Member1_Wallet.CreateRPCClient(); - rpcClientMW.AddNode(sidechainNode_GeneratorRole.Endpoint); - await Task.Delay(addNodeDelay); - rpcClientMW.AddNode(sidechainNode_FunderRole.Endpoint); - await Task.Delay(addNodeDelay); - - var rpcClientFR = sidechainNode_FunderRole.CreateRPCClient(); - rpcClientFR.AddNode(sidechainNode_Member1_Wallet.Endpoint); - await Task.Delay(addNodeDelay); - rpcClientFR.AddNode(sidechainNode_GeneratorRole.Endpoint); - await Task.Delay(addNodeDelay); - - // Let our two sidechain nodes sync together. - await IntegrationTestUtils.WaitLoop(() => IntegrationTestUtils.AreNodesSynced(sidechainNode_GeneratorRole, sidechainNode_Member1_Wallet)); - - // Create a wallet and add our multi-sig. - await ApiCalls.CreateFederationWallet(sidechainNode_Member1_Wallet.GetApiPort(), "multisig_wallet", "password"); - // var account_member1 = fedFolder.ImportPrivateKeyToWallet(sidechainNode_Member1_Wallet, "multisig_wallet", "password", "member1", "pass1", 2, 3, ApexNetwork.RegTest); - - // UCInit: The actor navigates to an initialize sidechain feature. He enters the multi-sig - // quorum parameters (eg 12 of 20) and enters the folder location (federation folder) - // where the collected public keys are located. - // The actor issues the Initialize Sidechain Command. The sidechain is initialized. - // UCInit: The actor receives the ScriptPubKey (redeem script) files for each Federated Member. - // A public address is also generated. (InitSidechain does this.) - await ApiCalls.InitSidechain("enigma", mainchainNode_GeneratorRole.GetApiPort(), sidechainNode_GeneratorRole.GetApiPort(), 2, 3, fedFolder.Folder); - - File.Exists(Path.Combine(fedFolder.Folder, "Mainchain_Address.txt")).Should().BeTrue(); - File.Exists(Path.Combine(fedFolder.Folder, "Sidechain_Address.txt")).Should().BeTrue(); - File.Exists(Path.Combine(fedFolder.Folder, "Mainchain_ScriptPubKey.txt")).Should().BeTrue(); - File.Exists(Path.Combine(fedFolder.Folder, "Sidechain_ScriptPubKey.txt")).Should().BeTrue(); - - // Let our two sidechain nodes sync together. - await IntegrationTestUtils.WaitLoop(() => IntegrationTestUtils.AreNodesSynced(sidechainNode_GeneratorRole, sidechainNode_Member1_Wallet)); - - // UCInit: These files must be sent back to the federation members to store with their - // important sidechain key files. There are four small files in total since a - // redeem script and an address are required for both sidechain and mainchain. - // UCGenF: The Sidechain Generator sends back two ScriptPubKeys and derived addresses - // that must also be stored securely with the other files. - fedFolder.DistributeScriptAndAddress(new[] { "member1", "member2", "member3" }); - - File.Exists(Path.Combine(fedFolder.Folder, "member1\\Mainchain_Address.txt")).Should().BeTrue(); - File.Exists(Path.Combine(fedFolder.Folder, "member1\\Sidechain_Address.txt")).Should().BeTrue(); - File.Exists(Path.Combine(fedFolder.Folder, "member1\\Mainchain_ScriptPubKey.txt")).Should().BeTrue(); - File.Exists(Path.Combine(fedFolder.Folder, "member1\\Sidechain_ScriptPubKey.txt")).Should().BeTrue(); - File.Exists(Path.Combine(fedFolder.Folder, "member2\\Mainchain_Address.txt")).Should().BeTrue(); - File.Exists(Path.Combine(fedFolder.Folder, "member2\\Sidechain_Address.txt")).Should().BeTrue(); - File.Exists(Path.Combine(fedFolder.Folder, "member2\\Mainchain_ScriptPubKey.txt")).Should().BeTrue(); - File.Exists(Path.Combine(fedFolder.Folder, "member2\\Sidechain_ScriptPubKey.txt")).Should().BeTrue(); - File.Exists(Path.Combine(fedFolder.Folder, "member3\\Mainchain_Address.txt")).Should().BeTrue(); - File.Exists(Path.Combine(fedFolder.Folder, "member3\\Sidechain_Address.txt")).Should().BeTrue(); - File.Exists(Path.Combine(fedFolder.Folder, "member3\\Mainchain_ScriptPubKey.txt")).Should().BeTrue(); - File.Exists(Path.Combine(fedFolder.Folder, "member3\\Sidechain_ScriptPubKey.txt")).Should().BeTrue(); - - // Check we imported the multi-sig correctly. - var memberFolderManager = fedFolder.CreateMemberFolderManager(); - // account_member1.MultiSigAddresses.First().Address.Should() - // .Be(memberFolderManager.ReadAddress(Chain.Sidechain)); - - // Read the new multi-sig addresses. - string multiSigAddress_Mainchain = memberFolderManager.ReadAddress(Chain.Mainchain); - string multiSigAddress_Sidechain = memberFolderManager.ReadAddress(Chain.Sidechain); - - // Check we got the right balance in the multi-sig after the sidechain premine. - //var amounts = this.multisigAddress.GetSpendableAmount(true); - //amounts.ConfirmedAmount.Should().Be(new Money(98000008, MoneyUnit.BTC)); - - // UCInit: The use case ends. - // UCGenF: The use case ends. - // At this stage we no longer need our Generator role nodes. - mainchainNode_GeneratorRole.Kill(); - sidechainNode_GeneratorRole.Kill(); - - // - // Act as Sidechain Funder - // - - // UCFund: The actor navigates to his Sidechain wallet and issues the Receive command. - // The wallet displays a Sidechain Destination Address which he can copy. - - // This step will be UI but we can simulate it with just the backend code that the UI will use. - string sidechainWallet = "sidechain_wallet"; - string mnemonic = await ApiCalls.Mnemonic(sidechainNode_Member1_Wallet.GetApiPort()); - string create_mnemonic = await ApiCalls.Create(sidechainNode_Member1_Wallet.GetApiPort(), mnemonic, sidechainWallet, - sidechainNode_Member1_Wallet.FullNode.DataFolder.WalletPath); - create_mnemonic.Should().Be(mnemonic); - //and gets an address. we'll use this as the sidechain destination address where he wants to send his funds - string addressSidechain = await ApiCalls.UnusedAddress(sidechainNode_Member1_Wallet.GetApiPort(), sidechainWallet); - - // USFund: The actor navigates to his Mainchain wallet and issues the command to Send Funds - // to Sidechain. The actor views the name of the chain and therefore can verify - // that he is sending to the correct chain. The actor enters the Sidechain - // Destination Address that he copied in the step above. He then also enters the - // Multi-Sig Federation Address that he obtained previously. - - //start mainchain - //we are now acting as a Sidechain Funder. - var mainchain_SidechainFunder1 = nodeBuilder.CreateCustomNode(false, fullNodeBuilder => - { - fullNodeBuilder - .UseBlockStore() - .UsePosConsensus() - .UseMempool() - .UseWallet() - .AddPowPosMining() - .UseApi() - .AddRPC(); - }, this.mainchainNetwork, agent: "MainchainSidechainFunder1 "); - - //start a second mainchain - var mainchain_SidechainFunder2 = nodeBuilder.CreateCustomNode(false, fullNodeBuilder => - { - fullNodeBuilder - .UseBlockStore() - .UsePosConsensus() - .UseMempool() - .UseWallet() - .AddPowPosMining() - .UseApi() - .AddRPC(); - }, this.mainchainNetwork, agent: "MainchainSidechainFunder2 "); - - //join our nodes together and startup - mainchain_SidechainFunder1.ConfigParameters.Add("addnode", $"127.0.0.1:{mainchain_SidechainFunder2.ProtocolPort}"); - mainchain_SidechainFunder2.ConfigParameters.Add("addnode", $"127.0.0.1:{mainchain_SidechainFunder1.ProtocolPort}"); - mainchain_SidechainFunder1.Start(); - mainchain_SidechainFunder2.Start(); - - await Task.Delay(5000); - - //mine some strat mainchain coins - string mainchainWallet = "mainchain_wallet"; - mnemonic = await ApiCalls.Mnemonic(mainchain_SidechainFunder1.GetApiPort()); - create_mnemonic = await ApiCalls.Create(mainchain_SidechainFunder1.GetApiPort(), mnemonic, mainchainWallet, - mainchain_SidechainFunder1.FullNode.DataFolder.WalletPath); - create_mnemonic.Should().Be(mnemonic); - //our source address - string addressMainchain = await ApiCalls.UnusedAddress(mainchain_SidechainFunder1.GetApiPort(), mainchainWallet); - - //put some strat in the source address - var powMinting = mainchain_SidechainFunder1.FullNode.NodeService(); - var bitcoinAddress = new BitcoinPubKeyAddress(addressMainchain, Network.StratisRegTest); - powMinting.GenerateBlocks(new ReserveScript(bitcoinAddress.ScriptPubKey), 50UL, int.MaxValue); - - //sync our mainchain nodes - await IntegrationTestUtils.WaitLoop(() => IntegrationTestUtils.AreNodesSynced(mainchain_SidechainFunder1, mainchain_SidechainFunder2)); - - //check we have expected funds in our mainchain wallet - var account_mainchain_funder1 = mainchain_SidechainFunder1.FullNode.WalletManager().GetAccounts("mainchain_wallet").First(); - // amounts = account_mainchain_funder1.GetSpendableAmount(); - // amounts.ConfirmedAmount.Should().Be(new Money(98000196, MoneyUnit.BTC)); - - // Send Funds (Deposit from Mainchain to Sidechain) - var sendingWalletAccountReference = new Bitcoin.Features.Wallet.WalletAccountReference("mainchain_wallet", "account 0"); - - var transactionBuildContext = new WtTransactionBuildContext( - sendingWalletAccountReference, - new List() { new Recipient() { Amount = new Money(3600, MoneyUnit.BTC), ScriptPubKey = BitcoinAddress.Create(multiSigAddress_Mainchain, Network.StratisRegTest).ScriptPubKey } }, - "1234", addressSidechain) - { - MinConfirmations = 1, - TransactionFee = new Money(0.001m, MoneyUnit.BTC), - Shuffle = true - }; - - // UCFund: The actor issues the command to Send the transaction and the wallet - // confirms and broadcasts the transaction in the normal manner. - var transaction = mainchain_SidechainFunder1.FullNode.WalletTransactionHandler().BuildTransaction(transactionBuildContext); - mainchain_SidechainFunder1.FullNode.NodeService().SendTransaction(new SendTransactionRequest(transaction.ToHex())); - - await Task.Delay(5000); - - //sync our node to distrubute the mempool - await IntegrationTestUtils.WaitLoop(() => IntegrationTestUtils.AreNodesSynced(mainchain_SidechainFunder1, mainchain_SidechainFunder2)); - - await Task.Delay(5000); - - // First we'll need to mine more blocks on the multi-sig so we can spend mature funds. - var powMinting_Sidechain = sidechainNode_Member1_Wallet.FullNode.NodeService(); - bitcoinAddress = new BitcoinPubKeyAddress(addressSidechain, ApexNetwork.RegTest); - powMinting_Sidechain.GenerateBlocks(new ReserveScript(bitcoinAddress.ScriptPubKey), 50UL, int.MaxValue); - - await IntegrationTestUtils.WaitLoop(() => IntegrationTestUtils.AreNodesSynced(sidechainNode_FunderRole, sidechainNode_Member1_Wallet)); - - // - // Act as a Federation Gateway (mainchain) - // - var mainchain_FederationGateway1 = nodeBuilder.CreateCustomNode(false, fullNodeBuilder => - { - fullNodeBuilder - .UseBlockStore() - .UsePosConsensus() - .UseMempool() - .UseWallet() - .AddPowPosMining() - .AddFederationGateway() - // .UseGeneralPurposeWallet() - .UseBlockNotification() - .UseApi() - .AddRPC(); - }, this.mainchainNetwork, agent: "MainchainFederationGateway1 "); - - string publickey = File.ReadAllText(Path.Combine(Directory.GetCurrentDirectory(), "Federations\\deposit_funds_to_sidechain\\member1\\PUBLIC_mainchain_member1.txt")); - mainchain_FederationGateway1.ConfigParameters.Add("federationfolder", Path.Combine(Directory.GetCurrentDirectory(), "Federations\\deposit_funds_to_sidechain")); - mainchain_FederationGateway1.ConfigParameters.Add("memberprivatefolder", Path.Combine(Directory.GetCurrentDirectory(), "Federations\\deposit_funds_to_sidechain\\member1")); - mainchain_FederationGateway1.ConfigParameters.Add("publickey", publickey); - mainchain_FederationGateway1.ConfigParameters.Add("membername", "member1"); - mainchain_FederationGateway1.ConfigParameters.Add("multisigM", "2"); - mainchain_FederationGateway1.ConfigParameters.Add("multisigN", "3"); - - await Task.Delay(5000); - - var mainchain_FederationGateway2 = nodeBuilder.CreateCustomNode(false, fullNodeBuilder => - { - fullNodeBuilder - .UseBlockStore() - .UsePosConsensus() - .UseMempool() - .UseWallet() - .AddPowPosMining() - .AddFederationGateway() - // .UseGeneralPurposeWallet() - .UseBlockNotification() - .UseApi() - .AddRPC(); - }, this.mainchainNetwork, agent: "MainchainFederationGateway2 "); - - publickey = File.ReadAllText(Path.Combine(Directory.GetCurrentDirectory(), "Federations\\deposit_funds_to_sidechain\\member2\\PUBLIC_mainchain_member2.txt")); - mainchain_FederationGateway2.ConfigParameters.Add("federationfolder", Path.Combine(Directory.GetCurrentDirectory(), "Federations\\deposit_funds_to_sidechain")); - mainchain_FederationGateway2.ConfigParameters.Add("memberprivatefolder", Path.Combine(Directory.GetCurrentDirectory(), "Federations\\deposit_funds_to_sidechain\\member2")); - mainchain_FederationGateway2.ConfigParameters.Add("publickey", publickey); - mainchain_FederationGateway2.ConfigParameters.Add("membername", "member2"); - mainchain_FederationGateway2.ConfigParameters.Add("multisigM", "2"); - mainchain_FederationGateway2.ConfigParameters.Add("multisigN", "3"); - - await Task.Delay(5000); - - var mainchain_FederationGateway3 = nodeBuilder.CreateCustomNode(false, fullNodeBuilder => - { - fullNodeBuilder - .UseBlockStore() - .UsePosConsensus() - .UseMempool() - .UseWallet() - .AddPowPosMining() - .AddFederationGateway() - // .UseGeneralPurposeWallet() - .UseBlockNotification() - .UseApi() - .AddRPC(); - }, this.mainchainNetwork, agent: "MainchainFederationGateway3 "); - - publickey = File.ReadAllText(Path.Combine(Directory.GetCurrentDirectory(), "Federations\\deposit_funds_to_sidechain\\member3\\PUBLIC_mainchain_member3.txt")); - mainchain_FederationGateway3.ConfigParameters.Add("federationfolder", Path.Combine(Directory.GetCurrentDirectory(), "Federations\\deposit_funds_to_sidechain")); - mainchain_FederationGateway3.ConfigParameters.Add("memberprivatefolder", Path.Combine(Directory.GetCurrentDirectory(), "Federations\\deposit_funds_to_sidechain\\member3")); - mainchain_FederationGateway3.ConfigParameters.Add("publickey", publickey); - mainchain_FederationGateway3.ConfigParameters.Add("membername", "member3"); - mainchain_FederationGateway3.ConfigParameters.Add("multisigM", "2"); - mainchain_FederationGateway3.ConfigParameters.Add("multisigN", "3"); - - await Task.Delay(5000); - - // - // Act as a Federation Gateway (sidechain) - // - var sidechain_FederationGateway1 = nodeBuilder.CreateCustomNode(false, fullNodeBuilder => - { - fullNodeBuilder - .UseBlockStore() - .UsePosConsensus() - .UseMempool() - .UseWallet() - .AddPowPosMining() - .AddFederationGateway() - // .UseGeneralPurposeWallet() - .UseBlockNotification() - .UseApi() - .AddRPC(); - }, - this.sidechainNetwork, - agent: "SidechainFederationGateway1 " - ); - - publickey = File.ReadAllText(Path.Combine(Directory.GetCurrentDirectory(), "Federations\\deposit_funds_to_sidechain\\member1\\PUBLIC_sidechain_member1.txt")); - sidechain_FederationGateway1.ConfigParameters.Add("federationfolder", Path.Combine(Directory.GetCurrentDirectory(), "Federations\\deposit_funds_to_sidechain")); - sidechain_FederationGateway1.ConfigParameters.Add("memberprivatefolder", Path.Combine(Directory.GetCurrentDirectory(), "Federations\\deposit_funds_to_sidechain\\member1")); - sidechain_FederationGateway1.ConfigParameters.Add("publickey", publickey); - sidechain_FederationGateway1.ConfigParameters.Add("membername", "member1"); - sidechain_FederationGateway1.ConfigParameters.Add("multisigM", "2"); - sidechain_FederationGateway1.ConfigParameters.Add("multisigN", "3"); - - await Task.Delay(5000); - - var sidechain_FederationGateway2 = nodeBuilder.CreateCustomNode(false, fullNodeBuilder => - { - fullNodeBuilder - .UseBlockStore() - .UsePosConsensus() - .UseMempool() - .UseWallet() - .AddPowPosMining() - .AddFederationGateway() - // .UseGeneralPurposeWallet() - .UseBlockNotification() - .UseApi() - .AddRPC(); - }, this.sidechainNetwork, - agent: "SidechainFederationGateway2 " - ); - - publickey = File.ReadAllText(Path.Combine(Directory.GetCurrentDirectory(), "Federations\\deposit_funds_to_sidechain\\member2\\PUBLIC_sidechain_member2.txt")); - sidechain_FederationGateway2.ConfigParameters.Add("federationfolder", Path.Combine(Directory.GetCurrentDirectory(), "Federations\\deposit_funds_to_sidechain")); - sidechain_FederationGateway2.ConfigParameters.Add("memberprivatefolder", Path.Combine(Directory.GetCurrentDirectory(), "Federations\\deposit_funds_to_sidechain\\member2")); - sidechain_FederationGateway2.ConfigParameters.Add("publickey", publickey); - sidechain_FederationGateway2.ConfigParameters.Add("membername", "member2"); - sidechain_FederationGateway2.ConfigParameters.Add("multisigM", "2"); - sidechain_FederationGateway2.ConfigParameters.Add("multisigN", "3"); - - await Task.Delay(5000); - - var sidechain_FederationGateway3 = nodeBuilder.CreateCustomNode(false, fullNodeBuilder => - { - fullNodeBuilder - .UseBlockStore() - .UsePosConsensus() - .UseMempool() - .UseWallet() - .AddPowPosMining() - .AddFederationGateway() - // .UseGeneralPurposeWallet() - .UseBlockNotification() - .UseApi() - .AddRPC(); - }, this.sidechainNetwork, agent: "SidechainFederationGateway3 "); - - publickey = File.ReadAllText(Path.Combine(Directory.GetCurrentDirectory(), "Federations\\deposit_funds_to_sidechain\\member3\\PUBLIC_sidechain_member3.txt")); - sidechain_FederationGateway3.ConfigParameters.Add("federationfolder", Path.Combine(Directory.GetCurrentDirectory(), "Federations\\deposit_funds_to_sidechain")); - sidechain_FederationGateway3.ConfigParameters.Add("memberprivatefolder", Path.Combine(Directory.GetCurrentDirectory(), "Federations\\deposit_funds_to_sidechain\\member3")); - sidechain_FederationGateway3.ConfigParameters.Add("publickey", publickey); - sidechain_FederationGateway3.ConfigParameters.Add("membername", "member3"); - sidechain_FederationGateway3.ConfigParameters.Add("multisigM", "2"); - sidechain_FederationGateway3.ConfigParameters.Add("multisigN", "3"); - - //link the mainchain and sidechain nodes together - mainchain_FederationGateway1.ConfigParameters.Add("counterchainapiport", sidechain_FederationGateway1.GetApiPort().ToString()); - mainchain_FederationGateway2.ConfigParameters.Add("counterchainapiport", sidechain_FederationGateway2.GetApiPort().ToString()); - mainchain_FederationGateway3.ConfigParameters.Add("counterchainapiport", sidechain_FederationGateway3.GetApiPort().ToString()); - sidechain_FederationGateway1.ConfigParameters.Add("counterchainapiport", mainchain_FederationGateway1.GetApiPort().ToString()); - sidechain_FederationGateway2.ConfigParameters.Add("counterchainapiport", mainchain_FederationGateway2.GetApiPort().ToString()); - sidechain_FederationGateway3.ConfigParameters.Add("counterchainapiport", mainchain_FederationGateway3.GetApiPort().ToString()); - - await Task.Delay(5000); - - //start mainchain and sidechain - mainchain_FederationGateway1.Start(); - mainchain_FederationGateway2.Start(); - mainchain_FederationGateway3.Start(); - - //give nodes a chance to start - await Task.Delay(60000); - - sidechain_FederationGateway1.Start(); - sidechain_FederationGateway2.Start(); - sidechain_FederationGateway3.Start(); - - //give nodes a chance to start - await Task.Delay(60000); - - //add mainchain nodes - var rpcClient1 = mainchain_FederationGateway1.CreateRPCClient(); - rpcClient1.AddNode(mainchain_SidechainFunder1.Endpoint); - await Task.Delay(addNodeDelay); - rpcClient1.AddNode(mainchain_SidechainFunder2.Endpoint); - await Task.Delay(addNodeDelay); - rpcClient1.AddNode(mainchain_FederationGateway2.Endpoint); - await Task.Delay(addNodeDelay); - rpcClient1.AddNode(mainchain_FederationGateway3.Endpoint); - await Task.Delay(addNodeDelay); - - var rpcClient2 = mainchain_FederationGateway2.CreateRPCClient(); - rpcClient2.AddNode(mainchain_SidechainFunder1.Endpoint); - await Task.Delay(addNodeDelay); - rpcClient2.AddNode(mainchain_SidechainFunder2.Endpoint); - await Task.Delay(addNodeDelay); - rpcClient2.AddNode(mainchain_FederationGateway1.Endpoint); - await Task.Delay(addNodeDelay); - rpcClient2.AddNode(mainchain_FederationGateway3.Endpoint); - await Task.Delay(addNodeDelay); - - var rpcClient3 = mainchain_FederationGateway3.CreateRPCClient(); - rpcClient3.AddNode(mainchain_SidechainFunder1.Endpoint); - await Task.Delay(addNodeDelay); - rpcClient3.AddNode(mainchain_SidechainFunder2.Endpoint); - await Task.Delay(addNodeDelay); - rpcClient3.AddNode(mainchain_FederationGateway1.Endpoint); - await Task.Delay(addNodeDelay); - rpcClient3.AddNode(mainchain_FederationGateway2.Endpoint); - await Task.Delay(addNodeDelay); - - //add sidechain nodes - var rpcSidechainClient1 = sidechain_FederationGateway1.CreateRPCClient(); - rpcSidechainClient1.AddNode(sidechainNode_FunderRole.Endpoint); - await Task.Delay(addNodeDelay); - rpcSidechainClient1.AddNode(sidechain_FederationGateway2.Endpoint); - await Task.Delay(addNodeDelay); - rpcSidechainClient1.AddNode(sidechain_FederationGateway3.Endpoint); - await Task.Delay(addNodeDelay); - - var rpcSidechainClient2 = sidechain_FederationGateway2.CreateRPCClient(); - rpcSidechainClient2.AddNode(sidechainNode_FunderRole.Endpoint); - await Task.Delay(addNodeDelay); - rpcSidechainClient2.AddNode(sidechain_FederationGateway1.Endpoint); - await Task.Delay(addNodeDelay); - rpcSidechainClient2.AddNode(sidechain_FederationGateway3.Endpoint); - await Task.Delay(addNodeDelay); - - var rpcSidechainClient3 = sidechain_FederationGateway3.CreateRPCClient(); - rpcSidechainClient3.AddNode(sidechainNode_FunderRole.Endpoint); - await Task.Delay(addNodeDelay); - rpcSidechainClient3.AddNode(sidechain_FederationGateway1.Endpoint); - await Task.Delay(addNodeDelay); - rpcSidechainClient3.AddNode(sidechain_FederationGateway2.Endpoint); - await Task.Delay(addNodeDelay); - - IntegrationTestUtils.AreConnected(sidechain_FederationGateway1, sidechain_FederationGateway2).Should().BeTrue(); - IntegrationTestUtils.AreConnected(sidechain_FederationGateway1, sidechain_FederationGateway3).Should().BeTrue(); - IntegrationTestUtils.AreConnected(sidechain_FederationGateway2, sidechain_FederationGateway1).Should().BeTrue(); - IntegrationTestUtils.AreConnected(sidechain_FederationGateway2, sidechain_FederationGateway3).Should().BeTrue(); - IntegrationTestUtils.AreConnected(sidechain_FederationGateway3, sidechain_FederationGateway1).Should().BeTrue(); - IntegrationTestUtils.AreConnected(sidechain_FederationGateway3, sidechain_FederationGateway2).Should().BeTrue(); - IntegrationTestUtils.AreConnected(sidechain_FederationGateway1, sidechainNode_FunderRole).Should().BeTrue(); - IntegrationTestUtils.AreConnected(sidechain_FederationGateway2, sidechainNode_FunderRole).Should().BeTrue(); - IntegrationTestUtils.AreConnected(sidechain_FederationGateway3, sidechainNode_FunderRole).Should().BeTrue(); - - IntegrationTestUtils.AreConnected(mainchain_FederationGateway1, mainchain_FederationGateway2).Should().BeTrue(); - IntegrationTestUtils.AreConnected(mainchain_FederationGateway1, mainchain_FederationGateway3).Should().BeTrue(); - IntegrationTestUtils.AreConnected(mainchain_FederationGateway2, mainchain_FederationGateway1).Should().BeTrue(); - IntegrationTestUtils.AreConnected(mainchain_FederationGateway2, mainchain_FederationGateway3).Should().BeTrue(); - IntegrationTestUtils.AreConnected(mainchain_FederationGateway3, mainchain_FederationGateway1).Should().BeTrue(); - IntegrationTestUtils.AreConnected(mainchain_FederationGateway3, mainchain_FederationGateway2).Should().BeTrue(); - - //create wallets on the sidechains - //sidechain_FederationGateway1 - await ApiCalls.CreateFederationWallet(sidechain_FederationGateway1.GetApiPort(), "multisig_wallet", "password"); - //var account_fed_member1_sidechain = fedFolder.ImportPrivateKeyToWallet(sidechain_FederationGateway1, "multisig_wallet", "password", "member1", "pass1", 2, 3, ApexNetwork.RegTest); - - //sidechain_FederationGateway2 - await ApiCalls.CreateFederationWallet(sidechain_FederationGateway2.GetApiPort(), "multisig_wallet", "password"); - //var account_fed_member2_sidechain = fedFolder.ImportPrivateKeyToWallet(sidechain_FederationGateway2, "multisig_wallet", "password", "member2", "pass2", 2, 3, ApexNetwork.RegTest); - - //sidechain_FederationGateway3 - await ApiCalls.CreateFederationWallet(sidechain_FederationGateway3.GetApiPort(), "multisig_wallet", "password"); - // var account_fed_member3_sidechain = fedFolder.ImportPrivateKeyToWallet(sidechain_FederationGateway3, "multisig_wallet", "password", "member3", "pass3", 2, 3, ApexNetwork.RegTest); - - await Task.Delay(5000); - - await IntegrationTestUtils.WaitLoop(() => IntegrationTestUtils.AreNodesSynced(sidechain_FederationGateway1, sidechainNode_Member1_Wallet)); - await IntegrationTestUtils.WaitLoop(() => IntegrationTestUtils.AreNodesSynced(sidechain_FederationGateway2, sidechainNode_Member1_Wallet)); - await IntegrationTestUtils.WaitLoop(() => IntegrationTestUtils.AreNodesSynced(sidechain_FederationGateway3, sidechainNode_Member1_Wallet)); - - IntegrationTestUtils.ResyncGeneralWallet(sidechain_FederationGateway1); - IntegrationTestUtils.ResyncGeneralWallet(sidechain_FederationGateway2); - IntegrationTestUtils.ResyncGeneralWallet(sidechain_FederationGateway3); - - await IntegrationTestUtils.WaitLoop(() => IntegrationTestUtils.IsGeneralWalletSyncedToHeight(sidechain_FederationGateway1, 53)); - await IntegrationTestUtils.WaitLoop(() => IntegrationTestUtils.IsGeneralWalletSyncedToHeight(sidechain_FederationGateway2, 53)); - await IntegrationTestUtils.WaitLoop(() => IntegrationTestUtils.IsGeneralWalletSyncedToHeight(sidechain_FederationGateway3, 53)); - - bitcoinAddress = new BitcoinPubKeyAddress(addressSidechain, ApexNetwork.RegTest); - powMinting_Sidechain.GenerateBlocks(new ReserveScript(bitcoinAddress.ScriptPubKey), 1UL, int.MaxValue); - - await IntegrationTestUtils.WaitLoop(() => IntegrationTestUtils.AreNodesSynced(sidechain_FederationGateway1, sidechainNode_Member1_Wallet)); - await IntegrationTestUtils.WaitLoop(() => IntegrationTestUtils.AreNodesSynced(sidechain_FederationGateway2, sidechainNode_Member1_Wallet)); - await IntegrationTestUtils.WaitLoop(() => IntegrationTestUtils.AreNodesSynced(sidechain_FederationGateway3, sidechainNode_Member1_Wallet)); - - await IntegrationTestUtils.WaitLoop(() => IntegrationTestUtils.IsGeneralWalletSyncedToHeight(sidechain_FederationGateway1, 54)); - await IntegrationTestUtils.WaitLoop(() => IntegrationTestUtils.IsGeneralWalletSyncedToHeight(sidechain_FederationGateway2, 54)); - await IntegrationTestUtils.WaitLoop(() => IntegrationTestUtils.IsGeneralWalletSyncedToHeight(sidechain_FederationGateway3, 54)); - - IntegrationTestUtils.SaveGeneralWallet(sidechain_FederationGateway1, "multisig_wallet"); - IntegrationTestUtils.SaveGeneralWallet(sidechain_FederationGateway2, "multisig_wallet"); - IntegrationTestUtils.SaveGeneralWallet(sidechain_FederationGateway3, "multisig_wallet"); - - //check we have the correct balance in the multisigs - //amounts = account_fed_member1_sidechain.GetSpendableAmount(true); - //amounts.ConfirmedAmount.Should().Be(new Money(98000008, MoneyUnit.BTC)); - - //amounts = account_fed_member2_sidechain.GetSpendableAmount(true); - //amounts.ConfirmedAmount.Should().Be(new Money(98000008, MoneyUnit.BTC)); - - //amounts = account_fed_member3_sidechain.GetSpendableAmount(true); - //amounts.ConfirmedAmount.Should().Be(new Money(98000008, MoneyUnit.BTC)); - - - //create wallets on the mainchains - //mainchain_FederationGateway1 - await ApiCalls.CreateFederationWallet(mainchain_FederationGateway1.GetApiPort(), "multisig_wallet", "password"); - // var account_fed_member1_mainchain = fedFolder.ImportPrivateKeyToWallet(mainchain_FederationGateway1, "multisig_wallet", "password", "member1", "pass1", 2, 3, Network.StratisRegTest); - - //mainchain_FederationGateway2 - await ApiCalls.CreateFederationWallet(mainchain_FederationGateway2.GetApiPort(), "multisig_wallet", "password"); - // var account_fed_member2_mainchain = fedFolder.ImportPrivateKeyToWallet(mainchain_FederationGateway2, "multisig_wallet", "password", "member2", "pass2", 2, 3, Network.StratisRegTest); - - //mainchain_FederationGateway3 - await ApiCalls.CreateFederationWallet(mainchain_FederationGateway3.GetApiPort(), "multisig_wallet", "password"); - // var account_fed_member3_mainchain = fedFolder.ImportPrivateKeyToWallet(mainchain_FederationGateway3, "multisig_wallet", "password", "member3", "pass3", 2, 3, Network.StratisRegTest); - - //generate a block to include our transaction - bitcoinAddress = new BitcoinPubKeyAddress(addressMainchain, Network.StratisRegTest); - powMinting.GenerateBlocks(new ReserveScript(bitcoinAddress.ScriptPubKey), 1UL, int.MaxValue); - - await Task.Delay(35000); - - await IntegrationTestUtils.WaitLoop(() => IntegrationTestUtils.AreNodesSynced(sidechain_FederationGateway1, sidechainNode_Member1_Wallet)); - await IntegrationTestUtils.WaitLoop(() => IntegrationTestUtils.AreNodesSynced(sidechain_FederationGateway2, sidechainNode_Member1_Wallet)); - await IntegrationTestUtils.WaitLoop(() => IntegrationTestUtils.AreNodesSynced(sidechain_FederationGateway3, sidechainNode_Member1_Wallet)); - - IntegrationTestUtils.ResyncGeneralWallet(sidechain_FederationGateway1); - IntegrationTestUtils.ResyncGeneralWallet(sidechain_FederationGateway2); - IntegrationTestUtils.ResyncGeneralWallet(sidechain_FederationGateway3); - - await IntegrationTestUtils.WaitLoop(() => IntegrationTestUtils.IsGeneralWalletSyncedToHeight(sidechain_FederationGateway1, 54)); - await IntegrationTestUtils.WaitLoop(() => IntegrationTestUtils.IsGeneralWalletSyncedToHeight(sidechain_FederationGateway2, 54)); - await IntegrationTestUtils.WaitLoop(() => IntegrationTestUtils.IsGeneralWalletSyncedToHeight(sidechain_FederationGateway3, 54)); - - bitcoinAddress = new BitcoinPubKeyAddress(addressSidechain, ApexNetwork.RegTest); - powMinting_Sidechain.GenerateBlocks(new ReserveScript(bitcoinAddress.ScriptPubKey), 1UL, int.MaxValue); - - await IntegrationTestUtils.WaitLoop(() => IntegrationTestUtils.AreNodesSynced(sidechain_FederationGateway1, sidechainNode_Member1_Wallet)); - await IntegrationTestUtils.WaitLoop(() => IntegrationTestUtils.AreNodesSynced(sidechain_FederationGateway2, sidechainNode_Member1_Wallet)); - await IntegrationTestUtils.WaitLoop(() => IntegrationTestUtils.AreNodesSynced(sidechain_FederationGateway3, sidechainNode_Member1_Wallet)); - - await IntegrationTestUtils.WaitLoop(() => IntegrationTestUtils.IsGeneralWalletSyncedToHeight(sidechain_FederationGateway1, 55)); - await IntegrationTestUtils.WaitLoop(() => IntegrationTestUtils.IsGeneralWalletSyncedToHeight(sidechain_FederationGateway2, 55)); - await IntegrationTestUtils.WaitLoop(() => IntegrationTestUtils.IsGeneralWalletSyncedToHeight(sidechain_FederationGateway3, 55)); - - IntegrationTestUtils.SaveGeneralWallet(sidechain_FederationGateway1, "multisig_wallet"); - IntegrationTestUtils.SaveGeneralWallet(sidechain_FederationGateway2, "multisig_wallet"); - IntegrationTestUtils.SaveGeneralWallet(sidechain_FederationGateway3, "multisig_wallet"); +// //creates the federation folder +// var fedFolder = new TestFederationFolder(); + +// // +// // Act as Sidechain Generator. +// // + +// // UCInit: The actor communicates with each Federation Member and they follow the process +// // described in the Generate Federation Member Key Pairs use case. + +// // +// // Act as Federation Member(s). +// // +// // The actor communicates with each Federation Member and they follow the process described in +// // the Generate Federation Member Key Pairs use case. +// // This calls the command line console to generate the keys and send their public key to +// // the SidechainGenerator. + + + +// // UCGenF: The Federation Member actor navigates to an application and issues a command to +// // Generate Federation Key Pairs. +// // UCGenF: The actor enters their full name. +// // UCGenF: The actor enters a Password and asked to confirm it. +// // UCGenF: The actor is reminded to not forget or share his password. +// // (Console app will output: "Keep this pass phrase safe.") +// // UCGenF: The actor issues the generate command. Text files are produced and it is made +// // absolutely clear once again that the user is not to lose his password and to +// // take care of the files. +// // (Console app output: "Two of the files are PRIVATE keys that you must keep secret. +// // Do not distribute these private keys.") + +// // The RunFedKeyPair creates a folder for each member to simulate what they create locally. +// fedFolder.RunFedKeyPairGen("member1", "pass1"); +// fedFolder.RunFedKeyPairGen("member2", "pass2"); +// fedFolder.RunFedKeyPairGen("member3", "pass3"); + +// // Give file operations a chance to complete. +// await Task.Delay(2000); + +// File.Exists(Path.Combine(fedFolder.Folder, "member1\\PRIVATE_DO_NOT_SHARE_Mainchain_member1.txt")).Should().BeTrue(); +// File.Exists(Path.Combine(fedFolder.Folder, "member1\\PRIVATE_DO_NOT_SHARE_Sidechain_member1.txt")).Should().BeTrue(); +// File.Exists(Path.Combine(fedFolder.Folder, "member1\\PUBLIC_Mainchain_member1.txt")).Should().BeTrue(); +// File.Exists(Path.Combine(fedFolder.Folder, "member1\\PUBLIC_Sidechain_member1.txt")).Should().BeTrue(); + +// File.Exists(Path.Combine(fedFolder.Folder, "member2\\PRIVATE_DO_NOT_SHARE_Mainchain_member2.txt")).Should().BeTrue(); +// File.Exists(Path.Combine(fedFolder.Folder, "member2\\PRIVATE_DO_NOT_SHARE_Sidechain_member2.txt")).Should().BeTrue(); +// File.Exists(Path.Combine(fedFolder.Folder, "member2\\PUBLIC_Mainchain_member2.txt")).Should().BeTrue(); +// File.Exists(Path.Combine(fedFolder.Folder, "member2\\PUBLIC_Sidechain_member2.txt")).Should().BeTrue(); + +// File.Exists(Path.Combine(fedFolder.Folder, "member3\\PRIVATE_DO_NOT_SHARE_Mainchain_member3.txt")).Should().BeTrue(); +// File.Exists(Path.Combine(fedFolder.Folder, "member3\\PRIVATE_DO_NOT_SHARE_Sidechain_member3.txt")).Should().BeTrue(); +// File.Exists(Path.Combine(fedFolder.Folder, "member3\\PUBLIC_Mainchain_member3.txt")).Should().BeTrue(); +// File.Exists(Path.Combine(fedFolder.Folder, "member3\\PUBLIC_Sidechain_member3.txt")).Should().BeTrue(); + +// // UCGenF: The actor communicates the public keys with the Sidechain Generator. +// // DistributeKeys copies the public keys from each member to the parent folder in order +// // to simulate the distribution of keys to the Sidechain Generator. +// // UCInit: The actor receives all the public keys from the Federation Members. +// fedFolder.DistributeKeys(new[] { "member1", "member2", "member3" }); + +// File.Exists(Path.Combine(fedFolder.Folder, "PUBLIC_Mainchain_member1.txt")).Should().BeTrue(); +// File.Exists(Path.Combine(fedFolder.Folder, "PUBLIC_Sidechain_member1.txt")).Should().BeTrue(); + +// File.Exists(Path.Combine(fedFolder.Folder, "PUBLIC_Mainchain_member2.txt")).Should().BeTrue(); +// File.Exists(Path.Combine(fedFolder.Folder, "PUBLIC_Sidechain_member2.txt")).Should().BeTrue(); + +// File.Exists(Path.Combine(fedFolder.Folder, "PUBLIC_Mainchain_member3.txt")).Should().BeTrue(); +// File.Exists(Path.Combine(fedFolder.Folder, "PUBLIC_Sidechain_member3.txt")).Should().BeTrue(); + +// // Give file operations a chance to complete. +// await Task.Delay(2000); + +// // +// // Act as Sidechain Generator +// // + +// // UCInit: The actor navigates to an initialize sidechain feature. He enters the multi-sig +// // quorum parameters (eg 12 of 20) and enters the folder location (federation folder) +// // where the collected public keys are located. + +// // This part of the use case is realized on a by running a mainchain and a sidechain each with +// // added Mainchain/Sidechain Generation Services. + +// // Create mainchain with MainchainGeneratorServices. +// var mainchainNode_GeneratorRole = nodeBuilder.CreateCustomNode(false, fullNodeBuilder => +// { +// // We will run 10+ nodes in this integration test. +// // All these nodes will output to one console. +// // We use the 'agent' to help identify nodes and +// // their connections in the console. +// fullNodeBuilder +// .UseBlockStore() +// .UsePosConsensus() +// .UseMempool() +// .UseWallet() +// .AddPowPosMining() +// //.AddMainchainGeneratorServices() +// .UseApi() +// .AddRPC(); +// }, this.mainchainNetwork, agent: "MainchainGeneratorRole "); +// mainchainNode_GeneratorRole.Start(); + +// await Task.Delay(3000); + +// //Create sidechain with SidechainGeneratorServices. +// var sidechainNode_GeneratorRole = nodeBuilder.CreateCustomNode(false, fullNodeBuilder => +// { +// fullNodeBuilder +// .UseBlockStore() +// .UsePosConsensus() +// .UseMempool() +// .UseWallet() +// .AddPowPosMining() +// //.AddSidechainGeneratorServices() +// .UseApi() +// .AddRPC(); +// }, +// this.sidechainNetwork, +// agent: "SidechainGeneratorRole " +// ); + +// //At the same time we create another sidechain node and connect it to the newly initialized Sidechain +// //to create a new sidechain network. +// var sidechainNode_Member1_Wallet = nodeBuilder.CreateCustomNode(false, fullNodeBuilder => +// { +// fullNodeBuilder +// .UseBlockStore() +// .UsePosConsensus() +// .UseMempool() +// .UseWallet() +// .AddPowPosMining() + +// // The multi-sigs will usually be monitored on the FederationGateway. +// // However, that is not a requirement and any node can monitor the +// // multi-sigs. In this case we will add the wallet to our FunderRole +// // node and use the wallet to confirm the premine is generated into +// // the multi-sig address. +// // .UseGeneralPurposeWallet() +// .UseApi() +// .AddRPC(); +// }, +// this.sidechainNetwork, +// agent: "SidechainMember1Wallet " +// ); + +// var sidechainNode_FunderRole = nodeBuilder.CreateCustomNode(false, fullNodeBuilder => +// { +// fullNodeBuilder +// .UseBlockStore() +// .UsePosConsensus() +// .UseMempool() +// .UseWallet() +// .AddPowPosMining() +// .UseApi() +// .AddRPC(); +// }, +// this.sidechainNetwork, +// agent: "SidechainFunderRole " +// ); + +// // Start the engines! +// sidechainNode_GeneratorRole.Start(); +// sidechainNode_Member1_Wallet.Start(); +// sidechainNode_FunderRole.Start(); + +// //give nodes startup time +// await Task.Delay(10000); + +// // Connect the sidechain nodes together. +// var rpcClientGR = sidechainNode_GeneratorRole.CreateRPCClient(); +// rpcClientGR.AddNode(sidechainNode_Member1_Wallet.Endpoint); +// await Task.Delay(addNodeDelay); +// rpcClientGR.AddNode(sidechainNode_FunderRole.Endpoint); +// await Task.Delay(addNodeDelay); + +// var rpcClientMW = sidechainNode_Member1_Wallet.CreateRPCClient(); +// rpcClientMW.AddNode(sidechainNode_GeneratorRole.Endpoint); +// await Task.Delay(addNodeDelay); +// rpcClientMW.AddNode(sidechainNode_FunderRole.Endpoint); +// await Task.Delay(addNodeDelay); + +// var rpcClientFR = sidechainNode_FunderRole.CreateRPCClient(); +// rpcClientFR.AddNode(sidechainNode_Member1_Wallet.Endpoint); +// await Task.Delay(addNodeDelay); +// rpcClientFR.AddNode(sidechainNode_GeneratorRole.Endpoint); +// await Task.Delay(addNodeDelay); + +// // Let our two sidechain nodes sync together. +// await IntegrationTestUtils.WaitLoop(() => IntegrationTestUtils.AreNodesSynced(sidechainNode_GeneratorRole, sidechainNode_Member1_Wallet)); + +// // Create a wallet and add our multi-sig. +// await ApiCalls.CreateFederationWallet(sidechainNode_Member1_Wallet.GetApiPort(), "multisig_wallet", "password"); +// // var account_member1 = fedFolder.ImportPrivateKeyToWallet(sidechainNode_Member1_Wallet, "multisig_wallet", "password", "member1", "pass1", 2, 3, ApexNetwork.RegTest); + +// // UCInit: The actor navigates to an initialize sidechain feature. He enters the multi-sig +// // quorum parameters (eg 12 of 20) and enters the folder location (federation folder) +// // where the collected public keys are located. +// // The actor issues the Initialize Sidechain Command. The sidechain is initialized. +// // UCInit: The actor receives the ScriptPubKey (redeem script) files for each Federated Member. +// // A public address is also generated. (InitSidechain does this.) +// //await ApiCalls.InitSidechain("enigma", mainchainNode_GeneratorRole.GetApiPort(), sidechainNode_GeneratorRole.GetApiPort(), 2, 3, fedFolder.Folder); + +// File.Exists(Path.Combine(fedFolder.Folder, "Mainchain_Address.txt")).Should().BeTrue(); +// File.Exists(Path.Combine(fedFolder.Folder, "Sidechain_Address.txt")).Should().BeTrue(); +// File.Exists(Path.Combine(fedFolder.Folder, "Mainchain_ScriptPubKey.txt")).Should().BeTrue(); +// File.Exists(Path.Combine(fedFolder.Folder, "Sidechain_ScriptPubKey.txt")).Should().BeTrue(); + +// // Let our two sidechain nodes sync together. +// await IntegrationTestUtils.WaitLoop(() => IntegrationTestUtils.AreNodesSynced(sidechainNode_GeneratorRole, sidechainNode_Member1_Wallet)); + +// // UCInit: These files must be sent back to the federation members to store with their +// // important sidechain key files. There are four small files in total since a +// // redeem script and an address are required for both sidechain and mainchain. +// // UCGenF: The Sidechain Generator sends back two ScriptPubKeys and derived addresses +// // that must also be stored securely with the other files. +// fedFolder.DistributeScriptAndAddress(new[] { "member1", "member2", "member3" }); + +// File.Exists(Path.Combine(fedFolder.Folder, "member1\\Mainchain_Address.txt")).Should().BeTrue(); +// File.Exists(Path.Combine(fedFolder.Folder, "member1\\Sidechain_Address.txt")).Should().BeTrue(); +// File.Exists(Path.Combine(fedFolder.Folder, "member1\\Mainchain_ScriptPubKey.txt")).Should().BeTrue(); +// File.Exists(Path.Combine(fedFolder.Folder, "member1\\Sidechain_ScriptPubKey.txt")).Should().BeTrue(); +// File.Exists(Path.Combine(fedFolder.Folder, "member2\\Mainchain_Address.txt")).Should().BeTrue(); +// File.Exists(Path.Combine(fedFolder.Folder, "member2\\Sidechain_Address.txt")).Should().BeTrue(); +// File.Exists(Path.Combine(fedFolder.Folder, "member2\\Mainchain_ScriptPubKey.txt")).Should().BeTrue(); +// File.Exists(Path.Combine(fedFolder.Folder, "member2\\Sidechain_ScriptPubKey.txt")).Should().BeTrue(); +// File.Exists(Path.Combine(fedFolder.Folder, "member3\\Mainchain_Address.txt")).Should().BeTrue(); +// File.Exists(Path.Combine(fedFolder.Folder, "member3\\Sidechain_Address.txt")).Should().BeTrue(); +// File.Exists(Path.Combine(fedFolder.Folder, "member3\\Mainchain_ScriptPubKey.txt")).Should().BeTrue(); +// File.Exists(Path.Combine(fedFolder.Folder, "member3\\Sidechain_ScriptPubKey.txt")).Should().BeTrue(); + +// // Check we imported the multi-sig correctly. +// //var memberFolderManager = fedFolder.CreateMemberFolderManager(); +// // account_member1.MultiSigAddresses.First().Address.Should() +// // .Be(memberFolderManager.ReadAddress(Chain.Sidechain)); + +// // Read the new multi-sig addresses. +// //string multiSigAddress_Mainchain = memberFolderManager.ReadAddress(Chain.Mainchain); +// //string multiSigAddress_Sidechain = memberFolderManager.ReadAddress(Chain.Sidechain); + +// // Check we got the right balance in the multi-sig after the sidechain premine. +// //var amounts = this.multisigAddress.GetSpendableAmount(true); +// //amounts.ConfirmedAmount.Should().Be(new Money(98000008, MoneyUnit.BTC)); + +// // UCInit: The use case ends. +// // UCGenF: The use case ends. +// // At this stage we no longer need our Generator role nodes. +// mainchainNode_GeneratorRole.Kill(); +// sidechainNode_GeneratorRole.Kill(); + +// // +// // Act as Sidechain Funder +// // + +// // UCFund: The actor navigates to his Sidechain wallet and issues the Receive command. +// // The wallet displays a Sidechain Destination Address which he can copy. + +// // This step will be UI but we can simulate it with just the backend code that the UI will use. +// string sidechainWallet = "sidechain_wallet"; +// string mnemonic = await ApiCalls.Mnemonic(sidechainNode_Member1_Wallet.GetApiPort()); +// string create_mnemonic = await ApiCalls.Create(sidechainNode_Member1_Wallet.GetApiPort(), mnemonic, sidechainWallet, +// sidechainNode_Member1_Wallet.FullNode.DataFolder.WalletPath); +// create_mnemonic.Should().Be(mnemonic); +// //and gets an address. we'll use this as the sidechain destination address where he wants to send his funds +// string addressSidechain = await ApiCalls.UnusedAddress(sidechainNode_Member1_Wallet.GetApiPort(), sidechainWallet); + +// // USFund: The actor navigates to his Mainchain wallet and issues the command to Send Funds +// // to Sidechain. The actor views the name of the chain and therefore can verify +// // that he is sending to the correct chain. The actor enters the Sidechain +// // Destination Address that he copied in the step above. He then also enters the +// // Multi-Sig Federation Address that he obtained previously. + +// //start mainchain +// //we are now acting as a Sidechain Funder. +// var mainchain_SidechainFunder1 = nodeBuilder.CreateCustomNode(false, fullNodeBuilder => +// { +// fullNodeBuilder +// .UseBlockStore() +// .UsePosConsensus() +// .UseMempool() +// .UseWallet() +// .AddPowPosMining() +// .UseApi() +// .AddRPC(); +// }, this.mainchainNetwork, agent: "MainchainSidechainFunder1 "); + +// //start a second mainchain +// var mainchain_SidechainFunder2 = nodeBuilder.CreateCustomNode(false, fullNodeBuilder => +// { +// fullNodeBuilder +// .UseBlockStore() +// .UsePosConsensus() +// .UseMempool() +// .UseWallet() +// .AddPowPosMining() +// .UseApi() +// .AddRPC(); +// }, this.mainchainNetwork, agent: "MainchainSidechainFunder2 "); + +// //join our nodes together and startup +// mainchain_SidechainFunder1.ConfigParameters.Add("addnode", $"127.0.0.1:{mainchain_SidechainFunder2.ProtocolPort}"); +// mainchain_SidechainFunder2.ConfigParameters.Add("addnode", $"127.0.0.1:{mainchain_SidechainFunder1.ProtocolPort}"); +// mainchain_SidechainFunder1.Start(); +// mainchain_SidechainFunder2.Start(); + +// await Task.Delay(5000); + +// //mine some strat mainchain coins +// string mainchainWallet = "mainchain_wallet"; +// mnemonic = await ApiCalls.Mnemonic(mainchain_SidechainFunder1.GetApiPort()); +// create_mnemonic = await ApiCalls.Create(mainchain_SidechainFunder1.GetApiPort(), mnemonic, mainchainWallet, +// mainchain_SidechainFunder1.FullNode.DataFolder.WalletPath); +// create_mnemonic.Should().Be(mnemonic); +// //our source address +// string addressMainchain = await ApiCalls.UnusedAddress(mainchain_SidechainFunder1.GetApiPort(), mainchainWallet); + +// //put some strat in the source address +// var powMinting = mainchain_SidechainFunder1.FullNode.NodeService(); +// var bitcoinAddress = new BitcoinPubKeyAddress(addressMainchain, Network.StratisRegTest); +// powMinting.GenerateBlocks(new ReserveScript(bitcoinAddress.ScriptPubKey), 50UL, int.MaxValue); + +// //sync our mainchain nodes +// await IntegrationTestUtils.WaitLoop(() => IntegrationTestUtils.AreNodesSynced(mainchain_SidechainFunder1, mainchain_SidechainFunder2)); + +// //check we have expected funds in our mainchain wallet +// var account_mainchain_funder1 = mainchain_SidechainFunder1.FullNode.WalletManager().GetAccounts("mainchain_wallet").First(); +// // amounts = account_mainchain_funder1.GetSpendableAmount(); +// // amounts.ConfirmedAmount.Should().Be(new Money(98000196, MoneyUnit.BTC)); + +// // Send Funds (Deposit from Mainchain to Sidechain) +// var sendingWalletAccountReference = new Bitcoin.Features.Wallet.WalletAccountReference("mainchain_wallet", "account 0"); + +// var transactionBuildContext = new WtTransactionBuildContext( +// sendingWalletAccountReference, +// new List() { new Recipient() { Amount = new Money(3600, MoneyUnit.BTC), ScriptPubKey = BitcoinAddress.Create(multiSigAddress_Mainchain, Network.StratisRegTest).ScriptPubKey } }, +// "1234", addressSidechain) +// { +// MinConfirmations = 1, +// TransactionFee = new Money(0.001m, MoneyUnit.BTC), +// Shuffle = true +// }; + +// // UCFund: The actor issues the command to Send the transaction and the wallet +// // confirms and broadcasts the transaction in the normal manner. +// var transaction = mainchain_SidechainFunder1.FullNode.WalletTransactionHandler().BuildTransaction(transactionBuildContext); +// mainchain_SidechainFunder1.FullNode.NodeService().SendTransaction(new SendTransactionRequest(transaction.ToHex())); + +// await Task.Delay(5000); + +// //sync our node to distrubute the mempool +// await IntegrationTestUtils.WaitLoop(() => IntegrationTestUtils.AreNodesSynced(mainchain_SidechainFunder1, mainchain_SidechainFunder2)); + +// await Task.Delay(5000); + +// // First we'll need to mine more blocks on the multi-sig so we can spend mature funds. +// var powMinting_Sidechain = sidechainNode_Member1_Wallet.FullNode.NodeService(); +// bitcoinAddress = new BitcoinPubKeyAddress(addressSidechain, ApexNetwork.RegTest); +// powMinting_Sidechain.GenerateBlocks(new ReserveScript(bitcoinAddress.ScriptPubKey), 50UL, int.MaxValue); + +// await IntegrationTestUtils.WaitLoop(() => IntegrationTestUtils.AreNodesSynced(sidechainNode_FunderRole, sidechainNode_Member1_Wallet)); + +// // +// // Act as a Federation Gateway (mainchain) +// // +// var mainchain_FederationGateway1 = nodeBuilder.CreateCustomNode(false, fullNodeBuilder => +// { +// fullNodeBuilder +// .UseBlockStore() +// .UsePosConsensus() +// .UseMempool() +// .UseWallet() +// .AddPowPosMining() +// .AddFederationGateway() +// // .UseGeneralPurposeWallet() +// .UseBlockNotification() +// .UseApi() +// .AddRPC(); +// }, this.mainchainNetwork, agent: "MainchainFederationGateway1 "); + +// string publickey = File.ReadAllText(Path.Combine(Directory.GetCurrentDirectory(), "Federations\\deposit_funds_to_sidechain\\member1\\PUBLIC_mainchain_member1.txt")); +// mainchain_FederationGateway1.ConfigParameters.Add("federationfolder", Path.Combine(Directory.GetCurrentDirectory(), "Federations\\deposit_funds_to_sidechain")); +// mainchain_FederationGateway1.ConfigParameters.Add("memberprivatefolder", Path.Combine(Directory.GetCurrentDirectory(), "Federations\\deposit_funds_to_sidechain\\member1")); +// mainchain_FederationGateway1.ConfigParameters.Add("publickey", publickey); +// mainchain_FederationGateway1.ConfigParameters.Add("membername", "member1"); +// mainchain_FederationGateway1.ConfigParameters.Add("multisigM", "2"); +// mainchain_FederationGateway1.ConfigParameters.Add("multisigN", "3"); + +// await Task.Delay(5000); + +// var mainchain_FederationGateway2 = nodeBuilder.CreateCustomNode(false, fullNodeBuilder => +// { +// fullNodeBuilder +// .UseBlockStore() +// .UsePosConsensus() +// .UseMempool() +// .UseWallet() +// .AddPowPosMining() +// .AddFederationGateway() +// // .UseGeneralPurposeWallet() +// .UseBlockNotification() +// .UseApi() +// .AddRPC(); +// }, this.mainchainNetwork, agent: "MainchainFederationGateway2 "); + +// publickey = File.ReadAllText(Path.Combine(Directory.GetCurrentDirectory(), "Federations\\deposit_funds_to_sidechain\\member2\\PUBLIC_mainchain_member2.txt")); +// mainchain_FederationGateway2.ConfigParameters.Add("federationfolder", Path.Combine(Directory.GetCurrentDirectory(), "Federations\\deposit_funds_to_sidechain")); +// mainchain_FederationGateway2.ConfigParameters.Add("memberprivatefolder", Path.Combine(Directory.GetCurrentDirectory(), "Federations\\deposit_funds_to_sidechain\\member2")); +// mainchain_FederationGateway2.ConfigParameters.Add("publickey", publickey); +// mainchain_FederationGateway2.ConfigParameters.Add("membername", "member2"); +// mainchain_FederationGateway2.ConfigParameters.Add("multisigM", "2"); +// mainchain_FederationGateway2.ConfigParameters.Add("multisigN", "3"); + +// await Task.Delay(5000); + +// var mainchain_FederationGateway3 = nodeBuilder.CreateCustomNode(false, fullNodeBuilder => +// { +// fullNodeBuilder +// .UseBlockStore() +// .UsePosConsensus() +// .UseMempool() +// .UseWallet() +// .AddPowPosMining() +// .AddFederationGateway() +// // .UseGeneralPurposeWallet() +// .UseBlockNotification() +// .UseApi() +// .AddRPC(); +// }, this.mainchainNetwork, agent: "MainchainFederationGateway3 "); + +// publickey = File.ReadAllText(Path.Combine(Directory.GetCurrentDirectory(), "Federations\\deposit_funds_to_sidechain\\member3\\PUBLIC_mainchain_member3.txt")); +// mainchain_FederationGateway3.ConfigParameters.Add("federationfolder", Path.Combine(Directory.GetCurrentDirectory(), "Federations\\deposit_funds_to_sidechain")); +// mainchain_FederationGateway3.ConfigParameters.Add("memberprivatefolder", Path.Combine(Directory.GetCurrentDirectory(), "Federations\\deposit_funds_to_sidechain\\member3")); +// mainchain_FederationGateway3.ConfigParameters.Add("publickey", publickey); +// mainchain_FederationGateway3.ConfigParameters.Add("membername", "member3"); +// mainchain_FederationGateway3.ConfigParameters.Add("multisigM", "2"); +// mainchain_FederationGateway3.ConfigParameters.Add("multisigN", "3"); + +// await Task.Delay(5000); + +// // +// // Act as a Federation Gateway (sidechain) +// // +// var sidechain_FederationGateway1 = nodeBuilder.CreateCustomNode(false, fullNodeBuilder => +// { +// fullNodeBuilder +// .UseBlockStore() +// .UsePosConsensus() +// .UseMempool() +// .UseWallet() +// .AddPowPosMining() +// .AddFederationGateway() +// // .UseGeneralPurposeWallet() +// .UseBlockNotification() +// .UseApi() +// .AddRPC(); +// }, +// this.sidechainNetwork, +// agent: "SidechainFederationGateway1 " +// ); + +// publickey = File.ReadAllText(Path.Combine(Directory.GetCurrentDirectory(), "Federations\\deposit_funds_to_sidechain\\member1\\PUBLIC_sidechain_member1.txt")); +// sidechain_FederationGateway1.ConfigParameters.Add("federationfolder", Path.Combine(Directory.GetCurrentDirectory(), "Federations\\deposit_funds_to_sidechain")); +// sidechain_FederationGateway1.ConfigParameters.Add("memberprivatefolder", Path.Combine(Directory.GetCurrentDirectory(), "Federations\\deposit_funds_to_sidechain\\member1")); +// sidechain_FederationGateway1.ConfigParameters.Add("publickey", publickey); +// sidechain_FederationGateway1.ConfigParameters.Add("membername", "member1"); +// sidechain_FederationGateway1.ConfigParameters.Add("multisigM", "2"); +// sidechain_FederationGateway1.ConfigParameters.Add("multisigN", "3"); + +// await Task.Delay(5000); + +// var sidechain_FederationGateway2 = nodeBuilder.CreateCustomNode(false, fullNodeBuilder => +// { +// fullNodeBuilder +// .UseBlockStore() +// .UsePosConsensus() +// .UseMempool() +// .UseWallet() +// .AddPowPosMining() +// .AddFederationGateway() +// // .UseGeneralPurposeWallet() +// .UseBlockNotification() +// .UseApi() +// .AddRPC(); +// }, this.sidechainNetwork, +// agent: "SidechainFederationGateway2 " +// ); + +// publickey = File.ReadAllText(Path.Combine(Directory.GetCurrentDirectory(), "Federations\\deposit_funds_to_sidechain\\member2\\PUBLIC_sidechain_member2.txt")); +// sidechain_FederationGateway2.ConfigParameters.Add("federationfolder", Path.Combine(Directory.GetCurrentDirectory(), "Federations\\deposit_funds_to_sidechain")); +// sidechain_FederationGateway2.ConfigParameters.Add("memberprivatefolder", Path.Combine(Directory.GetCurrentDirectory(), "Federations\\deposit_funds_to_sidechain\\member2")); +// sidechain_FederationGateway2.ConfigParameters.Add("publickey", publickey); +// sidechain_FederationGateway2.ConfigParameters.Add("membername", "member2"); +// sidechain_FederationGateway2.ConfigParameters.Add("multisigM", "2"); +// sidechain_FederationGateway2.ConfigParameters.Add("multisigN", "3"); + +// await Task.Delay(5000); + +// var sidechain_FederationGateway3 = nodeBuilder.CreateCustomNode(false, fullNodeBuilder => +// { +// fullNodeBuilder +// .UseBlockStore() +// .UsePosConsensus() +// .UseMempool() +// .UseWallet() +// .AddPowPosMining() +// .AddFederationGateway() +// // .UseGeneralPurposeWallet() +// .UseBlockNotification() +// .UseApi() +// .AddRPC(); +// }, this.sidechainNetwork, agent: "SidechainFederationGateway3 "); + +// publickey = File.ReadAllText(Path.Combine(Directory.GetCurrentDirectory(), "Federations\\deposit_funds_to_sidechain\\member3\\PUBLIC_sidechain_member3.txt")); +// sidechain_FederationGateway3.ConfigParameters.Add("federationfolder", Path.Combine(Directory.GetCurrentDirectory(), "Federations\\deposit_funds_to_sidechain")); +// sidechain_FederationGateway3.ConfigParameters.Add("memberprivatefolder", Path.Combine(Directory.GetCurrentDirectory(), "Federations\\deposit_funds_to_sidechain\\member3")); +// sidechain_FederationGateway3.ConfigParameters.Add("publickey", publickey); +// sidechain_FederationGateway3.ConfigParameters.Add("membername", "member3"); +// sidechain_FederationGateway3.ConfigParameters.Add("multisigM", "2"); +// sidechain_FederationGateway3.ConfigParameters.Add("multisigN", "3"); + +// //link the mainchain and sidechain nodes together +// mainchain_FederationGateway1.ConfigParameters.Add("counterchainapiport", sidechain_FederationGateway1.GetApiPort().ToString()); +// mainchain_FederationGateway2.ConfigParameters.Add("counterchainapiport", sidechain_FederationGateway2.GetApiPort().ToString()); +// mainchain_FederationGateway3.ConfigParameters.Add("counterchainapiport", sidechain_FederationGateway3.GetApiPort().ToString()); +// sidechain_FederationGateway1.ConfigParameters.Add("counterchainapiport", mainchain_FederationGateway1.GetApiPort().ToString()); +// sidechain_FederationGateway2.ConfigParameters.Add("counterchainapiport", mainchain_FederationGateway2.GetApiPort().ToString()); +// sidechain_FederationGateway3.ConfigParameters.Add("counterchainapiport", mainchain_FederationGateway3.GetApiPort().ToString()); + +// await Task.Delay(5000); + +// //start mainchain and sidechain +// mainchain_FederationGateway1.Start(); +// mainchain_FederationGateway2.Start(); +// mainchain_FederationGateway3.Start(); + +// //give nodes a chance to start +// await Task.Delay(60000); + +// sidechain_FederationGateway1.Start(); +// sidechain_FederationGateway2.Start(); +// sidechain_FederationGateway3.Start(); + +// //give nodes a chance to start +// await Task.Delay(60000); + +// //add mainchain nodes +// var rpcClient1 = mainchain_FederationGateway1.CreateRPCClient(); +// rpcClient1.AddNode(mainchain_SidechainFunder1.Endpoint); +// await Task.Delay(addNodeDelay); +// rpcClient1.AddNode(mainchain_SidechainFunder2.Endpoint); +// await Task.Delay(addNodeDelay); +// rpcClient1.AddNode(mainchain_FederationGateway2.Endpoint); +// await Task.Delay(addNodeDelay); +// rpcClient1.AddNode(mainchain_FederationGateway3.Endpoint); +// await Task.Delay(addNodeDelay); + +// var rpcClient2 = mainchain_FederationGateway2.CreateRPCClient(); +// rpcClient2.AddNode(mainchain_SidechainFunder1.Endpoint); +// await Task.Delay(addNodeDelay); +// rpcClient2.AddNode(mainchain_SidechainFunder2.Endpoint); +// await Task.Delay(addNodeDelay); +// rpcClient2.AddNode(mainchain_FederationGateway1.Endpoint); +// await Task.Delay(addNodeDelay); +// rpcClient2.AddNode(mainchain_FederationGateway3.Endpoint); +// await Task.Delay(addNodeDelay); + +// var rpcClient3 = mainchain_FederationGateway3.CreateRPCClient(); +// rpcClient3.AddNode(mainchain_SidechainFunder1.Endpoint); +// await Task.Delay(addNodeDelay); +// rpcClient3.AddNode(mainchain_SidechainFunder2.Endpoint); +// await Task.Delay(addNodeDelay); +// rpcClient3.AddNode(mainchain_FederationGateway1.Endpoint); +// await Task.Delay(addNodeDelay); +// rpcClient3.AddNode(mainchain_FederationGateway2.Endpoint); +// await Task.Delay(addNodeDelay); + +// //add sidechain nodes +// var rpcSidechainClient1 = sidechain_FederationGateway1.CreateRPCClient(); +// rpcSidechainClient1.AddNode(sidechainNode_FunderRole.Endpoint); +// await Task.Delay(addNodeDelay); +// rpcSidechainClient1.AddNode(sidechain_FederationGateway2.Endpoint); +// await Task.Delay(addNodeDelay); +// rpcSidechainClient1.AddNode(sidechain_FederationGateway3.Endpoint); +// await Task.Delay(addNodeDelay); + +// var rpcSidechainClient2 = sidechain_FederationGateway2.CreateRPCClient(); +// rpcSidechainClient2.AddNode(sidechainNode_FunderRole.Endpoint); +// await Task.Delay(addNodeDelay); +// rpcSidechainClient2.AddNode(sidechain_FederationGateway1.Endpoint); +// await Task.Delay(addNodeDelay); +// rpcSidechainClient2.AddNode(sidechain_FederationGateway3.Endpoint); +// await Task.Delay(addNodeDelay); + +// var rpcSidechainClient3 = sidechain_FederationGateway3.CreateRPCClient(); +// rpcSidechainClient3.AddNode(sidechainNode_FunderRole.Endpoint); +// await Task.Delay(addNodeDelay); +// rpcSidechainClient3.AddNode(sidechain_FederationGateway1.Endpoint); +// await Task.Delay(addNodeDelay); +// rpcSidechainClient3.AddNode(sidechain_FederationGateway2.Endpoint); +// await Task.Delay(addNodeDelay); + +// IntegrationTestUtils.AreConnected(sidechain_FederationGateway1, sidechain_FederationGateway2).Should().BeTrue(); +// IntegrationTestUtils.AreConnected(sidechain_FederationGateway1, sidechain_FederationGateway3).Should().BeTrue(); +// IntegrationTestUtils.AreConnected(sidechain_FederationGateway2, sidechain_FederationGateway1).Should().BeTrue(); +// IntegrationTestUtils.AreConnected(sidechain_FederationGateway2, sidechain_FederationGateway3).Should().BeTrue(); +// IntegrationTestUtils.AreConnected(sidechain_FederationGateway3, sidechain_FederationGateway1).Should().BeTrue(); +// IntegrationTestUtils.AreConnected(sidechain_FederationGateway3, sidechain_FederationGateway2).Should().BeTrue(); +// IntegrationTestUtils.AreConnected(sidechain_FederationGateway1, sidechainNode_FunderRole).Should().BeTrue(); +// IntegrationTestUtils.AreConnected(sidechain_FederationGateway2, sidechainNode_FunderRole).Should().BeTrue(); +// IntegrationTestUtils.AreConnected(sidechain_FederationGateway3, sidechainNode_FunderRole).Should().BeTrue(); + +// IntegrationTestUtils.AreConnected(mainchain_FederationGateway1, mainchain_FederationGateway2).Should().BeTrue(); +// IntegrationTestUtils.AreConnected(mainchain_FederationGateway1, mainchain_FederationGateway3).Should().BeTrue(); +// IntegrationTestUtils.AreConnected(mainchain_FederationGateway2, mainchain_FederationGateway1).Should().BeTrue(); +// IntegrationTestUtils.AreConnected(mainchain_FederationGateway2, mainchain_FederationGateway3).Should().BeTrue(); +// IntegrationTestUtils.AreConnected(mainchain_FederationGateway3, mainchain_FederationGateway1).Should().BeTrue(); +// IntegrationTestUtils.AreConnected(mainchain_FederationGateway3, mainchain_FederationGateway2).Should().BeTrue(); + +// //create wallets on the sidechains +// //sidechain_FederationGateway1 +// await ApiCalls.CreateFederationWallet(sidechain_FederationGateway1.GetApiPort(), "multisig_wallet", "password"); +// //var account_fed_member1_sidechain = fedFolder.ImportPrivateKeyToWallet(sidechain_FederationGateway1, "multisig_wallet", "password", "member1", "pass1", 2, 3, ApexNetwork.RegTest); + +// //sidechain_FederationGateway2 +// await ApiCalls.CreateFederationWallet(sidechain_FederationGateway2.GetApiPort(), "multisig_wallet", "password"); +// //var account_fed_member2_sidechain = fedFolder.ImportPrivateKeyToWallet(sidechain_FederationGateway2, "multisig_wallet", "password", "member2", "pass2", 2, 3, ApexNetwork.RegTest); + +// //sidechain_FederationGateway3 +// await ApiCalls.CreateFederationWallet(sidechain_FederationGateway3.GetApiPort(), "multisig_wallet", "password"); +// // var account_fed_member3_sidechain = fedFolder.ImportPrivateKeyToWallet(sidechain_FederationGateway3, "multisig_wallet", "password", "member3", "pass3", 2, 3, ApexNetwork.RegTest); + +// await Task.Delay(5000); + +// await IntegrationTestUtils.WaitLoop(() => IntegrationTestUtils.AreNodesSynced(sidechain_FederationGateway1, sidechainNode_Member1_Wallet)); +// await IntegrationTestUtils.WaitLoop(() => IntegrationTestUtils.AreNodesSynced(sidechain_FederationGateway2, sidechainNode_Member1_Wallet)); +// await IntegrationTestUtils.WaitLoop(() => IntegrationTestUtils.AreNodesSynced(sidechain_FederationGateway3, sidechainNode_Member1_Wallet)); + +// IntegrationTestUtils.ResyncGeneralWallet(sidechain_FederationGateway1); +// IntegrationTestUtils.ResyncGeneralWallet(sidechain_FederationGateway2); +// IntegrationTestUtils.ResyncGeneralWallet(sidechain_FederationGateway3); + +// await IntegrationTestUtils.WaitLoop(() => IntegrationTestUtils.IsGeneralWalletSyncedToHeight(sidechain_FederationGateway1, 53)); +// await IntegrationTestUtils.WaitLoop(() => IntegrationTestUtils.IsGeneralWalletSyncedToHeight(sidechain_FederationGateway2, 53)); +// await IntegrationTestUtils.WaitLoop(() => IntegrationTestUtils.IsGeneralWalletSyncedToHeight(sidechain_FederationGateway3, 53)); + +// bitcoinAddress = new BitcoinPubKeyAddress(addressSidechain, ApexNetwork.RegTest); +// powMinting_Sidechain.GenerateBlocks(new ReserveScript(bitcoinAddress.ScriptPubKey), 1UL, int.MaxValue); + +// await IntegrationTestUtils.WaitLoop(() => IntegrationTestUtils.AreNodesSynced(sidechain_FederationGateway1, sidechainNode_Member1_Wallet)); +// await IntegrationTestUtils.WaitLoop(() => IntegrationTestUtils.AreNodesSynced(sidechain_FederationGateway2, sidechainNode_Member1_Wallet)); +// await IntegrationTestUtils.WaitLoop(() => IntegrationTestUtils.AreNodesSynced(sidechain_FederationGateway3, sidechainNode_Member1_Wallet)); + +// await IntegrationTestUtils.WaitLoop(() => IntegrationTestUtils.IsGeneralWalletSyncedToHeight(sidechain_FederationGateway1, 54)); +// await IntegrationTestUtils.WaitLoop(() => IntegrationTestUtils.IsGeneralWalletSyncedToHeight(sidechain_FederationGateway2, 54)); +// await IntegrationTestUtils.WaitLoop(() => IntegrationTestUtils.IsGeneralWalletSyncedToHeight(sidechain_FederationGateway3, 54)); + +// IntegrationTestUtils.SaveGeneralWallet(sidechain_FederationGateway1, "multisig_wallet"); +// IntegrationTestUtils.SaveGeneralWallet(sidechain_FederationGateway2, "multisig_wallet"); +// IntegrationTestUtils.SaveGeneralWallet(sidechain_FederationGateway3, "multisig_wallet"); + +// //check we have the correct balance in the multisigs +// //amounts = account_fed_member1_sidechain.GetSpendableAmount(true); +// //amounts.ConfirmedAmount.Should().Be(new Money(98000008, MoneyUnit.BTC)); + +// //amounts = account_fed_member2_sidechain.GetSpendableAmount(true); +// //amounts.ConfirmedAmount.Should().Be(new Money(98000008, MoneyUnit.BTC)); + +// //amounts = account_fed_member3_sidechain.GetSpendableAmount(true); +// //amounts.ConfirmedAmount.Should().Be(new Money(98000008, MoneyUnit.BTC)); + + +// //create wallets on the mainchains +// //mainchain_FederationGateway1 +// await ApiCalls.CreateFederationWallet(mainchain_FederationGateway1.GetApiPort(), "multisig_wallet", "password"); +// // var account_fed_member1_mainchain = fedFolder.ImportPrivateKeyToWallet(mainchain_FederationGateway1, "multisig_wallet", "password", "member1", "pass1", 2, 3, Network.StratisRegTest); + +// //mainchain_FederationGateway2 +// await ApiCalls.CreateFederationWallet(mainchain_FederationGateway2.GetApiPort(), "multisig_wallet", "password"); +// // var account_fed_member2_mainchain = fedFolder.ImportPrivateKeyToWallet(mainchain_FederationGateway2, "multisig_wallet", "password", "member2", "pass2", 2, 3, Network.StratisRegTest); + +// //mainchain_FederationGateway3 +// await ApiCalls.CreateFederationWallet(mainchain_FederationGateway3.GetApiPort(), "multisig_wallet", "password"); +// // var account_fed_member3_mainchain = fedFolder.ImportPrivateKeyToWallet(mainchain_FederationGateway3, "multisig_wallet", "password", "member3", "pass3", 2, 3, Network.StratisRegTest); + +// //generate a block to include our transaction +// bitcoinAddress = new BitcoinPubKeyAddress(addressMainchain, Network.StratisRegTest); +// powMinting.GenerateBlocks(new ReserveScript(bitcoinAddress.ScriptPubKey), 1UL, int.MaxValue); + +// await Task.Delay(35000); + +// await IntegrationTestUtils.WaitLoop(() => IntegrationTestUtils.AreNodesSynced(sidechain_FederationGateway1, sidechainNode_Member1_Wallet)); +// await IntegrationTestUtils.WaitLoop(() => IntegrationTestUtils.AreNodesSynced(sidechain_FederationGateway2, sidechainNode_Member1_Wallet)); +// await IntegrationTestUtils.WaitLoop(() => IntegrationTestUtils.AreNodesSynced(sidechain_FederationGateway3, sidechainNode_Member1_Wallet)); + +// IntegrationTestUtils.ResyncGeneralWallet(sidechain_FederationGateway1); +// IntegrationTestUtils.ResyncGeneralWallet(sidechain_FederationGateway2); +// IntegrationTestUtils.ResyncGeneralWallet(sidechain_FederationGateway3); + +// await IntegrationTestUtils.WaitLoop(() => IntegrationTestUtils.IsGeneralWalletSyncedToHeight(sidechain_FederationGateway1, 54)); +// await IntegrationTestUtils.WaitLoop(() => IntegrationTestUtils.IsGeneralWalletSyncedToHeight(sidechain_FederationGateway2, 54)); +// await IntegrationTestUtils.WaitLoop(() => IntegrationTestUtils.IsGeneralWalletSyncedToHeight(sidechain_FederationGateway3, 54)); + +// bitcoinAddress = new BitcoinPubKeyAddress(addressSidechain, ApexNetwork.RegTest); +// powMinting_Sidechain.GenerateBlocks(new ReserveScript(bitcoinAddress.ScriptPubKey), 1UL, int.MaxValue); + +// await IntegrationTestUtils.WaitLoop(() => IntegrationTestUtils.AreNodesSynced(sidechain_FederationGateway1, sidechainNode_Member1_Wallet)); +// await IntegrationTestUtils.WaitLoop(() => IntegrationTestUtils.AreNodesSynced(sidechain_FederationGateway2, sidechainNode_Member1_Wallet)); +// await IntegrationTestUtils.WaitLoop(() => IntegrationTestUtils.AreNodesSynced(sidechain_FederationGateway3, sidechainNode_Member1_Wallet)); + +// await IntegrationTestUtils.WaitLoop(() => IntegrationTestUtils.IsGeneralWalletSyncedToHeight(sidechain_FederationGateway1, 55)); +// await IntegrationTestUtils.WaitLoop(() => IntegrationTestUtils.IsGeneralWalletSyncedToHeight(sidechain_FederationGateway2, 55)); +// await IntegrationTestUtils.WaitLoop(() => IntegrationTestUtils.IsGeneralWalletSyncedToHeight(sidechain_FederationGateway3, 55)); + +// IntegrationTestUtils.SaveGeneralWallet(sidechain_FederationGateway1, "multisig_wallet"); +// IntegrationTestUtils.SaveGeneralWallet(sidechain_FederationGateway2, "multisig_wallet"); +// IntegrationTestUtils.SaveGeneralWallet(sidechain_FederationGateway3, "multisig_wallet"); - //check the mainchain multi-sig has the sent funds locked. - // amounts = account_fed_member1_mainchain.GetSpendableAmount(true); - // amounts.ConfirmedAmount.Should().Be(new Money(3600, MoneyUnit.BTC)); +// //check the mainchain multi-sig has the sent funds locked. +// // amounts = account_fed_member1_mainchain.GetSpendableAmount(true); +// // amounts.ConfirmedAmount.Should().Be(new Money(3600, MoneyUnit.BTC)); - await Task.Delay(35000); +// await Task.Delay(35000); - //97996407.99000000 (98,000,008 - 3600 - 0.01 fee) - //check the sidechain multi-sig has sent funds out of the multisig. - //amounts = account_fed_member1_sidechain.GetSpendableAmount(true); - //amounts.ConfirmedAmount.Should().Be(new Money(98000008 - 3600 - 0.01m, MoneyUnit.BTC)); - - //3804.001 (3600, 204 mining plus 0.01 transaction fee.) - //check thos funds were received by the sidechain destination address - var account_sidechain_funder = sidechainNode_Member1_Wallet.FullNode.WalletManager().GetAccounts("sidechain_wallet").First(); - //amounts = account_sidechain_funder.GetSpendableAmount(); - //amounts.ConfirmedAmount.Should().Be(new Money(3600 + 208 + 0.01m, MoneyUnit.BTC)); - - // Now use the newly arrived funds to create a withdrawal transaction. - - // Withdraw Funds (Withdraw from Sidechain to Mainchain) - sendingWalletAccountReference = new Bitcoin.Features.Wallet.WalletAccountReference("sidechain_wallet", "account 0"); - - transactionBuildContext = new WtTransactionBuildContext( - sendingWalletAccountReference, - new List() { new Recipient() { Amount = new Money(2500, MoneyUnit.BTC), ScriptPubKey = BitcoinAddress.Create(multiSigAddress_Sidechain, ApexNetwork.RegTest).ScriptPubKey } }, - "1234", addressMainchain) - { - MinConfirmations = 1, - TransactionFee = new Money(0.001m, MoneyUnit.BTC), - Shuffle = true - }; - transaction = sidechainNode_Member1_Wallet.FullNode.WalletTransactionHandler().BuildTransaction(transactionBuildContext); - sidechainNode_Member1_Wallet.FullNode.NodeService().SendTransaction(new SendTransactionRequest(transaction.ToHex())); - - //sync our node to distrubute the mempool - await IntegrationTestUtils.WaitLoop(() => IntegrationTestUtils.AreNodesSynced(sidechainNode_FunderRole, sidechainNode_Member1_Wallet)); - - //generate a block to include our transaction - bitcoinAddress = new BitcoinPubKeyAddress(addressSidechain, ApexNetwork.RegTest); - powMinting_Sidechain.GenerateBlocks(new ReserveScript(bitcoinAddress.ScriptPubKey), 1UL, int.MaxValue); - - await IntegrationTestUtils.WaitLoop(() => IntegrationTestUtils.AreNodesSynced(sidechain_FederationGateway1, sidechainNode_Member1_Wallet)); - await IntegrationTestUtils.WaitLoop(() => IntegrationTestUtils.AreNodesSynced(sidechain_FederationGateway2, sidechainNode_Member1_Wallet)); - await IntegrationTestUtils.WaitLoop(() => IntegrationTestUtils.AreNodesSynced(sidechain_FederationGateway3, sidechainNode_Member1_Wallet)); - - await IntegrationTestUtils.WaitLoop(() => IntegrationTestUtils.IsGeneralWalletSyncedToHeight(sidechain_FederationGateway1, 56)); - await IntegrationTestUtils.WaitLoop(() => IntegrationTestUtils.IsGeneralWalletSyncedToHeight(sidechain_FederationGateway2, 56)); - await IntegrationTestUtils.WaitLoop(() => IntegrationTestUtils.IsGeneralWalletSyncedToHeight(sidechain_FederationGateway3, 56)); - - IntegrationTestUtils.SaveGeneralWallet(sidechain_FederationGateway1, "multisig_wallet"); - IntegrationTestUtils.SaveGeneralWallet(sidechain_FederationGateway2, "multisig_wallet"); - IntegrationTestUtils.SaveGeneralWallet(sidechain_FederationGateway3, "multisig_wallet"); - - await Task.Delay(35000); - - //mine a block on mainchain - bitcoinAddress = new BitcoinPubKeyAddress(addressMainchain, Network.StratisRegTest); - powMinting.GenerateBlocks(new ReserveScript(bitcoinAddress.ScriptPubKey), 1UL, int.MaxValue); - - await IntegrationTestUtils.WaitLoop(() => IntegrationTestUtils.AreNodesSynced(mainchain_FederationGateway1, mainchain_SidechainFunder1)); - await IntegrationTestUtils.WaitLoop(() => IntegrationTestUtils.AreNodesSynced(mainchain_FederationGateway2, mainchain_SidechainFunder1)); - await IntegrationTestUtils.WaitLoop(() => IntegrationTestUtils.AreNodesSynced(mainchain_FederationGateway3, mainchain_SidechainFunder1)); - - await IntegrationTestUtils.WaitLoop(() => IntegrationTestUtils.IsGeneralWalletSyncedToHeight(mainchain_FederationGateway1, 52)); - await IntegrationTestUtils.WaitLoop(() => IntegrationTestUtils.IsGeneralWalletSyncedToHeight(mainchain_FederationGateway2, 52)); - await IntegrationTestUtils.WaitLoop(() => IntegrationTestUtils.IsGeneralWalletSyncedToHeight(mainchain_FederationGateway3, 52)); - - IntegrationTestUtils.SaveGeneralWallet(mainchain_FederationGateway1, "multisig_wallet"); - IntegrationTestUtils.SaveGeneralWallet(mainchain_FederationGateway2, "multisig_wallet"); - IntegrationTestUtils.SaveGeneralWallet(mainchain_FederationGateway3, "multisig_wallet"); - - /// was 60000 - await Task.Delay(35000); - - //3804.001 (3600, 204 mining plus 0.01 transaction fee.) - //check thos funds were received by the sidechain destination address - //account_sidechain_funder = sidechainNode_Member1_Wallet.FullNode.WalletManager().GetAccounts("sidechain_wallet").First(); - //amounts = account_sidechain_funder.GetSpendableAmount(); - //var confirmedAmountDestinationSidechainAfterWithdrawal = amounts.ConfirmedAmount.ToString(); - //amounts.ConfirmedAmount.Should().Be(new Money(3812.01m - 2500, MoneyUnit.BTC)); - - ////97996407.99000000 (98,000,008 - 3600 - 0.01 fee) - ////check the sidechain multi-sig has locked up the withdrawing funds. - //amounts = account_fed_member1_sidechain.GetSpendableAmount(true); - //var confirmedAmountMultiSigOnSidechain2 = amounts.ConfirmedAmount.ToString(); - //amounts.ConfirmedAmount.Should().Be(new Money(97996407.99m + 2500, MoneyUnit.BTC)); - - ////"1099.99000000" - ////confirm the mainchain multi-sig has released the locked funds for withdrawal. - //amounts = account_fed_member1_mainchain.GetSpendableAmount(true); - //var confirmedAmountLockedOnMainchain2 = amounts.ConfirmedAmount.ToString(); - //amounts.ConfirmedAmount.Should().Be(new Money(3600 - 2500 - 0.01m, MoneyUnit.BTC)); - - ////97999104.01000000 - ////and confirm the destination has received the withdawal - //var account_mainchain_funder = mainchain_SidechainFunder1.FullNode.WalletManager().GetAccounts("mainchain_wallet").First(); - //amounts = account_mainchain_funder.GetSpendableAmount(); - //var confirmedAmountDestinationMainchain = amounts.ConfirmedAmount.ToString(); - //amounts.ConfirmedAmount.Should().Be(new Money(98000204 - 3600 + 2500 + 0.01m, MoneyUnit.BTC)); - - //now kill the member three nodes - mainchain_FederationGateway3.Kill(); - sidechain_FederationGateway3.Kill(); - - //time to die - await Task.Delay(5000); - - //create a new node three - var mainchain_FederationGateway3v2 = nodeBuilder.CreateCustomNode(false, fullNodeBuilder => - { - fullNodeBuilder - .UseBlockStore() - .UsePosConsensus() - .UseMempool() - .UseWallet() - .AddPowPosMining() - .AddFederationGateway() - .UseBlockNotification() - .UseApi() - .AddRPC(); - }, ApexNetwork.RegTest, agent: "MainchainFederationGateway3v2 "); - - publickey = File.ReadAllText(Path.Combine(Directory.GetCurrentDirectory(), "Federations\\deposit_funds_to_sidechain\\member3\\PUBLIC_mainchain_member3.txt")); - mainchain_FederationGateway3v2.ConfigParameters.Add("federationfolder", Path.Combine(Directory.GetCurrentDirectory(), "Federations\\deposit_funds_to_sidechain")); - mainchain_FederationGateway3v2.ConfigParameters.Add("memberprivatefolder", Path.Combine(Directory.GetCurrentDirectory(), "Federations\\deposit_funds_to_sidechain\\member3")); - mainchain_FederationGateway3v2.ConfigParameters.Add("publickey", publickey); - mainchain_FederationGateway3v2.ConfigParameters.Add("membername", "member3v2"); - mainchain_FederationGateway3v2.ConfigParameters.Add("multisigM", "2"); - mainchain_FederationGateway3v2.ConfigParameters.Add("multisigN", "3"); - - // change the fed3 sidechain api port - sidechain_FederationGateway3.ConfigParameters.AddOrReplace("counterchainapiport", mainchain_FederationGateway3v2.GetApiPort().ToString()); - mainchain_FederationGateway3v2.ConfigParameters.Add("counterchainapiport", sidechain_FederationGateway3.GetApiPort().ToString()); - - await Task.Delay(1000); - - //connect the nodes - mainchain_FederationGateway3v2.Start(); - sidechain_FederationGateway3.Start(); - - //give the node time to start - await Task.Delay(15000); - - //add mainchain nodes - rpcClient1 = mainchain_FederationGateway1.CreateRPCClient(); - rpcClient1.AddNode(mainchain_FederationGateway3v2.Endpoint); - await Task.Delay(addNodeDelay); - - rpcClient2 = mainchain_FederationGateway2.CreateRPCClient(); - rpcClient2.AddNode(mainchain_FederationGateway3v2.Endpoint); - await Task.Delay(addNodeDelay); - - rpcClient3 = mainchain_FederationGateway3v2.CreateRPCClient(); - await Task.Delay(addNodeDelay); - rpcClient3.AddNode(mainchain_SidechainFunder2.Endpoint); - await Task.Delay(addNodeDelay); - rpcClient3.AddNode(mainchain_FederationGateway1.Endpoint); - await Task.Delay(addNodeDelay); - rpcClient3.AddNode(mainchain_FederationGateway2.Endpoint); - await Task.Delay(addNodeDelay); - - // Check our network is still intact. - //IntegrationTestUtils.AreConnected(mainchain_FederationGateway1, mainchain_FederationGateway2).Should().BeTrue(); - //IntegrationTestUtils.AreConnected(mainchain_FederationGateway1, mainchain_FederationGateway3v2).Should().BeTrue(); - //IntegrationTestUtils.AreConnected(mainchain_FederationGateway2, mainchain_FederationGateway1).Should().BeTrue(); - //IntegrationTestUtils.AreConnected(mainchain_FederationGateway2, mainchain_FederationGateway3v2).Should().BeTrue(); - //IntegrationTestUtils.AreConnected(mainchain_FederationGateway3v2, mainchain_FederationGateway1).Should().BeTrue(); - //IntegrationTestUtils.AreConnected(mainchain_FederationGateway3v2, mainchain_FederationGateway2).Should().BeTrue(); - - await Task.Delay(90000); - } - } - } -} \ No newline at end of file +// //97996407.99000000 (98,000,008 - 3600 - 0.01 fee) +// //check the sidechain multi-sig has sent funds out of the multisig. +// //amounts = account_fed_member1_sidechain.GetSpendableAmount(true); +// //amounts.ConfirmedAmount.Should().Be(new Money(98000008 - 3600 - 0.01m, MoneyUnit.BTC)); + +// //3804.001 (3600, 204 mining plus 0.01 transaction fee.) +// //check thos funds were received by the sidechain destination address +// var account_sidechain_funder = sidechainNode_Member1_Wallet.FullNode.WalletManager().GetAccounts("sidechain_wallet").First(); +// //amounts = account_sidechain_funder.GetSpendableAmount(); +// //amounts.ConfirmedAmount.Should().Be(new Money(3600 + 208 + 0.01m, MoneyUnit.BTC)); + +// // Now use the newly arrived funds to create a withdrawal transaction. + +// // Withdraw Funds (Withdraw from Sidechain to Mainchain) +// sendingWalletAccountReference = new Bitcoin.Features.Wallet.WalletAccountReference("sidechain_wallet", "account 0"); + +// transactionBuildContext = new WtTransactionBuildContext( +// sendingWalletAccountReference, +// new List() { new Recipient() { Amount = new Money(2500, MoneyUnit.BTC), ScriptPubKey = BitcoinAddress.Create(multiSigAddress_Sidechain, ApexNetwork.RegTest).ScriptPubKey } }, +// "1234", addressMainchain) +// { +// MinConfirmations = 1, +// TransactionFee = new Money(0.001m, MoneyUnit.BTC), +// Shuffle = true +// }; +// transaction = sidechainNode_Member1_Wallet.FullNode.WalletTransactionHandler().BuildTransaction(transactionBuildContext); +// sidechainNode_Member1_Wallet.FullNode.NodeService().SendTransaction(new SendTransactionRequest(transaction.ToHex())); + +// //sync our node to distrubute the mempool +// await IntegrationTestUtils.WaitLoop(() => IntegrationTestUtils.AreNodesSynced(sidechainNode_FunderRole, sidechainNode_Member1_Wallet)); + +// //generate a block to include our transaction +// bitcoinAddress = new BitcoinPubKeyAddress(addressSidechain, ApexNetwork.RegTest); +// powMinting_Sidechain.GenerateBlocks(new ReserveScript(bitcoinAddress.ScriptPubKey), 1UL, int.MaxValue); + +// await IntegrationTestUtils.WaitLoop(() => IntegrationTestUtils.AreNodesSynced(sidechain_FederationGateway1, sidechainNode_Member1_Wallet)); +// await IntegrationTestUtils.WaitLoop(() => IntegrationTestUtils.AreNodesSynced(sidechain_FederationGateway2, sidechainNode_Member1_Wallet)); +// await IntegrationTestUtils.WaitLoop(() => IntegrationTestUtils.AreNodesSynced(sidechain_FederationGateway3, sidechainNode_Member1_Wallet)); + +// await IntegrationTestUtils.WaitLoop(() => IntegrationTestUtils.IsGeneralWalletSyncedToHeight(sidechain_FederationGateway1, 56)); +// await IntegrationTestUtils.WaitLoop(() => IntegrationTestUtils.IsGeneralWalletSyncedToHeight(sidechain_FederationGateway2, 56)); +// await IntegrationTestUtils.WaitLoop(() => IntegrationTestUtils.IsGeneralWalletSyncedToHeight(sidechain_FederationGateway3, 56)); + +// IntegrationTestUtils.SaveGeneralWallet(sidechain_FederationGateway1, "multisig_wallet"); +// IntegrationTestUtils.SaveGeneralWallet(sidechain_FederationGateway2, "multisig_wallet"); +// IntegrationTestUtils.SaveGeneralWallet(sidechain_FederationGateway3, "multisig_wallet"); + +// await Task.Delay(35000); + +// //mine a block on mainchain +// bitcoinAddress = new BitcoinPubKeyAddress(addressMainchain, Network.StratisRegTest); +// powMinting.GenerateBlocks(new ReserveScript(bitcoinAddress.ScriptPubKey), 1UL, int.MaxValue); + +// await IntegrationTestUtils.WaitLoop(() => IntegrationTestUtils.AreNodesSynced(mainchain_FederationGateway1, mainchain_SidechainFunder1)); +// await IntegrationTestUtils.WaitLoop(() => IntegrationTestUtils.AreNodesSynced(mainchain_FederationGateway2, mainchain_SidechainFunder1)); +// await IntegrationTestUtils.WaitLoop(() => IntegrationTestUtils.AreNodesSynced(mainchain_FederationGateway3, mainchain_SidechainFunder1)); + +// await IntegrationTestUtils.WaitLoop(() => IntegrationTestUtils.IsGeneralWalletSyncedToHeight(mainchain_FederationGateway1, 52)); +// await IntegrationTestUtils.WaitLoop(() => IntegrationTestUtils.IsGeneralWalletSyncedToHeight(mainchain_FederationGateway2, 52)); +// await IntegrationTestUtils.WaitLoop(() => IntegrationTestUtils.IsGeneralWalletSyncedToHeight(mainchain_FederationGateway3, 52)); + +// IntegrationTestUtils.SaveGeneralWallet(mainchain_FederationGateway1, "multisig_wallet"); +// IntegrationTestUtils.SaveGeneralWallet(mainchain_FederationGateway2, "multisig_wallet"); +// IntegrationTestUtils.SaveGeneralWallet(mainchain_FederationGateway3, "multisig_wallet"); + +// /// was 60000 +// await Task.Delay(35000); + +// //3804.001 (3600, 204 mining plus 0.01 transaction fee.) +// //check thos funds were received by the sidechain destination address +// //account_sidechain_funder = sidechainNode_Member1_Wallet.FullNode.WalletManager().GetAccounts("sidechain_wallet").First(); +// //amounts = account_sidechain_funder.GetSpendableAmount(); +// //var confirmedAmountDestinationSidechainAfterWithdrawal = amounts.ConfirmedAmount.ToString(); +// //amounts.ConfirmedAmount.Should().Be(new Money(3812.01m - 2500, MoneyUnit.BTC)); + +// ////97996407.99000000 (98,000,008 - 3600 - 0.01 fee) +// ////check the sidechain multi-sig has locked up the withdrawing funds. +// //amounts = account_fed_member1_sidechain.GetSpendableAmount(true); +// //var confirmedAmountMultiSigOnSidechain2 = amounts.ConfirmedAmount.ToString(); +// //amounts.ConfirmedAmount.Should().Be(new Money(97996407.99m + 2500, MoneyUnit.BTC)); + +// ////"1099.99000000" +// ////confirm the mainchain multi-sig has released the locked funds for withdrawal. +// //amounts = account_fed_member1_mainchain.GetSpendableAmount(true); +// //var confirmedAmountLockedOnMainchain2 = amounts.ConfirmedAmount.ToString(); +// //amounts.ConfirmedAmount.Should().Be(new Money(3600 - 2500 - 0.01m, MoneyUnit.BTC)); + +// ////97999104.01000000 +// ////and confirm the destination has received the withdawal +// //var account_mainchain_funder = mainchain_SidechainFunder1.FullNode.WalletManager().GetAccounts("mainchain_wallet").First(); +// //amounts = account_mainchain_funder.GetSpendableAmount(); +// //var confirmedAmountDestinationMainchain = amounts.ConfirmedAmount.ToString(); +// //amounts.ConfirmedAmount.Should().Be(new Money(98000204 - 3600 + 2500 + 0.01m, MoneyUnit.BTC)); + +// //now kill the member three nodes +// mainchain_FederationGateway3.Kill(); +// sidechain_FederationGateway3.Kill(); + +// //time to die +// await Task.Delay(5000); + +// //create a new node three +// var mainchain_FederationGateway3v2 = nodeBuilder.CreateCustomNode(false, fullNodeBuilder => +// { +// fullNodeBuilder +// .UseBlockStore() +// .UsePosConsensus() +// .UseMempool() +// .UseWallet() +// .AddPowPosMining() +// .AddFederationGateway() +// .UseBlockNotification() +// .UseApi() +// .AddRPC(); +// }, ApexNetwork.RegTest, agent: "MainchainFederationGateway3v2 "); + +// publickey = File.ReadAllText(Path.Combine(Directory.GetCurrentDirectory(), "Federations\\deposit_funds_to_sidechain\\member3\\PUBLIC_mainchain_member3.txt")); +// mainchain_FederationGateway3v2.ConfigParameters.Add("federationfolder", Path.Combine(Directory.GetCurrentDirectory(), "Federations\\deposit_funds_to_sidechain")); +// mainchain_FederationGateway3v2.ConfigParameters.Add("memberprivatefolder", Path.Combine(Directory.GetCurrentDirectory(), "Federations\\deposit_funds_to_sidechain\\member3")); +// mainchain_FederationGateway3v2.ConfigParameters.Add("publickey", publickey); +// mainchain_FederationGateway3v2.ConfigParameters.Add("membername", "member3v2"); +// mainchain_FederationGateway3v2.ConfigParameters.Add("multisigM", "2"); +// mainchain_FederationGateway3v2.ConfigParameters.Add("multisigN", "3"); + +// // change the fed3 sidechain api port +// sidechain_FederationGateway3.ConfigParameters.AddOrReplace("counterchainapiport", mainchain_FederationGateway3v2.GetApiPort().ToString()); +// mainchain_FederationGateway3v2.ConfigParameters.Add("counterchainapiport", sidechain_FederationGateway3.GetApiPort().ToString()); + +// await Task.Delay(1000); + +// //connect the nodes +// mainchain_FederationGateway3v2.Start(); +// sidechain_FederationGateway3.Start(); + +// //give the node time to start +// await Task.Delay(15000); + +// //add mainchain nodes +// rpcClient1 = mainchain_FederationGateway1.CreateRPCClient(); +// rpcClient1.AddNode(mainchain_FederationGateway3v2.Endpoint); +// await Task.Delay(addNodeDelay); + +// rpcClient2 = mainchain_FederationGateway2.CreateRPCClient(); +// rpcClient2.AddNode(mainchain_FederationGateway3v2.Endpoint); +// await Task.Delay(addNodeDelay); + +// rpcClient3 = mainchain_FederationGateway3v2.CreateRPCClient(); +// await Task.Delay(addNodeDelay); +// rpcClient3.AddNode(mainchain_SidechainFunder2.Endpoint); +// await Task.Delay(addNodeDelay); +// rpcClient3.AddNode(mainchain_FederationGateway1.Endpoint); +// await Task.Delay(addNodeDelay); +// rpcClient3.AddNode(mainchain_FederationGateway2.Endpoint); +// await Task.Delay(addNodeDelay); + +// // Check our network is still intact. +// //IntegrationTestUtils.AreConnected(mainchain_FederationGateway1, mainchain_FederationGateway2).Should().BeTrue(); +// //IntegrationTestUtils.AreConnected(mainchain_FederationGateway1, mainchain_FederationGateway3v2).Should().BeTrue(); +// //IntegrationTestUtils.AreConnected(mainchain_FederationGateway2, mainchain_FederationGateway1).Should().BeTrue(); +// //IntegrationTestUtils.AreConnected(mainchain_FederationGateway2, mainchain_FederationGateway3v2).Should().BeTrue(); +// //IntegrationTestUtils.AreConnected(mainchain_FederationGateway3v2, mainchain_FederationGateway1).Should().BeTrue(); +// //IntegrationTestUtils.AreConnected(mainchain_FederationGateway3v2, mainchain_FederationGateway2).Should().BeTrue(); + +// await Task.Delay(90000); +// } +// } +// } +//} \ No newline at end of file diff --git a/Stratis.FederatedPeg.IntegrationTests.csproj b/Stratis.FederatedPeg.IntegrationTests.csproj index 63cf7b6fd81..a04c0b185f4 100644 --- a/Stratis.FederatedPeg.IntegrationTests.csproj +++ b/Stratis.FederatedPeg.IntegrationTests.csproj @@ -33,8 +33,6 @@ - -