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); }
public UnitTestVotingDB() { db = new VotingsDB(); db.ConnectToDBAsync(); db.Clear(); //создаем подключение к БД string dbPath = Path.Combine(Environment.CurrentDirectory, "VotingsDB.db3"); db0 = new SQLiteAsyncConnection(dbPath); VotingsUser.PrivateKey = keys[1]; VotingsUser.PublicKey = keys[0]; //создаем тестовые транзакции user = Transaction.CreateUserTransacton(VotingsUser.PublicKey, userName, userId, prevHash); var list = new List <string>(); list.Add(VotingsUser.PublicKey); voting = Transaction.StartVotingTransation(list, votingName, votingNum, prevHash); vote = Transaction.VoteTransaction(VotingsUser.PublicKey, voting.Hash, votingNum); ban = Transaction.BanUserTransaction(cause, VotingsUser.PublicKey, prevHash); db0.InsertAsync(user).Wait(); db0.InsertAsync(voting).Wait(); db0.InsertAsync(vote).Wait(); db0.InsertAsync(ban).Wait(); //тестовый блок var trs = new List <Transaction>(); trs.Add(ban); trs.Add(vote); trs.Add(voting); trs.Add(user); block = new Block(trs, new Block()); block.PreviousHash = prevHash; block.Number = blockNum; db0.InsertAsync(block).Wait(); }