forked from btcpay-monero/monero-csharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMoneroUtilsUnitTest.cs
More file actions
136 lines (122 loc) · 4.82 KB
/
Copy pathMoneroUtilsUnitTest.cs
File metadata and controls
136 lines (122 loc) · 4.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
using Monero.Common;
using Monero.Wallet.Common;
using Xunit;
using static Monero.Common.MoneroUtils;
using static Xunit.Assert;
namespace Monero.UnitTests;
public class MoneroUtilsUnitTest
{
// Can validate keys
[Fact]
public void TestKeyValidation()
{
// test private view key validation
True(IsValidPrivateViewKey("86cf351d10894769feba29b9e201e12fb100b85bb52fc5825c864eef55c5840d"));
TestInvalidPrivateViewKey("");
TestInvalidPrivateViewKey(null);
TestInvalidPrivateViewKey(
"5B8s3obCY2ETeQB3GNAGPK2zRGen5UeW1WzegSizVsmf6z5NvM2GLoN6zzk1vHyzGAAfA8pGhuYAeCFZjHAp59jRVQkunGS");
// test public view key validation
True(IsValidPublicViewKey("99873d76ca874ff1aad676b835dd303abcb21c9911ca8a3d9130abc4544d8a0a"));
TestInvalidPublicViewKey("");
TestInvalidPublicViewKey(null);
TestInvalidPublicViewKey("z86cf351d10894769feba29b9e201e12fb100b85bb52fc5825c864eef55c5840d");
// test private spend key validation
True(IsValidPrivateSpendKey("e9ba887e93620ef9fafdfe0c6d3022949f1c5713cbd9ef631f18a0fb00421dee"));
TestInvalidPrivateSpendKey("");
TestInvalidPrivateSpendKey(null);
TestInvalidPrivateSpendKey("z86cf351d10894769feba29b9e201e12fb100b85bb52fc5825c864eef55c5840d");
// test public spend key validation
True(IsValidPublicSpendKey("3e48df9e9d8038dbf6f5382fac2becd8686273cda5bd87187e45dca7ec5af37b"));
TestInvalidPublicSpendKey("");
TestInvalidPublicSpendKey(null);
TestInvalidPublicSpendKey("z86cf351d10894769feba29b9e201e12fb100b85bb52fc5825c864eef55c5840d");
}
// Can convert between XMR and atomic units
[Fact]
public void TestAtomicUnitConversion()
{
True(1000000000000 == XmrToAtomicUnits(1));
True(1 == AtomicUnitsToXmr(1000000000000));
True(1000000000 == XmrToAtomicUnits(0.001));
True(.001 == AtomicUnitsToXmr(1000000000));
True(250000000000 == XmrToAtomicUnits(.25));
True(.25 == AtomicUnitsToXmr(250000000000));
True(1250000000000 == XmrToAtomicUnits(1.25));
True(1.25 == AtomicUnitsToXmr(1250000000000));
True(2796726190000 == XmrToAtomicUnits(2.79672619));
True(2.79672619 == AtomicUnitsToXmr(2796726190000));
True(2796726190001 == XmrToAtomicUnits(2.796726190001));
True(2.796726190001 == AtomicUnitsToXmr(2796726190001));
True(2796726189999 == XmrToAtomicUnits(2.796726189999));
True(2.796726189999 == AtomicUnitsToXmr(2796726189999));
True(2796726180000 == XmrToAtomicUnits(2.79672618));
True(2.79672618 == AtomicUnitsToXmr(2796726180000));
}
[Fact(Skip = "GetPaymentUri is not implemented yet")]
public void TestGetPaymentUri()
{
MoneroTxConfig config = new MoneroTxConfig()
.SetAddress(
"9xSyMy1r9h3BVjMrF3CTqQCQy36yCfkpn7uVfMyTUbez3hhumqBUqGUNNALjcd7f1HJBRdeH82bCC3veFHW7z3xm28gug4d")
.SetAmount(XmrToAtomicUnits(0.25))
.SetRecipientName("John Doe")
.SetNote("My transfer to wallet");
string paymentUri = "";
True(
"monero:9xSyMy1r9h3BVjMrF3CTqQCQy36yCfkpn7uVfMyTUbez3hhumqBUqGUNNALjcd7f1HJBRdeH82bCC3veFHW7z3xm28gug4d?tx_amount=0.25&recipient_name=John%20Doe&tx_description=My%20transfer%20to%20wallet" ==
paymentUri);
}
private static void TestInvalidPrivateViewKey(string? privateViewKey)
{
False(IsValidPrivateViewKey(privateViewKey));
try
{
ValidatePrivateViewKey(privateViewKey);
throw new Exception("Should have thrown exception");
}
catch (MoneroError e)
{
True(e.Message.Length > 0);
}
}
private static void TestInvalidPublicViewKey(string? publicViewKey)
{
False(IsValidPublicViewKey(publicViewKey));
try
{
ValidatePublicViewKey(publicViewKey);
throw new Exception("Should have thrown exception");
}
catch (MoneroError e)
{
True(e.Message.Length > 0);
}
}
private static void TestInvalidPrivateSpendKey(string? privateSpendKey)
{
try
{
False(IsValidPrivateSpendKey(privateSpendKey));
ValidatePrivateSpendKey(privateSpendKey);
throw new Exception("Should have thrown exception");
}
catch (MoneroError e)
{
True(e.Message.Length > 0);
}
}
private static void TestInvalidPublicSpendKey(string? publicSpendKey)
{
False(IsValidPublicSpendKey(publicSpendKey));
try
{
ValidatePublicSpendKey(publicSpendKey);
throw new Exception("Should have thrown exception");
}
catch (MoneroError e)
{
True(e.Message.Length > 0);
}
}
}