-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Changed rpc to Quicknode (#348)
* added kelindi to cla * updated .clabot * changed rpc_url to quicknode --------- Co-authored-by: Alvin Reyes <me@areyes.onl>
- Loading branch information
1 parent
2d49cc4
commit 6db6ec9
Showing
2 changed files
with
82 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |