Skip to content

Commit edc3202

Browse files
authored
Decouple singleton // Instance based classes (#193)
1 parent 431e36c commit edc3202

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+1343
-1366
lines changed

Assets/Tests/StorageTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public IEnumerator Gateway_WithoutClientId_Success()
3737
Assert.AreEqual(ThirdwebManager.Instance.SDK.Storage.IPFSGateway, "https://cloudflare-ipfs.com/ipfs/");
3838

3939
string testIpfsRawUrl = "ipfs://Qblabla";
40-
Assert.AreEqual(Utils.ReplaceIPFS(testIpfsRawUrl), "https://cloudflare-ipfs.com/ipfs/Qblabla");
40+
Assert.AreEqual(Utils.ReplaceIPFS(testIpfsRawUrl, ThirdwebManager.Instance.SDK.Storage.IPFSGateway), "https://cloudflare-ipfs.com/ipfs/Qblabla");
4141

4242
yield return null;
4343
}
@@ -52,7 +52,7 @@ public IEnumerator Gateway_WithClientId_Success()
5252
Assert.AreEqual(ThirdwebManager.Instance.SDK.Storage.IPFSGateway, $"https://{clientId}.ipfscdn.io/ipfs/");
5353

5454
string testIpfsRawUrl = "ipfs://Qblabla";
55-
Assert.AreEqual(Utils.ReplaceIPFS(testIpfsRawUrl), $"https://{clientId}.ipfscdn.io/ipfs/Qblabla");
55+
Assert.AreEqual(Utils.ReplaceIPFS(testIpfsRawUrl, ThirdwebManager.Instance.SDK.Storage.IPFSGateway), $"https://{clientId}.ipfscdn.io/ipfs/Qblabla");
5656

5757
yield return null;
5858
}
@@ -67,7 +67,7 @@ public IEnumerator Gateway_WithOverride_Success()
6767
Assert.AreEqual(ThirdwebManager.Instance.SDK.Storage.IPFSGateway, ipfsGatewayUrl);
6868

6969
string testIpfsRawUrl = "ipfs://Qblabla";
70-
Assert.AreEqual(Utils.ReplaceIPFS(testIpfsRawUrl), "https://ipfs.io/ipfs/Qblabla");
70+
Assert.AreEqual(Utils.ReplaceIPFS(testIpfsRawUrl, ThirdwebManager.Instance.SDK.Storage.IPFSGateway), "https://ipfs.io/ipfs/Qblabla");
7171

7272
yield return null;
7373
}

Assets/Tests/ThirdwebManagerTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ public IEnumerator Initialization_WithClientIdNoBundleIdOverride_AppliesCorrectl
154154
ThirdwebManager.Instance.clientId = "testClientId";
155155
Assert.IsNull(ThirdwebManager.Instance.bundleIdOverride);
156156

157-
string bundleId = Utils.GetBundleId();
157+
string bundleId = Application.identifier.ToLower();
158158
Assert.IsNotNull(bundleId);
159159

160160
ThirdwebManager.Instance.supportedChains = new List<ChainData> { new("arbitrum-sepolia", "421614", null), };

