Skip to content

Commit f478397

Browse files
Multiple wallet tests
1 parent 23109fe commit f478397

File tree

6 files changed

+274
-110
lines changed

6 files changed

+274
-110
lines changed

Monero.Lws.IntegrationTests/Monero.Lws.IntegrationTests.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@
2727
<Content Include="..\.dockerignore">
2828
<Link>.dockerignore</Link>
2929
</Content>
30+
<None Remove="settings.json" />
31+
<Content Include="settings.json">
32+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
33+
</Content>
3034
</ItemGroup>
3135

3236
<ItemGroup>

Monero.Lws.IntegrationTests/MoneroLwsServiceIntegrationTest.cs

Lines changed: 155 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ namespace Monero.Lws.IntegrationTests;
77

88
public class MoneroLwsServiceIntegrationTest
99
{
10-
private static readonly string Address = TestUtils.Address;
11-
private static readonly string ViewKey = TestUtils.PrivateViewKey;
10+
private static readonly List<WalletInfo> Wallets = TestUtils.Config.Wallets;
1211
private static readonly MoneroLwsService Lws = TestUtils.GetLwsService();
1312

1413
[Fact]
@@ -43,18 +42,21 @@ public async Task GetDaemonStatus()
4342
[Fact]
4443
public async Task TestLogin()
4544
{
46-
var response = await Lws.Login(Address, ViewKey, true, true);
47-
if (response.NewAddress)
45+
foreach (var wallet in Wallets)
4846
{
49-
Assert.True(response.GeneratedLocally);
50-
if (response.StartHeight != null)
47+
var response = await Lws.Login(wallet.PrimaryAddress, wallet.PrivateViewKey, true, true);
48+
if (response.NewAddress)
5149
{
52-
Assert.True(response.StartHeight > 0);
50+
Assert.True(response.GeneratedLocally);
51+
if (response.StartHeight != null)
52+
{
53+
Assert.True(response.StartHeight > 0);
54+
}
5355
}
54-
}
55-
else
56-
{
57-
Assert.Null(response.StartHeight);
56+
else
57+
{
58+
Assert.Null(response.StartHeight);
59+
}
5860
}
5961
}
6062

@@ -88,43 +90,49 @@ public async Task TestAcceptRequests()
8890
[Fact]
8991
public async Task TestGetAddressInfo()
9092
{
91-
var response = await Lws.GetAddressInfo(Address, ViewKey);
92-
Assert.True(response.StartHeight >= 0);
93-
Assert.True(response.BlockchainHeight > 0);
94-
Assert.True(response.ScannedBlockHeight > 0);
95-
Assert.True(response.ScannedHeight > 0);
96-
Assert.True(response.TransactionHeight > 0);
97-
Assert.False(string.IsNullOrEmpty(response.LockedFunds));
98-
Assert.False(string.IsNullOrEmpty(response.TotalReceived));
99-
Assert.False(string.IsNullOrEmpty(response.TotalSent));
100-
101-
if (response.TotalSent != "0")
102-
{
103-
Assert.NotNull(response.SpentOutputs);
104-
Assert.NotEmpty(response.SpentOutputs);
105-
TestSpends(response.SpentOutputs);
106-
}
93+
foreach (var wallet in Wallets)
94+
{
95+
var response = await Lws.GetAddressInfo(wallet.PrimaryAddress, wallet.PrivateViewKey);
96+
Assert.True(response.StartHeight >= 0);
97+
Assert.True(response.BlockchainHeight > 0);
98+
Assert.True(response.ScannedBlockHeight > 0);
99+
Assert.True(response.ScannedHeight > 0);
100+
Assert.True(response.TransactionHeight > 0);
101+
Assert.False(string.IsNullOrEmpty(response.LockedFunds));
102+
Assert.False(string.IsNullOrEmpty(response.TotalReceived));
103+
Assert.False(string.IsNullOrEmpty(response.TotalSent));
107104

108-
Assert.Null(response.Rates);
105+
if (response.TotalSent != "0")
106+
{
107+
Assert.NotNull(response.SpentOutputs);
108+
Assert.NotEmpty(response.SpentOutputs);
109+
TestSpends(response.SpentOutputs);
110+
}
111+
112+
Assert.Null(response.Rates);
113+
}
109114
}
110115

111116
[Fact]
112117
public async Task TestGetAddressTxs()
113118
{
114-
var response = await Lws.GetAddressTxs(Address, ViewKey);
115-
Assert.NotNull(response.TotalReceived);
116-
Assert.NotEmpty(response.TotalReceived);
117-
Assert.True(response.ScannedHeight > 0);
118-
Assert.True(response.ScannedBlockHeight > 0);
119-
Assert.True(response.StartHeight > 0);
120-
Assert.True(response.BlockchainHeight > 0);
121-
if (!response.TotalReceived.Equals("0"))
119+
foreach (var wallet in Wallets)
122120
{
123-
Assert.NotNull(response.Transactions);
124-
Assert.NotEmpty(response.Transactions);
125-
foreach (var tx in response.Transactions)
121+
var response = await Lws.GetAddressTxs(wallet.PrimaryAddress, wallet.PrivateViewKey);
122+
Assert.NotNull(response.TotalReceived);
123+
Assert.NotEmpty(response.TotalReceived);
124+
Assert.True(response.ScannedHeight > 0);
125+
Assert.True(response.ScannedBlockHeight > 0);
126+
Assert.True(response.StartHeight > 0);
127+
Assert.True(response.BlockchainHeight > 0);
128+
if (!response.TotalReceived.Equals("0"))
126129
{
127-
TestTransaction(tx);
130+
Assert.NotNull(response.Transactions);
131+
Assert.NotEmpty(response.Transactions);
132+
foreach (var tx in response.Transactions)
133+
{
134+
TestTransaction(tx);
135+
}
128136
}
129137
}
130138
}
@@ -139,51 +147,57 @@ public async Task TestGetRandomOuts()
139147
[Fact]
140148
public async Task TestGetUnspentOuts()
141149
{
142-
var response = await Lws.GetUnspentOuts(Address, ViewKey, "0", 0, true);
143-
Assert.True(response.PerByteFee > 0);
144-
Assert.True(response.FeeMask > 0);
145-
Assert.False(string.IsNullOrEmpty(response.Amount));
146-
Assert.Equal(4, response.Fees.Count);
147-
long lastFee = 0;
148-
foreach (var fee in response.Fees)
150+
foreach (var wallet in Wallets)
149151
{
150-
Assert.True(fee > lastFee);
151-
lastFee = fee;
152-
}
152+
var response = await Lws.GetUnspentOuts(wallet.PrimaryAddress, wallet.PrivateViewKey, "0", 0, true);
153+
Assert.True(response.PerByteFee > 0);
154+
Assert.True(response.FeeMask > 0);
155+
Assert.False(string.IsNullOrEmpty(response.Amount));
156+
Assert.Equal(4, response.Fees.Count);
157+
long lastFee = 0;
158+
foreach (var fee in response.Fees)
159+
{
160+
Assert.True(fee > lastFee);
161+
lastFee = fee;
162+
}
153163

154-
TestOutputs(response.Outputs);
164+
TestOutputs(response.Outputs);
165+
}
155166
}
156167

