コード例 #1
0
 public void TestNodeWithoutCli(string minValue, string maxValue)
 {
     ci           = new CommandInfo("set_block_volume");
     ci.Parameter = String.Format("{0} {1}", minValue, maxValue);
     CI.ExecuteCommand(ci);
     Assert.IsTrue(ci.Result);
 }
コード例 #2
0
        public void GetTxCounts(int begin, int end)
        {
            List <object> blockInfos = new List <object>();
            string        url        = "http://192.168.199.221:8000/chain";
            var           ch         = new CliHelper(url);
            var           ci         = new CommandInfo("get_block_info");

            for (int i = begin; i <= end; i++)
            {
                dynamic blockInfo = new System.Dynamic.ExpandoObject();
                int     height    = i;
                ci.Parameter = height.ToString();
                ch.ExecuteCommand(ci);
                Assert.IsTrue(ci.Result);
                ci.GetJsonInfo();

                var    result     = ci.JsonInfo;
                string count      = result["result"]["result"]["Body"]["TransactionsCount"].ToString();
                string txpoolSize = result["result"]["result"]["CurrentTransactionPoolSize"].ToString();
                blockInfo.Height   = height;
                blockInfo.TxCount  = count;
                blockInfo.PoolSize = txpoolSize;
                blockInfos.Add(blockInfo);
            }
            foreach (dynamic item in blockInfos)
            {
                string message = $"Height: {item.Height}, TxCount: {item.TxCount}, CurrentTransactionPoolSize: {item.PoolSize}";
                Console.WriteLine(message);
                System.Diagnostics.Debug.WriteLine(message);
            }
            Console.ReadLine();
        }
コード例 #3
0
        public void GetTxResult(string rpcUrl, string txId)
        {
            var CH = new CliHelper(rpcUrl);

            string method = "get_tx_result";
            var    ci     = new CommandInfo(method);

            ci.Parameter = txId;
            CH.ExecuteCommand(ci);
            ci.GetJsonInfo();
        }
コード例 #4
0
        public void GetSideChainTxId()
        {
            //Connect Chain
            var ci = new CommandInfo("connect_chain");

            CH.ExecuteCommand(ci);
            Assert.IsTrue(ci.Result, "Connect chain got exception.");
            ci.GetJsonInfo();
            SideChainTxId = ci.JsonInfo["SideChainContract"].ToString();
            ChainId       = ci.JsonInfo["chain_id"].ToString();

            //Load Sidechain ABI
            ci           = new CommandInfo("load_contract_abi");
            ci.Parameter = SideChainTxId;
            CH.ExecuteCommand(ci);
            Assert.IsTrue(ci.Result, "Load sidechain ABI got exception.");
        }