Assets/Tests/ThirdwebSDKTests.cs

Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
using System;
2+
using System.Collections;
3+
using System.Collections.Generic;
4+
using System.Numerics;
5+
using NUnit.Framework;
6+
using Thirdweb;
7+
using UnityEngine;
8+
using UnityEngine.TestTools;
9+
10+
public class ThirdwebSDKTests : ConfigManager
11+
{
12+
private ThirdwebSDK _sdk;
13+
private readonly string _dropErc20Address = "0xEBB8a39D865465F289fa349A67B3391d8f910da9";
14+
15+
[SetUp]
16+
public void SetUp()
17+
{
18+
var chainId = 421614;
19+
var clientId = GetClientId();
20+
var bundleId = Application.identifier.ToLower();
21+
var options = new ThirdwebSDK.Options()
22+
{
23+
clientId = clientId,
24+
bundleId = bundleId,
25+
supportedChains = new ThirdwebChainData[] { ThirdwebSession.FetchChainData(chainId) },
26+
smartWalletConfig = new ThirdwebSDK.SmartWalletConfig()
27+
{
28+
factoryAddress = Thirdweb.AccountAbstraction.Constants.DEFAULT_FACTORY_ADDRESS,
29+
gasless = true,
30+
bundlerUrl = $"https://{chainId}.bundler.thirdweb.com",
31+
paymasterUrl = $"https://{chainId}.bundler.thirdweb.com",
32+
entryPointAddress = Thirdweb.AccountAbstraction.Constants.DEFAULT_ENTRYPOINT_ADDRESS,
33+
}
34+
};
35+
_sdk = new ThirdwebSDK($"https://{chainId}.rpc.thirdweb.com/{clientId}&bundleId={bundleId}", 421614, options);
36+
}
37+
38+
[TearDown]
39+
public void TearDown()
40+
{
41+
_sdk = null;
42+
}
43+
44+
[UnityTest]
45+
public IEnumerator Initialization_Success()
46+
{
47+
Assert.IsNotNull(_sdk);
48+
Assert.AreEqual(_sdk.Session.Options.clientId, GetClientId());
49+
Assert.AreEqual(_sdk.Session.Options.bundleId, Application.identifier.ToLower());
50+
yield return null;
51+
}
52+
53+
[UnityTest]
54+
public IEnumerator ContractRead_Success()
55+
{
56+
var contract = _sdk.GetContract(_dropErc20Address);
57+
var readTask = contract.ERC20.BalanceOf(_dropErc20Address);
58+
yield return new WaitUntil(() => readTask.IsCompleted);
59+
if (readTask.IsFaulted)
60+
throw readTask.Exception;
61+
Assert.IsTrue(readTask.IsCompletedSuccessfully);
62+
Assert.NotNull(readTask.Result);
63+
}
64+
65+
[UnityTest]
66+
public IEnumerator ContractWrite_Success()
67+
{
68+
Utils.DeleteLocalAccount();
69+
var connection = new WalletConnection(provider: WalletProvider.SmartWallet, chainId: 421614, personalWallet: WalletProvider.LocalWallet);
70+
var connectTask = _sdk.Wallet.Connect(connection);
71+
yield return new WaitUntil(() => connectTask.IsCompleted);
72+
if (connectTask.IsFaulted)
73+
throw connectTask.Exception;
74+
Assert.IsTrue(connectTask.IsCompletedSuccessfully);
75+
76+
var contract = _sdk.GetContract(_dropErc20Address);
77+
var task = contract.ERC20.SetAllowance(_dropErc20Address, "0");
78+
yield return new WaitUntil(() => task.IsCompleted);
79+
if (task.IsFaulted)
80+
throw task.Exception;
81+
Assert.IsTrue(task.IsCompletedSuccessfully);
82+
Assert.IsNotNull(task.Result);
83+
Assert.IsTrue(task.Result.receipt.transactionHash.Length == 66);
84+
}
85+
86+
[UnityTest]
87+
public IEnumerator CustomContractRead_Success()
88+
{
89+
var contract = _sdk.GetContract(_dropErc20Address);
90+
var readTask = contract.Read<BigInteger>("balanceOf", _dropErc20Address);
91+
yield return new WaitUntil(() => readTask.IsCompleted);
92+
if (readTask.IsFaulted)
93+
throw readTask.Exception;
94+
Assert.IsTrue(readTask.IsCompletedSuccessfully);
95+
Assert.NotNull(readTask.Result);
96+
}
97+
98+
[UnityTest]
99+
public IEnumerator CustomContractWrite_Success()
100+
{
101+
Utils.DeleteLocalAccount();
102+
var connection = new WalletConnection(provider: WalletProvider.SmartWallet, chainId: 421614, personalWallet: WalletProvider.LocalWallet);
103+
var connectTask = _sdk.Wallet.Connect(connection);
104+
yield return new WaitUntil(() => connectTask.IsCompleted);
105+
if (connectTask.IsFaulted)
106+
throw connectTask.Exception;
107+
Assert.IsTrue(connectTask.IsCompletedSuccessfully);
108+
109+
var contract = _sdk.GetContract(_dropErc20Address);
110+
var task = contract.ERC20.SetAllowance(_dropErc20Address, "0");
111+
yield return new WaitUntil(() => task.IsCompleted);
112+
if (task.IsFaulted)
113+
throw task.Exception;
114+
Assert.IsTrue(task.IsCompletedSuccessfully);
115+
Assert.IsNotNull(task.Result);
116+
Assert.IsTrue(task.Result.receipt.transactionHash.Length == 66);
117+
}
118+
119+
[UnityTest]
120+
public IEnumerator WalletSignMessage_Success()
121+
{
122+
Utils.DeleteLocalAccount();
123+
var connection = new WalletConnection(provider: WalletProvider.LocalWallet, chainId: 421614);
124+
var connectTask = _sdk.Wallet.Connect(connection);
125+
yield return new WaitUntil(() => connectTask.IsCompleted);
126+
if (connectTask.IsFaulted)
127+
throw connectTask.Exception;
128+
Assert.IsTrue(connectTask.IsCompletedSuccessfully);
129+
130+
var message = "Hello, World!";
131+
var task = _sdk.Wallet.Sign(message);
132+
yield return new WaitUntil(() => task.IsCompleted);
133+
if (task.IsFaulted)
134+
throw task.Exception;
135+
Assert.IsTrue(task.IsCompletedSuccessfully);
136+
Assert.IsNotNull(task.Result);
137+
}
138+
139+
[UnityTest]
140+
public IEnumerator IPFSDownload_Success()
141+
{
142+
string url = "ipfs://QmNQ2djT2u4my5xpKPgJMnQEpoNjYZE8ugpLndvgEJBb3X";
143+
144+
var downloadTask = _sdk.Storage.DownloadText<string>(url);
145+
yield return new WaitUntil(() => downloadTask.IsCompleted);
146+
Assert.IsTrue(downloadTask.IsCompletedSuccessfully);
147+
Assert.IsNotNull(downloadTask.Result);
148+
Assert.IsTrue(downloadTask.Result.Length > 0);
149+
Assert.IsTrue(downloadTask.Result.StartsWith("{\"compiler\":{\"version\":\"0.8.23+commit.f704f362\"},\"language\":\"Solidity\""));
150+
}
151+
152+
[UnityTest]
153+
public IEnumerator IPFSUpload_Success()
154+
{
155+
string text = "Hello World!";
156+
var uploadTask = _sdk.Storage.UploadText(text);
157+
yield return new WaitUntil(() => uploadTask.IsCompleted);
158+
Assert.IsTrue(uploadTask.IsCompletedSuccessfully);
159+
Assert.IsNotNull(uploadTask.Result);
160+
Assert.IsNotNull(uploadTask.Result.IpfsHash);
161+
162+
string url = "ipfs://" + uploadTask.Result.IpfsHash;
163+
var downloadTask = _sdk.Storage.DownloadText<string>(url);
164+
yield return new WaitUntil(() => downloadTask.IsCompleted);
165+
Assert.IsTrue(downloadTask.IsCompletedSuccessfully);
166+
Assert.IsNotNull(downloadTask.Result);
167+
Assert.AreEqual(downloadTask.Result, text);
168+
}
169+
}
Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Tests/TransactionReadTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public void TearDown()
3737
public IEnumerator Static_WaitForTransactionResult_Success()
3838
{
3939
string txHash = "0x52b79681f549d7b01b12b8be5fa9dd88f7fee1411f965cbe7ec6e157ccb48af1";
40-
var task = Transaction.WaitForTransactionResult(txHash);
40+
var task = Transaction.WaitForTransactionResult(txHash, ThirdwebManager.Instance.SDK.Session.ChainId);
4141
yield return new WaitUntil(() => task.IsCompleted);
4242
Assert.IsTrue(task.IsCompletedSuccessfully);
4343
Assert.IsNotNull(task.Result);

Assets/Tests/WalletTests.cs

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -91,38 +91,38 @@ public IEnumerator Export_WithLocalWallet_Success()
9191
Assert.IsTrue(exportTask.Result.Length > 0);
9292
}
9393

