Exemplo n.º 1
0
        public void TestImportCert()
        {
            X509Certificate2 cert = NewCertificate();

            Assert.IsNotNull(cert);
            Assert.AreEqual(true, cert.HasPrivateKey);
            WalletAccount account = uut.Import(cert);

            Assert.IsNotNull(account);
        }
Exemplo n.º 2
0
        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"));
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        public void TestVerifyPassword()
        {
            bool result = uut.VerifyPassword("123");

            Assert.AreEqual(true, result);
            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();

            wallet["name"]     = "name";
            wallet["version"]  = new Version("1.0").ToString();
            wallet["scrypt"]   = new ScryptParameters(2, 1, 1).ToJson();
            wallet["accounts"] = new JArray();
            wallet["extra"]    = new JObject();
            uut     = new NEP6Wallet(null, "123", ProtocolSettings.Default, wallet);
            nep2key = keyPair.Export("123", ProtocolSettings.Default.AddressVersion, 2, 1, 1);
            uut.Import(nep2key, "123", 2, 1, 1);
            Assert.IsFalse(uut.VerifyPassword("1"));
            Assert.IsTrue(uut.VerifyPassword("123"));
        }
Exemplo n.º 5
0
        public void CreateMintTx()
        {
            if (!InitWallet())
            {
                return;
            }

            UInt160 to = Wallet.GetAccounts().First().ScriptHash;

            // Import all CN keys

            var wallet = new NEP6Wallet("");

            using var unlock = wallet.Unlock(WALLET_PASS);

            var cnWallets = Settings.Default.Wifs.Select(wif => wallet.Import(wif)).ToArray();

            // Get CN contract

            using var snapshot = Blockchain.Singleton.GetSnapshot();
            var validators = NativeContract.NEO.GetValidators(snapshot);
            var CNContract = Contract.CreateMultiSigContract(validators.Length - (validators.Length - 1) / 3, validators);

            wallet.CreateAccount(CNContract);

            Console.WriteLine($"Generated mint tx: from={CNContract.ScriptHash.ToAddress()} to={to.ToAddress()}");

            // Create TX

            var mintTx = wallet.MakeTransaction
                         (
                new TransferOutput[]
            {
                new TransferOutput()
                {
                    AssetId    = NEO.AssetId,
                    ScriptHash = to,
                    Value      = new BigDecimal(50_000_000, 0),
                },