Skip to content

Commit ed1d5ad

Browse files
Merge branch 'master' into Fix/markInactiveChains
2 parents 875bd1a + b167223 commit ed1d5ad

File tree

14 files changed

+247
-11
lines changed

14 files changed

+247
-11
lines changed

.gitmodules

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
url = https://github.com/0xsequence/contracts-library.git
44
[submodule "testchain/lib/forge-std"]
55
path = testchain/lib/forge-std
6-
url = https://github.com/foundry-rs/forge-stdy
6+
url = https://github.com/foundry-rs/forge-std
Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
using System.Numerics;
4+
using NUnit.Framework;
5+
using UnityEngine;
6+
using UnityEngine.TestTools;
7+
using Sequence.Utils;
8+
9+
public class DecimalNormalizerTests
10+
{
11+
[Test]
12+
public void Normalize_WithDefaultDecimals_ReturnsCorrectString()
13+
{
14+
string result = DecimalNormalizer.Normalize(1.5f);
15+
Assert.AreEqual("1500000000000000000", result);
16+
}
17+
18+
[Test]
19+
public void Normalize_WithCustomDecimals_ReturnsCorrectString()
20+
{
21+
string result = DecimalNormalizer.Normalize(1.5f, 6);
22+
Assert.AreEqual("1500000", result);
23+
}
24+
25+
[Test]
26+
public void Normalize_WithZero_ReturnsZero()
27+
{
28+
string result = DecimalNormalizer.Normalize(0f);
29+
Assert.AreEqual("0", result);
30+
}
31+
32+
[Test]
33+
public void Normalize_WithNegativeNumber_ReturnsPositiveResult()
34+
{
35+
string result = DecimalNormalizer.Normalize(-1.5f, 6);
36+
Assert.AreEqual("1500000", result);
37+
}
38+
39+
[Test]
40+
public void NormalizeAsBigInteger_WithDefaultDecimals_ReturnsCorrectBigInteger()
41+
{
42+
BigInteger result = DecimalNormalizer.NormalizeAsBigInteger(1.5f);
43+
BigInteger expected = new BigInteger(1500000000000000000);
44+
Assert.AreEqual(expected, result);
45+
}
46+
47+
[Test]
48+
public void NormalizeAsBigInteger_WithCustomDecimals_ReturnsCorrectBigInteger()
49+
{
50+
BigInteger result = DecimalNormalizer.NormalizeAsBigInteger(2.75f, 4);
51+
BigInteger expected = new BigInteger(27500);
52+
Assert.AreEqual(expected, result);
53+
}
54+
55+
[Test]
56+
public void NormalizeAsBigInteger_WithSmallNumber_ReturnsCorrectBigInteger()
57+
{
58+
BigInteger result = DecimalNormalizer.NormalizeAsBigInteger(0.001f, 6);
59+
BigInteger expected = new BigInteger(1000);
60+
Assert.AreEqual(expected, result);
61+
}
62+
63+
[Test]
64+
public void ReturnToNormalString_WithWholeNumber_ReturnsCorrectString()
65+
{
66+
BigInteger input = new BigInteger(1500000000000000000);
67+
string result = DecimalNormalizer.ReturnToNormalString(input, 18);
68+
Assert.AreEqual("1.5", result);
69+
}
70+
71+
[Test]
72+
public void ReturnToNormalString_WithCustomDecimals_ReturnsCorrectString()
73+
{
74+
BigInteger input = new BigInteger(1500000);
75+
string result = DecimalNormalizer.ReturnToNormalString(input, 6);
76+
Assert.AreEqual("1.5", result);
77+
}
78+
79+
[Test]
80+
public void ReturnToNormalString_WithSmallNumber_ReturnsCorrectString()
81+
{
82+
BigInteger input = new BigInteger(1000);
83+
string result = DecimalNormalizer.ReturnToNormalString(input, 6);
84+
Assert.AreEqual("0.001", result);
85+
}
86+
87+
[Test]
88+
public void ReturnToNormalString_WithZero_ReturnsZero()
89+
{
90+
BigInteger input = new BigInteger(0);
91+
string result = DecimalNormalizer.ReturnToNormalString(input, 18);
92+
Assert.AreEqual("0", result);
93+
}
94+
95+
[Test]
96+
public void ReturnToNormalString_WithNegativeNumber_ReturnsPositiveResult()
97+
{
98+
BigInteger input = new BigInteger(-1500000000000000000);
99+
string result = DecimalNormalizer.ReturnToNormalString(input, 18);
100+
Assert.AreEqual("1.5", result);
101+
}
102+
103+
[Test]
104+
public void ReturnToNormalString_WithTrailingZeros_TrimsZeros()
105+
{
106+
BigInteger input = new BigInteger(1500000000000000000);
107+
string result = DecimalNormalizer.ReturnToNormalString(input, 18);
108+
Assert.AreEqual("1.5", result);
109+
}
110+
111+
[Test]
112+
public void ReturnToNormal_WithBigInteger_ReturnsCorrectFloat()
113+
{
114+
BigInteger input = new BigInteger(1500000000000000000);
115+
float result = DecimalNormalizer.ReturnToNormal(input, 18);
116+
Assert.AreEqual(1.5f, result, 0.0001f);
117+
}
118+
119+
[Test]
120+
public void ReturnToNormal_WithCustomDecimals_ReturnsCorrectFloat()
121+
{
122+
BigInteger input = new BigInteger(2750000);
123+
float result = DecimalNormalizer.ReturnToNormal(input, 6);
124+
Assert.AreEqual(2.75f, result, 0.0001f);
125+
}
126+
127+
[Test]
128+
public void ReturnToNormalPrecise_WithBigInteger_ReturnsCorrectDecimal()
129+
{
130+
BigInteger input = new BigInteger(1500000000000000000);
131+
decimal result = DecimalNormalizer.ReturnToNormalPrecise(input, 18);
132+
Assert.AreEqual(1.5m, result);
133+
}
134+
135+
[Test]
136+
public void ReturnToNormalPrecise_WithCustomDecimals_ReturnsCorrectDecimal()
137+
{
138+
BigInteger input = new BigInteger(3250000);
139+
decimal result = DecimalNormalizer.ReturnToNormalPrecise(input, 6);
140+
Assert.AreEqual(3.25m, result);
141+
}
142+
143+
[Test]
144+
public void RoundTrip_NormalizeAndReturnToNormal_PreservesValue()
145+
{
146+
float originalValue = 12.34f;
147+
int decimals = 6;
148+
149+
BigInteger normalized = DecimalNormalizer.NormalizeAsBigInteger(originalValue, decimals);
150+
float returned = DecimalNormalizer.ReturnToNormal(normalized, decimals);
151+
152+
Assert.AreEqual(originalValue, returned, 0.0001f);
153+
}
154+
155+
[Test]
156+
public void EdgeCase_VerySmallNumber_HandlesCorrectly()
157+
{
158+
float verySmall = 0.000001f;
159+
int decimals = 18;
160+
161+
string normalized = DecimalNormalizer.Normalize(verySmall, decimals);
162+
BigInteger bigInt = BigInteger.Parse(normalized);
163+
float returned = DecimalNormalizer.ReturnToNormal(bigInt, decimals);
164+
165+
Assert.AreEqual(verySmall, returned, 0.0000001f);
166+
}
167+
168+
[Test]
169+
public void EdgeCase_LargeNumber_HandlesCorrectly()
170+
{
171+
float largeNumber = 9999.99f;
172+
int decimals = 6;
173+
174+
BigInteger normalized = DecimalNormalizer.NormalizeAsBigInteger(largeNumber, decimals);
175+
float returned = DecimalNormalizer.ReturnToNormal(normalized, decimals);
176+
177+
Assert.AreEqual(largeNumber, returned, 0.01f);
178+
}
179+
180+
[Test]
181+
public void BugReproTest_String()
182+
{
183+
BigInteger input = BigInteger.Parse("10000000000000000000000000");
184+
185+
string result = DecimalNormalizer.ReturnToNormalString(input, 18);
186+
187+
Assert.AreEqual("10000000", result);
188+
}
189+
190+
[Test]
191+
public void BugReproTest_Float()
192+
{
193+
BigInteger input = BigInteger.Parse("10000000000000000000000000");
194+
195+
float result = DecimalNormalizer.ReturnToNormal(input, 18);
196+
197+
Assert.AreEqual(10000000f, result);
198+
}
199+
200+
[Test]
201+
public void BugReproTest_Decimal()
202+
{
203+
BigInteger input = BigInteger.Parse("10000000000000000000000000");
204+
205+
decimal result = DecimalNormalizer.ReturnToNormalPrecise(input, 18);
206+
207+
Assert.AreEqual(decimal.Parse("10000000"), result);
208+
}
209+
}

