Skip to content

Commit ef28f85

Browse files
committed
optimize tests
1 parent 259be1a commit ef28f85

File tree

17 files changed

+152
-204
lines changed

17 files changed

+152
-204
lines changed

.editorconfig

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,4 +138,10 @@ csharp_prefer_braces = true:warning
138138
csharp_style_deconstructed_variable_declaration = true:warning
139139
csharp_prefer_simple_default_expression = false:warning
140140
csharp_style_pattern_local_over_anonymous_function = true:warning
141-
csharp_style_inlined_variable_declaration = true:warning
141+
csharp_style_inlined_variable_declaration = true:warning
142+
143+
# CA1822: Mark members as static
144+
dotnet_diagnostic.CA1822.severity = suggestion
145+
146+
# IDE0290: Use primary constructor
147+
dotnet_diagnostic.IDE0290.severity = silent

.github/workflows/dotnet-ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ on:
99
concurrency:
1010
group: build-and-test-${{ github.ref }}
1111
cancel-in-progress: true
12-
12+
1313
jobs:
1414
build-test-cov:
1515
runs-on: ubuntu-latest
@@ -35,7 +35,7 @@ jobs:
3535
id: test
3636
run: |
3737
dotnet tool install --global coverlet.console
38-
timeout 15m dotnet test /p:CollectCoverage=true /p:CoverletOutputFormat=lcov /p:CoverletOutput=./coverage.info
38+
timeout 30m dotnet test /p:CollectCoverage=true /p:CoverletOutputFormat=lcov /p:CoverletOutput=./coverage.info
3939
shell: bash
4040
env:
4141
THIRDWEB_SECRET_KEY: ${{ secrets.THIRDWEB_SECRET_KEY }}

Thirdweb.Tests/BaseTests.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ public class BaseTests
99
protected string? ClientIdBundleIdOnly { get; }
1010
protected string? BundleIdBundleIdOnly { get; }
1111

12+
protected ThirdwebClient Client { get; }
13+
1214
public BaseTests(ITestOutputHelper output)
1315
{
1416
DotEnv.Load();
@@ -17,6 +19,8 @@ public BaseTests(ITestOutputHelper output)
1719
this.ClientIdBundleIdOnly = Environment.GetEnvironmentVariable("THIRDWEB_CLIENT_ID_BUNDLE_ID_ONLY");
1820
this.BundleIdBundleIdOnly = Environment.GetEnvironmentVariable("THIRDWEB_BUNDLE_ID_BUNDLE_ID_ONLY");
1921

22+
this.Client = ThirdwebClient.Create(secretKey: this.SecretKey);
23+
2024
this.Output.WriteLine($"Started {this.GetType().FullName}");
2125
}
2226

Thirdweb.Tests/Thirdweb.Client/Thirdweb.Client.Tests.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
namespace Thirdweb.Tests.Client;
22

