Exemplo n.º 1
0
        public void GenerateRpcList(int threadNo, int times)
        {
            string account = AccountList[ContractList[threadNo].AccountId].Account;
            string abiPath = ContractList[threadNo].AbiPath;

            //Get Increment info
            var ci = new CommandInfo("get_increment");

            ci.Parameter = account;
            CH.ExecuteCommand(ci);
            Assert.IsTrue(ci.Result);
            ci.GetJsonInfo();
            string increNo = ci.JsonInfo["result"]["result"]["increment"].ToString();
            int    number  = Int32.Parse(increNo);

            HashSet <int> set = new HashSet <int>();

            for (int i = 0; i < times; i++)
            {
                Random rd         = new Random(DateTime.Now.Millisecond);
                int    randNumber = rd.Next(ThreadCount, AccountList.Count);
                int    countNo    = randNumber;
                set.Add(countNo);
                string account1 = AccountList[countNo].Account;
                AccountList[countNo].Increment++;

                //Execute Transfer
                string parameterinfo = "{\"from\":\"" + account +
                                       "\",\"to\":\"" + abiPath +
                                       "\",\"method\":\"Transfer\",\"incr\":\"" +
                                       number.ToString() + "\",\"params\":[\"" + account + "\",\"" + account1 + "\",\"1\"]}";
                ci           = new CommandInfo("broadcast_tx");
                ci.Parameter = parameterinfo;
                string requestInfo = CH.RpcGenerateTransactionRawTx(ci);
                ContractRpcList.Enqueue(requestInfo);
                number++;

                //Get Balance Info
                parameterinfo = "{\"from\":\"" + account +
                                "\",\"to\":\"" + abiPath +
                                "\",\"method\":\"GetBalance\",\"incr\":\"" +
                                number.ToString() + "\",\"params\":[\"" + account + "\"]}";
                ci           = new CommandInfo("broadcast_tx");
                ci.Parameter = parameterinfo;
                requestInfo  = CH.RpcGenerateTransactionRawTx(ci);
                ContractRpcList.Enqueue(requestInfo);
                number++;
            }
        }
Exemplo n.º 2
0
        public void GenerateRpcList(int round, int threadNo, int times)
        {
            string account = AccountList[ContractList[threadNo].AccountId].Account;
            string abiPath = ContractList[threadNo].AbiPath;

            HashSet <int> set = new HashSet <int>();

            for (int i = 0; i < times; i++)
            {
                Random rd         = new Random(DateTime.Now.Millisecond);
                int    randNumber = rd.Next(ThreadCount, AccountList.Count);
                int    countNo    = randNumber;
                set.Add(countNo);
                string account1 = AccountList[countNo].Account;
                AccountList[countNo].Increment++;

                //Execute Transfer
                string parameterinfo = "{\"from\":\"" + account +
                                       "\",\"to\":\"" + abiPath +
                                       "\",\"method\":\"Transfer\",\"incr\":\"" +
                                       GetCurrentTimeStamp() + "\",\"params\":[\"" + account + "\",\"" + account1 +
                                       "\",\"1\"]}";
                var ci = new CommandInfo("broadcast_tx");
                ci.Parameter = parameterinfo;
                string requestInfo = CH.RpcGenerateTransactionRawTx(ci);
                ContractRpcList.Enqueue(requestInfo);

                //Get Balance Info
                parameterinfo = "{\"from\":\"" + account +
                                "\",\"to\":\"" + abiPath +
                                "\",\"method\":\"GetBalance\",\"incr\":\"" +
                                GetCurrentTimeStamp() + "\",\"params\":[\"" + account + "\"]}";
                ci           = new CommandInfo("broadcast_tx");
                ci.Parameter = parameterinfo;
                requestInfo  = CH.RpcGenerateTransactionRawTx(ci);
                ContractRpcList.Enqueue(requestInfo);
            }
        }
Exemplo n.º 3
0
        public void GenerateContractList(int threadNo, int times)
        {
            string account = AccountList[ContractList[threadNo].AccountId].Account;
            string abiPath = ContractList[threadNo].AbiPath;

            HashSet <int> set = new HashSet <int>();

            List <string> rpcRequest = new List <string>();

            for (int i = 0; i < times; i++)
            {
                Random rd         = new Random(DateTime.Now.Millisecond);
                int    randNumber = rd.Next(ThreadCount, AccountList.Count);
                int    countNo    = randNumber;
                set.Add(countNo);
                string account1 = AccountList[countNo].Account;
                AccountList[countNo].Increment++;

                //Execute Transfer
                string parameterinfo = "{\"from\":\"" + account +
                                       "\",\"to\":\"" + abiPath +
                                       "\",\"method\":\"Transfer\",\"incr\":\"" +
                                       GetCurrentTimeStamp() + "\",\"params\":[\"" + account + "\",\"" + account1 +
                                       "\",\"1\"]}";
                var ci = new CommandInfo("broadcast_tx");
                ci.Parameter = parameterinfo;
                string requestInfo = CH.RpcGenerateTransactionRawTx(ci);
                rpcRequest.Add(requestInfo);

                //Get Balance Info
                parameterinfo = "{\"from\":\"" + account +
                                "\",\"to\":\"" + abiPath +
                                "\",\"method\":\"GetBalance\",\"incr\":\"" +
                                GetCurrentTimeStamp() + "\",\"params\":[\"" + account + "\"]}";
                ci           = new CommandInfo("broadcast_tx");
                ci.Parameter = parameterinfo;
                requestInfo  = CH.RpcGenerateTransactionRawTx(ci);
                rpcRequest.Add(requestInfo);
            }

            Logger.WriteInfo(
                "Thread [{0}] contracts rpc list from account :{1} and contract abi: {2} generated completed.",
                threadNo, account, abiPath);
            //Send RPC Requests
            var ci1 = new CommandInfo("broadcast_txs");

            foreach (var rpc in rpcRequest)
            {
                ci1.Parameter += "," + rpc;
            }

            ci1.Parameter = ci1.Parameter.Substring(1);
            CH.ExecuteCommand(ci1);
            Assert.IsTrue(ci1.Result);
            var result = ci1.InfoMsg[0].Replace("[", "").Replace("]", "").Split(",");

            Logger.WriteInfo("Batch request count: {0}, Pass count: {1} at {2}", rpcRequest.Count, result.Length,
                             DateTime.Now.ToString("HH:mm:ss.fff"));
            Logger.WriteInfo("Thread [{0}] completeed executed {1} times contracts work at {2}.", threadNo, times,
                             DateTime.Now.ToString());
            Logger.WriteInfo("{0} Transfer from Address {1}", set.Count, account);
            Thread.Sleep(100);
        }
Exemplo n.º 4
0
 public string GenerateBroadcastRawTx(string method, params string[] paramArray)
 {
     return(CH.RpcGenerateTransactionRawTx(Account, ContractAbi, method, paramArray));
 }