Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add error messages for contradicting flags #330

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,14 @@ func initCommon(args []string) error {
return err
}

if err := validateRemoteNodeVsBlockChainNodeFlags(initOptions.RemoteNodeURL, initOptions.BlockchainNodeProvider); err != nil {
return err
}

if err := validateRemoteNodeDeployVsContractAddressFlags(initOptions.RemoteNodeDeploy, initOptions.ContractAddress); err != nil {
return err
}

fmt.Println("initializing new FireFly stack...")

if len(args) > 0 {
Expand Down Expand Up @@ -260,6 +268,20 @@ func validatePrivateTransactionManagerBlockchainConnectorCombination(privateTran
return nil
}

func validateRemoteNodeVsBlockChainNodeFlags(remoteNodeUrl, blockchainNodePorvider string) error {
if len(remoteNodeUrl) != 0 && blockchainNodePorvider != "geth" {
return errors.New("`remote-noted-url` and `blockchain-node` can't both be specified")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return errors.New("`remote-noted-url` and `blockchain-node` can't both be specified")
return errors.New("Both flags `remote-node-url` and `blockchain-node` can't be specified")

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi @EnriqueL8, thanks for your review. I will correct the text and look for a place where to place the test.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi @EnriqueL8, now that I took a deeper look, I remembered why I didn't provide tests initially. I didn't find any of the initCommon behavior to have been tested. Can you please let me know if I'm mistaken, or if not - and still a test needs to be written for this part - where, according to the practices of this repo, shall it be?

Thanks in advance for your help.

}
return nil
}

func validateRemoteNodeDeployVsContractAddressFlags(remoteNodeDeploy bool, contractAddress string) error {
if remoteNodeDeploy && len(contractAddress) != 0 {
return errors.New("`contract-address` and `remote-node-deploy` can't both be specified")
}
return nil
}

func validateTokensProvider(input []string, blockchainNodeProviderInput string) error {
tokenProviders := make([]fftypes.FFEnum, len(input))
for i, t := range input {
Expand Down