Skip to content

Commit

Permalink
change field and add description limit (#16)
Browse files Browse the repository at this point in the history
* change field and add description limit

* update deps
  • Loading branch information
shrimalmadhur authored Oct 5, 2023
1 parent 475bc4f commit 9d3410d
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 75 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/Layr-Labs/eigensdk-go
go 1.21

require (
github.com/consensys/gnark-crypto v0.11.2
github.com/consensys/gnark-crypto v0.12.0
github.com/ethereum/go-ethereum v1.12.2
github.com/prometheus/client_golang v1.17.0
github.com/stretchr/testify v1.8.4
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ github.com/cockroachdb/redact v1.1.3 h1:AKZds10rFSIj7qADf0g46UixK8NNLwWTNdCIGS5w
github.com/cockroachdb/redact v1.1.3/go.mod h1:BVNblN9mBWFyMyqK1k3AAiSxhvhfK2oOZZ2lK+dpvRg=
github.com/consensys/bavard v0.1.13 h1:oLhMLOFGTLdlda/kma4VOJazblc7IM5y5QPd2A/YjhQ=
github.com/consensys/bavard v0.1.13/go.mod h1:9ItSMtA/dXMAiL7BG6bqW2m3NdSEObYWoH223nGHukI=
github.com/consensys/gnark-crypto v0.11.2 h1:GJjjtWJ+db1xGao7vTsOgAOGgjfPe7eRGPL+xxMX0qE=
github.com/consensys/gnark-crypto v0.11.2/go.mod h1:v2Gy7L/4ZRosZ7Ivs+9SfUDr0f5UlG+EM5t7MPHiLuY=
github.com/consensys/gnark-crypto v0.12.0 h1:1OnSpOykNkUIBIBJKdhwy2p0JlW5o+Az02ICzZmvvdg=
github.com/consensys/gnark-crypto v0.12.0/go.mod h1:v2Gy7L/4ZRosZ7Ivs+9SfUDr0f5UlG+EM5t7MPHiLuY=
github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w=
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/crate-crypto/go-kzg-4844 v0.3.0 h1:UBlWE0CgyFqqzTI+IFyCzA7A3Zw4iip6uzRv5NIXG0A=
Expand Down
36 changes: 29 additions & 7 deletions types/operator_metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,30 @@ import (
"strings"
)

// OperatorMetadata is the metadata operator uploads while registering
// itself to eigenlayer
type OperatorMetadata struct {
Name string `yaml:"name" json:"name"`
Website string `yaml:"website" json:"website"`
Description string `yaml:"description" json:"description"`
Logo string `yaml:"logo" json:"logo"`
TwitterProfileUrl string `yaml:"twitter_profile_url" json:"twitter_profile_url"`

// Name of the operator
// It is a required field
Name string `yaml:"name" json:"name"`

// Website of the operator
// It is a required field
Website string `yaml:"website" json:"website"`

// Description of the operator. There is a 200-character limit
// It is a required field
Description string `yaml:"description" json:"description"`

// Logo of the operator. This should be a link to a image file
// which is publicly accessible
// It is a required field
Logo string `yaml:"logo" json:"logo"`

// Twitter handle of the operator
// It is an optional field
Twitter string `yaml:"twitter" json:"twitter"`
}

func (om *OperatorMetadata) Validate() error {
Expand All @@ -26,6 +44,10 @@ func (om *OperatorMetadata) Validate() error {
return errors.New("description is required")
}

if len(om.Description) > 200 {
return errors.New("description should be less than 200 characters")
}

if len(om.Logo) == 0 {
return errors.New("logo is required")
}
Expand All @@ -42,8 +64,8 @@ func (om *OperatorMetadata) Validate() error {
}
}

if len(om.TwitterProfileUrl) != 0 {
err := checkIfUrlIsValid(om.TwitterProfileUrl)
if len(om.Twitter) != 0 {
err := checkIfUrlIsValid(om.Twitter)
if err != nil {
fmt.Println("error validating twitter profile url")
return err
Expand Down
131 changes: 71 additions & 60 deletions types/operator_metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,132 +11,143 @@ func TestOperatorMetadata(t *testing.T) {
{
name: "Valid metadata",
metadata: OperatorMetadata{
Name: "test",
Description: "test",
Logo: "https://test.com/test.png",
TwitterProfileUrl: "https://twitter.com/test",
Website: "https://test.com",
Name: "test",
Description: "test",
Logo: "https://test.com/test.png",
Twitter: "https://twitter.com/test",
Website: "https://test.com",
},
wantErr: false,
},
{
name: "Invalid metadata - no name",
metadata: OperatorMetadata{
Name: "",
Description: "test",
Logo: "https://test.com/test.png",
TwitterProfileUrl: "https://twitter.com/test",
Website: "https://test.com",
Name: "",
Description: "test",
Logo: "https://test.com/test.png",
Twitter: "https://twitter.com/test",
Website: "https://test.com",
},
wantErr: true,
},
{
name: "Invalid metadata - no description",
metadata: OperatorMetadata{
Name: "test",
Description: "",
Logo: "https://test.com/test.png",
TwitterProfileUrl: "https://twitter.com/test",
Website: "https://test.com",
Name: "test",
Description: "",
Logo: "https://test.com/test.png",
Twitter: "https://twitter.com/test",
Website: "https://test.com",
},
wantErr: true,
},
{
name: "Invalid metadata - description > 500 characters",
metadata: OperatorMetadata{
Name: "test",
Description: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.",
Logo: "https://test.com/test.png",
Twitter: "https://twitter.com/test",
Website: "https://test.com",
},
wantErr: true,
},
{
name: "Invalid metadata - no logo",
metadata: OperatorMetadata{
Name: "test",
Description: "test",
Logo: "",
TwitterProfileUrl: "https://twitter.com/test",
Website: "https://test.com",
Name: "test",
Description: "test",
Logo: "",
Twitter: "https://twitter.com/test",
Website: "https://test.com",
},
wantErr: true,
},
{
name: "Invalid metadata - invalid logo extension",
metadata: OperatorMetadata{
Name: "test",
Description: "test",
Logo: "https://test.com/test.exe",
TwitterProfileUrl: "https://twitter.com/test",
Website: "https://test.com",
Name: "test",
Description: "test",
Logo: "https://test.com/test.exe",
Twitter: "https://twitter.com/test",
Website: "https://test.com",
},
wantErr: true,
},
{
name: "Invalid metadata - invalid logo no extension",
metadata: OperatorMetadata{
Name: "test",
Description: "test",
Logo: "https://test.com/test",
TwitterProfileUrl: "https://twitter.com/test",
Website: "https://test.com",
Name: "test",
Description: "test",
Logo: "https://test.com/test",
Twitter: "https://twitter.com/test",
Website: "https://test.com",
},
wantErr: true,
},
{
name: "Invalid metadata - invalid website url #1",
metadata: OperatorMetadata{
Name: "test",
Description: "test",
Logo: "https://test.com/test.png",
TwitterProfileUrl: "https://twitter.com/test",
Website: "https",
Name: "test",
Description: "test",
Logo: "https://test.com/test.png",
Twitter: "https://twitter.com/test",
Website: "https",
},
wantErr: true,
},
{
name: "Invalid metadata - invalid website url #2",
metadata: OperatorMetadata{
Name: "test",
Description: "test",
Logo: "https://test.com/test.png",
TwitterProfileUrl: "https://twitter.com/test",
Website: "https:/test.com",
Name: "test",
Description: "test",
Logo: "https://test.com/test.png",
Twitter: "https://twitter.com/test",
Website: "https:/test.com",
},
wantErr: true,
},
{
name: "Invalid metadata - invalid website url #3",
metadata: OperatorMetadata{
Name: "test",
Description: "test",
Logo: "https://test.com/test.png",
TwitterProfileUrl: "https://twitter.com/test",
Website: "ps://test.com",
Name: "test",
Description: "test",
Logo: "https://test.com/test.png",
Twitter: "https://twitter.com/test",
Website: "ps://test.com",
},
wantErr: true,
},
{
name: "Invalid metadata - invalid twitter url #1",
metadata: OperatorMetadata{
Name: "test",
Description: "test",
Logo: "https://test.com/test.png",
TwitterProfileUrl: "http",
Website: "https://test.com",
Name: "test",
Description: "test",
Logo: "https://test.com/test.png",
Twitter: "http",
Website: "https://test.com",
},
wantErr: true,
},
{
name: "Invalid metadata - invalid twitter url #2",
metadata: OperatorMetadata{
Name: "test",
Description: "test",
Logo: "https://test.com/test.png",
TwitterProfileUrl: "ht://twitter.com/test",
Website: "https:/test.com",
Name: "test",
Description: "test",
Logo: "https://test.com/test.png",
Twitter: "ht://twitter.com/test",
Website: "https:/test.com",
},
wantErr: true,
},
{
name: "Invalid metadata - invalid twitter url #3",
metadata: OperatorMetadata{
Name: "test",
Description: "test",
Logo: "https://test.com/test.png",
TwitterProfileUrl: "https://twitt",
Website: "ps://test.com",
Name: "test",
Description: "test",
Logo: "https://test.com/test.png",
Twitter: "https://twitt",
Website: "ps://test.com",
},
wantErr: true,
},
Expand Down
10 changes: 5 additions & 5 deletions types/operator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import (

func TestOperatorValidate(t *testing.T) {
metadata := OperatorMetadata{
Name: "test",
Description: "test",
Logo: "https://test.com/test.png",
TwitterProfileUrl: "https://twitter.com/test",
Website: "https://test.com",
Name: "test",
Description: "test",
Logo: "https://test.com/test.png",
Twitter: "https://twitter.com/test",
Website: "https://test.com",
}

var tests = []struct {
Expand Down

0 comments on commit 9d3410d

Please sign in to comment.