コード例 #1
0
ファイル: Program.cs プロジェクト: Nethereum/TestPerformance
        public static async Task RunWriteTest(Web3 web3)
        {
            var listTasks = 500;

            var taskItems = new List <int>();

            for (var i = 0; i < listTasks; i++)
            {
                taskItems.Add(i);
            }

            var numProcs             = Environment.ProcessorCount;
            var concurrencyLevel     = numProcs * 2;
            var concurrentDictionary = new ConcurrentDictionary <int, string>(concurrencyLevel, listTasks * 2);

            var sw = Stopwatch.StartNew();

            Console.WriteLine("Deployment contracts:" + listTasks);
            await taskItems.ParallelForEachAsync(async (item, state) =>

                                                 //foreach (var item in taskItems)
            {
                var txnx = await StandardTokenService.DeployContractAsync(web3,
                                                                          new EIP20Deployment()
                {
                    TokenName = "TST", InitialAmount = 1000, TokenSymbol = "TST"
                });

                concurrentDictionary.TryAdd(item, txnx);
            }
                                                 , maxDegreeOfParalellism : 10);

            sw.Stop();
            Console.WriteLine("Done sending transactions in " + sw.ElapsedMilliseconds + "ms");

            Console.WriteLine();
            Console.WriteLine("Polling receipts....");

            var pollService = new TransactionReceiptPollingService(web3.TransactionManager);

            for (var i = 0; i < listTasks; i++)
            {
                string txn = null;
                concurrentDictionary.TryGetValue(i, out txn);
                var receipt = await pollService.PollForReceiptAsync(txn);

                if (i == listTasks - 1)
                {
                    Console.WriteLine("Last contract address:");
                    Console.WriteLine(receipt.ContractAddress);
                }
            }

            Console.WriteLine();
        }
コード例 #2
0
        public async void ShouldDeployAContractWithValueAndSendAValueUsingSignAndSend()
        {
            var contractByteCode =
                "0x6060604052600180546c0100000000000000000000000033810204600160a060020a03199091161790556002340460008190556002023414603e576002565b6103258061004c6000396000f3606060405236156100615760e060020a600035046308551a53811461006657806335a063b41461007d5780633fa4f245146100a05780637150d8ae146100ae57806373fac6f0146100c5578063c19d93fb146100e8578063d696069714610101575b610002565b346100025761011f600154600160a060020a031681565b346100025761013b60015433600160a060020a0390811691161461014f57610002565b346100025761013d60005481565b346100025761011f600254600160a060020a031681565b346100025761013b60025433600160a060020a039081169116146101e457610002565b346100025761013d60025460ff60a060020a9091041681565b61013b60025460009060ff60a060020a90910416156102a457610002565b60408051600160a060020a039092168252519081900360200190f35b005b60408051918252519081900360200190f35b60025460009060a060020a900460ff161561016957610002565b6040517f80b62b7017bb13cf105e22749ee2a06a417ffba8c7f57b665057e0f3c2e925d990600090a16040516002805460a160020a60a060020a60ff0219909116179055600154600160a060020a0390811691309091163180156108fc02916000818181858888f1935050505015156101e157610002565b50565b60025460019060a060020a900460ff1681146101ff57610002565b6040517f64ea507aa320f07ae13c28b5e9bf6b4833ab544315f5f2aa67308e21c252d47d90600090a16040516002805460a060020a60ff02191660a160020a179081905560008054600160a060020a03909216926108fc8315029291818181858888f19350505050158061029a5750600154604051600160a060020a039182169130163180156108fc02916000818181858888f19350505050155b156101e157610002565b6000546002023414806102b657610002565b6040517f764326667cab2f2f13cad5f7b7665c704653bd1acc250dcb7b422bce726896b490600090a150506002805460a060020a73ffffffffffffffffffffffffffffffffffffffff199091166c01000000000000000000000000338102041760a060020a60ff02191617905556";

            var abi =
                "[{'constant':true,'inputs':[],'name':'seller','outputs':[{'name':'','type':'address'}],'payable':false,'type':'function'},{'constant':false,'inputs':[],'name':'abort','outputs':[],'payable':false,'type':'function'},{'constant':true,'inputs':[],'name':'value','outputs':[{'name':'','type':'uint256'}],'payable':false,'type':'function'},{'constant':true,'inputs':[],'name':'buyer','outputs':[{'name':'','type':'address'}],'payable':false,'type':'function'},{'constant':false,'inputs':[],'name':'confirmReceived','outputs':[],'payable':false,'type':'function'},{'constant':true,'inputs':[],'name':'state','outputs':[{'name':'','type':'uint8'}],'payable':false,'type':'function'},{'constant':false,'inputs':[],'name':'confirmPurchase','outputs':[],'payable':true,'type':'function'},{'inputs':[],'type':'constructor'},{'anonymous':false,'inputs':[],'name':'aborted','type':'event'},{'anonymous':false,'inputs':[],'name':'purchaseConfirmed','type':'event'},{'anonymous':false,'inputs':[],'name':'itemReceived','type':'event'}]";


            var senderAddress = EthereumClientIntegrationFixture.AccountAddress;
            var web3          = _ethereumClientIntegrationFixture.GetWeb3();

            var transaction =
                await
                web3.Eth.DeployContract.SendRequestAsync(abi, contractByteCode,
                                                         senderAddress, new HexBigInteger(900000), new HexBigInteger(10000));

            var pollingService = new TransactionReceiptPollingService(web3.TransactionManager);
            var receipt        = await pollingService.PollForReceiptAsync(transaction);

            var contract = web3.Eth.GetContract(abi, receipt.ContractAddress);

            //get the function by name
            var valueFuntion = contract.GetFunction("value");

            //do a function call (not transaction) and get the result
            var callResult = await valueFuntion.CallAsync <int>();

            Assert.Equal(5000, callResult);

            var confirmPurchaseFunction = contract.GetFunction("confirmPurchase");
            var tx = await confirmPurchaseFunction.SendTransactionAsync(senderAddress,
                                                                        new HexBigInteger(900000), new HexBigInteger(10000));

            receipt = await pollingService.PollForReceiptAsync(tx);

            var stateFunction = contract.GetFunction("state");

            callResult = await stateFunction.CallAsync <int>();

            Assert.Equal(1, callResult);
        }
