Skip to content

Commit 83c9d89

Browse files
authored
contract tests (#10)
* contract tests * nulls * Update SmartAccount.cs
1 parent 591cea1 commit 83c9d89

File tree

6 files changed

+165
-16
lines changed

6 files changed

+165
-16
lines changed

.github/workflows/dotnet-ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ jobs:
3636
THIRDWEB_SECRET_KEY: ${{ secrets.THIRDWEB_SECRET_KEY }}
3737
THIRDWEB_CLIENT_ID_BUNDLE_ID_ONLY: ${{ secrets.THIRDWEB_CLIENT_ID_BUNDLE_ID_ONLY }}
3838
THIRDWEB_BUNDLE_ID_BUNDLE_ID_ONLY: ${{ secrets.THIRDWEB_BUNDLE_ID_BUNDLE_ID_ONLY }}
39+
PRIVATE_KEY: ${{ secrets.PRIVATE_KEY }}
3940

4041
- name: Codecov
4142
uses: codecov/codecov-action@v4

Thirdweb.Tests/BaseTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ public class BaseTests
88
protected readonly string? _secretKey;
99
protected readonly string? _clientIdBundleIdOnly;
1010
protected readonly string? _bundleIdBundleIdOnly;
11+
protected readonly string? _testPrivateKey;
1112

1213
public BaseTests(ITestOutputHelper output)
1314
{
@@ -16,6 +17,7 @@ public BaseTests(ITestOutputHelper output)
1617
_secretKey = Environment.GetEnvironmentVariable("THIRDWEB_SECRET_KEY");
1718
_clientIdBundleIdOnly = Environment.GetEnvironmentVariable("THIRDWEB_CLIENT_ID_BUNDLE_ID_ONLY");
1819
_bundleIdBundleIdOnly = Environment.GetEnvironmentVariable("THIRDWEB_BUNDLE_ID_BUNDLE_ID_ONLY");
20+
_testPrivateKey = Environment.GetEnvironmentVariable("PRIVATE_KEY");
1921
}
2022

2123
[Fact]

Thirdweb.Tests/Thirdweb.Contracts.Tests.cs

Lines changed: 145 additions & 0 deletions
Large diffs are not rendered by default.

Thirdweb/Thirdweb.Contracts/ThirdwebContract.cs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using System.Numerics;
22
using Nethereum.Hex.HexTypes;
3+
using Nethereum.Model;
34
using Nethereum.RPC.Eth.DTOs;
5+
using Org.BouncyCastle.Utilities.Encoders;
46

57
namespace Thirdweb
68
{
@@ -69,24 +71,23 @@ public static async Task<string> WriteContract(ThirdwebWallet wallet, ThirdwebCo
6971
// TODO: Implement 1559
7072
transaction.Gas = new HexBigInteger(await rpc.SendRequestAsync<string>("eth_estimateGas", transaction));
7173
transaction.GasPrice = new HexBigInteger(await rpc.SendRequestAsync<string>("eth_gasPrice"));
74+
transaction.GasPrice = new HexBigInteger(transaction.GasPrice.Value * 10 / 9);
7275
transaction.Value = new HexBigInteger(weiValue);
7376

7477
string hash;
75-
if (wallet.ActiveAccount.AccountType is ThirdwebAccountType.PrivateKeyAccount)
78+
switch (wallet.ActiveAccount.AccountType)
7679
{
77-
transaction.Nonce = new HexBigInteger(await rpc.SendRequestAsync<string>("eth_getTransactionCount", wallet.GetAddress(), "latest"));
78-
var signedTx = wallet.SignTransaction(transaction, contract.Chain);
79-
Console.WriteLine($"Signed transaction: {signedTx}");
80-
hash = await rpc.SendRequestAsync<string>("eth_sendRawTransaction", signedTx);
81-
}
82-
else if (wallet.ActiveAccount.AccountType is ThirdwebAccountType.SmartAccount)
83-
{
84-
var smartAccount = wallet.ActiveAccount as SmartAccount;
85-
hash = await smartAccount.SendTransaction(transaction);
86-
}
87-
else
88-
{
89-
throw new NotImplementedException("Account type not supported");
80+
case ThirdwebAccountType.PrivateKeyAccount:
81+
transaction.Nonce = new HexBigInteger(await rpc.SendRequestAsync<string>("eth_getTransactionCount", await wallet.GetAddress(), "latest"));
82+
var signedTx = await wallet.SignTransaction(transaction, contract.Chain);
83+
hash = await rpc.SendRequestAsync<string>("eth_sendRawTransaction", signedTx);
84+
break;
85+
case ThirdwebAccountType.SmartAccount:
86+
var smartAccount = wallet.ActiveAccount as SmartAccount;
87+
hash = await smartAccount.SendTransaction(transaction);
88+
break;
89+
default:
90+
throw new NotImplementedException("Account type not supported");
9091
}
9192
Console.WriteLine($"Transaction hash: {hash}");
9293
return hash;

Thirdweb/Thirdweb.Wallets/PrivateKeyAccount/PrivateKeyAccount.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace Thirdweb
1313
{
1414
public class PrivateKeyAccount : IThirdwebAccount
1515
{
16-
public ThirdwebAccountType AccountType => ThirdwebAccountType.SmartAccount;
16+
public ThirdwebAccountType AccountType => ThirdwebAccountType.PrivateKeyAccount;
1717

1818
private ThirdwebClient _client;
1919
private EthECKey _ecKey;

Thirdweb/Thirdweb.Wallets/SmartAccount/SmartAccount.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public SmartAccount(
4747
_gasless = gasless;
4848
_chainId = chainId;
4949
_accountAddressOverride = accountAddressOverride;
50-
_entryPoint ??= $"0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789"; // v0.6.0
50+
_entryPoint ??= Constants.DEFAULT_ENTRYPOINT_ADDRESS;
5151
_bundlerUrl ??= $"https://{chainId}.bundler.thirdweb.com";
5252
_paymasterUrl ??= $"https://{chainId}.bundler.thirdweb.com";
5353
}

0 commit comments

Comments
 (0)