public async void ShouldRejectPoItemAndRefundBuyer() { // Prepare a new PO Buyer.Po poAsRequested = await CreateBuyerPoAsync(quoteId : GetRandomInt()); var signature = poAsRequested.GetSignatureBytes(_contracts.Web3); // Test setup - transfer required funds from current Web3 acccount to wallet buyer StandardTokenService sts = new StandardTokenService(_contracts.Web3, poAsRequested.CurrencyAddress); var totalPoValue = poAsRequested.GetTotalCurrencyValue(); var txTransfer = await sts.TransferRequestAndWaitForReceiptAsync(poAsRequested.BuyerWalletAddress, totalPoValue); txTransfer.Status.Value.Should().Be(1); // Create PO on-chain // NB: this approves token transfer from WALLET BUYER contract (NOT msg.sender == current web3 account) to FUNDING contract var txReceiptCreate = await _contracts.Deployment.BuyerWalletService.CreatePurchaseOrderRequestAndWaitForReceiptAsync(poAsRequested, signature); txReceiptCreate.Status.Value.Should().Be(1); _output.WriteLine($"... PO created ..."); // Get the PO number that was assigned var logPoCreated = txReceiptCreate.DecodeAllEvents <PurchaseOrderCreatedLogEventDTO>().FirstOrDefault(); logPoCreated.Should().NotBeNull(); var poNumberAsBuilt = logPoCreated.Event.Po.PoNumber; // NB: Refunds go to the PO buyer wallet address (not the po buyer address from the PO header, which represents the user) // Balance of PO buyer address before refund var poBuyerWalletAddressBalanceBefore = await sts.BalanceOfQueryAsync(poAsRequested.BuyerWalletAddress); _output.WriteLine($"PO buyer wallet address balance before refund: {await poBuyerWalletAddressBalanceBefore.PrettifyAsync(sts)}"); // Do the refund (achieved by marking the PO item as rejected) var txReceiptPoItemReject = await _contracts.Deployment.SellerAdminService.SetPoItemRejectedRequestAndWaitForReceiptAsync( poAsRequested.EShopId, poNumberAsBuilt, PO_ITEM_NUMBER); txReceiptPoItemReject.Status.Value.Should().Be(1); var poItemValue = poAsRequested.PoItems[PO_ITEM_INDEX].CurrencyValue; _output.WriteLine($"... PO item rejected with value {await poItemValue.PrettifyAsync(sts)} ..."); // Check log exists for Escrow refund var logPoItemReject = txReceiptPoItemReject.DecodeAllEvents <PurchaseItemEscrowRefundedLogEventDTO>().FirstOrDefault(); logPoItemReject.Should().NotBeNull(); // Balance of PO buyer wallet address after PO item rejection var poBuyerWalletAddressBalanceAfter = await sts.BalanceOfQueryAsync(poAsRequested.BuyerWalletAddress); _output.WriteLine($"PO buyer wallet address balance after refund: {await poBuyerWalletAddressBalanceAfter.PrettifyAsync(sts)}"); // Checks var diff = poBuyerWalletAddressBalanceAfter - poBuyerWalletAddressBalanceBefore; diff.Should().Be(poItemValue, "PO buyer wallet should have increased by value of the PO item"); }
public async Task <decimal> GetTokenBalance(string accountAddress) { var service = new StandardTokenService(Web3Client, RskTestnetRifAddress); var wei = await service.BalanceOfQueryAsync(accountAddress).ConfigureAwait(false); return(Web3.Convert.FromWei(wei, 18)); }
public async void ShouldBeAbleTransferTokensUsingTheHdWallet() { var wallet = new Wallet(Words, Password); var account = wallet.GetAccount(0); var web3 = new Web3.Web3(account, _ethereumClientIntegrationFixture.GetWeb3().Client); ulong totalSupply = 1000000; var contractByteCode = "0x6060604052341561000f57600080fd5b604051602080610711833981016040528080519150505b60018054600160a060020a03191633600160a060020a0390811691909117918290556000838155911681526002602052604090208190555b505b6106a28061006f6000396000f300606060405236156100a15763ffffffff7c010000000000000000000000000000000000000000000000000000000060003504166306fdde0381146100a6578063095ea7b31461013157806318160ddd1461016757806323b872dd1461018c578063313ce567146101c857806370a08231146101f15780638da5cb5b1461022257806395d89b4114610251578063a9059cbb146102dc578063dd62ed3e14610312575b600080fd5b34156100b157600080fd5b6100b9610349565b60405160208082528190810183818151815260200191508051906020019080838360005b838110156100f65780820151818401525b6020016100dd565b50505050905090810190601f1680156101235780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b341561013c57600080fd5b610153600160a060020a0360043516602435610380565b604051901515815260200160405180910390f35b341561017257600080fd5b61017a6103ed565b60405190815260200160405180910390f35b341561019757600080fd5b610153600160a060020a03600435811690602435166044356103f4565b604051901515815260200160405180910390f35b34156101d357600080fd5b6101db610510565b60405160ff909116815260200160405180910390f35b34156101fc57600080fd5b61017a600160a060020a0360043516610515565b60405190815260200160405180910390f35b341561022d57600080fd5b610235610534565b604051600160a060020a03909116815260200160405180910390f35b341561025c57600080fd5b6100b9610543565b60405160208082528190810183818151815260200191508051906020019080838360005b838110156100f65780820151818401525b6020016100dd565b50505050905090810190601f1680156101235780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34156102e757600080fd5b610153600160a060020a036004351660243561057a565b604051901515815260200160405180910390f35b341561031d57600080fd5b61017a600160a060020a0360043581169060243516610649565b60405190815260200160405180910390f35b60408051908101604052601a81527f4578616d706c6520466978656420537570706c7920546f6b656e000000000000602082015281565b600160a060020a03338116600081815260036020908152604080832094871680845294909152808220859055909291907f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9259085905190815260200160405180910390a35060015b92915050565b6000545b90565b600160a060020a0383166000908152600260205260408120548290108015906104445750600160a060020a0380851660009081526003602090815260408083203390941683529290522054829010155b80156104505750600082115b80156104755750600160a060020a038316600090815260026020526040902054828101115b1561050457600160a060020a0380851660008181526002602081815260408084208054899003905560038252808420338716855282528084208054899003905594881680845291905290839020805486019055917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9085905190815260200160405180910390a3506001610508565b5060005b5b9392505050565b601281565b600160a060020a0381166000908152600260205260409020545b919050565b600154600160a060020a031681565b60408051908101604052600581527f4649584544000000000000000000000000000000000000000000000000000000602082015281565b600160a060020a0333166000908152600260205260408120548290108015906105a35750600082115b80156105c85750600160a060020a038316600090815260026020526040902054828101115b1561063a57600160a060020a033381166000818152600260205260408082208054879003905592861680825290839020805486019055917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9085905190815260200160405180910390a35060016103e7565b5060006103e7565b5b92915050565b600160a060020a038083166000908152600360209081526040808320938516835292905220545b929150505600a165627a7a72305820ec01add6c7f9d88976180c397e2a5b2e9f8fc1f95f5abb00e2a4c9dbf7bcfaf20029"; var abi = "[{\"constant\":true,\"inputs\":[],\"name\":\"name\",\"outputs\":[{\"name\":\"\",\"type\":\"string\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_spender\",\"type\":\"address\"},{\"name\":\"_amount\",\"type\":\"uint256\"}],\"name\":\"approve\",\"outputs\":[{\"name\":\"success\",\"type\":\"bool\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"totalSupply\",\"outputs\":[{\"name\":\"totalSupply\",\"type\":\"uint256\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_from\",\"type\":\"address\"},{\"name\":\"_to\",\"type\":\"address\"},{\"name\":\"_amount\",\"type\":\"uint256\"}],\"name\":\"transferFrom\",\"outputs\":[{\"name\":\"success\",\"type\":\"bool\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"decimals\",\"outputs\":[{\"name\":\"\",\"type\":\"uint8\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_owner\",\"type\":\"address\"}],\"name\":\"balanceOf\",\"outputs\":[{\"name\":\"balance\",\"type\":\"uint256\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"owner\",\"outputs\":[{\"name\":\"\",\"type\":\"address\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"symbol\",\"outputs\":[{\"name\":\"\",\"type\":\"string\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_to\",\"type\":\"address\"},{\"name\":\"_amount\",\"type\":\"uint256\"}],\"name\":\"transfer\",\"outputs\":[{\"name\":\"success\",\"type\":\"bool\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_owner\",\"type\":\"address\"},{\"name\":\"_spender\",\"type\":\"address\"}],\"name\":\"allowance\",\"outputs\":[{\"name\":\"remaining\",\"type\":\"uint256\"}],\"payable\":false,\"type\":\"function\"},{\"inputs\":[{\"name\":\"totalSupply\",\"type\":\"uint256\"}],\"payable\":false,\"type\":\"constructor\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"name\":\"_from\",\"type\":\"address\"},{\"indexed\":true,\"name\":\"_to\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_value\",\"type\":\"uint256\"}],\"name\":\"Transfer\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"name\":\"_owner\",\"type\":\"address\"},{\"indexed\":true,\"name\":\"_spender\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_value\",\"type\":\"uint256\"}],\"name\":\"Approval\",\"type\":\"event\"}]"; var receipt = await web3.Eth.DeployContract.SendRequestAndWaitForReceiptAsync(abi, contractByteCode, account.Address, new HexBigInteger(3000000), null, totalSupply); var standarErc20Service = new StandardTokenService(web3, receipt.ContractAddress); var pollingService = new TransactionReceiptPollingService(web3.TransactionManager); var transactionHash = await standarErc20Service.TransferRequestAsync( "0x98f5438cDE3F0Ff6E11aE47236e93481899d1C47", 10); var receiptSend = await pollingService.PollForReceiptAsync(transactionHash); var balance = await standarErc20Service.BalanceOfQueryAsync("0x98f5438cDE3F0Ff6E11aE47236e93481899d1C47"); Assert.Equal(10, balance); }
public async Task <decimal> GetERC20Balance(string address) { var standardToken = new StandardTokenService(_web3, NethereumConfig.CONTRACT_ADDRESS); // TODO: Test BalanceOfQueryAsync method var balance = await standardToken.BalanceOfQueryAsync(NethereumConfig.WALLET_B); return(Web3.Convert.FromWei(balance)); }
static async Task TransferToken() { var _TokenAddress = "0x4e3c5117ed03c6e3a47f4414506f2f4723ce79e1"; var _owner = "0x4438083Ef903ACD146D3f705d790f9188d5B11Ac"; var _account = new Account("fbde582d0deb10b30d0c1be8752650a9f4fc12c705610cb754b7ae3b0a2d4aa7", 5777); // var account = new Account(privatekey, Nethereum.Signer.Chain.MainNet); var _web3 = new Web3(_account, "http://127.0.0.1:7545"); _web3.TransactionManager.UseLegacyAsDefault = true; var _tokenService = new StandardTokenService(_web3, _TokenAddress); var ownerBalance = await _tokenService.BalanceOfQueryAsync(_owner); Console.WriteLine("Balance : " + ownerBalance); var _account2 = "0x43c020cA68FfaA09AFc1674A78047C1b40CBb60E"; var transferReceipt = await _tokenService.TransferRequestAndWaitForReceiptAsync(_account2, 1500); ownerBalance = await _tokenService.BalanceOfQueryAsync(_owner); Console.WriteLine("Balance : " + ownerBalance); var account2Balance = await _tokenService.BalanceOfQueryAsync(_account2); Console.WriteLine("Account2's Balance : " + account2Balance); var _transferEvent = _tokenService.GetTransferEvent(); var _allTransferFilter = await _transferEvent.CreateFilterAsync(new BlockParameter(transferReceipt.BlockNumber)); var eventLogsAll = await _transferEvent.GetAllChanges(_allTransferFilter); var transferLog = eventLogsAll.First(); Console.WriteLine("TxID : " + transferLog.Log.TransactionHash); Console.WriteLine("BlockNumber : " + transferLog.Log.BlockNumber.Value); Console.WriteLine("To : " + transferLog.Event.To.ToLower()); Console.WriteLine("Value : " + transferLog.Event.Value); }
public async Task <decimal> GetTokensAsync(string accountAddress) { try { var wei = await DaiTokenService.BalanceOfQueryAsync(accountAddress); return(Web3.Convert.FromWei(wei)); } catch (Exception e) { return(0); } }
public static async Task <decimal> GetTokenBalance(string address) { var web3 = new Web3(ConfigurationManager.GetString("NetworkProvider")); var tokenAddress = ConfigurationManager.GetString("TokenAddress"); var service = new StandardTokenService(web3, tokenAddress); BigInteger wei = await service.BalanceOfQueryAsync(address); var balance = Web3.Convert.FromWei(wei); return(balance); }
public async Task Run() { //The quorum account var coinbaseNode1 = "0x83e0ebe69d8758f9450425fa39ef08692e55340d"; var uriWithAccessTokenNode1 = "https://juanquorum1.blockchain.azure.com:3200/nNkcS8DyDSCLIC9oAoCw1orS"; //Initialising Web3Quorum with a custom QuorumAccount var web3Private = new Web3Quorum(new QuorumAccount(coinbaseNode1), uriWithAccessTokenNode1); //Set the nodes to work in private mode for this web3 instance web3Private.SetPrivateRequestParameters(new[] { "LHTjKEqQPy6gbo4r9ouj8ztfbB+F7kWd9vosSmeQcEw=", "sXVr5ENaJeqAA8eTKm74f6epYTMcbsl8Ovp+Y8Q3dzA=" }); //Unlock account to enable access var unlocked = await web3Private.Personal.UnlockAccount.SendRequestAsync(coinbaseNode1, "P455word1?1234", 30); //Deploying new ERC20 smart contract using the Standard token library service var erc20service = await StandardTokenService.DeployContractAndGetServiceAsync(web3Private, new EIP20Deployment() { InitialAmount = BigInteger.Parse("1000000000000000000000000"), DecimalUnits = 18, TokenName = "TEST", TokenSymbol = "TST", }); //After deploying the smart contract the owner "coinbaseNode1" will have a balance of 1000000000000000000000000 var balanceOwnerAccount = await erc20service.BalanceOfQueryAsync(coinbaseNode1); //Transfering 10000 var transferReceipt = await erc20service.TransferRequestAndWaitForReceiptAsync("0xc45ed03295fdb5667206c4c18f88b41b4f035358", 10000); //Validate that we get the new balance var balanceOwnerAfterTransfer = await erc20service.BalanceOfQueryAsync(coinbaseNode1); var balanceReceiverAccount = await erc20service.BalanceOfQueryAsync("0xc45ed03295fdb5667206c4c18f88b41b4f035358"); //Create a web3 instance in a different node not included in the Private list var web3NoAccess = new Web3("https://juanquorum3-juanquorum1.blockchain.azure.com:3200/ekgKWCEhxcq6d_HH3N10g9W0"); //initialising a new StardandTokenService with the same contract address var erc20noAccess = new StandardTokenService(web3NoAccess, erc20service.ContractHandler.ContractAddress); //validate we don't receive any amount var balanceOwnerAccountNoAccess = await erc20noAccess.BalanceOfQueryAsync(coinbaseNode1); }
static async Task TrasferFromDemo() { var _TokenAddress = "0x4e3c5117ed03c6e3a47f4414506f2f4723ce79e1"; var _account1Address = "0x4438083Ef903ACD146D3f705d790f9188d5B11Ac"; var _account1 = new Account("fbde582d0deb10b30d0c1be8752650a9f4fc12c705610cb754b7ae3b0a2d4aa7"); var _web3 = new Web3(_account1, "http://127.0.0.1:7545", 5777); _web3.TransactionManager.UseLegacyAsDefault = true; var _tokenService = new StandardTokenService(_web3, _TokenAddress); var ownerBalance = await _tokenService.BalanceOfQueryAsync(_account1Address); Console.WriteLine("Account1's Balance : " + ownerBalance); var _account2Address = "0x43c020cA68FfaA09AFc1674A78047C1b40CBb60E"; var _account3Address = "0x86Ac1893ff1Ef07Ec709C6b81516bc25eB3FF7aE"; var approveTransactionReceipt = await _tokenService.ApproveRequestAndWaitForReceiptAsync(_account3Address, 5000); var allowanceAmount = await _tokenService.AllowanceQueryAsync(_account1Address, _account3Address); Console.WriteLine("allowanceAmount : " + allowanceAmount); var _account3 = new Account("f4787bddd02d87d671697809885a3b36f902f4545a77556840b6b52a7dac8c5a"); _web3 = new Web3(_account3, "http://127.0.0.1:7545"); var _tokenServiceFrom = new StandardTokenService(_web3, _TokenAddress); var TransferFromReceipt = await _tokenServiceFrom.TransferFromRequestAndWaitForReceiptAsync(_account1Address, _account2Address, 2000); Console.WriteLine("================ TransferFrom ====================="); ownerBalance = await _tokenServiceFrom.BalanceOfQueryAsync(_account1Address); Console.WriteLine("Account1's Balance : " + ownerBalance); allowanceAmount = await _tokenServiceFrom.AllowanceQueryAsync(_account1Address, _account3Address); Console.WriteLine("allowanceAmount : " + allowanceAmount); }
public async Task RunAsync() { // Ethereum network to connect to var ethereumNetworkUrl = "https://mainnet.infura.io/"; // ERC20 token called Gemini Dollar GUSD deployed on MainNet here: // https://etherscan.io/address/0x056Fd409E1d7A124BD7017459dFEa2F387b6d5Cd#contracts var erc20TokenContractAddress = "0x056Fd409E1d7A124BD7017459dFEa2F387b6d5Cd"; var accountWithSomeTokens = "0xdc24703f9210d377951819f2cc1dcc4061b88a67"; // Setup web3 and token service, to allow us to interact with ERC20 contract var web3 = new Web3(ethereumNetworkUrl); var tokenService = new StandardTokenService(web3, erc20TokenContractAddress); // Check an address balance var symbol = await tokenService.SymbolQueryAsync(); var tokens = await tokenService.BalanceOfQueryAsync(accountWithSomeTokens); System.Console.WriteLine($"Address: {accountWithSomeTokens} holds: {tokens} {symbol}"); System.Console.ReadLine(); }
public async void ShouldCreatePoAndTransferFunds() { // Prepare a new PO Buyer.Po poAsRequested = await CreateBuyerPoAsync(quoteId : GetRandomInt()); var signature = poAsRequested.GetSignatureBytes(_contracts.Web3); //---------------------------------------------------------- // BEFORE PO RAISED //---------------------------------------------------------- // Balance of Web3, before test starts (check account running these tests has enough funds to pay for the PO) StandardTokenService sts = new StandardTokenService(_contracts.Web3, poAsRequested.CurrencyAddress); var totalPoValue = poAsRequested.GetTotalCurrencyValue(); var web3AddressBalance = await sts.BalanceOfQueryAsync(_contracts.Web3.TransactionManager.Account.Address); web3AddressBalance.Should().BeGreaterOrEqualTo(totalPoValue, "the Web3 account must be able to pay for whole PO"); _output.WriteLine($"PO: {poAsRequested.PoNumber} total value {await totalPoValue.PrettifyAsync(sts)}"); // Balance of BuyerWallet, before test starts var buyerWalletBalance = await sts.BalanceOfQueryAsync(poAsRequested.BuyerWalletAddress); _output.WriteLine($"Wallet Buyer balance before test: {await buyerWalletBalance.PrettifyAsync(sts)}"); // Test setup - transfer required funds from current Web3 acccount to wallet buyer var txTransfer = await sts.TransferRequestAndWaitForReceiptAsync(poAsRequested.BuyerWalletAddress, totalPoValue); txTransfer.Status.Value.Should().Be(1); // Balance of BuyerWallet, before PO raised buyerWalletBalance = await sts.BalanceOfQueryAsync(poAsRequested.BuyerWalletAddress); _output.WriteLine($"Wallet Buyer balance after receiving funding from Web3 account: {await buyerWalletBalance.PrettifyAsync(sts)}"); // Balance of Funding, before PO raised var fundingBalanceBefore = await sts.BalanceOfQueryAsync(_contracts.Deployment.FundingService.ContractHandler.ContractAddress); _output.WriteLine($"Funding balance before PO: {await fundingBalanceBefore.PrettifyAsync(sts)}"); //---------------------------------------------------------- // RAISE PO //---------------------------------------------------------- // Create PO on-chain // NB this approves token transfer from WALLET BUYER contract (NOT msg.sender == current web3 account) to FUNDING contract var txReceiptCreate = await _contracts.Deployment.BuyerWalletService.CreatePurchaseOrderRequestAndWaitForReceiptAsync(poAsRequested, signature); txReceiptCreate.Status.Value.Should().Be(1); _output.WriteLine($"... PO created ..."); //---------------------------------------------------------- // AFTER PO RAISED //---------------------------------------------------------- // Balance of BuyerWallet, after PO raised buyerWalletBalance = await sts.BalanceOfQueryAsync(poAsRequested.BuyerWalletAddress); _output.WriteLine($"Wallet Buyer balance after PO: {await buyerWalletBalance.PrettifyAsync(sts)}"); // Balance of Funding, after PO raised var fundingBalanceAfter = await sts.BalanceOfQueryAsync(_contracts.Deployment.FundingService.ContractHandler.ContractAddress); _output.WriteLine($"Funding balance after PO: {await fundingBalanceAfter.PrettifyAsync(sts)}"); // Check var diff = fundingBalanceAfter - fundingBalanceBefore; diff.Should().Be(totalPoValue, "funding contract should have increased in value by the PO value"); }
public async Task <decimal> GetTokensAsync(string accountAddress) { var wei = await standardTokenService.BalanceOfQueryAsync(accountAddress); return((decimal)wei); }
public async Task Run() { //Basic Authentication var web3 = new Web3("https://*****:*****@juanmemberq1.blockchain.azure.com:3200"); var blockNumber = await web3.Eth.Blocks.GetBlockNumber.SendRequestAsync(); //access keys var web32 = new Nethereum.Web3.Web3("https://juanmemberq1.blockchain.azure.com:3200/QNSQSAAE_WoMyS06TPH8KVa2"); blockNumber = await web32.Eth.Blocks.GetBlockNumber.SendRequestAsync(); //access keys websocket var websocketClient = new WebSocketClient(("wss://juanmemberq1.blockchain.azure.com:3300/QNSQSAAE_WoMyS06TPH8KVa2")); var web3WebSocket = new Web3(websocketClient); blockNumber = await web3WebSocket.Eth.Blocks.GetBlockNumber.SendRequestAsync(); //member account var accounts = await web3.Eth.Accounts.SendRequestAsync(); //0x411d5607e9bad791efbb4f50669a70879faf5656 var managedAccount = new ManagedAccount("0xca1e76c9876e5ba1e7c307696a7ea48eb25eec8c", "p455word"); var web3Managed = new Web3(managedAccount, "https://juanmemberq1.blockchain.azure.com:3200/QNSQSAAE_WoMyS06TPH8KVa2"); var balance = await web3Managed.Eth.GetBalance.SendRequestAsync("0xca1e76c9876e5ba1e7c307696a7ea48eb25eec8c"); var rootAddressBalance = await web3Managed.Eth.GetBalance.SendRequestAsync("0xfb091e4feceec1869daba758de9e9ef00c2e4d7a"); var service = await StandardTokenService.DeployContractAndGetServiceAsync(web3Managed, new EIP20Deployment() { InitialAmount = BigInteger.Parse("1000000000000000000000000"), DecimalUnits = 18, TokenName = "TEST", TokenSymbol = "TST" }); var receipt = await service.TransferRequestAndWaitForReceiptAsync("0x12890d2cce102216644c59daE5baed380d84830c", 10000000); var web3MyAccount = new Web3(new Account("0xb5b1870957d373ef0eeffecc6e4812c0fd08f554b37b233526acc331bf1544f7"), "https://juanmemberq1.blockchain.azure.com:3200/QNSQSAAE_WoMyS06TPH8KVa2"); var service2 = new StandardTokenService(web3MyAccount, service.ContractHandler.ContractAddress); var receipt2 = await service2.TransferRequestAndWaitForReceiptAsync("0x12890d2cce102216644c59daE5baed380d84830d", 10000); var balanceMyAccount = await service2.BalanceOfQueryAsync("0x12890d2cce102216644c59daE5baed380d84830c"); var websocketClient2 = new WebSocketClient(("wss://juanmemberq1.blockchain.azure.com:3300/QNSQSAAE_WoMyS06TPH8KVa2")); var web3WebSocket2 = new Web3(new Account("0xb5b1870957d373ef0eeffecc6e4812c0fd08f554b37b233526acc331bf1544f7"), websocketClient); var service3 = await StandardTokenService.DeployContractAndGetServiceAsync(web3WebSocket2, new EIP20Deployment() { InitialAmount = BigInteger.Parse("1000000000000000000000000"), DecimalUnits = 18, TokenName = "TEST", TokenSymbol = "TST" }); var receipt3 = await service3.TransferRequestAndWaitForReceiptAsync("0x12890d2cce102216644c59daE5baed380d84830d", 10000); var balanceMyAccount2 = await service2.BalanceOfQueryAsync("0x12890d2cce102216644c59daE5baed380d84830c"); }
public async void ShouldCompletePoItemAndPaySellerLessFees() { // Prepare a new PO Buyer.Po poAsRequested = await CreateBuyerPoAsync(quoteId : GetRandomInt()); var signature = poAsRequested.GetSignatureBytes(_contracts.Web3); // Test setup - transfer required funds from current Web3 acccount to wallet buyer BuyerWalletService bws = _contracts.Deployment.BuyerWalletService; SellerAdminService sas = _contracts.Deployment.SellerAdminService; StandardTokenService sts = new StandardTokenService(_contracts.Web3, poAsRequested.CurrencyAddress); var totalPoValue = poAsRequested.GetTotalCurrencyValue(); var txTransfer = await sts.TransferRequestAndWaitForReceiptAsync(poAsRequested.BuyerWalletAddress, totalPoValue); txTransfer.Status.Value.Should().Be(1); // Create PO on-chain // NB: this approves token transfer from BUYER WALLET contract (NOT msg.sender == current web3 account) to FUNDING contract var txReceiptCreate = await bws.CreatePurchaseOrderRequestAndWaitForReceiptAsync(poAsRequested, signature); txReceiptCreate.Status.Value.Should().Be(1); _output.WriteLine($"... PO created ..."); // Get the PO number that was assigned var logPoCreated = txReceiptCreate.DecodeAllEvents <PurchaseOrderCreatedLogEventDTO>().FirstOrDefault(); logPoCreated.Should().NotBeNull(); var poNumberAsBuilt = logPoCreated.Event.Po.PoNumber; // NB: Payment goes to the SellerAdmin address var sellerAdminBalanceBefore = await sts.BalanceOfQueryAsync(_contracts.Deployment.SellerAdminService.ContractHandler.ContractAddress); _output.WriteLine($"SellerAdmin balance before completion: {await sellerAdminBalanceBefore.PrettifyAsync(sts)}"); // Process PO item through to completion (completion step will release funds) // Mark PO item as Accepted var txReceiptAccept = await sas.SetPoItemAcceptedRequestAndWaitForReceiptAsync( poAsRequested.EShopId, poNumberAsBuilt, PO_ITEM_NUMBER, SALES_ORDER_NUMBER, SALES_ORDER_ITEM); txReceiptAccept.Status.Value.Should().Be(1); // Mark PO item as Ready for Goods Issue var txReceiptReadyForGI = await sas.SetPoItemReadyForGoodsIssueRequestAndWaitForReceiptAsync( poAsRequested.EShopId, poNumberAsBuilt, PO_ITEM_NUMBER); txReceiptReadyForGI.Status.Value.Should().Be(1); // Mark PO item as Goods Issued var txReceiptGI = await sas.SetPoItemGoodsIssuedRequestAndWaitForReceiptAsync( poAsRequested.EShopId, poNumberAsBuilt, PO_ITEM_NUMBER); txReceiptGI.Status.Value.Should().Be(1); // Mark PO item as Goods Received by the Buyer (so we don't have to wait 30 days) var txReceiptGR = await bws.SetPoItemGoodsReceivedRequestAndWaitForReceiptAsync( poAsRequested.EShopId, poNumberAsBuilt, PO_ITEM_NUMBER); txReceiptGR.Status.Value.Should().Be(1); // Mark PO item as Complete var txReceiptCompleted = await sas.SetPoItemCompletedRequestAndWaitForReceiptAsync( poAsRequested.EShopId, poNumberAsBuilt, PO_ITEM_NUMBER); txReceiptCompleted.Status.Value.Should().Be(1); var poItemValue = poAsRequested.PoItems[PO_ITEM_INDEX].CurrencyValue; _output.WriteLine($"... PO item completed with value {await poItemValue.PrettifyAsync(sts)} ..."); // Check log exists for Escrow release var logPoItemCompleted = txReceiptCompleted.DecodeAllEvents <PurchaseItemEscrowReleasedLogEventDTO>().FirstOrDefault(); logPoItemCompleted.Should().NotBeNull(); // Balance of PO buyer address after PO item rejection var sellerAdminBalanceAfter = await sts.BalanceOfQueryAsync(_contracts.Deployment.SellerAdminService.ContractHandler.ContractAddress); _output.WriteLine($"SellerAdmin balance after completion: {await sellerAdminBalanceAfter.PrettifyAsync(sts)}"); // Checks must include fees var feeBasisPoints = await _contracts.Deployment.PurchasingService.GetFeeBasisPointsQueryAsync(); var fee = poItemValue * feeBasisPoints / 10000; var diff = sellerAdminBalanceAfter - sellerAdminBalanceBefore; diff.Should().Be(poItemValue - fee, "SellerAdmin contract address should increase by PO item value minus fee"); }