コード例 #3
0
        public async void ShouldBeAbleToHandleNoncesOfMultipleTxnMultipleWeb3sSingleThreaded()
        {
            var senderAddress = "0x12890d2cce102216644c59daE5baed380d84830c";
            var privateKey    = "0xb5b1870957d373ef0eeffecc6e4812c0fd08f554b37b233526acc331bf1544f7";
            var abi           = @"[{""constant"":false,""inputs"":[{""name"":""val"",""type"":""int256""}],""name"":""multiply"",""outputs"":[{""name"":""d"",""type"":""int256""}],""type"":""function""},{""inputs"":[{""name"":""multiplier"",""type"":""int256""}],""type"":""constructor""}]";
            var byteCode      =
                "0x60606040526040516020806052833950608060405251600081905550602b8060276000396000f3606060405260e060020a60003504631df4f1448114601a575b005b600054600435026060908152602090f3";

            var multiplier = 7;

            var client        = ClientFactory.GetClient();
            var nonceProvider = new InMemoryNonceService(senderAddress, client);
            var account       = new Account(privateKey)
            {
                NonceService = nonceProvider
            };
            var web31 = new Web3(account, client);

            var txn1 = await
                       web31.Eth.DeployContract.SendRequestAsync(abi, byteCode, senderAddress, new HexBigInteger(900000), null, multiplier);

            var web32 = new Web3(account, client);


            var txn2 = await
                       web32.Eth.DeployContract.SendRequestAsync(abi, byteCode, senderAddress, new HexBigInteger(900000), null, multiplier);

            var web33 = new Web3(account, client);

            var txn3 = await
                       web33.Eth.DeployContract.SendRequestAsync(abi, byteCode, senderAddress, new HexBigInteger(900000), null, multiplier);

            var pollService = new TransactionReceiptPollingService(web31.TransactionManager);

            var receipt1 = pollService.PollForReceiptAsync(txn1);
            var receipt2 = pollService.PollForReceiptAsync(txn2);
            var receipt3 = pollService.PollForReceiptAsync(txn3);

            Assert.NotNull(receipt1);
            Assert.NotNull(receipt2);
            Assert.NotNull(receipt3);
        }
