示例#1
0
        public void TestTransactions()
        {
            InitMainNode();

            int addressCount = 20;
            LinkedList <PhantasmaKeys> addressList = new LinkedList <PhantasmaKeys>();

            for (int i = 0; i < addressCount; i++)
            {
                var key = PhantasmaKeys.Generate();

                if (addressList.Contains(key) == false)
                {
                    addressList.AddLast(key);
                }
            }

            var currentKey = addressList.First;

            var masterKeys = PhantasmaKeys.FromWIF(nexusWif);
            //Trace.Message($"Connecting to host: {host} with address {masterKeys.Address.Text}");

            var amount = UnitConversion.ToBigInteger(1000000, DomainSettings.StakingTokenDecimals);
            var hash   = SendTransfer(host, masterKeys, currentKey.Value.Address, amount);

            if (hash == Hash.Null)
            {
                return;
            }

            ConfirmTransaction(host, hash);

            int totalTxs = 0;
            int okTxs    = 0;

            BigInteger currentKeyBalance = GetBalance(currentKey.Value.Address);

            amount = UnitConversion.ToBigInteger(1000000, DomainSettings.FuelTokenDecimals);
            SendTransfer(host, masterKeys, currentKey.Value.Address, amount, "KCAL");

            //while (currentKeyBalance > 9999)
            while (totalTxs < 10)
            {
                var destKey = currentKey.Next != null ? currentKey.Next : addressList.First;

                var txHash = SendTransfer(host, currentKey.Value, destKey.Value.Address, currentKeyBalance - 9999);
                if (txHash == Hash.Null)
                {
                    amount = UnitConversion.ToBigInteger(1000000, DomainSettings.FuelTokenDecimals);
                    SendTransfer(host, masterKeys, currentKey.Value.Address, amount);
                }

                do
                {
                    Thread.Sleep(100);
                } while (!mempool.IsEmpty());

                var confirmation = ConfirmTransaction(host, hash);

                okTxs += confirmation ? 1 : 0;

                totalTxs++;
                currentKey        = destKey;
                currentKeyBalance = GetBalance(currentKey.Value.Address);

                Trace.WriteLine(currentKeyBalance);
            }
            Assert.IsTrue(okTxs == totalTxs);

            CloseNode();
        }