Skip to content

Commit 58c1de9

Browse files
committed
fix tests
1 parent 7503447 commit 58c1de9

File tree

2 files changed

+33
-13
lines changed

2 files changed

+33
-13
lines changed

Thirdweb.Tests/Thirdweb.Transactions.Tests.cs

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ private async Task<ThirdwebTransaction> CreateSampleTransaction()
1515
var wallet = await PrivateKeyWallet.Create(client, _testPrivateKey);
1616
var chainId = new BigInteger(421614);
1717

18-
var transaction = await ThirdwebTransaction.Create(client, wallet, new ThirdwebTransactionInput(), chainId);
18+
var transaction = await ThirdwebTransaction.Create(client, wallet, new ThirdwebTransactionInput() { From = await wallet.GetAddress(), To = await wallet.GetAddress(), }, chainId);
1919
return transaction;
2020
}
2121

@@ -24,18 +24,28 @@ public async Task Create_ValidatesInputParameters()
2424
{
2525
var client = ThirdwebClient.Create(secretKey: _secretKey);
2626
var wallet = await PrivateKeyWallet.Create(client, _testPrivateKey);
27-
var txInput = new ThirdwebTransactionInput() { From = await wallet.GetAddress() };
27+
var txInput = new ThirdwebTransactionInput() { From = await wallet.GetAddress(), To = Constants.ADDRESS_ZERO };
2828
var chainId = new BigInteger(421614);
2929
var transaction = await ThirdwebTransaction.Create(client, wallet, txInput, chainId);
3030
Assert.NotNull(transaction);
3131
}
3232

33+
[Fact]
34+
public async Task Create_ThrowsOnNoTo()
35+
{
36+
var client = ThirdwebClient.Create(secretKey: _secretKey);
37+
var wallet = await PrivateKeyWallet.Create(client, _testPrivateKey);
38+
var txInput = new ThirdwebTransactionInput() { From = await wallet.GetAddress() };
39+
var ex = await Assert.ThrowsAsync<ArgumentException>(() => ThirdwebTransaction.Create(client, wallet, txInput, BigInteger.Zero));
40+
Assert.Contains("Transaction recipient (to) must be provided", ex.Message);
41+
}
42+
3343
[Fact]
3444
public async Task Create_ThrowsOnInvalidAddress()
3545
{
3646
var client = ThirdwebClient.Create(secretKey: _secretKey);
3747
var wallet = await PrivateKeyWallet.Create(client, _testPrivateKey);
38-
var txInput = new ThirdwebTransactionInput() { From = "0x123" };
48+
var txInput = new ThirdwebTransactionInput() { From = "0x123", To = Constants.ADDRESS_ZERO };
3949
var ex = await Assert.ThrowsAsync<ArgumentException>(() => ThirdwebTransaction.Create(client, wallet, txInput, BigInteger.Zero));
4050
Assert.Contains("Transaction sender (from) must match wallet address", ex.Message);
4151
}
@@ -150,7 +160,7 @@ public async Task Send_ThrowsIfToAddressNotProvided()
150160
var transaction = await CreateSampleTransaction();
151161
_ = transaction.SetTo(null);
152162

153-
_ = await Assert.ThrowsAsync<ArgumentException>(() => ThirdwebTransaction.Send(transaction));
163+
_ = await Assert.ThrowsAsync<InvalidOperationException>(() => ThirdwebTransaction.Send(transaction));
154164
}
155165

156166
[Fact]
@@ -268,15 +278,11 @@ public async Task EstimateGasCosts_SmartWalletHigherThanPrivateKeyWallet()
268278
var privateKeyAccount = await PrivateKeyWallet.Create(client, _testPrivateKey);
269279
var smartAccount = await SmartWallet.Create(client, personalWallet: privateKeyAccount, factoryAddress: "0xbf1C9aA4B1A085f7DA890a44E82B0A1289A40052", gasless: true, chainId: 421614);
270280

271-
var transaction = await ThirdwebTransaction.Create(client, smartAccount, new ThirdwebTransactionInput(), 421614);
272-
_ = transaction.SetTo(Constants.ADDRESS_ZERO);
273-
_ = transaction.SetValue(new BigInteger(1000));
281+
var transaction = await ThirdwebTransaction.Create(client, smartAccount, new ThirdwebTransactionInput() { To = Constants.ADDRESS_ZERO, Value = new HexBigInteger(1000), }, 421614);
274282

275283
var smartCosts = await ThirdwebTransaction.EstimateGasCosts(transaction);
276284

277-
transaction = await ThirdwebTransaction.Create(client, privateKeyAccount, new ThirdwebTransactionInput(), 421614);
278-
_ = transaction.SetTo(Constants.ADDRESS_ZERO);
279-
_ = transaction.SetValue(new BigInteger(1000));
285+
transaction = await ThirdwebTransaction.Create(client, privateKeyAccount, new ThirdwebTransactionInput() { To = Constants.ADDRESS_ZERO, Value = new HexBigInteger(1000), }, 421614);
280286

281287
var privateCosts = await ThirdwebTransaction.EstimateGasCosts(transaction);
282288

@@ -339,9 +345,18 @@ public async Task Simulate_ReturnsData()
339345
var client = ThirdwebClient.Create(secretKey: _secretKey);
340346
var privateKeyAccount = await PrivateKeyWallet.Create(client, _testPrivateKey);
341347
var smartAccount = await SmartWallet.Create(client, personalWallet: privateKeyAccount, factoryAddress: "0xbf1C9aA4B1A085f7DA890a44E82B0A1289A40052", gasless: true, chainId: 421614);
342-
var transaction = await ThirdwebTransaction.Create(client, smartAccount, new ThirdwebTransactionInput(), 421614);
343-
_ = transaction.SetValue(new BigInteger(0));
344-
_ = transaction.SetGasLimit(250000);
348+
var transaction = await ThirdwebTransaction.Create(
349+
client,
350+
smartAccount,
351+
new ThirdwebTransactionInput()
352+
{
353+
To = Constants.ADDRESS_ZERO,
354+
Value = new HexBigInteger(0),
355+
Data = "0x",
356+
Gas = new HexBigInteger(250000),
357+
},
358+
421614
359+
);
345360

346361
var data = await ThirdwebTransaction.Simulate(transaction);
347362
Assert.NotNull(data);

Thirdweb/Thirdweb.Transactions/ThirdwebTransaction.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,11 @@ public static async Task<string> Sign(ThirdwebTransaction transaction)
242242

243243
public static async Task<string> Send(ThirdwebTransaction transaction)
244244
{
245+
if (transaction.Input.To == null)
246+
{
247+
throw new InvalidOperationException("Transaction recipient (to) must be provided");
248+
}
249+
245250
if (transaction.Input.GasPrice != null && (transaction.Input.MaxFeePerGas != null || transaction.Input.MaxPriorityFeePerGas != null))
246251
{
247252
throw new InvalidOperationException("Transaction GasPrice and MaxFeePerGas/MaxPriorityFeePerGas cannot be set at the same time");

0 commit comments

Comments
 (0)