コード例 #4
0
ファイル: NonceTests.cs プロジェクト: huyen-pk/Nethereum
        public async void ShouldBeAbleToHandleNoncesOfMultipleTxnMultipleWeb3sMultithreaded()
        {
            var senderAddress = EthereumClientIntegrationFixture.AccountAddress;
            var privateKey    = EthereumClientIntegrationFixture.AccountPrivateKey;
            var abi           =
                @"[{""constant"":false,""inputs"":[{""name"":""val"",""type"":""int256""}],""name"":""multiply"",""outputs"":[{""name"":""d"",""type"":""int256""}],""type"":""function""},{""inputs"":[{""name"":""multiplier"",""type"":""int256""}],""type"":""constructor""}]";
            var byteCode =
                "0x60606040526040516020806052833950608060405251600081905550602b8060276000396000f3606060405260e060020a60003504631df4f1448114601a575b005b600054600435026060908152602090f3";

            JsonRpc.Client.RpcClient.ConnectionTimeout = TimeSpan.FromSeconds(30.0);
            var multiplier = 7;

            var client        = _ethereumClientIntegrationFixture.GetClient();
            var nonceProvider = new InMemoryNonceService(senderAddress, client);
            //tested with 1000
            var listTasks = 10;
            var taskItems = new List <int>();

            for (var i = 0; i < listTasks; i++)
            {
                taskItems.Add(i);
            }

            var numProcs             = Environment.ProcessorCount;
            var concurrencyLevel     = numProcs * 2;
            var concurrentDictionary = new ConcurrentDictionary <int, string>(concurrencyLevel, listTasks * 2);


            Parallel.ForEach(taskItems, (item, state) =>
            {
                var account          = new Account(privateKey, EthereumClientIntegrationFixture.ChainId);
                account.NonceService = nonceProvider;
                var web3             = new Web3.Web3(account, client);
                // Wait for task completion synchronously in order to Parallel.ForEach work correctly
                var txn = web3.Eth.DeployContract.SendRequestAsync(abi, byteCode, senderAddress, new HexBigInteger(900000),
                                                                   null, multiplier).Result;
                concurrentDictionary.TryAdd(item, txn);
            });

            var web31       = new Web3.Web3(new Account(privateKey), client);
            var pollService = new TransactionReceiptPollingService(web31.TransactionManager);

            for (var i = 0; i < listTasks; i++)
            {
                string txn = null;
                concurrentDictionary.TryGetValue(i, out txn);
                var receipt = await pollService.PollForReceiptAsync(txn).ConfigureAwait(false);

                Assert.NotNull(receipt);
            }
        }
コード例 #5
0
        public async void ShouldBeAbleToHandleNoncesOfMultipleTxnMultipleWeb3sMultithreaded()
        {
            var senderAddress = "0x12890d2cce102216644c59daE5baed380d84830c";
            var privateKey    = "0xb5b1870957d373ef0eeffecc6e4812c0fd08f554b37b233526acc331bf1544f7";
            var abi           =
                @"[{""constant"":false,""inputs"":[{""name"":""val"",""type"":""int256""}],""name"":""multiply"",""outputs"":[{""name"":""d"",""type"":""int256""}],""type"":""function""},{""inputs"":[{""name"":""multiplier"",""type"":""int256""}],""type"":""constructor""}]";
            var byteCode =
                "0x60606040526040516020806052833950608060405251600081905550602b8060276000396000f3606060405260e060020a60003504631df4f1448114601a575b005b600054600435026060908152602090f3";

            var multiplier = 7;

            var client        = ClientFactory.GetClient();
            var nonceProvider = new InMemoryNonceService(senderAddress, client);
            //tested with 1000
            var listTasks = 10;
            var taskItems = new List <int>();

            for (var i = 0; i < listTasks; i++)
            {
                taskItems.Add(i);
            }

            var numProcs             = Environment.ProcessorCount;
            var concurrencyLevel     = numProcs * 2;
            var concurrentDictionary = new ConcurrentDictionary <int, string>(concurrencyLevel, listTasks * 2);


            Parallel.ForEach(taskItems, (item, state) =>
            {
                var account          = new Account(privateKey);
                account.NonceService = nonceProvider;
                var web3             = new Web3.Web3(account, client);
                // Wait for task completion synchronously in order to Parallel.ForEach work correctly
                var txn = web3.Eth.DeployContract.SendRequestAsync(abi, byteCode, senderAddress, new HexBigInteger(900000),
                                                                   null, multiplier).Result;
                concurrentDictionary.TryAdd(item, txn);
            });

            var web31       = new Web3.Web3(new Account(privateKey), client);
            var pollService = new TransactionReceiptPollingService(web31.TransactionManager);

            for (var i = 0; i < listTasks; i++)
            {
                string txn = null;
                concurrentDictionary.TryGetValue(i, out txn);
                var receipt = await pollService.PollForReceiptAsync(txn);

                Assert.NotNull(receipt);
            }
        }