Assets/SequenceSDK/Utils/Tests/DecimalNormalizerTests.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/SequenceSDK/WaaS/Tests/MockIntentSender.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public Task<T> PostIntent<T>(string payload, string path)
4646
throw new System.NotImplementedException();
4747
}
4848

49-
public Task<Session[]> ListSessions()
49+
public Task<Session[]> ListSessions(Address walletAddress = null)
5050
{
5151
throw new System.NotImplementedException();
5252
}

Packages/Sequence-Unity/Sequence/Samples~/DemoScene/Demo.unity

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ RenderSettings:
3838
m_ReflectionIntensity: 1
3939
m_CustomReflection: {fileID: 0}
4040
m_Sun: {fileID: 0}
41-
m_IndirectSpecularColor: {r: 0.44657815, g: 0.49641192, b: 0.57481617, a: 1}
41+
m_IndirectSpecularColor: {r: 0.44657844, g: 0.49641258, b: 0.57481694, a: 1}
4242
m_UseRadianceAmbientProbe: 0
4343
--- !u!157 &3
4444
LightmapSettings:
@@ -252,7 +252,7 @@ MonoBehaviour:
252252
saleAddress: 0x476f14887372e21fea64baba11c849b518a2e928
253253
itemsForSale: 010000000200000003000000
254254
secondarySale:
255-
collectionAddress: 0x079294e6ffec16234578c672fa3fbfd4b6c48640
255+
collectionAddress: 0x0ee3af1874789245467e7482f042ced9c5171073
256256
chain: 137
257257
checkout: 1
258258
_featureSelection: {fileID: 1094787527}

