示例#1
0
 public LoadTestSupervisorOptions()
 {
     InstanceOptions = new LoadTestOptions
     {
         Timeout = TimeSpan.FromMinutes(30)
     };
 }
示例#2
0
        static int RunLoadTest(LoadTestOptions opts)
        {
            var wallet = OpenWallet(opts);

            if (wallet == null)
            {
                return(1);
            }

            // create tags/addresses
            Console.WriteLine("::create tags/addrs");
            var one = "1"; var two = "2"; var cons = "consolidate";
            var tags = new string[] { one, two, cons };

            foreach (var tag in tags)
            {
                Console.WriteLine($"  - {tag}");
                if (!wallet.HasTag(tag))
                {
                    wallet.NewTag(tag);
                    wallet.Save();
                }
                var addr = wallet.NewOrExistingAddress(tag);
                Console.WriteLine($"    {addr.Address}");
            }
            wallet.Save();
            Console.WriteLine();

            for (var n = 0; n < opts.Count; n++)
            {
                // send funds to wallet addresses
                BigInteger    fee          = 0;
                BigInteger    feeUnit      = 0;
                BigInteger    feeMax       = 0;
                List <string> sentTxids    = null;
                string        originalAddr = null;
                if (wallet is BtcWallet)
                {
                    (var origAddr_, var withoutErrors, var sentTxIds_) = LoadTest.SendBtcFunds(wallet.IsMainnet(), opts.PrivateKey, wallet.GetAddresses(one).First().Address, wallet.GetAddresses(two).First().Address);
                    originalAddr = origAddr_;
                    sentTxids    = sentTxIds_;
                    fee          = 113;
                    feeUnit      = 1;
                    feeMax       = 10000;
                }
                else if (wallet is ZapWallet)
                {
                    (var origAddr_, var withoutErrors, var sentTxIds_) = LoadTest.SendZapFunds(wallet.IsMainnet(), opts.PrivateKey, wallet.GetAddresses(one).First().Address, wallet.GetAddresses(two).First().Address);
                    originalAddr = origAddr_;
                    sentTxids    = sentTxIds_;
                    fee          = 1;
                    feeUnit      = fee;
                    feeMax       = fee * 2;
                }
                else if (wallet is WavWallet)
                {
                    (var origAddr_, var withoutErrors, var sentTxIds_) = LoadTest.SendWavesFunds(wallet.IsMainnet(), opts.PrivateKey, wallet.GetAddresses(one).First().Address, wallet.GetAddresses(two).First().Address);
                    originalAddr = origAddr_;
                    sentTxids    = sentTxIds_;
                    fee          = 100000;
                    feeUnit      = fee;
                    feeMax       = fee * 2;
                }
                else if (wallet is EthWallet)
                {
                    throw new ApplicationException("TODO eth");
                }
                if (sentTxids.Count > 0)
                {
                    // sleep for a bit to wait for the tx to propagate
                    foreach (var i in Enumerable.Range(1, 10))
                    {
                        Console.Write(".");
                        System.Threading.Thread.Sleep(1000);
                    }
                }
                Console.WriteLine("\n");

                // consolidate
                Console.WriteLine("::consolidate");
                var dbtx = wallet.BeginDbTransaction();
                wallet.UpdateFromBlockchain(dbtx);
                wallet.Save();
                dbtx.Commit();
                var balance = wallet.GetBalance(new string[] { one, two });
                if (balance > 0)
                {
                    var err = wallet.Consolidate(new string[] { one, two }, cons, feeMax, feeUnit, out var wtxs);
                    foreach (var tx in wtxs)
                    {
                        Console.WriteLine($"  - {tx.ChainTx.TxId}");
                    }
                    Console.WriteLine($"  {err}");
                    wallet.Save();
                    if (err != WalletError.Success)
                    {
                        return(1);
                    }
                    // sleep for a bit to wait for the tx to propagate
                    foreach (var i in Enumerable.Range(1, 10))
                    {
                        Console.Write(".");
                        System.Threading.Thread.Sleep(1000);
                    }
                }
                else
                {
                    Console.WriteLine("  no balance.. skipping");
                }
                Console.WriteLine("\n");

                // send to original address
                Console.WriteLine("::send back to original address");
                dbtx = wallet.BeginDbTransaction();
                wallet.UpdateFromBlockchain(dbtx);
                wallet.Save();
                dbtx.Commit();
                balance = wallet.GetBalance(cons);
                if (balance > 0)
                {
                    var err = wallet.Spend(cons, cons, originalAddr, balance - fee, feeMax, feeUnit, out var wtxs);
                    foreach (var tx in wtxs)
                    {
                        Console.WriteLine($"  - {tx.ChainTx.TxId}");
                    }
                    Console.WriteLine($"  {err}");
                    wallet.Save();
                    if (err != WalletError.Success)
                    {
                        return(1);
                    }
                }
                else
                {
                    Console.WriteLine("  no balance.. skipping");
                }
                Console.WriteLine();
            }

            return(0);
        }