Skip to content

Commit

Permalink
fix: parseNetworkAndChainIDFromString logic
Browse files Browse the repository at this point in the history
  • Loading branch information
pseudoyu committed Apr 19, 2024
1 parent eb18543 commit 8360a45
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
2 changes: 1 addition & 1 deletion schema/network/ethereum_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func ParseNetworkAndChainIDFromString(networkString string) (Network, EthereumCh
}

chainID, err := EthereumChainIDString(networkString)
if err != nil {
if err == nil {
return network, chainID
}

Expand Down
45 changes: 45 additions & 0 deletions schema/network/ethereum_chain_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package network

import (
"testing"
)

func TestParseNetworkAndChainIDFromString(t *testing.T) {

Check failure on line 7 in schema/network/ethereum_chain_test.go

View workflow job for this annotation

GitHub Actions / Lint

Function TestParseNetworkAndChainIDFromString missing the call to method parallel
testCases := []struct {
name string
networkString string
expectedNet Network
expectedChainID EthereumChainID
}{
{
name: "Mainnet",
networkString: "ethereum",
expectedNet: Ethereum,
expectedChainID: EthereumChainIDMainnet,
},
{
name: "Arbitrum",
networkString: "arbitrum",
expectedNet: Arbitrum,
expectedChainID: EthereumChainIDArbitrum,
},
{
name: "Unknown",
networkString: "unknown",
expectedNet: Unknown,
expectedChainID: 0,
},
}

for _, tc := range testCases {

Check failure on line 34 in schema/network/ethereum_chain_test.go

View workflow job for this annotation

GitHub Actions / Lint

Range statement for test TestParseNetworkAndChainIDFromString missing the call to method parallel in test Run
t.Run(tc.name, func(t *testing.T) {
network, chainID := ParseNetworkAndChainIDFromString(tc.networkString)
if network != tc.expectedNet {
t.Errorf("Expected network %s, got %s", tc.expectedNet, network)
}
if chainID != tc.expectedChainID {
t.Errorf("Expected chainID %d, got %d", tc.expectedChainID, chainID)
}
})
}
}

0 comments on commit 8360a45

Please sign in to comment.