Skip to content

Commit 3fe35c4

Browse files
authored
Merge pull request #161 from IOTA-NET/31-test-sendamount
Added SendAmountTests
2 parents 71c296f + 4937f8d commit 3fe35c4

File tree

2 files changed

+141
-2
lines changed

2 files changed

+141
-2
lines changed
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
using FluentAssertions;
2+
using IotaWalletNet.Application.AccountContext.Commands.GenerateAddresses;
3+
using IotaWalletNet.Application.AccountContext.Queries.GetBalance;
4+
using IotaWalletNet.Application.Common.Interfaces;
5+
using IotaWalletNet.Domain.Common.Models.Address;
6+
using IotaWalletNet.Tests.Common.Interfaces;
7+
using Microsoft.Extensions.DependencyInjection;
8+
9+
namespace IotaWalletNet.Tests.AccountContext.Commands.RequestFromFaucet
10+
{
11+
12+
[Collection("Sequential")]
13+
public class SendAmountTests : DependencyTestBase, IDisposable
14+
{
15+
[Fact]
16+
public async Task AccountShouldBeAbleTSendTokens()
17+
{
18+
IWallet wallet = _serviceScope.ServiceProvider.GetRequiredService<IWallet>();
19+
20+
wallet = await CreateFullWalletAsync(wallet);
21+
22+
(_, IAccount? account) = await wallet.CreateAccountAsync("cookiemonster");
23+
24+
25+
string address = (await account.GetAddressesAsync()).Payload!.First().Address;
26+
27+
await account.RequestFromFaucetAsync(address);
28+
29+
await Task.Delay(TimeSpan.FromSeconds(SLEEP_DURATION_SECONDS_FAUCET));
30+
31+
long oldBalance = await GetBalanceAsync(account);
32+
33+
oldBalance.Should().Be(1000_000_000); //given by faucet, 1000 SMR
34+
35+
oldBalance = await TestSendAmountByUsingASingleAmount(oldBalance, account);
36+
37+
oldBalance = await TestSendAmountByUsingMultipleAmounts(oldBalance, account);
38+
39+
oldBalance = await TestSendAmountBuilderByUsingASingleAmount(oldBalance, account);
40+
41+
oldBalance = await TestSendAmountBuilderByUsingMultipleAmounts(oldBalance, account);
42+
}
43+
44+
private async Task<long> TestSendAmountByUsingASingleAmount(long oldBalance, IAccount account)
45+
{
46+
List<AddressWithAmount> addressWithAmounts = new List<AddressWithAmount>()
47+
{
48+
new AddressWithAmount(ANOTHER_WALLET_ADDRESS, "1000000")
49+
};
50+
51+
await account.SendAmountAsync(addressWithAmounts);
52+
53+
await Task.Delay(TimeSpan.FromSeconds(SLEEP_DURATION_SECONDS_TRANSACTION));
54+
55+
long newBalance = await GetBalanceAsync(account);
56+
57+
long difference = oldBalance - newBalance;
58+
59+
difference.Should().Be(1_000_000);
60+
61+
return newBalance;
62+
}
63+
64+
private async Task<long> TestSendAmountByUsingMultipleAmounts(long oldBalance, IAccount account)
65+
{
66+
List<AddressWithAmount> addressWithAmounts = new List<AddressWithAmount>()
67+
{
68+
new AddressWithAmount(ANOTHER_WALLET_ADDRESS, "1000000"),
69+
new AddressWithAmount(ANOTHER_WALLET_ADDRESS, "1000000")
70+
71+
};
72+
73+
await account.SendAmountAsync(addressWithAmounts);
74+
75+
await Task.Delay(TimeSpan.FromSeconds(SLEEP_DURATION_SECONDS_TRANSACTION));
76+
77+
long newBalance = await GetBalanceAsync(account);
78+
79+
long difference = oldBalance - newBalance;
80+
81+
difference.Should().Be(2_000_000);
82+
83+
return newBalance;
84+
85+
}
86+
87+
88+
private async Task<long> TestSendAmountBuilderByUsingASingleAmount(long oldBalance, IAccount account)
89+
{
90+
await account.SendAmountUsingBuilder()
91+
.AddAddressAndAmount(ANOTHER_WALLET_ADDRESS, 1_000_000)
92+
.SendAmountAsync();
93+
94+
await Task.Delay(TimeSpan.FromSeconds(SLEEP_DURATION_SECONDS_TRANSACTION));
95+
96+
long newBalance = await GetBalanceAsync(account);
97+
98+
long difference = oldBalance - newBalance;
99+
100+
difference.Should().Be(1_000_000);
101+
102+
return newBalance;
103+
}
104+
105+
private async Task<long> TestSendAmountBuilderByUsingMultipleAmounts(long oldBalance, IAccount account)
106+
{
107+
await account.SendAmountUsingBuilder()
108+
.AddAddressAndAmount(ANOTHER_WALLET_ADDRESS, 1_000_000)
109+
.AddAddressAndAmount(ANOTHER_WALLET_ADDRESS, 1_000_000)
110+
.SendAmountAsync();
111+
112+
await Task.Delay(TimeSpan.FromSeconds(SLEEP_DURATION_SECONDS_TRANSACTION));
113+
114+
long newBalance = await GetBalanceAsync(account);
115+
116+
long difference = oldBalance - newBalance;
117+
118+
difference.Should().Be(2000000);
119+
120+
return newBalance;
121+
122+
}
123+
124+
125+
private async Task<long> GetBalanceAsync(IAccount account)
126+
{
127+
await account.SyncAccountAsync();
128+
129+
GetBalanceResponse getBalanceResponse = await account.GetBalanceAsync();
130+
131+
long balance = long.Parse(getBalanceResponse.Payload!.BaseCoin.Total);
132+
133+
return balance;
134+
}
135+
136+
137+
138+
}
139+
}

csharp/IotaWalletNet/IotaWalletNet.Tests/Common/Interfaces/DependencyTestBase.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ public class DependencyTestBase : IDisposable
1212
protected const string DEFAULT_FAUCET_URL = @"https://faucet.testnet.shimmer.network";
1313
protected const string ANOTHER_WALLET_ADDRESS = "rms1qz8wf6jrchvsfmcnsfhlf6s53x3u85y0j4hvwth9a5ff3xhrxtmvvyc9ae7";
1414
protected const int SLEEP_DURATION_SECONDS_TRANSACTION = 10;
15-
protected const int SLEEP_DURATION_SECONDS_FAUCET = 15;
16-
protected const int SLEEP_DURATION_SECONDS_API_RATE_LIMIT = 2;
15+
protected const int SLEEP_DURATION_SECONDS_FAUCET = 10;
16+
protected const int SLEEP_DURATION_SECONDS_API_RATE_LIMIT = 0;
1717
protected List<string> filesCreated;
1818
public DependencyTestBase()
1919
{

0 commit comments

Comments
 (0)