Skip to content

Commit 79f6f92

Browse files
authored
SwitchNetwork now part of IThirdwebWallet (#111)
1 parent 3025488 commit 79f6f92

File tree

7 files changed

+143
-101
lines changed

7 files changed

+143
-101
lines changed

Thirdweb.Tests/Thirdweb.Transactions/Thirdweb.ZkSmartWallet.Tests.cs

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -102,39 +102,39 @@ public async Task SendGaslessZkTx_Success()
102102
// Assert.True(hash.Length == 66);
103103
// }
104104

105-
[Fact(Timeout = 120000)]
106-
public async Task SendGaslessZkTx_Abstract_Success()
107-
{
108-
var account = await this.GetSmartAccount(zkChainId: 11124);
109-
var hash = await account.SendTransaction(
110-
new ThirdwebTransactionInput(11124)
111-
{
112-
From = await account.GetAddress(),
113-
To = await account.GetAddress(),
114-
Value = new Nethereum.Hex.HexTypes.HexBigInteger(0),
115-
Data = "0x"
116-
}
117-
);
118-
Assert.NotNull(hash);
119-
Assert.True(hash.Length == 66);
120-
}
105+
// [Fact(Timeout = 120000)]
106+
// public async Task SendGaslessZkTx_Abstract_Success()
107+
// {
108+
// var account = await this.GetSmartAccount(zkChainId: 11124);
109+
// var hash = await account.SendTransaction(
110+
// new ThirdwebTransactionInput(11124)
111+
// {
112+
// From = await account.GetAddress(),
113+
// To = await account.GetAddress(),
114+
// Value = new Nethereum.Hex.HexTypes.HexBigInteger(0),
115+
// Data = "0x"
116+
// }
117+
// );
118+
// Assert.NotNull(hash);
119+
// Assert.True(hash.Length == 66);
120+
// }
121121

122-
[Fact(Timeout = 120000)]
123-
public async Task SendGaslessZkTx_Creator_Success()
124-
{
125-
var account = await this.GetSmartAccount(zkChainId: 4654);
126-
var hash = await account.SendTransaction(
127-
new ThirdwebTransactionInput(4654)
128-
{
129-
From = await account.GetAddress(),
130-
To = await account.GetAddress(),
131-
Value = new Nethereum.Hex.HexTypes.HexBigInteger(0),
132-
Data = "0x"
133-
}
134-
);
135-
Assert.NotNull(hash);
136-
Assert.True(hash.Length == 66);
137-
}
122+
// [Fact(Timeout = 120000)]
123+
// public async Task SendGaslessZkTx_Creator_Success()
124+
// {
125+
// var account = await this.GetSmartAccount(zkChainId: 4654);
126+
// var hash = await account.SendTransaction(
127+
// new ThirdwebTransactionInput(4654)
128+
// {
129+
// From = await account.GetAddress(),
130+
// To = await account.GetAddress(),
131+
// Value = new Nethereum.Hex.HexTypes.HexBigInteger(0),
132+
// Data = "0x"
133+
// }
134+
// );
135+
// Assert.NotNull(hash);
136+
// Assert.True(hash.Length == 66);
137+
// }
138138

139139
[Fact(Timeout = 120000)]
140140
public async Task ZkSync_Switch()

Thirdweb.Tests/Thirdweb.Wallets/Thirdweb.Wallets.Tests.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public WalletTests(ITestOutputHelper output)
1010
private async Task<SmartWallet> GetSmartAccount()
1111
{
1212
var privateKeyAccount = await PrivateKeyWallet.Generate(this.Client);
13-
var smartAccount = await SmartWallet.Create(personalWallet: privateKeyAccount, factoryAddress: "0xbf1C9aA4B1A085f7DA890a44E82B0A1289A40052", gasless: true, chainId: 421614);
13+
var smartAccount = await SmartWallet.Create(personalWallet: privateKeyAccount, chainId: 421614);
1414
return smartAccount;
1515
}
1616

@@ -230,4 +230,21 @@ public async Task RecoverAddress_AllVariants_NullTests()
230230
);
231231
#nullable restore
232232
}
233+
234+
[Fact(Timeout = 120000)]
235+
public async Task SwitchNetwork_Success()
236+
{
237+
var smartWallet = await this.GetSmartAccount();
238+
var wrappedSmartWallet = await SmartWallet.Create(personalWallet: smartWallet, chainId: 421614);
239+
240+
Assert.Equal(421614, smartWallet.ActiveChainId);
241+
Assert.Equal(421614, wrappedSmartWallet.ActiveChainId);
242+
243+
await wrappedSmartWallet.SwitchNetwork(11155111);
244+
245+
Assert.Equal(11155111, wrappedSmartWallet.ActiveChainId);
246+
Assert.Equal(11155111, smartWallet.ActiveChainId);
247+
248+
await (await PrivateKeyWallet.Generate(this.Client)).SwitchNetwork(11155111);
249+
}
233250
}

Thirdweb/Thirdweb.RPC/ThirdwebRPC.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ public async Task<TResponse> SendRequestAsync<TResponse>(string method, params o
148148
private ThirdwebRPC(ThirdwebClient client, BigInteger chainId)
149149
{
150150
this._httpClient = client.HttpClient;
151-
this._rpcUrl = new Uri($"https://{chainId}.rpc.thirdweb.com/");
151+
this._rpcUrl = new Uri($"https://{chainId}.rpc.thirdweb.com/{client.ClientId}");
152152
this._rpcTimeout = TimeSpan.FromMilliseconds(client.FetchTimeoutOptions.GetTimeout(TimeoutType.Rpc));
153153
_ = this.StartBackgroundFlushAsync();
154154
}

Thirdweb/Thirdweb.Wallets/IThirdwebWallet.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,12 @@ Task<List<LinkedAccount>> LinkAccount(
176176
/// <param name="willSelfExecute">Set to true if the wallet will also be the executor of the transaction, otherwise false.</param>
177177
/// <returns>The signed authorization as an <see cref="EIP7702Authorization"/> that can be used with <see cref="ThirdwebTransactionInput.AuthorizationList"/>.</returns>
178178
Task<EIP7702Authorization> SignAuthorization(BigInteger chainId, string contractAddress, bool willSelfExecute);
179+
180+
/// <summary>
181+
/// Attempts to set the active network to the specified chain ID.
182+
/// </summary>
183+
/// <param name="chainId">The chain ID to switch to.</param>
184+
Task SwitchNetwork(BigInteger chainId);
179185
}
180186

181187
/// <summary>

Thirdweb/Thirdweb.Wallets/InAppWallet/EcosystemWallet/EcosystemWallet.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -986,5 +986,10 @@ public Task<EIP7702Authorization> SignAuthorization(BigInteger chainId, string c
986986
throw new NotImplementedException();
987987
}
988988

989+
public Task SwitchNetwork(BigInteger chainId)
990+
{
991+
return Task.CompletedTask;
992+
}
993+
989994
#endregion
990995
}

Thirdweb/Thirdweb.Wallets/PrivateKeyWallet/PrivateKeyWallet.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,5 +469,10 @@ public async Task<EIP7702Authorization> SignAuthorization(BigInteger chainId, st
469469
return new EIP7702Authorization(chainId, contractAddress, nonce, authorizationSignature.V, authorizationSignature.R, authorizationSignature.S);
470470
}
471471

472+
public Task SwitchNetwork(BigInteger chainId)
473+
{
474+
return Task.CompletedTask;
475+
}
476+
472477
#endregion
473478
}

0 commit comments

Comments
 (0)