From bcfbca98fa8e4f0fcc85887db692f0d6c4244a9e Mon Sep 17 00:00:00 2001 From: Tanz0rz Date: Tue, 12 Mar 2024 17:09:10 -0600 Subject: [PATCH] Improving client config naming now that it is in the models package (#35) --- README.md | 2 +- client/client.go | 4 ++-- client/client_test.go | 10 +++++----- client/client_test_helpers.go | 2 +- client/examples/orderbook/create_order/main.go | 2 +- client/examples/orderbook/get_orders/main.go | 2 +- client/examples/swap/get_swap/main.go | 2 +- client/models/client_types.go | 4 ++-- client/orderbook_e2e_test.go | 10 +++++----- client/orderbook_integration_test.go | 2 +- client/swap_actions_e2e_test.go | 18 +++++++++--------- 11 files changed, 29 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index 3689eded..a3accdba 100644 --- a/README.md +++ b/README.md @@ -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, diff --git a/client/client.go b/client/client.go index 281680bf..7f7ddf31 100644 --- a/client/client.go +++ b/client/client.go @@ -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) diff --git a/client/client_test.go b/client/client_test.go index 8f0b855f..213494be 100644 --- a/client/client_test.go +++ b/client/client_test.go @@ -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{ { @@ -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{ { @@ -42,7 +42,7 @@ func TestNewConfig(t *testing.T) { }, { description: "Error - no API key", - config: models.Config{ + config: models.ClientConfig{ DevPortalApiKey: "", Web3HttpProviders: []models.Web3Provider{ { @@ -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", diff --git a/client/client_test_helpers.go b/client/client_test_helpers.go index 00c52666..7fd41142 100644 --- a/client/client_test_helpers.go +++ b/client/client_test_helpers.go @@ -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{ { diff --git a/client/examples/orderbook/create_order/main.go b/client/examples/orderbook/create_order/main.go index 5d65d7a2..3b5d50eb 100644 --- a/client/examples/orderbook/create_order/main.go +++ b/client/examples/orderbook/create_order/main.go @@ -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{ { diff --git a/client/examples/orderbook/get_orders/main.go b/client/examples/orderbook/get_orders/main.go index 26871056..ddcf5799 100644 --- a/client/examples/orderbook/get_orders/main.go +++ b/client/examples/orderbook/get_orders/main.go @@ -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{ { diff --git a/client/examples/swap/get_swap/main.go b/client/examples/swap/get_swap/main.go index ba1dd941..5131d551 100644 --- a/client/examples/swap/get_swap/main.go +++ b/client/examples/swap/get_swap/main.go @@ -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{ { diff --git a/client/models/client_types.go b/client/models/client_types.go index 22e8cc95..4d0cb12a 100644 --- a/client/models/client_types.go +++ b/client/models/client_types.go @@ -2,7 +2,7 @@ package models import "fmt" -type Config struct { +type ClientConfig struct { DevPortalApiKey string Web3HttpProviders []Web3Provider } @@ -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") diff --git a/client/orderbook_e2e_test.go b/client/orderbook_e2e_test.go index 306501d9..085a8d31 100644 --- a/client/orderbook_e2e_test.go +++ b/client/orderbook_e2e_test.go @@ -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{ { @@ -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{ { @@ -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{ { @@ -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{ { diff --git a/client/orderbook_integration_test.go b/client/orderbook_integration_test.go index d16e7a94..1f08c1e4 100644 --- a/client/orderbook_integration_test.go +++ b/client/orderbook_integration_test.go @@ -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{ { diff --git a/client/swap_actions_e2e_test.go b/client/swap_actions_e2e_test.go index c90627c4..af8fc13d 100644 --- a/client/swap_actions_e2e_test.go +++ b/client/swap_actions_e2e_test.go @@ -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 @@ -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{ { @@ -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{ { @@ -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{ { @@ -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{ { @@ -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{ { @@ -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{ { @@ -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{ { @@ -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{ {