Skip to content

Commit cb902ab

Browse files
committed
add more switch tests
1 parent 67770be commit cb902ab

File tree

1 file changed

+56
-4
lines changed

1 file changed

+56
-4
lines changed

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

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,56 @@ public async Task ExecuteTransaction_07_WhenAll_Success()
314314
Assert.True(hashes[1].TransactionHash.Length == 66);
315315
}
316316

317+
[Fact(Timeout = 120000)]
318+
public async Task SwitchNetwork_Success()
319+
{
320+
var smartWallet = await SmartWallet.Create(personalWallet: await PrivateKeyWallet.Generate(this.Client), chainId: 11155111);
321+
var addy1 = await smartWallet.GetAddress();
322+
await smartWallet.SwitchNetwork(421614);
323+
var addy2 = await smartWallet.GetAddress();
324+
Assert.Equal(addy1, addy2);
325+
}
326+
327+
[Fact(Timeout = 120000)]
328+
public async Task SwitchNetwork_WithCustomFactory_ToZk_Success()
329+
{
330+
var smartWallet = await SmartWallet.Create(personalWallet: await PrivateKeyWallet.Generate(this.Client), chainId: 11155111, factoryAddress: "0xc5A43D081Dc10316EE640504Ea1cBc74666F3874");
331+
var addy1 = await smartWallet.GetAddress();
332+
await smartWallet.SwitchNetwork(300);
333+
var addy2 = await smartWallet.GetAddress();
334+
Assert.NotEqual(addy1, addy2);
335+
}
336+
337+
[Fact(Timeout = 120000)]
338+
public async Task SwitchNetwork_WithCustomFactory_FromZk_Success()
339+
{
340+
var smartWallet = await SmartWallet.Create(personalWallet: await PrivateKeyWallet.Generate(this.Client), chainId: 300, factoryAddress: "0xc5A43D081Dc10316EE640504Ea1cBc74666F3874");
341+
var addy1 = await smartWallet.GetAddress();
342+
await smartWallet.SwitchNetwork(11155111);
343+
var addy2 = await smartWallet.GetAddress();
344+
Assert.NotEqual(addy1, addy2);
345+
}
346+
347+
[Fact(Timeout = 120000)]
348+
public async Task SwitchNetwork_ZkToNonZkSuccess()
349+
{
350+
var smartWallet = await SmartWallet.Create(personalWallet: await PrivateKeyWallet.Generate(this.Client), chainId: 300);
351+
var addy1 = await smartWallet.GetAddress();
352+
await smartWallet.SwitchNetwork(421614);
353+
var addy2 = await smartWallet.GetAddress();
354+
Assert.NotEqual(addy1, addy2);
355+
}
356+
357+
[Fact(Timeout = 120000)]
358+
public async Task SwitchNetwork_NonZkToZk_Success()
359+
{
360+
var smartWallet = await SmartWallet.Create(personalWallet: await PrivateKeyWallet.Generate(this.Client), chainId: 421614);
361+
var addy1 = await smartWallet.GetAddress();
362+
await smartWallet.SwitchNetwork(300);
363+
var addy2 = await smartWallet.GetAddress();
364+
Assert.NotEqual(addy1, addy2);
365+
}
366+
317367
[Fact(Timeout = 120000)]
318368
public async Task MultiChainTransaction_Success()
319369
{
@@ -322,13 +372,15 @@ public async Task MultiChainTransaction_Success()
322372

323373
var smartWallet = await SmartWallet.Create(personalWallet: await PrivateKeyWallet.Generate(this.Client), chainId: chainId1, gasless: true);
324374

325-
var address1 = await smartWallet.GetAddress();
326-
var receipt1 = await smartWallet.ExecuteTransaction(new ThirdwebTransactionInput(chainId1) { To = address1, });
375+
var randomAddy = await (await PrivateKeyWallet.Generate(this.Client)).GetAddress();
376+
377+
var receipt1 = await smartWallet.ExecuteTransaction(new ThirdwebTransactionInput(chainId1) { To = randomAddy, });
327378
var nonce1 = await smartWallet.GetTransactionCount(chainId: chainId1, blocktag: "latest");
379+
var address1 = await smartWallet.GetAddress();
328380

329-
var address2 = await smartWallet.GetAddress();
330-
var receipt2 = await smartWallet.ExecuteTransaction(new ThirdwebTransactionInput(chainId2) { To = address2, });
381+
var receipt2 = await smartWallet.ExecuteTransaction(new ThirdwebTransactionInput(chainId2) { To = randomAddy, });
331382
var nonce2 = await smartWallet.GetTransactionCount(chainId: chainId2, blocktag: "latest");
383+
var address2 = await smartWallet.GetAddress();
332384

333385
Assert.NotNull(address1);
334386
Assert.NotNull(address2);

0 commit comments

Comments
 (0)