Пример #1
0
        public async Task Create_NoWhitelist_Mempool_Rejects()
        {
            using (var chain = new PoAMockChain(2, this.nodeFactory).Build())
            {
                MockChainNode node1 = chain.Nodes[0];
                MockChainNode node2 = chain.Nodes[1];
                this.SetupNodes(chain, node1, node2);

                // Create a valid transaction.
                byte[] toSend      = ContractCompiler.CompileFile("SmartContracts/StorageDemo.cs").Compilation;
                var    buildResult = node1.BuildCreateContractTransaction(toSend, 0);

                Transaction tx = node1.CoreNode.FullNode.Network.CreateTransaction(buildResult.Hex);

                var broadcasterManager = node1.CoreNode.FullNode.NodeService <IBroadcasterManager>();

                await broadcasterManager.BroadcastTransactionAsync(tx);

                // Give it enough time to reach if it was valid.
                Thread.Sleep(3000);

                // Nothing arrives.
                Assert.Empty(node1.CoreNode.CreateRPCClient().GetRawMempool());

                // If we were to whitelist it later, the mempool increases.
                chain.WhitelistCode(toSend);

                await broadcasterManager.BroadcastTransactionAsync(tx);

                node1.WaitMempoolCount(1);
            }
        }
Пример #2
0
        public void Create_Whitelisted_Contract()
        {
            using (var chain = new PoAMockChain(2, this.nodeFactory).Build())
            {
                MockChainNode node1 = chain.Nodes[0];
                MockChainNode node2 = chain.Nodes[1];
                this.SetupNodes(chain, node1, node2);

                // Compile file
                byte[] toSend = ContractCompiler.CompileFile("SmartContracts/StorageDemo.cs").Compilation;

                // Add the hash to all the nodes on the chain.
                chain.WhitelistCode(toSend);

                // Send create with value, and ensure balance is stored.
                BuildCreateContractTransactionResponse sendResponse = node1.SendCreateContractTransaction(toSend, 30);
                node1.WaitMempoolCount(1);
                chain.MineBlocks(1);

                // Check the balance exists at contract location.
                Assert.Equal((ulong)30 * 100_000_000, node1.GetContractBalance(sendResponse.NewContractAddress));
            }
        }