コード例 #5
0
        static void Main(string[] args)
        {
            #region Basic Preparation
            //Init Logger
            string logName = "ContractTest_" + DateTime.Now.ToString("MMddHHmmss") + ".log";
            string dir     = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "logs", logName);
            Logger.InitLogHelper(dir);

            string url = "http://192.168.199.222:8000/chain";
            var    ch  = new CliHelper(url, AccountManager.GetDefaultDataDir());

            //Account preparation
            List <string> accList = new List <string>();
            var           ci      = new CommandInfo("account new", "account");
            for (int i = 0; i < 50; i++)
            {
                ci.Parameter = "123";
                ci           = ch.ExecuteCommand(ci);
                if (ci.Result)
                {
                    accList.Add(ci.InfoMsg?[0].Replace("Account address:", "").Trim());
                }
            }

            //Unlock
            ci           = new CommandInfo("account unlock", "account");
            ci.Parameter = String.Format("{0} {1} {2}", accList[0], "123", "notimeout");
            ci           = ch.ExecuteCommand(ci);

            //Connect Chain
            ci = new CommandInfo("connect_chain");
            ch.ExecuteCommand(ci);
            Assert.IsTrue(ci.Result, "Connect chain got exception.");

            //Get AElf.Contracts.Token ABI
            ci.GetJsonInfo();
            TokenAbi = ci.JsonInfo["AElf.Contracts.Token"].ToObject <string>();

            //Load default Contract Abi
            ci = new CommandInfo("load_contract_abi");
            ch.RpcLoadContractAbi(ci);
            Assert.IsTrue(ci.Result, "Load contract abi got exception.");

            #endregion

            #region AElf.Token operation
            var contract = new ContractBase(ch, TokenAbi);
            contract.Account = accList[0];

            //Deploy
            //contract.DeployContract(out var txId);

            //Load
            contract.LoadContractAbi();

            //Init
            contract.ExecuteContractMethod(out var txId1, "Initialize", "elfToken", "ELF", "2000000", "2");
            contract.CheckTransactionResult(out var initCi, txId1);

            //Transfer to Account A, B, C
            contract.ExecuteContractMethod(out var txIdA, "Transfer", accList[1], "5000");
            contract.ExecuteContractMethod(out var txIdB, "Transfer", accList[2], "10000");
            contract.ExecuteContractMethod(out var txIdC, "Transfer", accList[3], "15000");

            //check result
            contract.CheckTransactionResult(out var aCi, txIdA);
            contract.CheckTransactionResult(out var bCi, txIdB);
            contract.CheckTransactionResult(out var cCi, txIdC);

            //Get balance
            contract.ExecuteContractMethod(out var txOwner, "BalanceOf", accList[0]);
            contract.ExecuteContractMethod(out var txBA, "BalanceOf", accList[1]);
            contract.ExecuteContractMethod(out var txBB, "BalanceOf", accList[2]);
            contract.ExecuteContractMethod(out var txBC, "BalanceOf", accList[3]);

            //Query Result
            contract.GetTransactionResult(txOwner, out var ciOwner);
            contract.CheckTransactionResult(out var ciA, txBA);
            contract.CheckTransactionResult(out var ciB, txBB);
            contract.CheckTransactionResult(out var ciC, txBC);

            //Convert to Value
            ciOwner.GetJsonInfo();
            string valueStr1 = ciOwner.JsonInfo["result"]["result"]["return"].ToString();
            Logger.WriteInfo($"Owner current balance: {Convert.ToInt32(valueStr1, 16)}");

            ciA.GetJsonInfo();
            string valueStrA = ciA.JsonInfo["result"]["result"]["return"].ToString();
            Logger.WriteInfo($"A current balance: {Convert.ToInt32(valueStrA, 16)}");

            ciB.GetJsonInfo();
            string valueStrB = ciB.JsonInfo["result"]["result"]["return"].ToString();
            Logger.WriteInfo($"B current balance: {Convert.ToInt32(valueStrB, 16)}");

            ciC.GetJsonInfo();
            string valueStrC = ciC.JsonInfo["result"]["result"]["return"].ToString();
            Logger.WriteInfo($"C current balance: {Convert.ToInt32(valueStrC, 16)}");

            #endregion

            #region AElf.Contract.Resource
            #endregion
        }
コード例 #6
0
        public void GetAllBlocksInfo(string rpcUrl)
        {
            var           CH             = new CliHelper(rpcUrl);
            List <string> transactionIds = new List <string>();

            string method = "get_block_height";
            var    ci     = new CommandInfo(method);

            CH.ExecuteCommand(ci);
            ci.GetJsonInfo();
            var    result        = ci.JsonInfo;
            string countStr      = result["result"]["result"]["block_height"].ToString();
            int    currentHeight = Int32.Parse(countStr);

            for (int i = 1; i <= currentHeight; i++)
            {
                method       = "get_block_info";
                ci           = new CommandInfo(method);
                ci.Parameter = $"{i.ToString()} true";
                CH.ExecuteCommand(ci);
                ci.GetJsonInfo();
                result = ci.JsonInfo;
                string   txcount      = result["result"]["result"]["Body"]["TransactionsCount"].ToString();
                string[] transactions = result["result"]["result"]["Body"]["Transactions"].ToString().Replace("[\n", "").Replace("\n]", "").Replace("\"", "").Split(",");
                foreach (var tx in transactions)
                {
                    if (tx.Trim() != "")
                    {
                        transactionIds.Add(tx.Trim());
                    }

                    /*
                     * method = "get_tx_result";
                     * ci = new CommandInfo(method);
                     * ci.Parameter = tx.Trim();
                     * if (ci.Parameter == "")
                     *  break;
                     * CH.ExecuteCommand(ci);
                     * Thread.Sleep(20);
                     */
                }
                string txPoolSize = result["result"]["result"]["CurrentTransactionPoolSize"].ToString();
                Logger.WriteInfo("Height: {0},  TxCount: {1}, TxPoolSize: {2}, Time: {3}", i, txcount, txPoolSize, DateTime.Now.ToString());
                Thread.Sleep(50);
            }

            //Query tx result informtion
            Logger.WriteInfo("Begin tx result query.");
            for (int i = 0; i < 10; i++)
            {
                foreach (var tx in transactionIds)
                {
                    method       = "get_tx_result";
                    ci           = new CommandInfo(method);
                    ci.Parameter = tx;
                    CH.ExecuteCommand(ci);
                    Thread.Sleep(10);
                }
            }

            Logger.WriteInfo("Complete all query operation.");
        }