157168
[Fact]
158169
public async Task TestImportWallet()
159170
{
160-
var response = await Lws.ImportWallet(Address, ViewKey, 0);
161-
if (string.IsNullOrEmpty(response.ImportFee) || response.ImportFee.Equals("0"))
162-
{
163-
Assert.True(string.IsNullOrEmpty(response.PaymentAddress));
164-
Assert.True(string.IsNullOrEmpty(response.PaymentId));
165-
}
166-
else
171+
foreach (var wallet in Wallets)
167172
{
168-
Assert.False(string.IsNullOrEmpty(response.PaymentAddress));
169-
Assert.False(string.IsNullOrEmpty(response.PaymentId));
170-
}
173+
var response = await Lws.ImportWallet(wallet.PrimaryAddress, wallet.PrivateViewKey, 0);
174+
if (string.IsNullOrEmpty(response.ImportFee) || response.ImportFee.Equals("0"))
175+
{
176+
Assert.True(string.IsNullOrEmpty(response.PaymentAddress));
177+
Assert.True(string.IsNullOrEmpty(response.PaymentId));
178+
}
179+
else
180+
{
181+
Assert.False(string.IsNullOrEmpty(response.PaymentAddress));
182+
Assert.False(string.IsNullOrEmpty(response.PaymentId));
183+
}
171184

172-
Assert.NotNull(response.Status);
185+
Assert.NotNull(response.Status);
173186

174-
if (response.NewRequest)
175-
{
176-
Assert.False(response.RequestFulfilled);
177-
Assert.Equal("Accepted, waiting for approval", response.Status);
178-
}
187+
if (response.NewRequest)
188+
{
189+
Assert.False(response.RequestFulfilled);
190+
Assert.Equal("Accepted, waiting for approval", response.Status);
191+
}
179192

180-
if (response.RequestFulfilled)
181-
{
182-
Assert.NotNull(response.Status);
183-
}
184-
else if (!response.NewRequest)
185-
{
186-
Assert.Equal("Waiting for Approval", response.Status);
193+
if (response.RequestFulfilled)
194+
{
195+
Assert.NotNull(response.Status);
196+
}
197+
else if (!response.NewRequest)
198+
{
199+
Assert.Equal("Waiting for Approval", response.Status);
200+
}
187201
}
188202
}
189203

