コード例 #1
0
        public void SendOneMillionCoinsFromPowWalletToPosWallet()
        {
            var context = SharedSteps.CreateTransactionBuildContext(
                this.PowWallet,
                this.WalletAccount,
                this.PowWalletPassword,
                new List <Recipient>()
            {
                new Recipient {
                    Amount = Money.COIN * 1000000, ScriptPubKey = this.posReceiverAddress.ScriptPubKey
                }
            },
                FeeType.Medium,
                101);

            context.OverrideFeeRate = new FeeRate(Money.Satoshis(20000));

            var unspent = this.nodes[this.PowMiner].FullNode.WalletManager().GetSpendableTransactionsInWallet(this.PowWallet);
            var coins   = new List <Coin>();

            var blockTimestamp = unspent.OrderBy(u => u.Transaction.CreationTime).Select(ts => ts.Transaction.CreationTime).First();
            var transaction    = new Transaction
            {
                Time = (uint)blockTimestamp.ToUnixTimeSeconds()
            };

            foreach (var item in unspent.OrderByDescending(a => a.Transaction.Amount))
            {
                coins.Add(new Coin(item.Transaction.Id, (uint)item.Transaction.Index, item.Transaction.Amount, item.Transaction.ScriptPubKey));
            }

            var coin = coins.First();
            var txIn = transaction.AddInput(new TxIn(coin.Outpoint, this.powSenderAddress.ScriptPubKey));

            transaction.AddOutput(new TxOut(new Money(9699999999995400), this.powSenderAddress.ScriptPubKey));
            transaction.AddOutput(new TxOut(new Money(100000000000000), this.posReceiverAddress.ScriptPubKey));
            transaction.Sign(this.powSenderPrivateKey, new[] { coin });

            this.nodes[this.PowMiner].FullNode.NodeService <WalletController>().SendTransaction(new SendTransactionRequest(transaction.ToHex()));
        }
コード例 #2
0
        public void MiningNodeWithOneConnectionAlwaysSynced()
        {
            const string miner          = "miner";
            const string connector      = "connector";
            const string node1          = "networkNode1";
            const string node2          = "networkNode2";
            const string walletName     = "dummyWallet";
            const string walletPassword = "******";

            var    sharedSteps    = new SharedSteps();
            string testFolderPath = Path.Combine(this.GetType().Name, nameof(MiningNodeWithOneConnectionAlwaysSynced));

            using (var builder = new NodeGroupBuilder(testFolderPath))
            {
                var nodes = builder.StratisPowNode(miner).Start().NotInIBD().WithWallet(walletName, walletPassword)
                            .StratisPowNode(connector).Start().NotInIBD().WithWallet(walletName, walletPassword)
                            .StratisPowNode(node1).Start().NotInIBD().WithWallet(walletName, walletPassword)
                            .StratisPowNode(node2).Start().NotInIBD().WithWallet(walletName, walletPassword)
                            .WithConnections()
                            .Connect(miner, connector)
                            .Connect(connector, node1).Connect(connector, node2)
                            .Connect(node1, node2)
                            .AndNoMoreConnections().Build();

                nodes.Values.ToList().ForEach(n =>
                {
                    sharedSteps.MineBlocks(1, n, "account 0", walletName, walletPassword);
                    sharedSteps.WaitForNodeToSync(nodes.Values.ToArray());
                });

                int networkHeight = nodes[miner].FullNode.Chain.Height;
                Assert.Equal(networkHeight, nodes.Count);

                // Random node on network generates a block.
                nodes[node1].GenerateStratisWithMiner(1);

                // Wait until connector get the hash of network's block.
                while ((nodes[connector].FullNode.ChainBehaviorState.ConsensusTip.HashBlock != nodes[node1].FullNode.ChainBehaviorState.ConsensusTip.HashBlock) ||
                       (nodes[node1].FullNode.ChainBehaviorState.ConsensusTip.Height == networkHeight))
                {
                    Thread.Sleep(1);
                }

                Assert.Equal(nodes[connector].FullNode.Chain.Tip.HashBlock, nodes[node1].FullNode.Chain.Tip.HashBlock);
                Assert.Equal(nodes[miner].FullNode.Chain.Tip.Height, networkHeight);
                Assert.Equal(nodes[connector].FullNode.Chain.Tip.Height, networkHeight + 1);

                // Miner mines the block.
                nodes[miner].GenerateStratisWithMiner(1);
                TestHelper.WaitLoop(() => TestHelper.IsNodeSynced(nodes[miner]));

                networkHeight++;

                Assert.Equal(nodes[connector].FullNode.Chain.Tip.HashBlock, nodes[node1].FullNode.Chain.Tip.HashBlock);
                Assert.Equal(nodes[miner].FullNode.Chain.Tip.Height, networkHeight);
                Assert.Equal(nodes[connector].FullNode.Chain.Tip.Height, networkHeight);

                nodes[connector].GenerateStratisWithMiner(1);
                networkHeight++;

                sharedSteps.WaitForNodeToSync(nodes.Values.ToArray());

                nodes.Values.All(n => n.FullNode.Chain.Height == networkHeight).Should()
                .BeTrue(because: "all nodes have synced to chain height");

                Assert.Equal(nodes[node1].FullNode.Chain.Tip.HashBlock, nodes[miner].FullNode.Chain.Tip.HashBlock);
            }
        }
コード例 #3
0
 public ProofOfStakeSteps(string displayName)
 {
     this.sharedSteps      = new SharedSteps();
     this.NodeGroupBuilder = new NodeGroupBuilder(Path.Combine(this.GetType().Name, displayName), KnownNetworks.StratisRegTest);
 }
コード例 #4
0
 public ProofOfStakeSteps(string displayName)
 {
     this.sharedSteps      = new SharedSteps();
     this.NodeGroupBuilder = new NodeGroupBuilder(Path.Combine(this.GetType().Name, displayName));
 }
コード例 #5
0
 public ProofOfStakeSteps(string displayName)
 {
     this.sharedSteps      = new SharedSteps();
     this.nodeGroupBuilder = new NodeGroupBuilder(displayName);
 }