Skip to content

Commit

Permalink
feat: Changed rpc to Quicknode (#348)
Browse files Browse the repository at this point in the history
* added kelindi to cla

* updated .clabot

* changed rpc_url to quicknode

---------

Co-authored-by: Alvin Reyes <me@areyes.onl>
  • Loading branch information
kelindi and alvin-reyes authored Sep 11, 2024
1 parent 2d49cc4 commit 6db6ec9
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/options/configs/testnet.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ mediator = ["0x7B49d6ee530B0A538D26E344f3B02E79ACa96De2"]
api_host = "https://api-testnet.lilypad.tech/"

[web3]
rpc_url = "wss://arb-sepolia.g.alchemy.com/v2/4PDb7czJf8E6z7ZjhXB0Z5fdU1XaQT0u"
rpc_url = "wss://capable-tame-butterfly.arbitrum-sepolia.quiknode.pro/b866a1312df26e5763237e1aff0a300bd4501647"
chain_id = 421614
controller_address = "0x4a83270045FB4BCd1bdFe1bD6B00762A9D8bbF4E"
payments_address = "0xdE7CEa09A23e7Aa4980B95F69B8912F39A0e323A"
Expand Down
81 changes: 81 additions & 0 deletions pkg/web3/sdk_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package web3_test

import (
"errors"
"log"
"os"
"testing"
"github.com/BurntSushi/toml"
"github.com/lilypad-tech/lilypad/pkg/options"
"github.com/lilypad-tech/lilypad/pkg/web3"
)

func getConfig() (*options.Config, error) {
var config options.Config

config_toml, err := os.ReadFile("../options/configs/testnet.toml") // Changed fs.ReadFile to os.ReadFile

_, err = toml.Decode(string(config_toml), &config)
if err != nil {
return nil, errors.New("unable to parse config file")
}

return &config, nil
}

func CreateTestWeb3SDK() (*web3.Web3SDK, error) {
// Load environment variables from .local.dev

config, err := getConfig()
if err != nil {
log.Fatalf("Error loading config file")
}

options := web3.Web3Options{
RpcURL: config.Web3.RpcURL,
ChainID: config.Web3.ChainID,
PrivateKey: config.Web3.PrivateKey,
ControllerAddress: config.Web3.ControllerAddress,
PaymentsAddress: config.Web3.PaymentsAddress,
StorageAddress: config.Web3.StorageAddress,
UsersAddress: config.Web3.UsersAddress,
TokenAddress: config.Web3.TokenAddress,
MediationAddress: config.Web3.MediationAddress,
JobCreatorAddress: config.Web3.JobCreatorAddress,
}

sdk, err := web3.NewContractSDK(options)
if err != nil {
return nil, err
}

return sdk, nil
}


func TestGetBalance(t *testing.T) {
sdk, err := CreateTestWeb3SDK()
if err != nil {
t.Fatalf("Failed to create Web3SDK: %v", err)
}
balance, err := sdk.GetBalance("0x0000000000000000000000000000000000000000")
if err != nil {
t.Fatalf("Failed to get balance: %v", err)
}

t.Logf("Balance: %d\n", balance)
}

func TestGetBlockNumber(t *testing.T) {
sdk, err := CreateTestWeb3SDK()
if err != nil {
t.Fatalf("Failed to create Web3SDK: %v", err)
}
var blockNumberHex string
err = sdk.Client.Client().Call(&blockNumberHex, "eth_blockNumber")
if err != nil {
t.Fatalf("error for getBlockNumber: %s", err.Error())
}

t.Logf("Block number: %s\n", blockNumberHex)
}

0 comments on commit 6db6ec9

Please sign in to comment.