public async void ShouldDeployForwarder_TransferEther_CloneItUsingFactory_FlushEtherManyClonesUsingFactory() { var destinationAddress = "0x6C547791C3573c2093d81b919350DB1094707011"; //Using ropsten infura //var web3 = _ethereumClientIntegrationFixture.GetInfuraWeb3(InfuraNetwork.Ropsten); var web3 = _ethereumClientIntegrationFixture.GetWeb3(); //Getting the current Ether balance of the destination, we are going to transfer 0.001 ether var balanceDestination = await web3.Eth.GetBalance.SendRequestAsync(destinationAddress); var balanceDestinationEther = Web3.Web3.Convert.FromWei(balanceDestination); //Deploying first the default forwarder (template for all clones) var defaultForwarderDeploymentReceipt = await ForwarderService.DeployContractAndWaitForReceiptAsync(web3, new ForwarderDeployment()); var defaultForwaderContractAddress = defaultForwarderDeploymentReceipt.ContractAddress; var defaultForwarderService = new ForwarderService(web3, defaultForwaderContractAddress); //initialiasing with the destination address await defaultForwarderService.ChangeDestinationRequestAndWaitForReceiptAsync(destinationAddress); var destinationInContract = await defaultForwarderService.DestinationQueryAsync(); //validate the destination address has been set correctly Assert.True(destinationInContract.IsTheSameAddress(destinationAddress)); //Deploying the factory var factoryDeploymentReceipt = await ForwarderFactoryService.DeployContractAndWaitForReceiptAsync(web3, new ForwarderFactoryDeployment()); var factoryAddress = factoryDeploymentReceipt.ContractAddress; var factoryService = new ForwarderFactoryService(web3, factoryDeploymentReceipt.ContractAddress); var addresses = await SendEtherAndCreateClones(50, web3, factoryService, 0.001M, factoryAddress, defaultForwaderContractAddress); //Flushing from the factory var flushAllReceipt = await factoryService.FlushEtherRequestAndWaitForReceiptAsync(addresses); //check here the cost ^^^ var totalEtherTransfered = 0.001M * addresses.Count; var newbalanceDestination = await web3.Eth.GetBalance.SendRequestAsync(destinationAddress); Assert.Equal(totalEtherTransfered + balanceDestinationEther, Web3.Web3.Convert.FromWei(newbalanceDestination)); }
public async void ShouldDeployForwarder_TransferEther_CloneItUsingFactory_FlushEther2ClonesUsingFactory() { var destinationAddress = "0x6C547791C3573c2093d81b919350DB1094707011"; //Using ropsten infura //var web3 = _ethereumClientIntegrationFixture.GetInfuraWeb3(InfuraNetwork.Ropsten); var web3 = _ethereumClientIntegrationFixture.GetWeb3(); //Getting the current Ether balance of the destination, we are going to transfer 0.001 ether var balanceDestination = await web3.Eth.GetBalance.SendRequestAsync(destinationAddress); var balanceDestinationEther = Web3.Web3.Convert.FromWei(balanceDestination); //Deploying first the default forwarder (template for all clones) var defaultForwarderDeploymentReceipt = await ForwarderService.DeployContractAndWaitForReceiptAsync(web3, new ForwarderDeployment()); var defaultForwaderContractAddress = defaultForwarderDeploymentReceipt.ContractAddress; var defaultForwarderService = new ForwarderService(web3, defaultForwaderContractAddress); //initialiasing with the destination address await defaultForwarderService.ChangeDestinationRequestAndWaitForReceiptAsync(destinationAddress); var destinationInContract = await defaultForwarderService.DestinationQueryAsync(); //validate the destination address has been set correctly Assert.True(destinationInContract.IsTheSameAddress(destinationAddress)); //Deploying the factory var factoryDeploymentReceipt = await ForwarderFactoryService.DeployContractAndWaitForReceiptAsync(web3, new ForwarderFactoryDeployment()); var factoryAddress = factoryDeploymentReceipt.ContractAddress; var factoryService = new ForwarderFactoryService(web3, factoryDeploymentReceipt.ContractAddress); //Lets create new contract to be paid var salt = BigInteger.Parse("12"); //salt id var saltHex = new IntTypeEncoder().Encode(salt).ToHex(); //Calculate the new contract address var contractCalculatedAddress = CalculateCreate2AddressMinimalProxy(factoryAddress, saltHex, defaultForwaderContractAddress); //Let's tranfer some ether, with some extra gas to allow forwarding if the smart contract is deployed (UX problem) var transferEtherReceipt = await web3.Eth.GetEtherTransferService().TransferEtherAndWaitForReceiptAsync(contractCalculatedAddress, (decimal)0.001, null, 4500000); //Lets create new contract to be paid var salt2 = BigInteger.Parse("13"); //salt id var saltHex2 = new IntTypeEncoder().Encode(salt2).ToHex(); //Calculate the new contract address var contractCalculatedAddress2 = CalculateCreate2AddressMinimalProxy(factoryAddress, saltHex2, defaultForwaderContractAddress); //Let's tranfer some ether, with some extra gas to allow forwarding if the smart contract is deployed (UX problem) var transferEtherReceipt2 = await web3.Eth.GetEtherTransferService().TransferEtherAndWaitForReceiptAsync(contractCalculatedAddress2, (decimal)0.001, null, 4500000); //Create the clone with the salt to match the address var txnReceipt = await factoryService.CloneForwarderRequestAndWaitForReceiptAsync(defaultForwaderContractAddress, salt); var clonedAdress = txnReceipt.DecodeAllEvents <ForwarderClonedEventDTO>()[0].Event.ClonedAdress; Assert.True(clonedAdress.IsTheSameAddress(contractCalculatedAddress)); //Create the clone2 with the salt to match the address var txnReceipt2 = await factoryService.CloneForwarderRequestAndWaitForReceiptAsync(defaultForwaderContractAddress, salt2); var clonedAdress2 = txnReceipt2.DecodeAllEvents <ForwarderClonedEventDTO>()[0].Event.ClonedAdress; Assert.True(clonedAdress2.IsTheSameAddress(contractCalculatedAddress2)); //Flushing from the factory var flushAllReceipt = await factoryService.FlushEtherRequestAndWaitForReceiptAsync(new List <string> { contractCalculatedAddress, contractCalculatedAddress2 }); //////validate balances... for two forwarders of 0.001 + 0.001 var newbalanceDestination = await web3.Eth.GetBalance.SendRequestAsync(destinationAddress); Assert.Equal((decimal)0.001 + (decimal)0.001 + balanceDestinationEther, Web3.Web3.Convert.FromWei(newbalanceDestination)); }