From 6db6ec93d884fa50b9f6f5424278ac940caf4da2 Mon Sep 17 00:00:00 2001 From: Kelindi Date: Wed, 11 Sep 2024 16:42:00 -0400 Subject: [PATCH] feat: Changed rpc to Quicknode (#348) * added kelindi to cla * updated .clabot * changed rpc_url to quicknode --------- Co-authored-by: Alvin Reyes --- pkg/options/configs/testnet.toml | 2 +- pkg/web3/sdk_test.go | 81 ++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 pkg/web3/sdk_test.go diff --git a/pkg/options/configs/testnet.toml b/pkg/options/configs/testnet.toml index baba3cc4..0e658e2f 100644 --- a/pkg/options/configs/testnet.toml +++ b/pkg/options/configs/testnet.toml @@ -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" diff --git a/pkg/web3/sdk_test.go b/pkg/web3/sdk_test.go new file mode 100644 index 00000000..c63aadf8 --- /dev/null +++ b/pkg/web3/sdk_test.go @@ -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) +}