Skip to content

Commit

Permalink
Improving client config naming now that it is in the models package (#35
Browse files Browse the repository at this point in the history
)
  • Loading branch information
Tanz0rz authored Mar 12, 2024
1 parent e7c9902 commit bcfbca9
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 29 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func main() {
// Build the config for the client
config := models.ClientConfig{
DevPortalApiKey: os.Getenv("DEV_PORTAL_TOKEN"),
Web3HttpProviders: []models.Web3ProviderConfig{
Web3HttpProviders: []models.Web3Provider{
{
ChainId: chains.Polygon,
Url: web3providers.Polygon,
Expand Down
4 changes: 2 additions & 2 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ type Client struct {
OrderbookApi *OrderbookService
}

// NewClient creates and initializes a new Client instance based on the provided Config.
func NewClient(config models.Config) (*Client, error) {
// NewClient creates and initializes a new Client instance based on the provided ClientConfig.
func NewClient(config models.ClientConfig) (*Client, error) {
err := config.Validate()
if err != nil {
return nil, fmt.Errorf("config validation error: %v", err)
Expand Down
10 changes: 5 additions & 5 deletions client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/stretchr/testify/require"
)

var SimpleEthereumConfig = models.Config{
var SimpleEthereumConfig = models.ClientConfig{
DevPortalApiKey: os.Getenv("DEV_PORTAL_TOKEN"),
Web3HttpProviders: []models.Web3Provider{
{
Expand All @@ -24,12 +24,12 @@ var SimpleEthereumConfig = models.Config{
func TestNewConfig(t *testing.T) {
testcases := []struct {
description string
config models.Config
config models.ClientConfig
expectedErrorDescription string
}{
{
description: "Success",
config: models.Config{
config: models.ClientConfig{
DevPortalApiKey: "abc123",
Web3HttpProviders: []models.Web3Provider{
{
Expand All @@ -42,7 +42,7 @@ func TestNewConfig(t *testing.T) {
},
{
description: "Error - no API key",
config: models.Config{
config: models.ClientConfig{
DevPortalApiKey: "",
Web3HttpProviders: []models.Web3Provider{
{
Expand All @@ -55,7 +55,7 @@ func TestNewConfig(t *testing.T) {
},
{
description: "Error - no web3 provider key",
config: models.Config{
config: models.ClientConfig{
DevPortalApiKey: "123",
},
expectedErrorDescription: "config validation error: at least one web3 provider URL is required",
Expand Down
2 changes: 1 addition & 1 deletion client/client_test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func setup() (*Client, *http.ServeMux, string, func(), error) {
// the base URL of the client will have its destination swapped to use this new test server for requests
server := httptest.NewServer(mux)
c, err := NewClient(
models.Config{
models.ClientConfig{
DevPortalApiKey: os.Getenv("DEV_PORTAL_TOKEN"),
Web3HttpProviders: []models.Web3Provider{
{
Expand Down
2 changes: 1 addition & 1 deletion client/examples/orderbook/create_order/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
func main() {

// Build the config for the client
config := models.Config{
config := models.ClientConfig{
DevPortalApiKey: os.Getenv("DEV_PORTAL_TOKEN"),
Web3HttpProviders: []models.Web3Provider{
{
Expand Down
2 changes: 1 addition & 1 deletion client/examples/orderbook/get_orders/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
func main() {

// Build the config for the client
config := models.Config{
config := models.ClientConfig{
DevPortalApiKey: os.Getenv("DEV_PORTAL_TOKEN"),
Web3HttpProviders: []models.Web3Provider{
{
Expand Down
2 changes: 1 addition & 1 deletion client/examples/swap/get_swap/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
func main() {

// Build the config for the client
config := models.Config{
config := models.ClientConfig{
DevPortalApiKey: os.Getenv("DEV_PORTAL_TOKEN"),
Web3HttpProviders: []models.Web3Provider{
{
Expand Down
4 changes: 2 additions & 2 deletions client/models/client_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package models

import "fmt"

type Config struct {
type ClientConfig struct {
DevPortalApiKey string
Web3HttpProviders []Web3Provider
}
Expand All @@ -12,7 +12,7 @@ type Web3Provider struct {
Url string
}

func (c *Config) Validate() error {
func (c *ClientConfig) Validate() error {

if c.DevPortalApiKey == "" {
return fmt.Errorf("API key is required")
Expand Down
10 changes: 5 additions & 5 deletions client/orderbook_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ func TestCreateOrderE2E(t *testing.T) {

testcases := []struct {
description string
config models.Config
config models.ClientConfig
createOrderParams models.CreateOrderParams
expectedOutput string
}{
{
description: "Arbitrum - Create limit order offering 1 FRAX for 1 DAI",
config: models.Config{
config: models.ClientConfig{
DevPortalApiKey: os.Getenv("DEV_PORTAL_TOKEN"),
Web3HttpProviders: []models.Web3Provider{
{
Expand All @@ -51,7 +51,7 @@ func TestCreateOrderE2E(t *testing.T) {
},
{
description: "Polygon - Create limit order offering 1 FRAX for 1 DAI",
config: models.Config{
config: models.ClientConfig{
DevPortalApiKey: os.Getenv("DEV_PORTAL_TOKEN"),
Web3HttpProviders: []models.Web3Provider{
{
Expand All @@ -74,7 +74,7 @@ func TestCreateOrderE2E(t *testing.T) {
},
{
description: "Ethereum - Create limit order offering 1 1INCH for 1 DAI",
config: models.Config{
config: models.ClientConfig{
DevPortalApiKey: os.Getenv("DEV_PORTAL_TOKEN"),
Web3HttpProviders: []models.Web3Provider{
{
Expand All @@ -98,7 +98,7 @@ func TestCreateOrderE2E(t *testing.T) {
},
{
description: "BSC - Create limit order offering 1 USDC for 1 DAI",
config: models.Config{
config: models.ClientConfig{
DevPortalApiKey: os.Getenv("DEV_PORTAL_TOKEN"),
Web3HttpProviders: []models.Web3Provider{
{
Expand Down
2 changes: 1 addition & 1 deletion client/orderbook_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func TestCreateOrderIntegration(t *testing.T) {
},
}

c, err := NewClient(models.Config{
c, err := NewClient(models.ClientConfig{
DevPortalApiKey: helpers.GetenvSafe("DEV_PORTAL_TOKEN"),
Web3HttpProviders: []models.Web3Provider{
{
Expand Down
18 changes: 9 additions & 9 deletions client/swap_actions_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestSwapTokensTenderlyE2E(t *testing.T) {
testcases := []struct {
description string
tenderlyDescription string
config models.Config
config models.ClientConfig
swapParams models.SwapTokensParams
stateOverrides map[string]tenderly.StateObject
approvalType onchain.ApprovalType
Expand All @@ -35,7 +35,7 @@ func TestSwapTokensTenderlyE2E(t *testing.T) {
{
description: "Polygon - Swap 0.01 DAI for USDC - Approval - Does not support traditional permit interface",
tenderlyDescription: "DP-DAI->USDC-Approval",
config: models.Config{
config: models.ClientConfig{
DevPortalApiKey: os.Getenv("DEV_PORTAL_TOKEN"),
Web3HttpProviders: []models.Web3Provider{
{
Expand Down Expand Up @@ -72,7 +72,7 @@ func TestSwapTokensTenderlyE2E(t *testing.T) {
{
description: "Polygon - Swap 0.01 USDC for DAI - Permit - Contract has a version value of 2",
tenderlyDescription: "DP-USDC->DAI-Approval",
config: models.Config{
config: models.ClientConfig{
DevPortalApiKey: os.Getenv("DEV_PORTAL_TOKEN"),
Web3HttpProviders: []models.Web3Provider{
{
Expand Down Expand Up @@ -109,7 +109,7 @@ func TestSwapTokensTenderlyE2E(t *testing.T) {
{
description: "Polygon - Swap 0.01 FRAX for USDC - Approval - Forced",
tenderlyDescription: "DP-FRAX->USDC-Approval",
config: models.Config{
config: models.ClientConfig{
DevPortalApiKey: os.Getenv("DEV_PORTAL_TOKEN"),
Web3HttpProviders: []models.Web3Provider{
{
Expand Down Expand Up @@ -146,7 +146,7 @@ func TestSwapTokensTenderlyE2E(t *testing.T) {
{
description: "Polygon - Swap 0.01 FRAX for USDC - Permit",
tenderlyDescription: "DP-FRAX->USDC-Permit",
config: models.Config{
config: models.ClientConfig{
DevPortalApiKey: os.Getenv("DEV_PORTAL_TOKEN"),
Web3HttpProviders: []models.Web3Provider{
{
Expand Down Expand Up @@ -183,7 +183,7 @@ func TestSwapTokensTenderlyE2E(t *testing.T) {
{
description: "Arbitrum - Swap 0.01 USDC for DAI - Approve - Arbitrum unsupported right now",
tenderlyDescription: "DP-USDC->DAI-Approve",
config: models.Config{
config: models.ClientConfig{
DevPortalApiKey: os.Getenv("DEV_PORTAL_TOKEN"),
Web3HttpProviders: []models.Web3Provider{
{
Expand Down Expand Up @@ -220,7 +220,7 @@ func TestSwapTokensTenderlyE2E(t *testing.T) {
{
description: "Arbitrum - Swap $0.01 worth of ETH for USDC - Native token for ERC20",
tenderlyDescription: "DP-ETH->USDC",
config: models.Config{
config: models.ClientConfig{
DevPortalApiKey: os.Getenv("DEV_PORTAL_TOKEN"),
Web3HttpProviders: []models.Web3Provider{
{
Expand Down Expand Up @@ -257,7 +257,7 @@ func TestSwapTokensTenderlyE2E(t *testing.T) {
{
description: "Ethereum - Swap $0.01 worth of 1inch for ETH - Force Permit1",
tenderlyDescription: "DP-1inch->ETH-Permit1",
config: models.Config{
config: models.ClientConfig{
DevPortalApiKey: os.Getenv("DEV_PORTAL_TOKEN"),
Web3HttpProviders: []models.Web3Provider{
{
Expand Down Expand Up @@ -294,7 +294,7 @@ func TestSwapTokensTenderlyE2E(t *testing.T) {
{
description: "Ethereum - Swap $0.01 worth of USDC for ETH - Version 2 - Permit1",
tenderlyDescription: "DP-1inch->ETH-Permit1",
config: models.Config{
config: models.ClientConfig{
DevPortalApiKey: os.Getenv("DEV_PORTAL_TOKEN"),
Web3HttpProviders: []models.Web3Provider{
{
Expand Down

0 comments on commit bcfbca9

Please sign in to comment.