@@ -197,51 +211,70 @@ public async Task TestUpsertSubaddrs()
197211
};
198212
entry.Ranges.Add([2, 10]);
199213
subaddrs.Add(entry);
200-
var response = await Lws.UpsertSubaddrs(Address, ViewKey, subaddrs, true);
201-
TestSubaddrs(response, true, true);
214+
foreach (var wallet in Wallets)
215+
{
216+
var response = await Lws.UpsertSubaddrs(wallet.PrimaryAddress, wallet.PrivateViewKey, subaddrs, true);
217+
TestSubaddrs(response, true, true);
218+
}
202219
}
203220

204221
[Fact]
205222
public async Task TestProvisionSubaddrs()
206223
{
207-
var response = await Lws.ProvisionSubaddrs(Address, ViewKey, 0, 20, 1, 1, true);
208-
TestSubaddrs(response, true, true);
224+
foreach (var wallet in Wallets)
225+
{
226+
var response = await Lws.ProvisionSubaddrs(wallet.PrimaryAddress, wallet.PrivateViewKey, 0, 20, 1, 1, true);
227+
TestSubaddrs(response, true, true);
228+
}
209229
}
210230

211231
[Fact]
212232
public async Task TestGetSubaddrs()
213233
{
214-
var response = await Lws.GetSubaddrs(Address, ViewKey);
215-
Assert.Empty(response.NewSubaddrs);
216-
Assert.NotNull(response.AllSubaddrs);
217-
Assert.NotEmpty(response.AllSubaddrs);
218-
foreach (var entry in response.AllSubaddrs)
234+
foreach (var wallet in Wallets)
219235
{
220-
TestSubaddrsEntry(entry);
236+
var response = await Lws.GetSubaddrs(wallet.PrimaryAddress, wallet.PrivateViewKey);
237+
Assert.Empty(response.NewSubaddrs);
238+
Assert.NotNull(response.AllSubaddrs);
239+
Assert.NotEmpty(response.AllSubaddrs);
240+
foreach (var entry in response.AllSubaddrs)
241+
{
242+
TestSubaddrsEntry(entry);
243+
}
221244
}
222245
}
223246

