public void RecoverWalletSuccessfullyReturnsWalletModel()
        {
            Bitcoin.Wallet.Wallet wallet = new Bitcoin.Wallet.Wallet
            {
                Name    = "myWallet",
                Network = WalletHelpers.GetNetwork("mainnet")
            };
            var mockWalletWrapper = new Mock <IWalletManager>();

            mockWalletWrapper.Setup(w => w.LoadWallet(It.IsAny <string>(), It.IsAny <string>())).Returns(wallet);
            string dir        = AssureEmptyDir("TestData/ControllersTests/RecoverWalletSuccessfullyReturnsWalletModel");
            var    dataFolder = new DataFolder(new NodeSettings {
                DataDir = dir
            });

            var controller = new WalletController(mockWalletWrapper.Object, new Mock <IWalletSyncManager>().Object, It.IsAny <ConnectionManager>(), Network.Main, new Mock <ConcurrentChain>().Object, dataFolder);

            // Act
            var result = controller.Load(new WalletLoadRequest
            {
                Name       = "myWallet",
                FolderPath = "",
                Password   = ""
            });

            // Assert
            mockWalletWrapper.VerifyAll();
            var viewResult = Assert.IsType <OkResult>(result);

            Assert.Equal(200, viewResult.StatusCode);
        }
        public void WrongNetworkThrowsArgumentException()
        {
            var exception = Record.Exception(() => WalletHelpers.GetNetwork("myNetwork"));

            Assert.NotNull(exception);
            Assert.IsType <ArgumentException>(exception);
        }
Beispiel #3
0
        public void LoadWalletSuccessfullyReturnsWalletModel()
        {
            Bitcoin.Wallet.Wallet wallet = new Bitcoin.Wallet.Wallet
            {
                Name    = "myWallet",
                Network = WalletHelpers.GetNetwork("mainnet")
            };

            var mockWalletWrapper = new Mock <IWalletManager>();

            mockWalletWrapper.Setup(w => w.RecoverWallet(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <DateTime>(), null)).Returns(wallet);

            var controller = new WalletController(mockWalletWrapper.Object, new Mock <IWalletSyncManager>().Object, It.IsAny <ConnectionManager>(), Network.Main, new Mock <ConcurrentChain>().Object);

            // Act
            var result = controller.Recover(new WalletRecoveryRequest
            {
                Name       = "myWallet",
                FolderPath = "",
                Password   = "",
                Network    = "MainNet",
                Mnemonic   = "mnemonic"
            });

            // Assert
            mockWalletWrapper.VerifyAll();
            var viewResult = Assert.IsType <OkResult>(result);

            Assert.Equal(200, viewResult.StatusCode);
        }
        /// <inheritdoc />
        public Wallet RecoverWallet(string password, string folderPath, string name, string network, string mnemonic, DateTime creationTime, string passphrase = null)
        {
            // for now the passphrase is set to be the password by default.
            if (passphrase == null)
            {
                passphrase = password;
            }

            // generate the root seed used to generate keys
            ExtKey extendedKey = (new Mnemonic(mnemonic)).DeriveExtKey(passphrase);

            Network coinNetwork = WalletHelpers.GetNetwork(network);

            // create a wallet file
            Wallet wallet = this.GenerateWalletFile(password, folderPath, name, coinNetwork, extendedKey, creationTime);

            // generate multiple accounts and addresses from the get-go
            for (int i = 0; i < WalletRecoveryAccountsCount; i++)
            {
                HdAccount account = CreateNewAccount(wallet, this.coinType, password);
                this.CreateAddressesInAccount(account, coinNetwork, UnusedAddressesBuffer);
                this.CreateAddressesInAccount(account, coinNetwork, UnusedAddressesBuffer, true);
            }

            int blockSyncStart = this.chain.GetHeightAtTime(creationTime);

            this.UpdateLastBlockSyncedHeight(wallet, blockSyncStart);

            // save the changes to the file and add addresses to be tracked
            this.SaveToFile(wallet);
            this.Load(wallet);
            this.LoadKeysLookup();

            return(wallet);
        }
Beispiel #5
0
        public void RecoverWalletSuccessfullyReturnsWalletModel()
        {
            Wallet.Wallet wallet = new Wallet.Wallet
            {
                Name    = "myWallet",
                Network = WalletHelpers.GetNetwork("mainnet")
            };
            var mockWalletWrapper = new Mock <IWalletManager>();

            mockWalletWrapper.Setup(w => w.LoadWallet(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>())).Returns(wallet);

            var controller = new WalletController(mockWalletWrapper.Object, new Mock <ITracker>().Object);

            // Act
            var result = controller.Load(new WalletLoadRequest
            {
                Name       = "myWallet",
                FolderPath = "",
                Password   = ""
            });

            // Assert
            mockWalletWrapper.VerifyAll();
            var viewResult = Assert.IsType <JsonResult>(result);

            Assert.NotNull(viewResult.Value);
            Assert.IsType <WalletModel>(viewResult.Value);

            var model = viewResult.Value as WalletModel;

            Assert.Equal("Main", model.Network);
        }
Beispiel #6
0
        /// <inheritdoc />
        public Mnemonic CreateWallet(string password, string folderPath, string name, string network, string passphrase = null)
        {
            // for now the passphrase is set to be the password by default.
            if (passphrase == null)
            {
                passphrase = password;
            }

            // generate the root seed used to generate keys from a mnemonic picked at random
            // and a passphrase optionally provided by the user
            Mnemonic mnemonic    = new Mnemonic(Wordlist.English, WordCount.Twelve);
            ExtKey   extendedKey = mnemonic.DeriveExtKey(passphrase);

            Network coinNetwork = WalletHelpers.GetNetwork(network);

            // create a wallet file
            Wallet wallet = this.GenerateWalletFile(password, folderPath, name, coinNetwork, extendedKey);

            // generate multiple accounts and addresses from the get-go
            for (int i = 0; i < WalletCreationAccountsCount; i++)
            {
                HdAccount account = CreateNewAccount(wallet, this.coinType, password);
                this.CreateAddressesInAccount(account, coinNetwork, UnusedAddressesBuffer);
                this.CreateAddressesInAccount(account, coinNetwork, UnusedAddressesBuffer, true);
            }

            // save the changes to the file and add addresses to be tracked
            this.SaveToFile(wallet);
            this.PubKeys = this.LoadKeys(this.coinType);
            this.Load(wallet);

            return(mnemonic);
        }
        public void GetNetworkIsCaseInsensitive()
        {
            Network testNetwork = WalletHelpers.GetNetwork("Test");

            Assert.Equal(Network.TestNet, testNetwork);

            Network mainNetwork = WalletHelpers.GetNetwork("MainNet");

            Assert.Equal(Network.Main, mainNetwork);
        }
        public void GetTestNetNetworkRetuirnsNetworkTest()
        {
            Network network = WalletHelpers.GetNetwork("testnet");

            Assert.Equal(Network.TestNet, network);
        }
        public void GetMainNetNetworkRetuirnsNetworkMain()
        {
            Network network = WalletHelpers.GetNetwork("mainnet");

            Assert.Equal(Network.Main, network);
        }
Beispiel #10
0
 /// <inheritdoc />
 public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
 {
     return(WalletHelpers.GetNetwork((string)reader.Value));
 }