public void PaymentSplitContractTest() { Account account = fluentClient.ConstructAccount(baseKeyPair); BaseKeyPair rec1 = BaseKeyPair.Generate(); BaseKeyPair rec2 = BaseKeyPair.Generate(); BaseKeyPair rec3 = BaseKeyPair.Generate(); //map(address, int) Dictionary <string, int> input = new Dictionary <string, int>(); input.Add(rec1.PublicKey, 40); input.Add(rec2.PublicKey, 40); input.Add(rec3.PublicKey, 20); decimal paymentValue = 1m.ToAettos(Unit.AE); string paymentSplitterSource = File.ReadAllText(Path.Combine(ResourcePath, "contracts", "PaymentSplitter.aes"), Encoding.UTF8); Contract contract = account.ConstructContract(paymentSplitterSource); ContractReturn depReturn = contract.MeasureAndDeploy(0, 0, Constants.BaseConstants.MINIMAL_GAS_PRICE, "init", input).WaitForFinish(TimeSpan.FromSeconds(30)); Assert.IsTrue(depReturn.Events.Any(a => a.Name == "AddingInitialRecipients")); ContractReturn callReturn = contract.MeasureAndCall("payAndSplit", Constants.BaseConstants.MINIMAL_GAS_PRICE, (ulong)paymentValue).WaitForFinish(TimeSpan.FromSeconds(30)); Assert.IsTrue(callReturn.Events.Any(a => a.Name == "PaymentReceivedAndSplitted")); Assert.AreEqual(new BigInteger(paymentValue * 0.4m), fluentClient.ConstructAccount(rec1).Balance); Assert.AreEqual(new BigInteger(paymentValue * 0.4m), fluentClient.ConstructAccount(rec2).Balance); Assert.AreEqual(new BigInteger(paymentValue * 0.2m), fluentClient.ConstructAccount(rec3).Balance); }
public async Task <(object result, bool done)> CheckForFinishAsync(object input, CancellationToken token = default(CancellationToken)) { Contract co = (Contract)input; TxInfoObject res = await co.Account.Client.GetTransactionInfoByHashAsync(co.TxHash, token).ConfigureAwait(false); if (string.IsNullOrEmpty(co.ContractId) && !string.IsNullOrEmpty(res.CallInfo?.ContractId)) { co.ContractId = res.CallInfo?.ContractId; } return(await ContractReturn.CreateAsync(co.Account, co, _function, res.CallInfo, res.TXInfo, token).ConfigureAwait(false), true); }
public void IdentityContractTest() { Account account = fluentClient.ConstructAccount(baseKeyPair); Contract contract = account.ConstructContract(TestConstants.TestContractSourceCode); Assert.AreEqual(TestConstants.TestContractByteCode, contract.ByteCode); ContractReturn ret = contract.Deploy(0, 0, 2000000000, 100000).WaitForFinish(TimeSpan.FromSeconds(30)); ContractReturn <int> re = contract.StaticCall <int>("main", 0, 42); Assert.AreEqual(re.ReturnValue, 42); }
public static InProgress <ContractReturn <T> > MeasureAndCall <T>(this Contract contract, string function, ulong gasPrice = Constants.BaseConstants.MINIMAL_GAS_PRICE, ulong amount = 0, params object[] pars) => contract.MeasureAndCallAsync <T>(function, gasPrice, amount, CancellationToken.None, pars).RunAndUnwrap();
public static InProgress <ContractReturn <T> > MeasureAndDeploy <T>(this Contract contract, BigInteger amount, BigInteger deposit, ulong gasPrice = Constants.BaseConstants.MINIMAL_GAS_PRICE, string constructorFunction = "init", params object[] pars) => contract.MeasureAndDeployAsync <T>(amount, deposit, gasPrice, constructorFunction, CancellationToken.None, pars).RunAndUnwrap();
public static InProgress <ContractReturn> Call(this Contract contract, string function, ulong gasPrice = Constants.BaseConstants.MINIMAL_GAS_PRICE, ulong gas = Constants.BaseConstants.CONTRACT_GAS, ulong amount = 0, params object[] pars) => contract.CallAsync(function, gasPrice, gas, amount, CancellationToken.None, pars).RunAndUnwrap();
public static ContractReturn <T> StaticCall <T>(this Contract contract, string function, ulong amount, params object[] pars) => contract.StaticCallAsync <T>(function, amount, CancellationToken.None, pars).RunAndUnwrap();
public static Contract ConstructContract(this ClientModels.Account account, string sourcecode, ushort vmVersion = Constants.BaseConstants.VM_VERSION, ushort abiVersion = Constants.BaseConstants.ABI_VERSION) => Contract.CreateAsync(account, sourcecode, null, null, vmVersion, abiVersion).RunAndUnwrap();