public void TestMethodBlockchain() { var keys = CommonHelpers.GetPublicPrivateKeys(); VotingsUser.PublicKey = "MFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEhWfjbJW2Xd+f0Gls8bi2pzrV5av+R7eG6H8ysQXKNY99mL5j+fUSoJRDaZz9dxhPq3+zmRiewNy0BesJljUl1Q=="; VotingsUser.PrivateKey = "MHQCAQEEICUx8Nb2dysdxxbGHvw6yEWLgqw6PW+YLd74Z0PVxBfMoAcGBSuBBAAKoUQDQgAEhWfjbJW2Xd+f0Gls8bi2pzrV5av+R7eG6H8ysQXKNY99mL5j+fUSoJRDaZz9dxhPq3+zmRiewNy0BesJljUl1Q=="; VotingsUser.CreateOwnBlocks = true; VotingsUser.PeerDiscovery = true; var db = new VotingsDB(); db.ConnectToDBAsync(); db.Clear(); var blockchain = new BlockChainVotings.BlockChainVotings(); blockchain.Start(); Assert.IsTrue(blockchain.Started == true); //проверка корня blockchain.CheckRoot(); Assert.IsTrue(db.GetUserCreation(VotingsUser.RootPublicKey).Signature == VotingsUser.RootCreationSignature); Assert.IsTrue(db.GetVoting(0).Signature == VotingsUser.FirstVotingSignature); Assert.IsTrue(db.GetBlock(0).Signature == VotingsUser.FirstBlockSignature); //создание пользователя var newUser = keys[0]; blockchain.CreateUser(newUser, "somename", "12345"); Assert.IsNotNull(db.GetUserCreation(newUser)); //голосования var list = new List <String>(); list.Add(newUser); list.Add(VotingsUser.RootPublicKey); blockchain.CreateVoting(list, "voting"); Assert.IsTrue(JObject.Parse(db.GetVoting(1).Info)["name"].Value <string>() == "voting"); //голоса blockchain.CreateVote(newUser, db.GetVoting(1).Hash); Assert.IsTrue(db.GetUserVote(VotingsUser.PublicKey, 1).RecieverHash == newUser); //бан blockchain.BanUser(newUser, "cause"); Assert.IsTrue(db.GetUserBan(newUser).RecieverHash == newUser); //создание блока for (int i = 0; i < 6; i++) { blockchain.CreateUser(newUser + i, "somename", "12345"); } Assert.IsTrue(db.GetLastBlock().Transactions.Contains(db.GetUserCreation(newUser).Hash)); Assert.IsTrue(db.GetFreeTransactions(100).Count == 0); }
private void RegForm_SuccssesLogin(object sender, EventArgs e) { this.WindowState = FormWindowState.Normal; this.ShowInTaskbar = true; notifyIcon1.Visible = false; blockChain.CheckRoot(); this.Enabled = true; //============= if (VotingsUser.PublicKey == VotingsUser.RootPublicKey) { materialRaisedButtonBanUser.Show(); materialRaisedButtonCreateUser.Show(); materialRaisedButtonCreateVoting.Show(); materialRaisedButtonVote.Hide(); materialLabelAvaliableVotings.Hide(); } else { materialRaisedButtonBanUser.Hide(); materialRaisedButtonCreateUser.Hide(); materialRaisedButtonCreateVoting.Hide(); materialRaisedButtonVote.Show(); materialLabelAvaliableVotings.Show(); } materialCheckBoxCreateBlocks.Checked = VotingsUser.CreateOwnBlocks; materialCheckBoxPeerDiscovery.Checked = VotingsUser.PeerDiscovery; materialCheckBoxUseLanLocalIP.Checked = VotingsUser.UseLanLocalIP; textBoxTrackers.Text = VotingsUser.Trackers; textBoxTrackers.Select(0, 0); //============ //обработчики событий изменения БД blockChain.NewBlock += (s, a) => { Invoke(new Action(() => { materialLabelBlocksVal.Text = a.Data.ToString(); })); }; blockChain.NewTransaction += (s, a) => { //обновляем имя и количество транзакций Invoke(new Action(() => { materialLabelTransactionsVal.Text = a.Data.ToString(); materialLabelAvaliableVotings.Text = Properties.Resources.avaliableN + " " + blockChain.GetOpenedVotings().Count + " " + Properties.Resources.nVotings; })); string name2 = null; if (helloStatus == false) { name2 = blockChain.GetMyName(); if (name2 != null) { Invoke(new Action(() => { if (helloStatus == false) { materialLabelHello.Text = Properties.Resources.hello + ", " + name2; helloStatus = true; } })); } } }; blockChain.NewUser += (s, a) => { Invoke(new Action(() => { materialLabelUsersVal.Text = a.Data.ToString(); })); }; blockChain.NewVoting += (s, a) => { Invoke(new Action(() => { materialLabelAvaliableVotings.Text = Properties.Resources.avaliableN + " " + blockChain.GetOpenedVotings().Count + " " + Properties.Resources.nVotings; materialLabelVotingsVal.Text = blockChain.GetVotings().Count.ToString(); var notify = new NotifyForm(blockChain.GetVotingName(a.Data)); notify.ButtonPressed += (s2, a2) => notifyIcon1_Click(s2, a2); notify.Show(); })); }; CommonHelpers.PeersCountChanged += (s, a) => { Invoke(new Action(() => { materialLabelPeersVal.Text = a.Data.ToString(); })); }; CommonHelpers.TrackersCountChanged += (s, a) => { Invoke(new Action(() => { materialLabelTrackersVal.Text = a.Data.ToString(); })); }; //Задаем начальные значения materialLabelBlocksVal.Text = blockChain.GetBlocksCount().ToString(); materialLabelTransactionsVal.Text = blockChain.GetTransactionsCount().ToString(); materialLabelUsersVal.Text = blockChain.GetUsersCount().ToString(); materialLabelAvaliableVotings.Text = Properties.Resources.avaliableN + " " + blockChain.GetOpenedVotings().Count + " " + Properties.Resources.nVotings; materialLabelPeersVal.Text = 0.ToString(); materialLabelTrackersVal.Text = 0.ToString(); materialLabelVotingsVal.Text = blockChain.GetVotings().Count.ToString(); string name = blockChain.GetMyName(); if (name != null) { materialLabelHello.Text = Properties.Resources.hello + ", " + name; helloStatus = true; } else { materialLabelHello.Text = Properties.Resources.hello + ", " + Properties.Resources.user; } ChangeLabelsFont(); Task.Run(() => blockChain.Start()); buttonStart.Enabled = false; }