コード例 #6
0
        public async void Test()
        {
            var web3            = _ethereumClientIntegrationFixture.GetWeb3();
            var accountAddresss = EthereumClientIntegrationFixture.AccountAddress;
            var pollingService  = new TransactionReceiptPollingService(web3.TransactionManager);
            var contractAddress = await pollingService.DeployContractAndGetAddressAsync(() =>
                                                                                        CoinService.DeployContractAsync(web3, accountAddresss, new HexBigInteger(4000000)))
                                  .ConfigureAwait(false);

            var coinService = new CoinService(web3, contractAddress);
            var txn         = await coinService.MintAsync(accountAddresss, accountAddresss, 100, new HexBigInteger(4000000))
                              .ConfigureAwait(false);

            var receipt = await pollingService.PollForReceiptAsync(txn).ConfigureAwait(false);

            var eventSent = coinService.GetEventSent();
            var sent      = await eventSent.GetAllChangesAsync <SentEventDTO>(eventSent.CreateFilterInput())
                            .ConfigureAwait(false);

            txn = await coinService.RaiseEventMetadataAsync(accountAddresss, accountAddresss, 100, "Description",
                                                            "The metadata created here blah blah blah", new HexBigInteger(4000000)).ConfigureAwait(false);

            receipt = await pollingService.PollForReceiptAsync(txn).ConfigureAwait(false);

            var metadataEvent = coinService.GetEventMetadataEvent();
            var metadata      =
                await metadataEvent.GetAllChangesAsync <MetadataEventEventDTO>(
                    metadataEvent.CreateFilterInput(new BlockParameter(receipt.BlockNumber), null))
                .ConfigureAwait(false);

            var result = metadata[0].Event;

            Assert.Equal(result.Creator.ToLower(), accountAddresss.ToLower());
            Assert.Equal(100, result.Id);
            Assert.Equal("The metadata created here blah blah blah", result.Metadata);
            Assert.Equal("Description", result.Description);
        }
コード例 #7
0
ファイル: NonceTests.cs プロジェクト: huyen-pk/Nethereum
        public async void ShouldBeAbleToHandleNoncesOfMultipleTxnSingleWeb3SingleThreaded()
        {
            var senderAddress = EthereumClientIntegrationFixture.AccountAddress;
            var privateKey    = EthereumClientIntegrationFixture.AccountPrivateKey;
            var abi           =
                @"[{""constant"":false,""inputs"":[{""name"":""val"",""type"":""int256""}],""name"":""multiply"",""outputs"":[{""name"":""d"",""type"":""int256""}],""type"":""function""},{""inputs"":[{""name"":""multiplier"",""type"":""int256""}],""type"":""constructor""}]";
            var byteCode =
                "0x60606040526040516020806052833950608060405251600081905550602b8060276000396000f3606060405260e060020a60003504631df4f1448114601a575b005b600054600435026060908152602090f3";

            var multiplier = 7;

            var web3 = new Web3.Web3(new Account(privateKey, EthereumClientIntegrationFixture.ChainId), _ethereumClientIntegrationFixture.GetClient());

            var txn1 = await
                       web3.Eth.DeployContract.SendRequestAsync(abi, byteCode, senderAddress, new HexBigInteger(900000), null,
                                                                multiplier).ConfigureAwait(false);

            var txn2 = await
                       web3.Eth.DeployContract.SendRequestAsync(abi, byteCode, senderAddress, new HexBigInteger(900000), null,
                                                                multiplier).ConfigureAwait(false);

            var txn3 = await
                       web3.Eth.DeployContract.SendRequestAsync(abi, byteCode, senderAddress, new HexBigInteger(900000), null,
                                                                multiplier).ConfigureAwait(false);

            var pollService = new TransactionReceiptPollingService(web3.TransactionManager);

            var receipt1 = await pollService.PollForReceiptAsync(txn1).ConfigureAwait(false);

            var receipt2 = await pollService.PollForReceiptAsync(txn2).ConfigureAwait(false);

            var receipt3 = await pollService.PollForReceiptAsync(txn3).ConfigureAwait(false);

            Assert.NotNull(receipt1);
            Assert.NotNull(receipt2);
            Assert.NotNull(receipt3);
        }
コード例 #8
0
        public async Task <string> SendEthAsync(string target, double amount)
        {
            if (target == null)
            {
                throw new ArgumentNullException(nameof(target));
            }

            var tx = await m_Web3.Eth.TransactionManager.SendTransactionAsync(
                m_WalletAddress, target, new HexBigInteger((BigInteger)(amount *WeisInEth)));

            var txPollingService = new TransactionReceiptPollingService(m_Web3.TransactionManager);
            await txPollingService.PollForReceiptAsync(tx);

            return(tx);
        }