Skip to content

Commit

Permalink
Merge pull request #15 from oxen-io/local-ci
Browse files Browse the repository at this point in the history
local ci instead of sepolia
  • Loading branch information
darcys22 authored Apr 23, 2024
2 parents 209daad + f13be2a commit c7263b5
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 30 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ jobs:
- name: Install prerequisites
run: sudo apt-get update && sudo apt-get install -y cmake build-essential libboost-all-dev libssl-dev libcurl4-openssl-dev libsodium-dev

- name: Install Foundry
run: |
curl -L https://foundry.paradigm.xyz | bash
/home/runner/.config/.foundry/bin/foundryup
- name: Start node in background
run: |
/home/runner/.config/.foundry/bin/anvil &
echo "NODE_PID=$!" >> $GITHUB_ENV
- name: Create Build Directory
run: mkdir -p build

Expand All @@ -33,3 +43,7 @@ jobs:
- name: Run tests
run: ctest -VV --repeat until-pass:2 --test-dir build

- name: Kill node
run: kill $NODE_PID
if: always()

49 changes: 19 additions & 30 deletions test/src/ethereum_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,19 @@
#include <catch2/catch_test_macros.hpp>
#include <catch2/catch_all.hpp>

TEST_CASE( "Get balance from sepolia network", "[ethereum]" ) {
// Construct the client with the local RPC URL
//Provider client("Sepolia Client", std::string("https://rpc.sepolia.org"));
Provider client("Sepolia Client", std::string("https://eth-sepolia.g.alchemy.com/v2/xjUjCAfxli88pqe7UjR4Tt1Jp2GKPJvy"));
// Construct the client with the local RPC URL
inline constexpr std::string_view PRIVATE_KEY = "96a656cbd64281ea82257ca9978093b25117592287e4e07f5be660d1701f03e9";
inline constexpr std::string_view ADDRESS = "0x2ccb8b65024e4aa9615a8e704dfb11be76674f1f";
inline constexpr std::string_view ANVIL_ADDRESS = "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266";
inline constexpr std::string_view ANVIL_PRIVATE_KEY = "ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80";
std::vector<unsigned char> seckey = utils::fromHexString(std::string(PRIVATE_KEY));
std::vector<unsigned char> anvilseckey = utils::fromHexString(std::string(ANVIL_PRIVATE_KEY));
auto provider = std::make_shared<Provider>("Client", std::string("127.0.0.1:8545"));
Signer signer(provider);

TEST_CASE( "Get balance from sepolia network", "[ethereum]" ) {
// Get the balance of the test address
auto balance = client.getBalance("0x2Ccb8b65024E4aA9615a8E704DFb11BE76674f1F");
auto balance = provider->getBalance(std::string(ANVIL_ADDRESS));

// Check that the balance is greater than zero
REQUIRE( balance != "" );
Expand All @@ -24,20 +30,14 @@ TEST_CASE( "HashTest", "[utils]" ) {
REQUIRE( hash_hello_world == "57caa176af1ac0433c5df30e8dabcd2ec1af1e92a26eced5f719b88458777cd6" );
}

inline constexpr std::string_view PRIVATE_KEY = "96a656cbd64281ea82257ca9978093b25117592287e4e07f5be660d1701f03e9";
inline constexpr std::string_view ADDRESS = "0x2ccb8b65024e4aa9615a8e704dfb11be76674f1f";
TEST_CASE( "SigningTest", "[signer]" ) {
std::vector<unsigned char> seckey = utils::fromHexString(std::string(PRIVATE_KEY));
Signer signer;
std::string hash_hello_world = utils::toHexString(utils::hash("Hello World!\n"));
const auto signature_bytes = signer.signMessage("Hello World!", seckey);
std::string signature_hex = utils::toHexString(signature_bytes);
REQUIRE( signature_hex == "35f409302082e02b5126c82be93a3946d30e93722ce3ff87bdb01fc385fe312054f3fade7fab80dcabadabf96af75577327dfd064abd47a36543a475e04840e701" );
}

TEST_CASE( "Get address from private key", "[signer]" ) {
std::vector<unsigned char> seckey = utils::fromHexString(std::string(PRIVATE_KEY));
Signer signer;
std::string created_address = signer.secretKeyToAddressString(seckey);
REQUIRE( created_address == ADDRESS );
}
Expand Down Expand Up @@ -77,40 +77,29 @@ TEST_CASE( "Hashes an unsigned transaction correctly", "[transaction]" ) {
}

TEST_CASE( "Signs an unsigned transaction correctly", "[transaction]" ) {
std::vector<unsigned char> seckey = utils::fromHexString(std::string(PRIVATE_KEY));
Signer signer;
Transaction tx("0xA6C077fd9283421C657EcEa8a9c1422cc6CEbc80", 1000000000000000000, 21000);
tx.nonce = 1;
tx.chainId = 1;
const auto signature_hex_string = signer.signTransaction(tx, seckey);
REQUIRE( signature_hex_string == "0x02f86a0101808082520894a6c077fd9283421c657ecea8a9c1422cc6cebc80880de0b6b3a764000080c080a084987299f8dd115333356ab03430ca8de593e03ba03d4ecd72daf15205119cf8a0216c9869da3497ae96dcb98713908af1a0abf866c12d51def821caf0374cccbb" );
}

inline constexpr std::string_view LOCAL_PRIVATE_KEY = "11070278466b8a23d8709c6c583015f1c0b386c91f63d29b87d48a1174fe7276";
TEST_CASE( "Does a self transfer on Sepolia", "[transaction]" ) {
//auto provider = std::make_shared<Provider>("Sepolia Client", std::string("https://rpc.sepolia.org"));
auto provider = std::make_shared<Provider>("Sepolia Client", std::string("https://eth-sepolia.g.alchemy.com/v2/xjUjCAfxli88pqe7UjR4Tt1Jp2GKPJvy"));
Signer signer(provider);
Transaction tx(std::string(ADDRESS), 100000000000000, 21000);
tx.chainId = 11155111; //SEPOLIA
tx.nonce = provider->getTransactionCount(std::string(ADDRESS), "pending");
TEST_CASE( "Does a self transfer", "[transaction]" ) {
Transaction tx(std::string(ANVIL_ADDRESS), 100000000000000, 21000);
tx.chainId = 31337; //LOCAL
tx.nonce = provider->getTransactionCount(std::string(ANVIL_ADDRESS), "pending");
const auto feeData = provider->getFeeData();
tx.maxFeePerGas = feeData.maxFeePerGas;
tx.maxPriorityFeePerGas = feeData.maxPriorityFeePerGas;
std::vector<unsigned char> seckey = utils::fromHexString(std::string(PRIVATE_KEY));
const auto signature_hex_string = signer.signTransaction(tx, seckey);
const auto signature_hex_string = signer.signTransaction(tx, anvilseckey);
const auto hash = provider->sendTransaction(tx);
REQUIRE(hash != "");
REQUIRE(provider->transactionSuccessful(hash));
}

TEST_CASE( "Does a self transfer on Sepolia using signer to populate", "[transaction]" ) {
//auto provider = std::make_shared<Provider>("Sepolia Client", std::string("https://rpc.sepolia.org"));
auto provider = std::make_shared<Provider>("Sepolia Client", std::string("https://eth-sepolia.g.alchemy.com/v2/xjUjCAfxli88pqe7UjR4Tt1Jp2GKPJvy"));
Signer signer(provider);
Transaction tx("0x2Ccb8b65024E4aA9615a8E704DFb11BE76674f1F", 100000000000000, 21000);
std::vector<unsigned char> seckey = utils::fromHexString(std::string(PRIVATE_KEY));
const auto hash = signer.sendTransaction(tx, seckey);
TEST_CASE( "Does a self transfer on network using signer to populate", "[transaction]" ) {
Transaction tx(std::string(ANVIL_ADDRESS), 100000000000000, 21000);
const auto hash = signer.sendTransaction(tx, anvilseckey);
REQUIRE(hash != "");
REQUIRE(provider->transactionSuccessful(hash));
}

0 comments on commit c7263b5

Please sign in to comment.