Packages/Sequence-Unity/Sequence/SequenceFrontend/Scripts/UI/Boilerplates/BoilerplateFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public static SequenceInGameShop OpenSequenceInGameShop(Transform parent, IWalle
115115
public static ViewMarketplaceListingsPanel OpenViewMarketplaceListingsPanel(Transform parent, IWallet wallet, Chain chain, Address marketplaceCollectionAddress, Action onClose = null)
116116
{
117117
return GetOrSpawnBoilerplate<ViewMarketplaceListingsPanel>("Marketplace/ViewMarketplaceListingsPanel", parent,
118-
b => b.Open(wallet, chain, onClose));
118+
b => b.Open(wallet, chain, marketplaceCollectionAddress, onClose));
119119
}
120120

121121
/// <summary>

Packages/Sequence-Unity/Sequence/SequenceSDK/Authentication/OpenIdAuthenticator.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,8 @@ private string GenerateSignInUrl(string baseUrl, string clientId, string state)
231231

232232
string url =
233233
$"{baseUrl}?response_type=code+id_token&client_id={clientId}&redirect_uri={_redirectUrl}&scope=openid+email&state={state}/";
234-
if (PlayerPrefs.HasKey(LoginEmail))
234+
235+
if (PlayerPrefs.HasKey(LoginEmail) && !string.IsNullOrEmpty(PlayerPrefs.GetString(LoginEmail)))
235236
{
236237
url = url.RemoveTrailingSlash() + $"&login_hint={PlayerPrefs.GetString(LoginEmail)}".AppendTrailingSlashIfNeeded();
237238
url = url.Replace(" ", "");

Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/IIntentSender.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public interface IIntentSender
77
public Task<T> SendIntent<T, T2>(T2 args, IntentType type, uint timeBeforeExpiryInSeconds = 30, uint currentTime = 0);
88
public Task<bool> DropSession(string dropSessionId);
99
public Task<T> PostIntent<T>(string payload, string path);
10-
public Task<Session[]> ListSessions();
10+
public Task<Session[]> ListSessions(Address walletAddress = null);
1111
public Task<SuccessfulTransactionReturn> GetTransactionReceipt(SuccessfulTransactionReturn response);
1212
}
1313
}

Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/IntentSender.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,14 @@ public async Task<T> PostIntent<T>(string payload, string path)
173173
return result;
174174
}
175175

176-
public async Task<Session[]> ListSessions()
176+
public async Task<Session[]> ListSessions(Address walletAddress = null)
177177
{
178+
if (walletAddress == null)
179+
{
180+
walletAddress = _sessionWallet.GetAddress();
181+
}
178182
Session[] sessions = await SendIntent<Session[], IntentDataListSessions>(
179-
new IntentDataListSessions(_sessionWallet.GetAddress()), IntentType.ListSessions);
183+
new IntentDataListSessions(walletAddress), IntentType.ListSessions);
180184
return sessions;
181185
}
182186

Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/SequenceWallet.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ public async Task<Session[]> ListSessions()
247247
Session[] results = null;
248248
try
249249
{
250-
results = await _intentSender.ListSessions();
250+
results = await _intentSender.ListSessions(GetWalletAddress());
251251
}
252252
catch (Exception e)
253253
{

0 commit comments

Comments
 (0)