3-
public class ClientTests(ITestOutputHelper output) : BaseTests(output)
3+
public class ClientTests : BaseTests
44
{
5+
public ClientTests(ITestOutputHelper output)
6+
: base(output) { }
7+
58
[Fact(Timeout = 120000)]
69
public void NoSecretKeyNoClientId()
710
{

Thirdweb.Tests/Thirdweb.Contracts/Thirdweb.Contracts.Tests.cs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22

33
namespace Thirdweb.Tests.Contracts;
44

5-
public class ContractsTests(ITestOutputHelper output) : BaseTests(output)
5+
public class ContractsTests : BaseTests
66
{
7+
public ContractsTests(ITestOutputHelper output)
8+
: base(output) { }
9+
710
[Fact(Timeout = 120000)]
811
public async Task FetchAbi()
912
{
10-
var abi = await ThirdwebContract.FetchAbi(client: ThirdwebClient.Create(secretKey: this.SecretKey), address: "0x1320Cafa93fb53Ed9068E3272cb270adbBEf149C", chainId: 84532);
13+
var abi = await ThirdwebContract.FetchAbi(client: this.Client, address: "0x1320Cafa93fb53Ed9068E3272cb270adbBEf149C", chainId: 84532);
1114
Assert.NotNull(abi);
1215
Assert.NotEmpty(abi);
1316
}
@@ -22,21 +25,21 @@ public async Task InitTest_NullClient()
2225
[Fact(Timeout = 120000)]
2326
public async Task InitTest_NullAddress()
2427
{
25-
var exception = await Assert.ThrowsAsync<ArgumentException>(async () => await ThirdwebContract.Create(ThirdwebClient.Create(secretKey: this.SecretKey), null, 1, "[]"));
28+
var exception = await Assert.ThrowsAsync<ArgumentException>(async () => await ThirdwebContract.Create(this.Client, null, 1, "[]"));
2629
Assert.Contains("Address must be provided", exception.Message);
2730
}
2831

2932
[Fact(Timeout = 120000)]
3033
public async Task InitTest_ZeroChain()
3134
{
32-
var exception = await Assert.ThrowsAsync<ArgumentException>(async () => await ThirdwebContract.Create(ThirdwebClient.Create(secretKey: this.SecretKey), "0x123", 0, "[]"));
35+
var exception = await Assert.ThrowsAsync<ArgumentException>(async () => await ThirdwebContract.Create(this.Client, "0x123", 0, "[]"));
3336
Assert.Contains("Chain must be provided", exception.Message);
3437
}
3538

3639
[Fact(Timeout = 120000)]
3740
public async Task InitTest_NullAbi()
3841
{
39-
var res = await ThirdwebContract.Create(ThirdwebClient.Create(secretKey: this.SecretKey), "0x81ebd23aA79bCcF5AaFb9c9c5B0Db4223c39102e", 421614, null);
42+
var res = await ThirdwebContract.Create(this.Client, "0x81ebd23aA79bCcF5AaFb9c9c5B0Db4223c39102e", 421614, null);
4043
Assert.NotNull(res);
4144
}
4245

@@ -173,7 +176,7 @@ public async Task WriteTest_PrivateKeyAccount()
173176
[Fact(Timeout = 120000)]
174177
public async Task SignatureMint_Generate()
175178
{
176-
var client = ThirdwebClient.Create(secretKey: this.SecretKey);
179+
var client = this.Client;
177180
var signer = await PrivateKeyWallet.Generate(client);
178181

179182
var randomDomain = "Test";
@@ -251,15 +254,15 @@ public async Task SignatureMint_Generate()
251254

252255
private async Task<SmartWallet> GetAccount()
253256
{
254-
var client = ThirdwebClient.Create(secretKey: this.SecretKey);
257+
var client = this.Client;
255258
var privateKeyAccount = await PrivateKeyWallet.Generate(client);
256259
var smartAccount = await SmartWallet.Create(personalWallet: privateKeyAccount, factoryAddress: "0xbf1C9aA4B1A085f7DA890a44E82B0A1289A40052", gasless: true, chainId: 421614);
257260
return smartAccount;
258261
}
259262

260263
private async Task<ThirdwebContract> GetContract()
261264
{
262-
var client = ThirdwebClient.Create(secretKey: this.SecretKey);
265+
var client = this.Client;
263266
var contract = await ThirdwebContract.Create(client: client, address: "0xEBB8a39D865465F289fa349A67B3391d8f910da9", chain: 421614);
264267
return contract;
265268
}

Thirdweb.Tests/Thirdweb.Extensions/Thirdweb.Extensions.Tests.cs

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -13,48 +13,44 @@ public class ExtensionsTests : BaseTests
1313
private readonly string _dropErc1155ContractAddress = "0x6A7a26c9a595E6893C255C9dF0b593e77518e0c3";
1414

1515
private readonly BigInteger _chainId = 421614;
16-
private readonly ThirdwebClient _client;
1716

1817
public ExtensionsTests(ITestOutputHelper output)
19-
: base(output)
20-
{
21-
this._client = ThirdwebClient.Create(secretKey: this.SecretKey);
22-
}
18+
: base(output) { }
2319

2420
private async Task<IThirdwebWallet> GetSmartWallet()
2521
{
26-
var privateKeyWallet = await PrivateKeyWallet.Generate(this._client);
22+
var privateKeyWallet = await PrivateKeyWallet.Generate(this.Client);
2723
return await SmartWallet.Create(personalWallet: privateKeyWallet, chainId: 421614);
2824
}
2925

3026
private async Task<ThirdwebContract> GetTokenERC20Contract()
3127
{
32-
return await ThirdwebContract.Create(this._client, this._tokenErc20ContractAddress, this._chainId);
28+
return await ThirdwebContract.Create(this.Client, this._tokenErc20ContractAddress, this._chainId);
3329
}
3430

3531
private async Task<ThirdwebContract> GetTokenERC721Contract()
3632
{
37-
return await ThirdwebContract.Create(this._client, this._tokenErc721ContractAddress, this._chainId);
33+
return await ThirdwebContract.Create(this.Client, this._tokenErc721ContractAddress, this._chainId);
3834
}
3935

4036
private async Task<ThirdwebContract> GetTokenERC1155Contract()
4137
{
42-
return await ThirdwebContract.Create(this._client, this._tokenErc1155ContractAddress, this._chainId);
38+
return await ThirdwebContract.Create(this.Client, this._tokenErc1155ContractAddress, this._chainId);
4339
}
4440

4541
private async Task<ThirdwebContract> GetDrop20Contract()
4642
{
47-
return await ThirdwebContract.Create(this._client, this._dropErc20ContractAddress, this._chainId);
43+
return await ThirdwebContract.Create(this.Client, this._dropErc20ContractAddress, this._chainId);
4844
}
4945

5046
private async Task<ThirdwebContract> GetDrop721Contract()
5147
{
52-
return await ThirdwebContract.Create(this._client, this._dropErc721ContractAddress, this._chainId);
48+
return await ThirdwebContract.Create(this.Client, this._dropErc721ContractAddress, this._chainId);
5349
}
5450

5551
private async Task<ThirdwebContract> GetDrop1155Contract()
5652
{
57-
return await ThirdwebContract.Create(this._client, this._dropErc1155ContractAddress, this._chainId);
53+
return await ThirdwebContract.Create(this.Client, this._dropErc1155ContractAddress, this._chainId);
5854
}
5955

6056
#region Common
@@ -149,7 +145,7 @@ public async Task GetBalanceRaw()
149145
{
150146
var address = "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045"; // vitalik.eth
151147
var chainId = BigInteger.One;
152-
var balance = await ThirdwebExtensions.GetBalanceRaw(this._client, chainId, address);
148+
var balance = await ThirdwebExtensions.GetBalanceRaw(this.Client, chainId, address);
153149
Assert.True(balance >= 0);
154150
}
155151

@@ -159,7 +155,7 @@ public async Task GetBalanceRaw_WithERC20()
159155
var address = "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045"; // vitalik.eth
160156
var chainId = this._chainId;
161157
var contractAddress = this._tokenErc20ContractAddress;
162-
var balance = await ThirdwebExtensions.GetBalanceRaw(this._client, chainId, address, contractAddress);
158+
var balance = await ThirdwebExtensions.GetBalanceRaw(this.Client, chainId, address, contractAddress);
163159
Assert.True(balance >= 0);
164160
}
165161

@@ -202,7 +198,7 @@ public async Task GetTransactionCountRaw()
202198
{
203199
var address = "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045"; // vitalik.eth
204200
var chainId = BigInteger.One;
205-
var transactionCount = await ThirdwebExtensions.GetTransactionCountRaw(this._client, chainId, address);
201+
var transactionCount = await ThirdwebExtensions.GetTransactionCountRaw(this.Client, chainId, address);
206202
Assert.True(transactionCount >= 0);
207203
}
208204

@@ -212,7 +208,7 @@ public async Task GetTransactionCountRaw_WithBlockTag()
212208
var address = "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045"; // vitalik.eth
213209
var chainId = this._chainId;
214210
var blockTag = "latest";
215-
var transactionCount = await ThirdwebExtensions.GetTransactionCountRaw(this._client, chainId, address, blockTag);
211+
var transactionCount = await ThirdwebExtensions.GetTransactionCountRaw(this.Client, chainId, address, blockTag);
216212
Assert.True(transactionCount >= 0);
217213
}
218214

@@ -974,7 +970,7 @@ public async Task DropERC721_NullChecks()
974970
_ = await Assert.ThrowsAsync<ArgumentNullException>(async () => await contract.DropERC721_GetActiveClaimCondition());
975971
}
976972

977-
// [Fact(Timeout = 120000)]
973+
//
978974
// public async Task DropERC721_Claim_ShouldThrowTokens()
979975
// {
980976
// var contract = await GetDrop721Contract();
@@ -1184,8 +1180,8 @@ public async Task TokenERC20_NullChecks()
11841180
public async Task TokenERC20_GenerateMintSignature_WithVerify()
11851181
{
11861182
var contract = await this.GetTokenERC20Contract();
1187-
var fakeAuthorizedSigner = await PrivateKeyWallet.Generate(this._client);
1188-
var randomReceiver = await PrivateKeyWallet.Generate(this._client);
1183+
var fakeAuthorizedSigner = await PrivateKeyWallet.Generate(this.Client);
1184+
var randomReceiver = await PrivateKeyWallet.Generate(this.Client);
11891185
var mintRequest = new TokenERC20_MintRequest { To = await randomReceiver.GetAddress(), Quantity = BigInteger.Parse("1.5".ToWei()), };
11901186

11911187
(var payload, var signature) = await contract.TokenERC20_GenerateMintSignature(fakeAuthorizedSigner, mintRequest);
@@ -1294,8 +1290,8 @@ public async Task TokenERC721_NullChecks()
12941290
public async Task TokenERC721_GenerateMintSignature_WithUri_WithVerify()
12951291
{
12961292
var contract = await this.GetTokenERC721Contract();
1297-
var fakeAuthorizedSigner = await PrivateKeyWallet.Generate(this._client);
1298-
var randomReceiver = await PrivateKeyWallet.Generate(this._client);
1293+
var fakeAuthorizedSigner = await PrivateKeyWallet.Generate(this.Client);
1294+
var randomReceiver = await PrivateKeyWallet.Generate(this.Client);
12991295
var mintRequest = new TokenERC721_MintRequest { To = await randomReceiver.GetAddress(), Uri = "", };
13001296

13011297
(var payload, var signature) = await contract.TokenERC721_GenerateMintSignature(fakeAuthorizedSigner, mintRequest);
@@ -1329,8 +1325,8 @@ public async Task TokenERC721_GenerateMintSignature_WithUri_WithVerify()
13291325
public async Task TokenERC721_GenerateMintSignature_WithNFTMetadata_WithVerify()
13301326
{
13311327
var contract = await this.GetTokenERC721Contract();
1332-
var fakeAuthorizedSigner = await PrivateKeyWallet.Generate(this._client);
1333-
var randomReceiver = await PrivateKeyWallet.Generate(this._client);
1328+
var fakeAuthorizedSigner = await PrivateKeyWallet.Generate(this.Client);
1329+
var randomReceiver = await PrivateKeyWallet.Generate(this.Client);
13341330
var mintRequest = new TokenERC721_MintRequest { To = await randomReceiver.GetAddress() };
13351331

13361332
(var payload, var signature) = await contract.TokenERC721_GenerateMintSignature(
@@ -1462,8 +1458,8 @@ public async Task TokenERC1155_NullChecks()
14621458
public async Task TokenERC1155_GenerateMintSignature_WithUri_WithVerify()
14631459
{
14641460
var contract = await this.GetTokenERC1155Contract();
1465-
var fakeAuthorizedSigner = await PrivateKeyWallet.Generate(this._client);
1466-
var randomReceiver = await PrivateKeyWallet.Generate(this._client);
1461+
var fakeAuthorizedSigner = await PrivateKeyWallet.Generate(this.Client);
1462+
var randomReceiver = await PrivateKeyWallet.Generate(this.Client);
14671463
var mintRequest = new TokenERC1155_MintRequest { To = await randomReceiver.GetAddress(), Uri = "", };
14681464

14691465
(var payload, var signature) = await contract.TokenERC1155_GenerateMintSignature(fakeAuthorizedSigner, mintRequest);
@@ -1499,8 +1495,8 @@ public async Task TokenERC1155_GenerateMintSignature_WithUri_WithVerify()
14991495
public async Task TokenERC1155_GenerateMintSignature_WithNFTMetadata_WithVerify()
15001496
{
15011497
var contract = await this.GetTokenERC1155Contract();
1502-
var fakeAuthorizedSigner = await PrivateKeyWallet.Generate(this._client);
1503-
var randomReceiver = await PrivateKeyWallet.Generate(this._client);
1498+
var fakeAuthorizedSigner = await PrivateKeyWallet.Generate(this.Client);
1499+
var randomReceiver = await PrivateKeyWallet.Generate(this.Client);
15041500
var mintRequest = new TokenERC1155_MintRequest { To = await randomReceiver.GetAddress() };
15051501

15061502
(var payload, var signature) = await contract.TokenERC1155_GenerateMintSignature(

Thirdweb.Tests/Thirdweb.Http/Thirdweb.Http.Tests.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
namespace Thirdweb.Tests.Http;
44

5-
public class HttpTests(ITestOutputHelper output) : BaseTests(output)
5+
public class HttpTests : BaseTests
66
{
7+
public HttpTests(ITestOutputHelper output)
8+
: base(output) { }
79

810
#region ThirdwebHttpClient
911

@@ -28,7 +30,11 @@ public async Task PostAsync_ShouldReturnSuccessResponse()
2830
// Arrange
2931
var httpClient = new ThirdwebHttpClient();
3032
var requestUri = "https://jsonplaceholder.typicode.com/posts";
31-
var content = new StringContent(/*lang=json,strict*/ "{\"title\": \"foo\", \"body\": \"bar\", \"userId\": 1}", Encoding.UTF8, "application/json");
33+
var content = new StringContent( /*lang=json,strict*/
34+
"{\"title\": \"foo\", \"body\": \"bar\", \"userId\": 1}",
35+
Encoding.UTF8,
36+
"application/json"
37+
);
3238

3339
// Act
3440
var response = await httpClient.PostAsync(requestUri, content);
@@ -102,7 +108,11 @@ public async Task PutAsync_ShouldThrowNotImplementedException()
102108
// Arrange
103109
var httpClient = new ThirdwebHttpClient();
104110
var requestUri = "https://jsonplaceholder.typicode.com/posts/1";
105-
var content = new StringContent(/*lang=json,strict*/ "{\"title\": \"foo\", \"body\": \"bar\", \"userId\": 1}", Encoding.UTF8, "application/json");
111+
var content = new StringContent( /*lang=json,strict*/
112+
"{\"title\": \"foo\", \"body\": \"bar\", \"userId\": 1}",
113+
Encoding.UTF8,
114+
"application/json"
115+
);
106116

107117
// Act & Assert
108118
_ = await Assert.ThrowsAsync<NotImplementedException>(() => httpClient.PutAsync(requestUri, content));

Thirdweb.Tests/Thirdweb.RPC/Thirdweb.RPC.Tests.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33

44
namespace Thirdweb.Tests.RPC;
55

6-
public class RpcTests(ITestOutputHelper output) : BaseTests(output)
6+
public class RpcTests : BaseTests
77
{
8+
public RpcTests(ITestOutputHelper output)
9+
: base(output) { }
10+
811
[Fact(Timeout = 120000)]
912
public async Task GetBlockNumber()
1013
{

Thirdweb.Tests/Thirdweb.Storage/Thirdweb.Storage.Tests.cs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
namespace Thirdweb.Tests.Storage;
22

3-
public class StorageTests(ITestOutputHelper output) : BaseTests(output)
3+
public class StorageTests : BaseTests
44
{
5+
public StorageTests(ITestOutputHelper output)
6+
: base(output) { }
7+
58
[Fact(Timeout = 120000)]
69
public async Task DownloadTest_SecretKey()
710
{
@@ -74,7 +77,10 @@ public async Task UploadTest_SecretKey()
7477
{
7578
var client = ThirdwebClient.Create(secretKey: this.SecretKey);
7679
var path = Path.Combine(Path.GetTempPath(), "testJson.json");
77-
File.WriteAllText(path, /*lang=json,strict*/ "{\"test\": \"test\"}");
80+
File.WriteAllText(
81+
path, /*lang=json,strict*/
82+
"{\"test\": \"test\"}"
83+
);
7884
var res = await ThirdwebStorage.Upload(client, path);
7985
Assert.StartsWith($"https://{client.ClientId}.ipfscdn.io/ipfs/", res.PreviewUrl);
8086
}
@@ -84,7 +90,10 @@ public async Task UploadTest_Client_BundleId()
8490
{
8591
var client = ThirdwebClient.Create(clientId: this.ClientIdBundleIdOnly, bundleId: this.BundleIdBundleIdOnly);
8692
var path = Path.Combine(Path.GetTempPath(), "testJson.json");
87-
File.WriteAllText(path, /*lang=json,strict*/ "{\"test\": \"test\"}");
93+
File.WriteAllText(
94+
path, /*lang=json,strict*/
95+
"{\"test\": \"test\"}"
96+
);
8897
var res = await ThirdwebStorage.Upload(client, path);
8998
Assert.StartsWith($"https://{client.ClientId}.ipfscdn.io/ipfs/", res.PreviewUrl);
9099
}
@@ -102,7 +111,10 @@ public async Task UploadTest_401()
102111
{
103112
var client = ThirdwebClient.Create(clientId: "invalid", bundleId: "hello");
104113
var path = Path.Combine(Path.GetTempPath(), "testJson.json");
105-
File.WriteAllText(path, /*lang=json,strict*/ "{\"test\": \"test\"}");
114+
File.WriteAllText(
115+
path, /*lang=json,strict*/
116+
"{\"test\": \"test\"}"
117+
);
106118
var exception = await Assert.ThrowsAsync<Exception>(() => ThirdwebStorage.Upload(client, path));
107119
Assert.Contains("Failed to upload", exception.Message);
108120
Assert.Contains("401", exception.Message);

0 commit comments

Comments
 (0)