Skip to content

Commit

Permalink
fix: sonar warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Luisfc68 committed Nov 28, 2024
1 parent caebe94 commit 9d4d1a9
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 33 deletions.
11 changes: 6 additions & 5 deletions cmd/utils/register_pegin/register_pegin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,19 +133,20 @@ func TestExecuteRegisterPegIn(t *testing.T) {
}

func TestRegisterPegInScriptInput_ToEnv(t *testing.T) {
const btcRpcHost = "http://localhost:1111"
t.Run("Should parse RegisterPegIn script input successfully", func(t *testing.T) {
scriptInput := new(RegisterPegInScriptInput)
ReadRegisterPegInScriptInput(scriptInput)
require.NoError(t, flag.Set("network", "regtest"))
require.NoError(t, flag.Set("input-file", "/file/path"))
require.NoError(t, flag.Set("btc-rpc-host", "http://localhost:1111"))
require.NoError(t, flag.Set("btc-rpc-host", btcRpcHost))
require.NoError(t, flag.Set("btc-rpc-user", "btcUser"))
require.NoError(t, flag.Set("btc-rpc-password", "btcPassword"))
env, err := scriptInput.ToEnv(term.ReadPassword)
require.NoError(t, err)
assert.Equal(t, "regtest", env.LpsStage)
assert.Equal(t, "regtest", env.Btc.Network)
assert.Equal(t, "http://localhost:1111", env.Btc.Endpoint)
assert.Equal(t, btcRpcHost, env.Btc.Endpoint)
assert.Equal(t, "btcUser", env.Btc.Username)
assert.Equal(t, "btcPassword", env.Btc.Password)
// we assert the rsk defaults to ensure the method called its parent method
Expand All @@ -161,19 +162,19 @@ func TestRegisterPegInScriptInput_ToEnv(t *testing.T) {
ReadRegisterPegInScriptInput(scriptInput)
require.NoError(t, flag.Set("network", "regtest"))
require.NoError(t, flag.Set("input-file", "/file/path"))
require.NoError(t, flag.Set("btc-rpc-host", "http://localhost:1111"))
require.NoError(t, flag.Set("btc-rpc-host", btcRpcHost))
env, err := scriptInput.ToEnv(term.ReadPassword)
require.NoError(t, err)
assert.Equal(t, "regtest", env.LpsStage)
assert.Equal(t, "regtest", env.Btc.Network)
assert.Equal(t, "http://localhost:1111", env.Btc.Endpoint)
assert.Equal(t, btcRpcHost, env.Btc.Endpoint)
assert.Equal(t, "none", env.Btc.Username)
assert.Equal(t, "none", env.Btc.Password)
})
}

func TestParseRegisterPegInScriptInput(t *testing.T) {
parse := func() {}
parse := func() { /* mock function to prevent calling flag.Parse inside a test */ }
input := RegisterPegInScriptInput{
BaseInput: scripts.BaseInput{
AwsLocalEndpoint: "http://localhost:4566", RskEndpoint: "http://localhost:4444", Network: "regtest",
Expand Down
62 changes: 35 additions & 27 deletions cmd/utils/scripts/input_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,35 @@ import (
"testing"
)

const (
awsMockEndpoint = "http://localhost:1122"
rskMockEndpoint = "http://localhost:3344"
mockFilePath = "/file/path"
mockKeystoreSecret = "UnitTest/Keystore-Secret"
mockPwdSecret = "UnitTest/Password-Secret"
)

func TestReadBaseInput(t *testing.T) {
t.Run("should read base input", func(t *testing.T) {
input := new(scripts.BaseInput)
scripts.ReadBaseInput(input)
require.NoError(t, flag.Set("network", "regtest"))
require.NoError(t, flag.Set("secret-src", "aws"))
require.NoError(t, flag.Set("aws-endpoint", "http://localhost:1122"))
require.NoError(t, flag.Set("rsk-endpoint", "http://localhost:3344"))
require.NoError(t, flag.Set("aws-endpoint", awsMockEndpoint))
require.NoError(t, flag.Set("rsk-endpoint", rskMockEndpoint))
require.NoError(t, flag.Set("lbc-address", "0xBEd51d83cc4676660E3Fc3819dfAD8238549B975"))
require.NoError(t, flag.Set("keystore-secret", "UnitTest/Keystore-Secret"))
require.NoError(t, flag.Set("password-secret", "UnitTest/Password-Secret"))
require.NoError(t, flag.Set("keystore-file", "/file/path"))
require.NoError(t, flag.Set("keystore-secret", mockKeystoreSecret))
require.NoError(t, flag.Set("password-secret", mockPwdSecret))
require.NoError(t, flag.Set("keystore-file", mockFilePath))
flag.Parse()
assert.Equal(t, "regtest", input.Network)
assert.Equal(t, "aws", input.SecretSource)
assert.Equal(t, "http://localhost:1122", input.AwsLocalEndpoint)
assert.Equal(t, "http://localhost:3344", input.RskEndpoint)
assert.Equal(t, awsMockEndpoint, input.AwsLocalEndpoint)
assert.Equal(t, rskMockEndpoint, input.RskEndpoint)
assert.Equal(t, "0xBEd51d83cc4676660E3Fc3819dfAD8238549B975", input.CustomLbcAddress)
assert.Equal(t, "UnitTest/Keystore-Secret", input.EncryptedJsonSecret)
assert.Equal(t, "UnitTest/Password-Secret", input.EncryptedJsonPasswordSecret)
assert.Equal(t, "/file/path", input.KeystoreFile)
assert.Equal(t, mockKeystoreSecret, input.EncryptedJsonSecret)
assert.Equal(t, mockPwdSecret, input.EncryptedJsonPasswordSecret)
assert.Equal(t, mockFilePath, input.KeystoreFile)
assert.Empty(t, input.KeystorePassword)
})
}
Expand All @@ -37,56 +45,56 @@ func TestBaseInput_ToEnv(t *testing.T) {
t.Run("should convert base input to environment with aws source", func(t *testing.T) {
input := scripts.BaseInput{
Network: "regtest",
RskEndpoint: "http://localhost:3344",
RskEndpoint: rskMockEndpoint,
CustomLbcAddress: "0xBEd51d83cc4676660E3Fc3819dfAD8238549B975",
AwsLocalEndpoint: "http://localhost:1122",
AwsLocalEndpoint: awsMockEndpoint,
SecretSource: "aws",
EncryptedJsonSecret: "UnitTest/Keystore-Secret",
EncryptedJsonPasswordSecret: "UnitTest/Password-Secret",
KeystoreFile: "/file/path",
EncryptedJsonSecret: mockKeystoreSecret,
EncryptedJsonPasswordSecret: mockPwdSecret,
KeystoreFile: mockFilePath,
}
env, err := input.ToEnv(func(fd int) ([]byte, error) {
return []byte(""), nil
})
require.NoError(t, err)
assert.Equal(t, "regtest", env.LpsStage)
assert.Equal(t, "http://localhost:1122", env.AwsLocalEndpoint)
assert.Equal(t, awsMockEndpoint, env.AwsLocalEndpoint)
assert.Equal(t, "aws", env.SecretSource)
assert.Equal(t, "native", env.WalletManagement)
assert.Equal(t, "http://localhost:3344", env.Rsk.Endpoint)
assert.Equal(t, rskMockEndpoint, env.Rsk.Endpoint)
assert.Equal(t, uint64(33), env.Rsk.ChainId)
assert.Equal(t, "0xBEd51d83cc4676660E3Fc3819dfAD8238549B975", env.Rsk.LbcAddress)
assert.Equal(t, "0x0000000000000000000000000000000001000006", env.Rsk.BridgeAddress)
assert.Equal(t, 0, env.Rsk.AccountNumber)
assert.Equal(t, "UnitTest/Keystore-Secret", env.Rsk.EncryptedJsonSecret)
assert.Equal(t, "UnitTest/Password-Secret", env.Rsk.EncryptedJsonPasswordSecret)
assert.Equal(t, mockKeystoreSecret, env.Rsk.EncryptedJsonSecret)
assert.Equal(t, mockPwdSecret, env.Rsk.EncryptedJsonPasswordSecret)
assert.Equal(t, "regtest", env.Btc.Network)
})

t.Run("should convert base input to environment with env source", func(t *testing.T) {
input := scripts.BaseInput{
Network: "regtest",
RskEndpoint: "http://localhost:3344",
AwsLocalEndpoint: "http://localhost:1122",
RskEndpoint: rskMockEndpoint,
AwsLocalEndpoint: awsMockEndpoint,
SecretSource: "env",
EncryptedJsonSecret: "UnitTest/Keystore-Secret",
EncryptedJsonPasswordSecret: "UnitTest/Password-Secret",
KeystoreFile: "/file/path",
EncryptedJsonSecret: mockKeystoreSecret,
EncryptedJsonPasswordSecret: mockPwdSecret,
KeystoreFile: mockFilePath,
}
env, err := input.ToEnv(func(fd int) ([]byte, error) {
return []byte("test-pwd"), nil
})
require.NoError(t, err)
assert.Equal(t, "regtest", env.LpsStage)
assert.Equal(t, "http://localhost:1122", env.AwsLocalEndpoint)
assert.Equal(t, awsMockEndpoint, env.AwsLocalEndpoint)
assert.Equal(t, "env", env.SecretSource)
assert.Equal(t, "native", env.WalletManagement)
assert.Equal(t, "http://localhost:3344", env.Rsk.Endpoint)
assert.Equal(t, rskMockEndpoint, env.Rsk.Endpoint)
assert.Equal(t, uint64(33), env.Rsk.ChainId)
assert.Equal(t, "0x8901a2bbf639bfd21a97004ba4d7ae2bd00b8da8", env.Rsk.LbcAddress)
assert.Equal(t, "0x0000000000000000000000000000000001000006", env.Rsk.BridgeAddress)
assert.Equal(t, 0, env.Rsk.AccountNumber)
assert.Equal(t, "/file/path", env.Rsk.KeystoreFile)
assert.Equal(t, mockFilePath, env.Rsk.KeystoreFile)
assert.Equal(t, "test-pwd", env.Rsk.KeystorePassword)
assert.Equal(t, "regtest", env.Btc.Network)
})
Expand Down
2 changes: 1 addition & 1 deletion internal/adapters/dataproviders/rootstock/lbc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ func TestLiquidityBridgeContractImpl_SetProviderStatus(t *testing.T) {
func TestLiquidityBridgeContractImpl_UpdateProvider(t *testing.T) {
const (
name = "test name"
url = "http://test.com"
url = "http://test.update.example.com"
)

lbcMock := &mocks.LbcAdapterMock{}
Expand Down

0 comments on commit 9d4d1a9

Please sign in to comment.