chore(sonar): define a constant instead of duplicating literal

Signed-off-by: Julian Strobl <jmastr@mailbox.org>
This commit is contained in:
Julian Strobl 2024-11-15 12:35:36 +01:00
parent 702b9d6f7e
commit 0e045fa703
No known key found for this signature in database
GPG Key ID: E0A8F9AD733499A7
3 changed files with 29 additions and 17 deletions

View File

@ -14,6 +14,8 @@ import (
const ( const (
flagSerialPort = "serial-port" flagSerialPort = "serial-port"
SerialPort = "/dev/ttyACM0"
) )
func TrustWalletCmd() *cobra.Command { func TrustWalletCmd() *cobra.Command {
@ -43,7 +45,7 @@ Provided mnemonics must be 12 or 24 words long and adhere to bip39.`,
Args: cobra.RangeArgs(0, 1), Args: cobra.RangeArgs(0, 1),
} }
cmd.Flags().String(flagSerialPort, "/dev/ttyACM0", "The serial port your Trust Wallet is connected to") cmd.Flags().String(flagSerialPort, SerialPort, "The serial port your Trust Wallet is connected to")
flags.AddQueryFlagsToCmd(cmd) flags.AddQueryFlagsToCmd(cmd)
return cmd return cmd
@ -107,7 +109,7 @@ raw planetmint key (hex encoded)`,
Args: cobra.ExactArgs(0), Args: cobra.ExactArgs(0),
} }
cmd.Flags().String(flagSerialPort, "/dev/ttyACM0", "The serial port your Trust Wallet is connected to") cmd.Flags().String(flagSerialPort, SerialPort, "The serial port your Trust Wallet is connected to")
flags.AddQueryFlagsToCmd(cmd) flags.AddQueryFlagsToCmd(cmd)
return cmd return cmd

View File

@ -15,6 +15,10 @@ import (
"github.com/stretchr/testify/suite" "github.com/stretchr/testify/suite"
) )
const (
SerialPort = "/dev/ttyACM0"
)
// E2ETestSuite struct definition of machine suite // E2ETestSuite struct definition of machine suite
type E2ETestSuite struct { type E2ETestSuite struct {
suite.Suite suite.Suite
@ -111,7 +115,7 @@ func (s *E2ETestSuite) TestOccSigning() {
msg := banktypes.NewMsgSend(addr, val.Address, coin) msg := banktypes.NewMsgSend(addr, val.Address, coin)
libConfig := lib.GetConfig() libConfig := lib.GetConfig()
libConfig.SetSerialPort("/dev/ttyACM0") libConfig.SetSerialPort(SerialPort)
out, err := lib.BroadcastTxWithFileLock(addr, msg) out, err := lib.BroadcastTxWithFileLock(addr, msg)
s.Require().NoError(err) s.Require().NoError(err)
@ -124,7 +128,7 @@ func (s *E2ETestSuite) TestOccSigning() {
// set sample mnemonic on trust wallet // set sample mnemonic on trust wallet
func setKeys() (string, error) { func setKeys() (string, error) {
connector, err := trustwallet.NewTrustWalletConnector("/dev/ttyACM0") connector, err := trustwallet.NewTrustWalletConnector(SerialPort)
if err != nil { if err != nil {
return "", err return "", err
} }
@ -132,7 +136,7 @@ func setKeys() (string, error) {
} }
func loadKeys() (*trustwallet.PlanetMintKeys, error) { func loadKeys() (*trustwallet.PlanetMintKeys, error) {
connector, err := trustwallet.NewTrustWalletConnector("/dev/ttyACM0") connector, err := trustwallet.NewTrustWalletConnector(SerialPort)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -8,6 +8,12 @@ import (
"sync" "sync"
) )
const (
NoDataReturned = "no data returned"
NoPublicKeyReturned = "no public key returned"
NoSignatureReturned = "no signature returned"
)
var ( var (
keys *PlanetMintKeys keys *PlanetMintKeys
) )
@ -47,7 +53,7 @@ func (t *Connector) ValiseGet() (string, error) {
if len(response.Data) > 1 { if len(response.Data) > 1 {
return response.Data[1], nil return response.Data[1], nil
} }
return "", errors.New("no data returned") return "", errors.New(NoDataReturned)
} }
func (t *Connector) CreateMnemonic() (string, error) { func (t *Connector) CreateMnemonic() (string, error) {
@ -58,7 +64,7 @@ func (t *Connector) CreateMnemonic() (string, error) {
if len(response.Data) > 1 { if len(response.Data) > 1 {
return response.Data[1], nil return response.Data[1], nil
} }
return "", errors.New("no data returned") return "", errors.New(NoDataReturned)
} }
func (t *Connector) InjectPlanetminkeyToSE050(slot int) (bool, error) { func (t *Connector) InjectPlanetminkeyToSE050(slot int) (bool, error) {
@ -69,7 +75,7 @@ func (t *Connector) InjectPlanetminkeyToSE050(slot int) (bool, error) {
if len(response.Data) > 1 { if len(response.Data) > 1 {
return response.Data[1] == "0", nil return response.Data[1] == "0", nil
} }
return false, errors.New("no data returned") return false, errors.New(NoDataReturned)
} }
func (t *Connector) RecoverFromMnemonic(mnemonic string) (string, error) { func (t *Connector) RecoverFromMnemonic(mnemonic string) (string, error) {
@ -80,7 +86,7 @@ func (t *Connector) RecoverFromMnemonic(mnemonic string) (string, error) {
if len(response.Data) > 1 { if len(response.Data) > 1 {
return response.Data[1], nil return response.Data[1], nil
} }
return "", errors.New("no data returned") return "", errors.New(NoDataReturned)
} }
func (t *Connector) GetPlanetmintKeys() (*PlanetMintKeys, error) { func (t *Connector) GetPlanetmintKeys() (*PlanetMintKeys, error) {
@ -111,7 +117,7 @@ func (t *Connector) GetSeedSE050() (string, error) {
if len(response.Data) > 1 { if len(response.Data) > 1 {
return response.Data[1], nil return response.Data[1], nil
} }
return "", errors.New("no data returned") return "", errors.New(NoDataReturned)
} }
func (t *Connector) SignHashWithPlanetmint(dataToSign string) (string, error) { func (t *Connector) SignHashWithPlanetmint(dataToSign string) (string, error) {
@ -122,7 +128,7 @@ func (t *Connector) SignHashWithPlanetmint(dataToSign string) (string, error) {
if len(response.Data) > 1 { if len(response.Data) > 1 {
return response.Data[1], nil return response.Data[1], nil
} }
return "", errors.New("no signature returned") return "", errors.New(NoSignatureReturned)
} }
func (t *Connector) SignHashWithRDDL(dataToSign string) (string, error) { func (t *Connector) SignHashWithRDDL(dataToSign string) (string, error) {
@ -133,7 +139,7 @@ func (t *Connector) SignHashWithRDDL(dataToSign string) (string, error) {
if len(response.Data) > 1 { if len(response.Data) > 1 {
return response.Data[1], nil return response.Data[1], nil
} }
return "", errors.New("no signature returned") return "", errors.New(NoSignatureReturned)
} }
func (t *Connector) CreateOptegaKeypair(ctx int) (string, error) { func (t *Connector) CreateOptegaKeypair(ctx int) (string, error) {
@ -144,7 +150,7 @@ func (t *Connector) CreateOptegaKeypair(ctx int) (string, error) {
if len(response.Data) > 1 { if len(response.Data) > 1 {
return response.Data[1], nil return response.Data[1], nil
} }
return "", errors.New("no public key returned") return "", errors.New(NoPublicKeyReturned)
} }
func (t *Connector) SignWithOptega(ctx int, dataToSign, pubkey string) (string, error) { func (t *Connector) SignWithOptega(ctx int, dataToSign, pubkey string) (string, error) {
@ -155,7 +161,7 @@ func (t *Connector) SignWithOptega(ctx int, dataToSign, pubkey string) (string,
if len(response.Data) > 1 { if len(response.Data) > 1 {
return response.Data[1], nil return response.Data[1], nil
} }
return "", errors.New("no signature returned") return "", errors.New(NoSignatureReturned)
} }
func (t *Connector) UnwrapPublicKey(publicKey string) (bool, string) { func (t *Connector) UnwrapPublicKey(publicKey string) (bool, string) {
@ -187,7 +193,7 @@ func (t *Connector) CreateSE050KeypairNIST(ctx int) (string, error) {
if len(response.Data) > 1 { if len(response.Data) > 1 {
return response.Data[1], nil return response.Data[1], nil
} }
return "", errors.New("no public key returned") return "", errors.New(NoPublicKeyReturned)
} }
func (t *Connector) GetPublicKeyFromSE050(ctx int) (string, error) { func (t *Connector) GetPublicKeyFromSE050(ctx int) (string, error) {
@ -202,7 +208,7 @@ func (t *Connector) GetPublicKeyFromSE050(ctx int) (string, error) {
} }
return pubKey, nil return pubKey, nil
} }
return "", errors.New("no public key returned") return "", errors.New(NoPublicKeyReturned)
} }
func (t *Connector) SignWithSE050(dataToSign string, ctx int) (string, error) { func (t *Connector) SignWithSE050(dataToSign string, ctx int) (string, error) {
@ -213,7 +219,7 @@ func (t *Connector) SignWithSE050(dataToSign string, ctx int) (string, error) {
if len(response.Data) > 1 { if len(response.Data) > 1 {
return response.Data[1], nil return response.Data[1], nil
} }
return "", errors.New("no signature returned") return "", errors.New(NoSignatureReturned)
} }
func (t *Connector) VerifySE050Signature(dataToSign, signature string, ctx int) (bool, error) { func (t *Connector) VerifySE050Signature(dataToSign, signature string, ctx int) (bool, error) {