94-
[UnityTest]
95-
public IEnumerator Authenticate_WithLocalWallet_Success()
96-
{
97-
yield return Connect_WithLocalWallet_Success();
98-
99-
var authenticateTask = ThirdwebManager.Instance.SDK.Wallet.Authenticate("example.com");
100-
yield return new WaitUntil(() => authenticateTask.IsCompleted);
101-
Assert.IsTrue(authenticateTask.IsCompletedSuccessfully);
102-
Assert.IsNotNull(authenticateTask.Result);
103-
Assert.IsTrue(authenticateTask.Result.signature.Length == 132);
104-
}
105-
106-
[UnityTest]
107-
public IEnumerator Verify_WithLocalWallet_Success()
108-
{
109-
yield return Connect_WithLocalWallet_Success();
110-
111-
var authenticateTask = ThirdwebManager.Instance.SDK.Wallet.Authenticate("example.com");
112-
yield return new WaitUntil(() => authenticateTask.IsCompleted);
113-
Assert.IsTrue(authenticateTask.IsCompletedSuccessfully);
114-
Assert.IsNotNull(authenticateTask.Result);
115-
Assert.IsTrue(authenticateTask.Result.signature.Length == 132);
116-
117-
var verifyTask = ThirdwebManager.Instance.SDK.Wallet.Verify(authenticateTask.Result);
118-
yield return new WaitUntil(() => verifyTask.IsCompleted);
119-
Assert.IsTrue(verifyTask.IsCompletedSuccessfully);
120-
121-
var getAddressTask = ThirdwebManager.Instance.SDK.Wallet.GetAddress();
122-
yield return new WaitUntil(() => getAddressTask.IsCompleted);
123-
Assert.IsTrue(getAddressTask.IsCompletedSuccessfully);
124-
Assert.AreEqual(verifyTask.Result, getAddressTask.Result);
125-
}
94+
// [UnityTest]
95+
// public IEnumerator Authenticate_WithLocalWallet_Success()
96+
// {
97+
// yield return Connect_WithLocalWallet_Success();
98+
99+
// var authenticateTask = ThirdwebManager.Instance.SDK.Wallet.Authenticate("example.com");
100+
// yield return new WaitUntil(() => authenticateTask.IsCompleted);
101+
// Assert.IsTrue(authenticateTask.IsCompletedSuccessfully);
102+
// Assert.IsNotNull(authenticateTask.Result);
103+
// Assert.IsTrue(authenticateTask.Result.signature.Length == 132);
104+
// }
105+
106+
// [UnityTest]
107+
// public IEnumerator Verify_WithLocalWallet_Success()
108+
// {
109+
// yield return Connect_WithLocalWallet_Success();
110+
111+
// var authenticateTask = ThirdwebManager.Instance.SDK.Wallet.Authenticate("example.com");
112+
// yield return new WaitUntil(() => authenticateTask.IsCompleted);
113+
// Assert.IsTrue(authenticateTask.IsCompletedSuccessfully);
114+
// Assert.IsNotNull(authenticateTask.Result);
115+
// Assert.IsTrue(authenticateTask.Result.signature.Length == 132);
116+
117+
// var verifyTask = ThirdwebManager.Instance.SDK.Wallet.Verify(authenticateTask.Result);
118+
// yield return new WaitUntil(() => verifyTask.IsCompleted);
119+
// Assert.IsTrue(verifyTask.IsCompletedSuccessfully);
120+
121+
// var getAddressTask = ThirdwebManager.Instance.SDK.Wallet.GetAddress();
122+
// yield return new WaitUntil(() => getAddressTask.IsCompleted);
123+
// Assert.IsTrue(getAddressTask.IsCompletedSuccessfully);
124+
// Assert.AreEqual(verifyTask.Result, getAddressTask.Result);
125+
// }
126126

127127
[UnityTest]
128128
public IEnumerator GetBalance_WithLocalWallet_Success()
Binary file not shown.

Assets/Thirdweb/Core/Plugins/Nethereum/Nethereum.GnosisSafe.dll.meta

Lines changed: 0 additions & 75 deletions
This file was deleted.
Binary file not shown.

0 commit comments

Comments
 (0)