Skip to content

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
onikonychev committed May 22, 2024
1 parent 4213a19 commit 79516f5
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 101 deletions.
22 changes: 1 addition & 21 deletions eth/chain_id.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,19 @@
package eth

import (
"fmt"
"math/big"
"regexp"

"github.com/NibiruChain/nibiru/app/appconst"
)

var (
// one of any lower case letter from "a"-"z"
regexChainID = `[a-z]{1,}`
// one of either "_" or "-"
regexEIP155Separator = `[_-]{1}`
// one of "_"
// regexEIP155Separator = `_{1}`
regexEIP155 = `[1-9][0-9]*`
regexEpochSeparator = `-{1}`
regexEpoch = `[1-9][0-9]*`
nibiruEvmChainId = regexp.MustCompile(fmt.Sprintf(`^(%s)%s(%s)%s(%s)$`,
regexChainID,
regexEIP155Separator,
regexEIP155,
regexEpochSeparator,
regexEpoch))
)

// IsValidChainID returns false if the given chain identifier is incorrectly
// formatted.
func IsValidChainID(chainID string) bool {
if len(chainID) > 48 {

Check failure on line 13 in eth/chain_id.go

View workflow job for this annotation

GitHub Actions / lint

S1008: should use 'return len(chainID) <= 48' instead of 'if len(chainID) > 48 { return false }; return true' (gosimple)
return false
}

return nibiruEvmChainId.MatchString(chainID)
return true
}

// ParseEthChainID parses a string chain identifier's epoch to an
Expand Down
80 changes: 0 additions & 80 deletions eth/chain_id_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package eth

import (
"math/big"
"strings"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -43,82 +42,3 @@ func TestParseChainID_Happy(t *testing.T) {
require.True(t, IsValidChainID(tc.chainID))
}
}

func TestParseChainID_Sad(t *testing.T) {
testCases := []struct {
name string
chainID string
}{
{
chainID: "chain_1_1",
name: "invalid chain-id, double underscore",
},
{
chainID: "-",
name: "invalid chain-id, dash only",
},
{
chainID: "-1",
name: "invalid chain-id, undefined identifier and EIP155",
},
{
chainID: "_1-1",
name: "invalid chain-id, undefined identifier",
},
{
chainID: "NIBIRU_1-1",
name: "invalid chain-id, uppercases",
},
{
chainID: "Nibiru_1-1",
name: "invalid chain-id, mixed cases",
},
{
chainID: "$&*#!_1-1",
name: "invalid chain-id, special chars",
},
{
chainID: "nibiru_001-1",
name: "invalid eip155 chain-id, cannot start with 0",
},
{
chainID: "nibiru_0x212-1",
name: "invalid eip155 chain-id, cannot invalid base",
},
{
chainID: "nibiru_1-0x212",
name: "invalid eip155 chain-id, cannot invalid base",
},
{
chainID: "nibiru_nibiru_9000-1",
name: "invalid eip155 chain-id, non-integer",
},
{
chainID: "nibiru_-",
name: "invalid epoch, undefined",
},
{
chainID: " ",
name: "blank chain ID",
},
{
chainID: "",
name: "empty chain ID",
},
{
chainID: "_-",
name: "empty content for chain id, eip155 and epoch numbers",
},
{
chainID: "nibiru_" + strings.Repeat("1", 45) + "-1",
name: "long chain-id",
},
}

for _, tc := range testCases {
chainIDEpoch, err := ParseEthChainIDStrict(tc.chainID)
require.Error(t, err, tc.name)
require.Nil(t, chainIDEpoch)
require.False(t, IsValidChainID(tc.chainID), tc.name)
}
}

0 comments on commit 79516f5

Please sign in to comment.