Esempio n. 1
0
        public async Task RPC_GetReceipt_Returns_ValueAsync()
        {
            using (var chain = new PoAMockChain(2, this.nodeFactory).Build())
            {
                MockChainNode node1 = chain.Nodes[0];
                MockChainNode node2 = chain.Nodes[1];

                // Get premine
                this.SetupNodes(chain, node1, node2);

                // Create a valid transaction.
                byte[] toSend = ContractCompiler.CompileFile("SmartContracts/StandardToken.cs").Compilation;

                var createParams = new[] { this.methodParameterStringSerializer.Serialize(10000uL) };
                BuildCreateContractTransactionResponse createResponse = node1.SendCreateContractTransaction(toSend, 0, createParams);
                node2.WaitMempoolCount(1);

                chain.MineBlocks(1);

                // Check for the receipt.
                RPCClient rpc    = node2.CoreNode.CreateRPCClient();
                var       result = await rpc.SendCommandAsync("getreceipt", createResponse.TransactionId.ToString());

                Assert.True(result.Result.Value <bool>("success"));

                // Send a token.
                var parameters = new string[]
                {
                    this.methodParameterStringSerializer.Serialize(node1.MinerAddress.Address.ToAddress(node1.CoreNode.FullNode.Network)),
                    this.methodParameterStringSerializer.Serialize(1uL)
                };

                BuildCallContractTransactionResponse callResponse = node1.SendCallContractTransaction("TransferTo", createResponse.NewContractAddress, 0, parameters);

                node2.WaitMempoolCount(1);

                chain.MineBlocks(1);

                result = await rpc.SendCommandAsync("searchreceipts", createResponse.NewContractAddress, "TransferLog");

                Assert.True(result.Result.First.Value <bool>("success"));

                var logs = (JArray)result.Result.First["logs"];
                Assert.NotEmpty(logs);
            }
        }
        public void Create_Signed_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 = new CSharpContractSigner(new ContractSigner()).PackageSignedCSharpFile(this.network.SigningContractPrivKey, "SmartContracts/StorageDemo.cs");

                // 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));
            }
        }
Esempio n. 3
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));
            }
        }