@@ -7,6 +7,90 @@ public class RpcTests : BaseTests
7
7
public RpcTests ( ITestOutputHelper output )
8
8
: base ( output ) { }
9
9
10
+ [ Fact ]
11
+ public void RpcOverride_None ( )
12
+ {
13
+ var client = ThirdwebClient . Create ( secretKey : this . SecretKey ) ;
14
+ var thirdwebRpc = $ "https://1.rpc.thirdweb.com/{ client . ClientId } ";
15
+ var rpc = ThirdwebRPC . GetRpcInstance ( client , 1 ) ;
16
+ Assert . Equal ( thirdwebRpc , rpc . RpcUrl . AbsoluteUri ) ;
17
+ }
18
+
19
+ [ Fact ]
20
+ public void RpcOverride_Single ( )
21
+ {
22
+ var customRpc = "https://eth.llamarpc.com/" ;
23
+ var client = ThirdwebClient . Create ( secretKey : this . SecretKey , rpcOverrides : new Dictionary < BigInteger , string > { { 1 , customRpc } } ) ;
24
+ var rpc = ThirdwebRPC . GetRpcInstance ( client , 1 ) ;
25
+ Assert . Equal ( customRpc , client . RpcOverrides [ 1 ] ) ;
26
+ Assert . Equal ( customRpc , rpc . RpcUrl . AbsoluteUri ) ;
27
+ }
28
+
29
+ [ Fact ]
30
+ public void RpcOverride_Multiple ( )
31
+ {
32
+ var customRpc1 = "https://eth.llamarpc.com/" ;
33
+ var customRpc42161 = "https://arbitrum.llamarpc.com/" ;
34
+ var client = ThirdwebClient . Create ( secretKey : this . SecretKey , rpcOverrides : new Dictionary < BigInteger , string > { { 1 , customRpc1 } , { 42161 , customRpc42161 } } ) ;
35
+ var rpc1 = ThirdwebRPC . GetRpcInstance ( client , 1 ) ;
36
+ var rpc42161 = ThirdwebRPC . GetRpcInstance ( client , 42161 ) ;
37
+ Assert . Equal ( customRpc1 , client . RpcOverrides [ 1 ] ) ;
38
+ Assert . Equal ( customRpc1 , rpc1 . RpcUrl . AbsoluteUri ) ;
39
+ Assert . Equal ( customRpc42161 , client . RpcOverrides [ 42161 ] ) ;
40
+ Assert . Equal ( customRpc42161 , rpc42161 . RpcUrl . AbsoluteUri ) ;
41
+ }
42
+
43
+ [ Fact ]
44
+ public void RpcOverride_Single_Default ( )
45
+ {
46
+ var customRpc = "https://eth.llamarpc.com/" ;
47
+ var client = ThirdwebClient . Create ( secretKey : this . SecretKey , rpcOverrides : new Dictionary < BigInteger , string > { { 1 , customRpc } } ) ;
48
+
49
+ var thirdwebRpc = $ "https://42161.rpc.thirdweb.com/{ client . ClientId } ";
50
+
51
+ var rpc1 = ThirdwebRPC . GetRpcInstance ( client , 1 ) ;
52
+ Assert . Equal ( customRpc , rpc1 . RpcUrl . AbsoluteUri ) ;
53
+
54
+ var rpc42161 = ThirdwebRPC . GetRpcInstance ( client , 42161 ) ;
55
+ Assert . Equal ( thirdwebRpc , rpc42161 . RpcUrl . AbsoluteUri ) ;
56
+ }
57
+
58
+ [ Fact ]
59
+ public void RpcOverride_Multiple_Default ( )
60
+ {
61
+ var customRpc1 = "https://eth.llamarpc.com/" ;
62
+ var customRpc42161 = "https://arbitrum.llamarpc.com/" ;
63
+ var client = ThirdwebClient . Create ( secretKey : this . SecretKey , rpcOverrides : new Dictionary < BigInteger , string > { { 1 , customRpc1 } , { 42161 , customRpc42161 } } ) ;
64
+
65
+ var thirdwebRpc = $ "https://421614.rpc.thirdweb.com/{ client . ClientId } ";
66
+
67
+ var rpc1 = ThirdwebRPC . GetRpcInstance ( client , 1 ) ;
68
+ Assert . Equal ( customRpc1 , rpc1 . RpcUrl . AbsoluteUri ) ;
69
+
70
+ var rpc42161 = ThirdwebRPC . GetRpcInstance ( client , 42161 ) ;
71
+ Assert . Equal ( customRpc42161 , rpc42161 . RpcUrl . AbsoluteUri ) ;
72
+
73
+ var rpc421614 = ThirdwebRPC . GetRpcInstance ( client , 421614 ) ;
74
+ Assert . Equal ( thirdwebRpc , rpc421614 . RpcUrl . AbsoluteUri ) ;
75
+ }
76
+
77
+ [ Fact ( Timeout = 120000 ) ]
78
+ public async Task Request_WithRpcOverride ( )
79
+ {
80
+ var customRpc = "https://eth.llamarpc.com/" ;
81
+ var client = ThirdwebClient . Create ( secretKey : this . SecretKey , rpcOverrides : new Dictionary < BigInteger , string > { { 1 , customRpc } } ) ;
82
+
83
+ var rpc = ThirdwebRPC . GetRpcInstance ( client , 1 ) ;
84
+ var blockNumber = await rpc . SendRequestAsync < string > ( "eth_blockNumber" ) ;
85
+ Assert . NotNull ( blockNumber ) ;
86
+ Assert . StartsWith ( "0x" , blockNumber ) ;
87
+
88
+ var rpc2 = ThirdwebRPC . GetRpcInstance ( client , 42161 ) ;
89
+ var blockNumber2 = await rpc2 . SendRequestAsync < string > ( "eth_blockNumber" ) ;
90
+ Assert . NotNull ( blockNumber2 ) ;
91
+ Assert . StartsWith ( "0x" , blockNumber2 ) ;
92
+ }
93
+
10
94
[ Fact ( Timeout = 120000 ) ]
11
95
public async Task GetBlockNumber ( )
12
96
{
@@ -69,18 +153,4 @@ public async Task TestRpcError()
69
153
var exception = await Assert . ThrowsAsync < Exception > ( async ( ) => await rpc . SendRequestAsync < string > ( "eth_invalidMethod" ) ) ;
70
154
Assert . Contains ( "RPC Error for request" , exception . Message ) ;
71
155
}
72
-
73
- // [Fact(Timeout = 120000)]
74
- // public async Task TestCache()
75
- // {
76
- // var client = ThirdwebClient.Create(secretKey: this.SecretKey);
77
- // var rpc = ThirdwebRPC.GetRpcInstance(client, 421614);
78
- // var blockNumber1 = await rpc.SendRequestAsync<string>("eth_blockNumber");
79
- // await ThirdwebTask.Delay(1);
80
- // var blockNumber2 = await rpc.SendRequestAsync<string>("eth_blockNumber");
81
- // Assert.Equal(blockNumber1, blockNumber2);
82
- // await ThirdwebTask.Delay(1000);
83
- // var blockNumber3 = await rpc.SendRequestAsync<string>("eth_blockNumber");
84
- // Assert.NotEqual(blockNumber1, blockNumber3);
85
- // }
86
156
}
0 commit comments