224247
[Fact]
225248
public async Task TestRescan()
226249
{
227-
var response = await Lws.Rescan(0, [Address]);
250+
List<string> addresses = [];
251+
foreach (var wallet in Wallets)
252+
{
253+
addresses.Add(wallet.PrimaryAddress);
254+
}
255+
256+
var response = await Lws.Rescan(0, addresses);
228257
Assert.NotEmpty(response.UpdatedAddresses);
229-
Assert.Single(response.UpdatedAddresses);
230-
Assert.Equal(Address, response.UpdatedAddresses.First());
258+
Assert.Equal(response.UpdatedAddresses.Count, addresses.Count);
259+
TestAddressesEqual(addresses, response.UpdatedAddresses);
231260
}
232261

233262
[Fact]
234263
public async Task TestValidate()
235264
{
236-
var response = await Lws.Validate(TestUtils.PublicViewKey, TestUtils.PublicSpendKey, TestUtils.PrivateViewKey);
237-
238-
if (response.Error != null)
265+
foreach (var wallet in Wallets)
239266
{
240-
Assert.Fail($"{response.Error.Field}: {response.Error.Details}");
241-
}
267+
var response = await Lws.Validate(wallet.PublicViewKey, wallet.PublicSpendKey,
268+
wallet.PrivateViewKey);
242269

243-
Assert.False(string.IsNullOrEmpty(response.Address));
244-
Assert.Equal(TestUtils.Address, response.Address);
270+
if (response.Error != null)
271+
{
272+
Assert.Fail($"{response.Error.Field}: {response.Error.Details}");
273+
}
274+
275+
Assert.False(string.IsNullOrEmpty(response.Address));
276+
Assert.Equal(wallet.PrimaryAddress, response.Address);
277+
}
245278
}
246279

247280
[Fact]
@@ -284,20 +317,24 @@ public async Task TestAddAccount()
284317
[Fact]
285318
public async Task TestModifyAccountStatus()
286319
{
320+
List<string> addresses = [];
321+
foreach (var wallet in Wallets)
322+
{
323+
addresses.Add(wallet.PrimaryAddress);
324+
}
325+
287326
// deactivate account
288-
var response = await Lws.ModifyAccountStatus("inactive", [TestUtils.Address]);
289-
Assert.NotEmpty(response.UpdatedAddresses);
290-
Assert.Single(response.UpdatedAddresses);
291-
Assert.Equal(TestUtils.Address, response.UpdatedAddresses.First());
327+
var response = await Lws.ModifyAccountStatus("inactive", addresses);
328+
TestAddressesEqual(addresses, response.UpdatedAddresses);
292329
// wait for lws to catch up
293330
Thread.Sleep(5000);
294331
// reactivate account
295-
response = await Lws.ModifyAccountStatus("active", [TestUtils.Address]);
296-
Assert.NotEmpty(response.UpdatedAddresses);
297-
Assert.Single(response.UpdatedAddresses);
298-
Assert.Equal(TestUtils.Address, response.UpdatedAddresses.First());
332+
response = await Lws.ModifyAccountStatus("active", addresses);
333+
TestAddressesEqual(addresses, response.UpdatedAddresses);
299334
}
300-
335+
336+
#region Test Utils
337+
301338
private static void TestTransaction(MoneroLwsTransaction? tx)
302339
{
303340
Assert.NotNull(tx);
@@ -500,4 +537,19 @@ private static void TestAccounts(List<MoneroLwsAccount>? accounts)
500537
{
501538
TestAccounts(accounts, false);
502539
}
540+
541+
private static void TestAddressesEqual(List<string>? addresses, List<string>? others)
542+
{
543+
Assert.NotNull(addresses);
544+
Assert.NotNull(others);
545+
Assert.Equal(addresses.Count, others.Count);
546+
for (int i = 0; i < others.Count; i++)
547+
{
548+
var address = addresses[i];
549+
var other = others[i];
550+
Assert.Equal(address, other);
551+
}
552+
}
553+
554+
#endregion
503555
}

0 commit comments

Comments
 (0)