Ejemplo n.º 1
0
        public void GenerateKeyAddressesTest()
        {
            Result     result;
            PrivateKey key1;
            PrivateKey key2;

            File.Create(Path.Combine(_configurationProvider.GetConfig <KeystoreConfig>().KeyStoreDirectory, "not_a_key"));

            (key1, result) = _store.GenerateKey(_testPasswordSecured);
            Assert.AreEqual(ResultType.Success, result.ResultType, "generate key 1");

            (key2, result) = _store.GenerateKey(_testPasswordSecured);
            Assert.AreEqual(ResultType.Success, result.ResultType, "generate key 2");

            //get key addreses
            (IReadOnlyCollection <Address> addresses, Result getAllResult) = _store.GetKeyAddresses();
            Assert.AreEqual(ResultType.Success, getAllResult.ResultType, "get key");
            Assert.IsTrue(addresses.Count() >= 2);
            Assert.IsNotNull(addresses.FirstOrDefault(x => x.Equals(key1.Address)), "key 1 not null");
            Assert.IsNotNull(addresses.FirstOrDefault(x => x.Equals(key2.Address)), "key 2 not null");

            //delete generated keys
            result = _store.DeleteKey(key1.Address, _testPasswordSecured);
            Assert.AreEqual(ResultType.Success, result.ResultType, "delete key 1");

            result = _store.DeleteKey(key2.Address, _testPasswordSecured);
            Assert.AreEqual(ResultType.Success, result.ResultType, "delete key 2");
        }
Ejemplo n.º 2
0
        public void Personal_import_raw_key()
        {
            Address         expectedAddress = new Address("707Fc13C0eB628c074f7ff514Ae21ACaeE0ec072");
            PrivateKey      privateKey      = new PrivateKey("a8fceb14d53045b1c8baedf7bc1f38b2540ce132ac28b1ec8b93b8113165abc0");
            string          passphrase      = "testPass";
            IPersonalModule module          = new PersonalModule(_ecdsa, _wallet, _keyStore);
            string          serialized      = RpcTest.TestSerializedRequest(module, "personal_importRawKey", privateKey.KeyBytes.ToHexString(), passphrase);

            Assert.AreEqual($"{{\"jsonrpc\":\"2.0\",\"result\":\"{expectedAddress.ToString()}\",\"id\":67}}", serialized);
            _keyStore.DeleteKey(expectedAddress);
        }