public void GetEventFilterBuilderFromEventDto() { var transferEventDto = new TransferEventDTO(); //from instance of an Event NewFilterInput filterFromEventDto = transferEventDto.GetFilterBuilder() .AddTopic(t => t.From, "") .AddTopic(t => t.To, "") .Build(contractAddresses: new string[] { "", "" }); Assert.NotNull(filterFromEventDto); }
public async Task Transfering_ShouldIncreaseTheBalanceOfReceiver(int valueToSend) { var contractDeploymentDefault = SimpleStandardContractTest.GetDeploymentMessage(); Assert.False(valueToSend > contractDeploymentDefault.InitialAmount, "value to send is bigger than the total supply, please adjust the test data"); GivenADeployedContract(contractDeploymentDefault); var receiver = SimpleStandardContractTest.ReceiverAddress; var transferMessage = new TransferFunction() { Value = valueToSend, FromAddress = DefaultTestAccountConstants.Address, To = receiver, }; var expectedEvent = new TransferEventDTO() { From = DefaultTestAccountConstants.Address.ToLower(), To = SimpleStandardContractTest.ReceiverAddress.ToLower(), Value = valueToSend }; GivenATransaction(transferMessage). ThenExpectAnEvent(expectedEvent); var queryBalanceReceiverMessage = new BalanceOfFunction() { Owner = ReceiverAddress }; var balanceOfExpectedResult = new BalanceOfOutputDTO() { Balance = valueToSend }; WhenQuerying <BalanceOfFunction, BalanceOfOutputDTO>(queryBalanceReceiverMessage) .ThenExpectResult(balanceOfExpectedResult); }
//Sample of new features / requests public IEnumerator DeployAndTransferToken() { var url = "http://localhost:8545"; var privateKey = "0xb5b1870957d373ef0eeffecc6e4812c0fd08f554b37b233526acc331bf1544f7"; var account = "0x12890d2cce102216644c59daE5baed380d84830c"; //initialising the transaction request sender var transactionRequest = new TransactionSignedUnityRequest(url, privateKey); var deployContract = new EIP20Deployment() { InitialAmount = 10000, FromAddress = account, TokenName = "TST", TokenSymbol = "TST" }; //deploy the contract and True indicates we want to estimate the gas yield return(transactionRequest.SignAndSendDeploymentContractTransaction <EIP20DeploymentBase>(deployContract)); if (transactionRequest.Exception != null) { Debug.Log(transactionRequest.Exception.Message); yield break; } var transactionHash = transactionRequest.Result; Debug.Log("Deployment transaction hash:" + transactionHash); //create a poll to get the receipt when mined var transactionReceiptPolling = new TransactionReceiptPollingRequest(url); //checking every 2 seconds for the receipt yield return(transactionReceiptPolling.PollForReceipt(transactionHash, 2)); var deploymentReceipt = transactionReceiptPolling.Result; Debug.Log("Deployment contract address:" + deploymentReceipt.ContractAddress); //Query request using our acccount and the contracts address (no parameters needed and default values) var queryRequest = new QueryUnityRequest <BalanceOfFunction, BalanceOfFunctionOutput>(url, account); yield return(queryRequest.Query(new BalanceOfFunction() { Owner = account }, deploymentReceipt.ContractAddress)); //Getting the dto response already decoded var dtoResult = queryRequest.Result; Debug.Log(dtoResult.Balance); var transactionTransferRequest = new TransactionSignedUnityRequest(url, privateKey); var newAddress = "0xde0B295669a9FD93d5F28D9Ec85E40f4cb697BAe"; var transactionMessage = new TransferFunction { FromAddress = account, To = newAddress, Value = 1000, }; yield return(transactionTransferRequest.SignAndSendTransaction(transactionMessage, deploymentReceipt.ContractAddress)); var transactionTransferHash = transactionTransferRequest.Result; Debug.Log("Transfer txn hash:" + transactionHash); transactionReceiptPolling = new TransactionReceiptPollingRequest(url); yield return(transactionReceiptPolling.PollForReceipt(transactionTransferHash, 2)); var transferReceipt = transactionReceiptPolling.Result; var transferEvent = transferReceipt.DecodeAllEvents <TransferEventDTO>(); Debug.Log("Transferd amount from event: " + transferEvent[0].Event.Value); var getLogsRequest = new EthGetLogsUnityRequest(url); var eventTransfer = TransferEventDTO.GetEventABI(); yield return(getLogsRequest.SendRequest(eventTransfer.CreateFilterInput(deploymentReceipt.ContractAddress, account))); var eventDecoded = getLogsRequest.Result.DecodeAllEvents <TransferEventDTO>(); Debug.Log("Transferd amount from get logs event: " + eventDecoded[0].Event.Value); }
//Sample of new features / requests public IEnumerator DeployAndTransferToken() { var url = "http://localhost:8545"; var privateKey = "0xa5ca770c997e53e182c5015bcf1b58ba5cefe358bf217800d8ec7d64ca919edd"; var account = "0x47E95DCdb798Bc315198138bC930758E6f399f81"; //initialising the transaction request sender var transactionRequest = new TransactionSignedUnityRequest(url, privateKey, account); var deployContract = new EIP20Deployment() { InitialAmount = 10000, FromAddress = account, TokenName = "TST", TokenSymbol = "TST" }; //deploy the contract and True indicates we want to estimate the gas yield return(transactionRequest.SignAndSendDeploymentContractTransaction <EIP20DeploymentBase>(deployContract)); if (transactionRequest.Exception != null) { Debug.Log(transactionRequest.Exception.Message); yield break; } var transactionHash = transactionRequest.Result; Debug.Log("Deployment transaction hash:" + transactionHash); //create a poll to get the receipt when mined var transactionReceiptPolling = new TransactionReceiptPollingRequest(url); //checking every 2 seconds for the receipt yield return(transactionReceiptPolling.PollForReceipt(transactionHash, 2)); var deploymentReceipt = transactionReceiptPolling.Result; Debug.Log("Deployment contract address:" + deploymentReceipt.ContractAddress); //Query request using our acccount and the contracts address (no parameters needed and default values) var queryRequest = new QueryUnityRequest <BalanceOfFunction, BalanceOfFunctionOutput>(url, account); yield return(queryRequest.Query(new BalanceOfFunction() { Owner = account }, deploymentReceipt.ContractAddress)); //Getting the dto response already decoded var dtoResult = queryRequest.Result; Debug.Log(dtoResult.Balance); var transactionTransferRequest = new TransactionSignedUnityRequest(url, privateKey, account); var newAddress = "0x4e70A9177Aff5077217f069E582992f7F9bec945"; var transactionMessage = new TransferFunction { FromAddress = account, To = newAddress, Value = 1000, }; yield return(transactionTransferRequest.SignAndSendTransaction(transactionMessage, deploymentReceipt.ContractAddress)); var transactionTransferHash = transactionTransferRequest.Result; Debug.Log("Transfer txn hash:" + transactionHash); transactionReceiptPolling = new TransactionReceiptPollingRequest(url); yield return(transactionReceiptPolling.PollForReceipt(transactionTransferHash, 2)); var transferReceipt = transactionReceiptPolling.Result; var transferEvent = transferReceipt.DecodeAllEvents <TransferEventDTO>(); Debug.Log("Transferd amount from event: " + transferEvent[0].Event.Value); var getLogsRequest = new EthGetLogsUnityRequest(url); var eventTransfer = TransferEventDTO.GetEventABI(); yield return(getLogsRequest.SendRequest(eventTransfer.CreateFilterInput(deploymentReceipt.ContractAddress, account))); var eventDecoded = getLogsRequest.Result.DecodeAllEvents <TransferEventDTO>(); Debug.Log("Transferd amount from get logs event: " + eventDecoded[0].Event.Value); }