public void getRelayers() { var lib = new RecentCore(NodeUrl); var wallet = lib.importWalletFromSeedPhrase("combine close before lawsuit asthma glimpse yard debate mixture stool adjust ride"); var r3 = lib.getRelayers(null).Result; //var cid = lib.uploadBinary(File.ReadAllBytes(@"C:\Users\jzari_000\Pictures\img001.jpg")).Result; //var ipfsUrl = lib.getIpfsCIDUrl(cid); //File.WriteAllBytes(@"C:\Users\jzari_000\Pictures\" + cid + ".jpg", lib.downloadBinary(cid).Result); }
public void TestMethod1() { var lib = new RecentCore(); var wallet = lib.importWalletFromSeedPhrase("combine close before lawsuit asthma glimpse yard debate mixture stool adjust ride"); //Parallel.For(0, 100, i => //{ // var l = lib.addRelayer($"https://2.google.com.{i}", "2.Google.{i}", true, 0.1m, false, null).Result; //}); //for (int i = 0; i < 10; i++) //{ // var l = lib.addRelayer($"https://www.google.com.{i}", "Google.{i}", true, 0.1m, false, null).Result; //} //var r11 = lib.addRelayer("https://www.google.com1", "Google1", true, 0.1m, false, null).Result; //var r12 = lib.addRelayer("https://www.google.com2", "Google1", true, 0.1m, false, null).Result; //var r2 = lib.getRelayer("https://www.google.com1").Result; var r3 = lib.getRelayers().Result; }
public void Flow() { var relayerLib = new RecentCore(NodeUrl); var relayerWallet = relayerLib.importWalletFromSeedPhrase("combine close before lawsuit asthma glimpse yard debate mixture stool adjust ride"); var relayers = relayerLib.getRelayers(null, true, relayerWallet.address).Result; var currentEpoch = relayerLib.getCurrentRelayersEpoch().Result; var relayer = relayerLib.getRelayer(currentEpoch, relayerWallet.address).Result; var requiredAmount = relayerLib.getFundRequiredForRelayer(10, 10, 1).Result; if (relayer.maxUsers == 0) { var tx = relayerLib.requestRelayerLicense(currentEpoch, "https://localhost:5001/", $"Test Epoch {currentEpoch}", 12.1m, 10, 10, 1, 1000, requiredAmount, false, true, null).Result; relayer = relayerLib.getRelayer(currentEpoch, relayerWallet.address).Result; } else { currentEpoch += 1; var nextEpochRelayer = relayerLib.getRelayer(currentEpoch, relayerWallet.address).Result; if (nextEpochRelayer.maxUsers == 0) { var tx = relayerLib.requestRelayerLicense(currentEpoch, "https://localhost:5001/", $"Test Epoch {currentEpoch}", 12.1m, 10, 10, 1, 1000, requiredAmount, false, true, null).Result; nextEpochRelayer = relayerLib.getRelayer(currentEpoch, relayerWallet.address).Result; } } var userLib = new RecentCore(NodeUrl); var userWallet = userLib.importWalletFromPK("E5ADE4B50BA041A9C77DBA91401BEA949393F2C24433B0338702E7AE06443089"); var userBalance = userLib.getBalance().Result; if (userBalance == 0) { var tx = userLib.transfer(0.01m, userWallet.address, false, true, null).Result; Assert.AreEqual(userLib.getBalance().Result, 0.01m); } var currentBlock = userLib.getLastBlock().Result; var userBalanceOnRelayer = userLib.getUserDepositOnRelayer(userWallet.address, relayer.owner).Result; if (userBalanceOnRelayer.lockUntilBlock < currentBlock && userBalanceOnRelayer.balance > 0m) { var tx = userLib.withdrawFundsFromRelayer(relayer.owner, userBalanceOnRelayer.balance, false, true, null).Result; userBalanceOnRelayer = userLib.getUserDepositOnRelayer(userWallet.address, relayer.owner).Result; Assert.AreEqual(userBalanceOnRelayer.balance, 0m); } if (userBalanceOnRelayer.balance == 0m) { var tx = userLib.depositToRelayer(relayer.owner, 0.01m, currentBlock + 10, false, true, null).Result; userBalanceOnRelayer = userLib.getUserDepositOnRelayer(userWallet.address, relayer.owner).Result; relayer = userLib.getRelayer(relayer.owner, true, userWallet.address).Result; Assert.AreEqual(relayer.currentUsers, (uint)1); Assert.AreEqual(userBalanceOnRelayer.balance, 0.01m); } var serviceProviderLib = new RecentCore(NodeUrl); var serviceProviderWallet = serviceProviderLib.importWalletFromPK("B68811986F995A45C66CF30D7C9A015268A1BB2E4697D6DBB23D7B96FC3607B0"); var beneficiaryAddress = "0xd316413c82bc4a23c2b52d43504f91c15f906208"; var nonce = Guid.NewGuid().ToString("N"); var offchainPaymentAmount = 0m; for (int i = 0; i < 1; i++) { var delta = 0.001m; offchainPaymentAmount += 0.001m; var offchainTx = new SignedOffchainTransaction { amount = userLib.recentToWei(offchainPaymentAmount), beneficiary = beneficiaryAddress, fee = (uint)(relayer.fee * 10m), nonce = nonce, relayerId = relayer.owner }; var signedTx = userLib.signOffchainPayment(offchainTx); var signerTest = userLib.checkOffchainSignature(signedTx).Result; currentBlock = relayerLib.getLastBlock().Result; offchainTx.txUntilBlock = currentBlock + relayer.offchainTxDelay; var signedFromRelayerTx = relayerLib.relayerSignOffchainPayment(signedTx).Result; var relayerTest = relayerLib.checkOffchainRelayerSignature(signedTx).Result; var beneficiaryBalanceBefore = userLib.getBalance(beneficiaryAddress).Result; var userBalanceOnRelayerBefore = userLib.getUserDepositOnRelayer(userWallet.address, relayer.owner).Result; var relayerBalanceBefore = userLib.getBalance(relayer.owner).Result; var signerBeneficiaryRelationForNonceBefore = userLib.userToBeneficiaryFinalizedAmountForNonce(userWallet.address, beneficiaryAddress, relayer.owner, nonce).Result; var txOutput = serviceProviderLib.finalizeOffchainRelayerTransaction(signedFromRelayerTx, false, true, null).Result; var signerBeneficiaryRelationForNonceAfter = userLib.userToBeneficiaryFinalizedAmountForNonce(userWallet.address, beneficiaryAddress, relayer.owner, nonce).Result; var beneficiaryBalanceAfter = userLib.getBalance(beneficiaryAddress).Result; var userBalanceOnRelayerAfter = userLib.getUserDepositOnRelayer(userWallet.address, relayer.owner).Result; var relayerBalanceAfter = userLib.getBalance(relayer.owner).Result; var fee = delta * relayer.fee / 100m; Assert.AreEqual(signerBeneficiaryRelationForNonceBefore + delta, signerBeneficiaryRelationForNonceAfter); Assert.AreEqual(relayerBalanceBefore + fee, relayerBalanceAfter); Assert.AreEqual(beneficiaryBalanceBefore + delta - fee, beneficiaryBalanceAfter); Assert.AreEqual(userBalanceOnRelayerBefore.balance - delta, userBalanceOnRelayerAfter.balance); } offchainPaymentAmount = 0.001m; nonce = Guid.NewGuid().ToString("N"); var offchainTxPenaltyFunded = new SignedOffchainTransaction { amount = userLib.recentToWei(offchainPaymentAmount), beneficiary = beneficiaryAddress, fee = (uint)(relayer.fee * 10m), nonce = nonce, relayerId = relayer.owner }; var signedTxPenaltyFunded = userLib.signOffchainPayment(offchainTxPenaltyFunded); var signerTestPenaltyFunded = userLib.checkOffchainSignature(signedTxPenaltyFunded); currentBlock = relayerLib.getLastBlock().Result; offchainTxPenaltyFunded.txUntilBlock = currentBlock + 1; var signedFromRelayerTxPenaltyFunded = relayerLib.relayerSignOffchainPayment(signedTxPenaltyFunded).Result; var relayerTestPenaltyFunded = relayerLib.checkOffchainRelayerSignature(signedTxPenaltyFunded).Result; var beneficiaryBalanceBeforePenaltyFunded = userLib.getBalance(beneficiaryAddress).Result; var userBalanceOnRelayerBeforePenaltyFunded = userLib.getUserDepositOnRelayer(userWallet.address, relayer.owner).Result; var relayerBalanceBeforePenaltyFunded = userLib.getBalance(relayer.owner).Result; var signerBeneficiaryRelationForNonceBeforePenaltyFunded = userLib.userToBeneficiaryFinalizedAmountForNonce(userWallet.address, beneficiaryAddress, relayer.owner, nonce).Result; var relayerPenaltyFundsBefore = relayerLib.getRelayer(relayer.owner).Result.remainingPenaltyFunds; var txOutputPenaltyFunded = serviceProviderLib.finalizeOffchainRelayerTransaction(signedFromRelayerTxPenaltyFunded, false, true, null).Result; var signerBeneficiaryRelationForNonceAfterPenaltyFunded = userLib.userToBeneficiaryFinalizedAmountForNonce(userWallet.address, beneficiaryAddress, relayer.owner, nonce).Result; var beneficiaryBalanceAfterPenaltyFunded = userLib.getBalance(beneficiaryAddress).Result; var userBalanceOnRelayerAfterPenaltyFunded = userLib.getUserDepositOnRelayer(userWallet.address, relayer.owner).Result; var relayerBalanceAfterPenaltyFunded = userLib.getBalance(relayer.owner).Result; var relayerPenaltyFundsAfter = relayerLib.getRelayer(relayer.owner).Result.remainingPenaltyFunds; var feePenaltyFunded = 0m; Assert.AreEqual(relayerPenaltyFundsBefore - offchainPaymentAmount, relayerPenaltyFundsAfter); Assert.AreEqual(signerBeneficiaryRelationForNonceBeforePenaltyFunded + offchainPaymentAmount, signerBeneficiaryRelationForNonceAfterPenaltyFunded); Assert.AreEqual(relayerBalanceBeforePenaltyFunded + feePenaltyFunded, relayerBalanceAfterPenaltyFunded); Assert.AreEqual(beneficiaryBalanceBeforePenaltyFunded + offchainPaymentAmount - feePenaltyFunded, beneficiaryBalanceAfterPenaltyFunded); Assert.AreEqual(userBalanceOnRelayerBeforePenaltyFunded.balance, userBalanceOnRelayerAfterPenaltyFunded.balance); }