Skip to content

Commit 9b69090

Browse files
authored
fix tests (#136)
1 parent 06241aa commit 9b69090

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ public async Task TestAuth()
106106
{
107107
var client = ThirdwebClient.Create(clientId: "hi", fetchTimeoutOptions: new TimeoutOptions(rpc: 60000));
108108
var rpc = ThirdwebRPC.GetRpcInstance(client, 1);
109-
_ = await Assert.ThrowsAsync<HttpRequestException>(async () => await rpc.SendRequestAsync<string>("eth_blockNumber"));
109+
var ex = await Assert.ThrowsAsync<HttpRequestException>(async () => await rpc.SendRequestAsync<string>("eth_blockNumber"));
110+
Assert.Contains("Unauthorized", ex.Message);
110111
}
111112

112113
[Fact(Timeout = 120000)]

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,12 @@ public async Task DownloadTest_Base64Uri()
7171
}
7272

7373
[Fact(Timeout = 120000)]
74-
public async Task DownloadTest_400()
74+
public async Task DownloadTest_404()
7575
{
7676
var client = ThirdwebClient.Create(secretKey: this.SecretKey);
77-
var exception = await Assert.ThrowsAsync<Exception>(() => ThirdwebStorage.Download<string>(client, "https://0.rpc.thirdweb.com/"));
77+
var exception = await Assert.ThrowsAsync<Exception>(() => ThirdwebStorage.Download<string>(client, "https://example.com/invalid-file"));
7878
Assert.Contains("Failed to download", exception.Message);
79-
Assert.Contains("400", exception.Message);
79+
Assert.Contains("404", exception.Message);
8080
}
8181

8282
[Fact(Timeout = 120000)]

Thirdweb/Thirdweb.RPC/ThirdwebRPC.cs

+6-2
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,12 @@ private async Task SendBatchAsync(List<RpcRequest> batch)
181181
throw new HttpRequestException(errorDetail);
182182
}
183183

184-
var responseJson = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
185-
var responses = JsonConvert.DeserializeObject<List<RpcResponse<object>>>(responseJson);
184+
var responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
185+
if (responseContent.Equals("Unauthorized", StringComparison.OrdinalIgnoreCase))
186+
{
187+
throw new HttpRequestException("Unauthorized");
188+
}
189+
var responses = JsonConvert.DeserializeObject<List<RpcResponse<object>>>(responseContent);
186190

187191
foreach (var rpcResponse in responses)
188192
{

0 commit comments

Comments
 (0)