public void TestVerifyPassword() { bool result = uut.VerifyPassword("123"); Assert.AreEqual(true, result); Assert.ThrowsException <ArgumentNullException>(() => uut.CreateAccount(keyPair.PrivateKey)); uut.Unlock("123"); uut.CreateAccount(keyPair.PrivateKey); result = uut.Contains(testScriptHash); Assert.AreEqual(true, result); result = uut.VerifyPassword("123"); Assert.AreEqual(true, result); uut.DeleteAccount(testScriptHash); Assert.AreEqual(false, uut.Contains(testScriptHash)); JObject wallet = new JObject(); wallet["name"] = "name"; wallet["version"] = new Version().ToString(); wallet["scrypt"] = new ScryptParameters(0, 0, 0).ToJson(); wallet["accounts"] = new JArray(); wallet["extra"] = new JObject(); uut = new NEP6Wallet(wallet); nep2key = keyPair.Export("123", 0, 0, 0); uut.Import(nep2key, "123", 0, 0, 0); Assert.IsFalse(uut.VerifyPassword("1")); Assert.IsTrue(uut.VerifyPassword("123")); }
public void TestImportNep2() { bool result = uut.Contains(testScriptHash); Assert.AreEqual(false, result); uut.Import(nep2key, "123", 0, 0, 0); result = uut.Contains(testScriptHash); Assert.AreEqual(true, result); uut.DeleteAccount(testScriptHash); result = uut.Contains(testScriptHash); Assert.AreEqual(false, result); JObject wallet = new JObject(); wallet["name"] = "name"; wallet["version"] = new Version().ToString(); wallet["scrypt"] = new ScryptParameters(0, 0, 0).ToJson(); wallet["accounts"] = new JArray(); wallet["extra"] = new JObject(); uut = new NEP6Wallet(wallet); result = uut.Contains(testScriptHash); Assert.AreEqual(false, result); uut.Import(nep2key, "123", 0, 0, 0); result = uut.Contains(testScriptHash); Assert.AreEqual(true, result); }
public void TestSetup() { wallet = TestUtils.GenerateTestWallet(); byte[] array1 = { 0x01 }; hash = new UInt160(Crypto.Default.Hash160(array1)); account = new TLP6Account(wallet, hash); }
public void TestConstructorWithKeyPair() { TLP6Wallet wallet = new TLP6Wallet("a"); byte[] array1 = { 0x01 }; var hash = new UInt160(Crypto.Default.Hash160(array1)); string password = "******"; var account = new TLP6Account(wallet, hash, keyPair, password); account.ScriptHash.Should().Be(hash); account.Decrypted.Should().BeTrue(); account.HasKey.Should().BeTrue(); }
private static Wallet OpenWallet(string path, string password) { if (Path.GetExtension(path) == ".db3") { return(UserWallet.Open(path, password)); } else { var nep6wallet = new TLP6Wallet(path); nep6wallet.Unlock(password); return(nep6wallet); } }
public void TestSave() { JObject wallet = new JObject(); wallet["name"] = "name"; wallet["version"] = new System.Version().ToString(); wallet["scrypt"] = new ScryptParameters(0, 0, 0).ToJson(); wallet["accounts"] = new JArray(); wallet["extra"] = new JObject(); File.WriteAllText(wPath, wallet.ToString()); uut = new NEP6Wallet(wPath); uut.Unlock("123"); uut.CreateAccount(keyPair.PrivateKey); bool result = uut.Contains(testScriptHash); Assert.AreEqual(true, result); uut.Save(); result = uut.Contains(testScriptHash); Assert.AreEqual(true, result); }
private bool OnUpgradeWalletCommand(string[] args) { if (args.Length < 3) { Console.WriteLine("error"); return(true); } string path = args[2]; if (Path.GetExtension(path) != ".db3") { Console.WriteLine("Can't upgrade the wallet file."); return(true); } if (!File.Exists(path)) { Console.WriteLine("File does not exist."); return(true); } string password = ReadUserInput("password", true); if (password.Length == 0) { Console.WriteLine("cancelled"); return(true); } string path_new = Path.ChangeExtension(path, ".json"); if (File.Exists(path_new)) { Console.WriteLine($"File '{path_new}' already exists"); return(true); } TLP6Wallet.Migrate(path_new, path, password).Save(); Console.WriteLine($"Wallet file upgrade complete. New wallet file has been auto-saved at: {path_new}"); return(true); }
public void TestSetup() { uut = CreateWallet(); wPath = CreateWalletFile(); }
private bool OnCreateWalletCommand(string[] args) { if (args.Length < 3) { Console.WriteLine("error"); return(true); } if (system.RpcServer != null) { if (!ReadUserInput("Warning: Opening the wallet with RPC turned on could result in asset loss. Are you sure you want to do this? (yes|no)", false).IsYes()) { return(true); } } string path = args[2]; string password = ReadUserInput("password", true); if (password.Length == 0) { Console.WriteLine("cancelled"); return(true); } string password2 = ReadUserInput("password", true); if (password != password2) { Console.WriteLine("error"); return(true); } switch (Path.GetExtension(path)) { case ".db3": { Program.Wallet = UserWallet.Create(path, password); WalletAccount account = Program.Wallet.CreateAccount(); Console.WriteLine($"address: {account.Address}"); Console.WriteLine($" pubkey: {account.GetKey().PublicKey.EncodePoint(true).ToHexString()}"); if (system.RpcServer != null) { system.RpcServer.Wallet = Program.Wallet; } } break; case ".json": { var wallet = new TLP6Wallet(path); wallet.Unlock(password); WalletAccount account = wallet.CreateAccount(); wallet.Save(); Program.Wallet = wallet; Console.WriteLine($"address: {account.Address}"); Console.WriteLine($" pubkey: {account.GetKey().PublicKey.EncodePoint(true).ToHexString()}"); if (system.RpcServer != null) { system.RpcServer.Wallet = Program.Wallet; } } break; default: Console.WriteLine("Wallet files in that format are not supported, please use a .json or .db3 file extension."); break; } return(true); }