Skip to content

Commit

Permalink
contract tests (#10)
Browse files Browse the repository at this point in the history
* contract tests

* nulls

* Update SmartAccount.cs
  • Loading branch information
0xFirekeeper authored Apr 8, 2024
1 parent 591cea1 commit 83c9d89
Show file tree
Hide file tree
Showing 6 changed files with 165 additions and 16 deletions.
1 change: 1 addition & 0 deletions .github/workflows/dotnet-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ jobs:
THIRDWEB_SECRET_KEY: ${{ secrets.THIRDWEB_SECRET_KEY }}
THIRDWEB_CLIENT_ID_BUNDLE_ID_ONLY: ${{ secrets.THIRDWEB_CLIENT_ID_BUNDLE_ID_ONLY }}
THIRDWEB_BUNDLE_ID_BUNDLE_ID_ONLY: ${{ secrets.THIRDWEB_BUNDLE_ID_BUNDLE_ID_ONLY }}
PRIVATE_KEY: ${{ secrets.PRIVATE_KEY }}

- name: Codecov
uses: codecov/codecov-action@v4
Expand Down
2 changes: 2 additions & 0 deletions Thirdweb.Tests/BaseTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public class BaseTests
protected readonly string? _secretKey;
protected readonly string? _clientIdBundleIdOnly;
protected readonly string? _bundleIdBundleIdOnly;
protected readonly string? _testPrivateKey;

public BaseTests(ITestOutputHelper output)
{
Expand All @@ -16,6 +17,7 @@ public BaseTests(ITestOutputHelper output)
_secretKey = Environment.GetEnvironmentVariable("THIRDWEB_SECRET_KEY");
_clientIdBundleIdOnly = Environment.GetEnvironmentVariable("THIRDWEB_CLIENT_ID_BUNDLE_ID_ONLY");
_bundleIdBundleIdOnly = Environment.GetEnvironmentVariable("THIRDWEB_BUNDLE_ID_BUNDLE_ID_ONLY");
_testPrivateKey = Environment.GetEnvironmentVariable("PRIVATE_KEY");
}

[Fact]
Expand Down
145 changes: 145 additions & 0 deletions Thirdweb.Tests/Thirdweb.Contracts.Tests.cs

Large diffs are not rendered by default.

29 changes: 15 additions & 14 deletions Thirdweb/Thirdweb.Contracts/ThirdwebContract.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System.Numerics;
using Nethereum.Hex.HexTypes;
using Nethereum.Model;
using Nethereum.RPC.Eth.DTOs;
using Org.BouncyCastle.Utilities.Encoders;

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

string hash;
if (wallet.ActiveAccount.AccountType is ThirdwebAccountType.PrivateKeyAccount)
switch (wallet.ActiveAccount.AccountType)
{
transaction.Nonce = new HexBigInteger(await rpc.SendRequestAsync<string>("eth_getTransactionCount", wallet.GetAddress(), "latest"));
var signedTx = wallet.SignTransaction(transaction, contract.Chain);
Console.WriteLine($"Signed transaction: {signedTx}");
hash = await rpc.SendRequestAsync<string>("eth_sendRawTransaction", signedTx);
}
else if (wallet.ActiveAccount.AccountType is ThirdwebAccountType.SmartAccount)
{
var smartAccount = wallet.ActiveAccount as SmartAccount;
hash = await smartAccount.SendTransaction(transaction);
}
else
{
throw new NotImplementedException("Account type not supported");
case ThirdwebAccountType.PrivateKeyAccount:
transaction.Nonce = new HexBigInteger(await rpc.SendRequestAsync<string>("eth_getTransactionCount", await wallet.GetAddress(), "latest"));
var signedTx = await wallet.SignTransaction(transaction, contract.Chain);
hash = await rpc.SendRequestAsync<string>("eth_sendRawTransaction", signedTx);
break;
case ThirdwebAccountType.SmartAccount:
var smartAccount = wallet.ActiveAccount as SmartAccount;
hash = await smartAccount.SendTransaction(transaction);
break;
default:
throw new NotImplementedException("Account type not supported");
}
Console.WriteLine($"Transaction hash: {hash}");
return hash;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace Thirdweb
{
public class PrivateKeyAccount : IThirdwebAccount
{
public ThirdwebAccountType AccountType => ThirdwebAccountType.SmartAccount;
public ThirdwebAccountType AccountType => ThirdwebAccountType.PrivateKeyAccount;

private ThirdwebClient _client;
private EthECKey _ecKey;
Expand Down
2 changes: 1 addition & 1 deletion Thirdweb/Thirdweb.Wallets/SmartAccount/SmartAccount.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public SmartAccount(
_gasless = gasless;
_chainId = chainId;
_accountAddressOverride = accountAddressOverride;
_entryPoint ??= $"0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789"; // v0.6.0
_entryPoint ??= Constants.DEFAULT_ENTRYPOINT_ADDRESS;
_bundlerUrl ??= $"https://{chainId}.bundler.thirdweb.com";
_paymasterUrl ??= $"https://{chainId}.bundler.thirdweb.com";
}
Expand Down

0 comments on commit 83c9d89

Please sign in to comment.