-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding
appointee
remove
and set
command implementation and unit…
… tests. (#250) Co-authored-by: Brandon Chatham <[email protected]>
- Loading branch information
1 parent
54287d6
commit 2c1c048
Showing
12 changed files
with
533 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
package appointee | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
gethtypes "github.com/ethereum/go-ethereum/core/types" | ||
"testing" | ||
|
||
"github.com/Layr-Labs/eigensdk-go/chainio/clients/elcontracts" | ||
"github.com/Layr-Labs/eigensdk-go/logging" | ||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/urfave/cli/v2" | ||
) | ||
|
||
type mockRemoveUserPermissionWriter struct { | ||
removePermissionFunc func(ctx context.Context, request elcontracts.RemovePermissionRequest) (*gethtypes.Receipt, error) | ||
} | ||
|
||
func (m *mockRemoveUserPermissionWriter) RemovePermission( | ||
ctx context.Context, | ||
request elcontracts.RemovePermissionRequest, | ||
) (*gethtypes.Receipt, error) { | ||
return m.removePermissionFunc(ctx, request) | ||
} | ||
|
||
func generateMockRemoveWriter(err error) func(logging.Logger, *removeConfig) (RemoveUserPermissionWriter, error) { | ||
return func(logger logging.Logger, config *removeConfig) (RemoveUserPermissionWriter, error) { | ||
return &mockRemoveUserPermissionWriter{ | ||
removePermissionFunc: func(ctx context.Context, request elcontracts.RemovePermissionRequest) (*gethtypes.Receipt, error) { | ||
return &gethtypes.Receipt{}, err | ||
}, | ||
}, nil | ||
} | ||
} | ||
|
||
func TestRemoveCmd_Success(t *testing.T) { | ||
app := cli.NewApp() | ||
app.Commands = []*cli.Command{ | ||
RemoveCmd(generateMockRemoveWriter(nil)), | ||
} | ||
|
||
args := []string{ | ||
"TestRemoveCmd_Success", | ||
"remove", | ||
"--account-address", "0x1234567890abcdef1234567890abcdef12345678", | ||
"--appointee-address", "0xabcdef1234567890abcdef1234567890abcdef12", | ||
"--target-address", "0x9876543210fedcba9876543210fedcba98765432", | ||
"--selector", "0x1A2B3C4D", | ||
"--network", "holesky", | ||
"--eth-rpc-url", "https://ethereum-holesky.publicnode.com/", | ||
"--ecdsa-private-key", "0xabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcd", | ||
} | ||
|
||
err := app.Run(args) | ||
assert.NoError(t, err) | ||
} | ||
|
||
func TestRemoveCmd_GeneratorError(t *testing.T) { | ||
expectedError := "failed to create permission writer" | ||
app := cli.NewApp() | ||
app.Commands = []*cli.Command{ | ||
RemoveCmd(func(logger logging.Logger, config *removeConfig) (RemoveUserPermissionWriter, error) { | ||
return nil, errors.New(expectedError) | ||
}), | ||
} | ||
|
||
args := []string{ | ||
"TestRemoveCmd_GeneratorError", | ||
"remove", | ||
"--account-address", "0x1234567890abcdef1234567890abcdef12345678", | ||
"--appointee-address", "0xabcdef1234567890abcdef1234567890abcdef12", | ||
"--target-address", "0x9876543210fedcba9876543210fedcba98765432", | ||
"--selector", "0x1A2B3C4D", | ||
"--network", "holesky", | ||
"--eth-rpc-url", "https://ethereum-holesky.publicnode.com/", | ||
"--ecdsa-private-key", "0xabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcd", | ||
} | ||
|
||
err := app.Run(args) | ||
assert.Error(t, err) | ||
assert.Contains(t, err.Error(), expectedError) | ||
} | ||
|
||
func TestRemoveCmd_RemovePermissionError(t *testing.T) { | ||
expectedError := "error removing permission" | ||
app := cli.NewApp() | ||
app.Commands = []*cli.Command{ | ||
RemoveCmd(generateMockRemoveWriter(errors.New(expectedError))), | ||
} | ||
|
||
args := []string{ | ||
"TestRemoveCmd_RemovePermissionError", | ||
"remove", | ||
"--account-address", "0x1234567890abcdef1234567890abcdef12345678", | ||
"--appointee-address", "0xabcdef1234567890abcdef1234567890abcdef12", | ||
"--target-address", "0x9876543210fedcba9876543210fedcba98765432", | ||
"--selector", "0x1A2B3C4D", | ||
"--network", "holesky", | ||
"--eth-rpc-url", "https://ethereum-holesky.publicnode.com/", | ||
"--ecdsa-private-key", "0xabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcd", | ||
"--path-to-key-store", "/path/to/keystore.json", | ||
} | ||
|
||
err := app.Run(args) | ||
assert.Error(t, err) | ||
assert.Contains(t, err.Error(), expectedError) | ||
} |
Oops, something went wrong.