private void setupWatchContractCall(string guid) { ContractDeployment deployment = GetContractDeployment <WatchContractDeployment>(); // setup the service and common parameter watchContractService = new WatchContractService(web3, deployment.DeploymentAddress); GUID = BigInteger.Parse(guid); }
private ContractDeployment GetContractDeployment <T>() where T : ContractDeploymentMessage, new() { T contract = new T(); ContractDeployment deployment = null; WatchContractDeployment watchContractDeployment = null; SimpleStorageDeployment simpleStorageDeployment = null; if (contract is WatchContractDeployment) { watchContractDeployment = contract as WatchContractDeployment; } else if (contract is SimpleStorageDeployment) { simpleStorageDeployment = contract as SimpleStorageDeployment; } try { deployment = this.context.ContractDeployments.Where(s => s.ByteCode == contract.ByteCode && s.ServerUrl == this.url).First(); } catch (InvalidOperationException ex) { logger.LogError($"contract does not currently exist: {ex}"); } if (deployment == null) { deployment = new ContractDeployment(); if (watchContractDeployment != null) { watchContractDeployment.GasPrice = 0; TransactionReceipt receipt = WatchContractService.DeployContractAndWaitForReceiptAsync(web3, watchContractDeployment).GetAwaiter().GetResult(); deployment.DeploymentAddress = receipt.ContractAddress; deployment.ByteCode = watchContractDeployment.ByteCode; } else if (simpleStorageDeployment != null) { simpleStorageDeployment.GasPrice = 0; TransactionReceipt receipt = SimpleStorageService.DeployContractAndWaitForReceiptAsync(web3, simpleStorageDeployment).GetAwaiter().GetResult(); deployment.DeploymentAddress = receipt.ContractAddress; deployment.ByteCode = simpleStorageDeployment.ByteCode; } deployment.ServerUrl = this.url; this.context.Add(deployment); this.context.SaveChanges(); } return(deployment); }
void DeployCodeAndAssertTx(string code, bool eip3541Enabled, ContractDeployment context, bool withoutAnyInvalidCodeErrors) { TestState.CreateAccount(TestItem.AddressC, 100.Ether()); byte[] salt = { 4, 5, 6 }; byte[] byteCode = Prepare.EvmCode .FromCode(code) .Done; byte[] createContract; switch (context) { case ContractDeployment.CREATE: createContract = Prepare.EvmCode.Create(byteCode, UInt256.Zero).Done; break; case ContractDeployment.CREATE2: createContract = Prepare.EvmCode.Create2(byteCode, salt, UInt256.Zero).Done; break; default: createContract = byteCode; break; } _processor = new TransactionProcessor(SpecProvider, TestState, Storage, Machine, LimboLogs.Instance); long blockNumber = eip3541Enabled ? LondonTestBlockNumber : LondonTestBlockNumber - 1; (Block block, Transaction transaction) = PrepareTx(blockNumber, 100000, createContract); transaction.GasPrice = 20.GWei(); transaction.To = null; transaction.Data = createContract; TestAllTracerWithOutput tracer = CreateTracer(); _processor.Execute(transaction, block.Header, tracer); Assert.AreEqual(withoutAnyInvalidCodeErrors, tracer.ReportedActionErrors.All(x => x != EvmExceptionType.InvalidCode), $"Code {code}, Context {context}"); }
public ContractDeploymentsFixture(IMessageSink diagnosticMessageSink) { _diagnosticMessageSink = diagnosticMessageSink; var appConfig = ConfigurationUtils.Build(Array.Empty <string>(), "UserSecret"); // Web3 var web3Config = appConfig.GetSection("Web3Config").Get <Web3Config>(); var privateKey = web3Config.TransactionCreatorPrivateKey; Web3 = new Web3.Web3(new Account(privateKey), web3Config.BlockchainUrl); // New deployment var contractDeploymentConfig = appConfig.GetSection("NewDeployment").Get <ContractNewDeploymentConfig>(); // ...or attach to an existing deployment, swap to this: // var contractDeploymentConfig = appConfig.GetSection("ExistingDeployment").Get<ContractConnectExistingConfig>(); Deployment = new ContractDeployment(Web3, contractDeploymentConfig, new DiagnosticMessageSinkLogger(_diagnosticMessageSink)); // Secondary users var secondaryUserConfig = appConfig.GetSection("SecondaryUsers").Get <SecondaryUserConfig>(); Web3SecondaryUser = new Web3.Web3(new Account(secondaryUserConfig.UserPrivateKey), web3Config.BlockchainUrl); }
private void setupSimpleStorageContractCall() { ContractDeployment deployment = GetContractDeployment <SimpleStorageDeployment>(); simpleStorageService = new SimpleStorageService(web3, deployment.DeploymentAddress); }
public static async Task <ContractService> DeployContractAndGetServiceAsync(Nethereum.Web3.Web3 web3, ContractDeployment contractDeployment, CancellationTokenSource cancellationTokenSource = null) { var receipt = await DeployContractAndWaitForReceiptAsync(web3, contractDeployment, cancellationTokenSource); return(new ContractService(web3, receipt.ContractAddress)); }
public static Task <string> DeployContractAsync(Nethereum.Web3.Web3 web3, ContractDeployment contractDeployment) { return(web3.Eth.GetContractDeploymentHandler <ContractDeployment>().SendRequestAsync(contractDeployment)); }
public static Task <TransactionReceipt> DeployContractAndWaitForReceiptAsync(Nethereum.Web3.Web3 web3, ContractDeployment contractDeployment, CancellationTokenSource cancellationTokenSource = null) { return(web3.Eth.GetContractDeploymentHandler <ContractDeployment>().SendRequestAndWaitForReceiptAsync(contractDeployment, cancellationTokenSource)); }
public void All_tx_should_pass_before_3541( [ValueSource(nameof(Eip3541TestCases))] Eip3541TestCase test, [ValueSource(nameof(ContractDeployments))] ContractDeployment contractDeployment) { DeployCodeAndAssertTx(test.Code, false, contractDeployment, true); }
public void Wrong_contract_creation_should_return_invalid_code_after_3541( [ValueSource(nameof(Eip3541TestCases))] Eip3541TestCase test, [ValueSource(nameof(ContractDeployments))] ContractDeployment contractDeployment) { DeployCodeAndAssertTx(test.Code, true, contractDeployment, test.WithoutAnyInvalidCodeErrors); }
private async void validateTransaction(ComplaintDto input) { try { var inputRequest = new ComplaintRequestDto() { NewApplicant = input.Applicant, NewDefendant = input.Defendant, NewGuid = input.Id.ToString(), NewTypeProcess = input.TypeProcess.ToString() }; using var client = new HttpClient(); client.BaseAddress = new Uri("https://u1mj5i89xd-u1vfy33yzc-connect.us1-azure.kaleido.io/gateways/complaint/?kld-from=0x1f3f30734dcda9f511bbdcc6fe7ae174ab1d510d&kld-sync=true"); AuthenticationHeaderValue authenticationHeader = new AuthenticationHeaderValue("Basic", "dTF3cW9nd2NoNjpWUTNKSGhQVW5MM1FXODZpRnhFeDdZc3BFYkRYNjVVajJFblpxZHRRRmFV"); client.DefaultRequestHeaders.Authorization = authenticationHeader; client.DefaultRequestHeaders.Accept.Add( new MediaTypeWithQualityHeaderValue("application/json")); var httpContent = new StringContent(JsonConvert.SerializeObject(inputRequest), Encoding.UTF8, "application/json"); var response = await client.PostAsync( client.BaseAddress, httpContent); // Setup // Here we're using local chain eg Geth https://github.com/Nethereum/TestChains#geth var url = "https://u1mj5i89xd-u1vfy33yzc-connect.us1-azure.kaleido.io/gateways/complaint/?kld-from=0x1f3f30734dcda9f511bbdcc6fe7ae174ab1d510d&kld-sync=true"; var privateKey = "0x1f3f30734dcda9f511bbdcc6fe7ae174ab1d510d"; var account = new Account(privateKey); var web3 = new Web3(account, url, null, authenticationHeader); //var senderAddress = "0x1f3f30734dcda9f511bbdcc6fe7ae174ab1d510d"; //var password = "******"; //var account = new ManagedAccount(senderAddress, password); //var account = new Account(privateKey); //var web3 = new Web3(account, url); Console.WriteLine("Deploying..."); var deployment = new ContractDeployment(); deployment.NewApplicant = "ANDRES"; deployment.NewDefendant = "TOBIAS"; deployment.NewGuid = "3FA85F64-5717-4562-B3FC-2C963F66AFA6"; deployment.NewTypeProcess = "Civil"; deployment.FromAddress = "0x1f3f30734dcda9f511bbdcc6fe7ae174ab1d510d"; var receipt = await ContractService.DeployContractAndWaitForReceiptAsync(web3, deployment); var service = new ContractService(web3, receipt.ContractAddress); Console.WriteLine($"Contract Deployment Tx Status: {receipt.Status.Value}"); Console.WriteLine($"Contract Address: {service.ContractHandler.ContractAddress}"); Console.WriteLine(""); //Console.WriteLine("Sending a transaction to the function set()..."); //var receiptForSetFunctionCall = await service.DeployContractAndGetServiceAsync() // .SetRequestAndWaitForReceiptAsync( // new SetFunction() { X = 42, Gas = 400000 }); //Console.WriteLine($"Finished storing an int: Tx Hash: {receiptForSetFunctionCall.TransactionHash}"); //Console.WriteLine($"Finished storing an int: Tx Status: {receiptForSetFunctionCall.Status.Value}"); //Console.WriteLine(""); //Console.WriteLine("Calling the function get()..."); //var intValueFromGetFunctionCall = await service.GetQueryAsync(); //Console.WriteLine($"Int value: {intValueFromGetFunctionCall} (expecting value 42)"); //Console.WriteLine(""); } catch (Exception ex) { Console.WriteLine(ex.Message); } Console.WriteLine("Finished"); Console.ReadLine(); }