-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #576 from rsksmart/refund_scripts/refund-user-pegout
Refund user pegout
- Loading branch information
Showing
34 changed files
with
361 additions
and
106 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
102 changes: 102 additions & 0 deletions
102
cmd/utils/refund_user_pegout/refund_user_pegout_test.go
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,102 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"testing" | ||
|
||
"github.com/rsksmart/liquidity-provider-server/test" | ||
"github.com/rsksmart/liquidity-provider-server/test/mocks" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
"golang.org/x/term" | ||
) | ||
|
||
const ( | ||
testRskEndpoint = "http://localhost:4444" | ||
testQuoteHash = "d93f58c82100a6cee4f19ac505c11d51b52cafe220f7f1944b70496f33d277fc" | ||
testAwsLocalEndpoint = "http://localhost:4566" | ||
testNetwork = "regtest" | ||
testKeystoreFile = "./keystore.json" | ||
) | ||
|
||
func TestReadRefundUserPegOutScriptInput(t *testing.T) { | ||
t.Run("should set flag values", func(t *testing.T) { | ||
// Reset flags before test | ||
flag.CommandLine = flag.NewFlagSet("", flag.ExitOnError) | ||
|
||
scriptInput := new(RefundUserPegOutScriptInput) | ||
ReadRefundUserPegOutScriptInput(scriptInput) | ||
|
||
// Set test values | ||
err := flag.CommandLine.Parse([]string{ | ||
"-network", testNetwork, | ||
"-quote-hash", testQuoteHash, | ||
"-rsk-endpoint", testRskEndpoint, | ||
"-secret-src", "env", | ||
"-keystore-file", testKeystoreFile, | ||
}) | ||
require.NoError(t, err) | ||
|
||
assert.Equal(t, testNetwork, scriptInput.Network) | ||
assert.Equal(t, testQuoteHash, scriptInput.QuoteHashBytes) | ||
assert.Equal(t, testRskEndpoint, scriptInput.RskEndpoint) | ||
assert.Equal(t, "env", scriptInput.SecretSource) | ||
assert.Equal(t, testKeystoreFile, scriptInput.KeystoreFile) | ||
}) | ||
} | ||
|
||
func TestParseRefundUserPegOutScriptInput(t *testing.T) { | ||
|
||
parse := func() { // parse is a no-op function used as a placeholder in tests since the actual parsing | ||
// functionality is not relevant for these test cases | ||
} | ||
|
||
t.Run("should validate required fields", func(t *testing.T) { | ||
scriptInput := &RefundUserPegOutScriptInput{ | ||
Network: "", | ||
QuoteHashBytes: "", | ||
RskEndpoint: "", | ||
SecretSource: "", | ||
} | ||
|
||
_, err := ParseRefundUserPegOutScriptInput(parse, scriptInput, term.ReadPassword) | ||
require.Error(t, err) | ||
assert.Contains(t, err.Error(), "invalid input") | ||
}) | ||
|
||
t.Run("should parse valid input", func(t *testing.T) { | ||
scriptInput := &RefundUserPegOutScriptInput{ | ||
Network: testNetwork, | ||
QuoteHashBytes: testQuoteHash, | ||
RskEndpoint: testRskEndpoint, | ||
SecretSource: "aws", | ||
AwsLocalEndpoint: testAwsLocalEndpoint, | ||
} | ||
|
||
env, err := ParseRefundUserPegOutScriptInput(parse, scriptInput, func(fd int) ([]byte, error) { | ||
return []byte("password"), nil | ||
}) | ||
require.NoError(t, err) | ||
assert.Equal(t, testNetwork, env.LpsStage) | ||
assert.Equal(t, testRskEndpoint, env.Rsk.Endpoint) | ||
assert.Equal(t, "aws", env.SecretSource) | ||
assert.Equal(t, testAwsLocalEndpoint, env.AwsLocalEndpoint) | ||
}) | ||
} | ||
|
||
func TestRefundUserPegOut(t *testing.T) { | ||
t.Run("should execute refund user peg out successfully", func(t *testing.T) { | ||
lbc := &mocks.LbcMock{} | ||
expectedTxHash := test.AnyHash | ||
|
||
// Setup mock expectations | ||
lbc.On("RefundUserPegOut", testQuoteHash).Return(expectedTxHash, nil) | ||
|
||
txHash, err := ExecuteRefundUserPegOut(lbc, testQuoteHash) | ||
require.NoError(t, err) | ||
assert.Equal(t, expectedTxHash, txHash) | ||
|
||
// Verify all expectations were met | ||
lbc.AssertExpectations(t) | ||
}) | ||
} |
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
Oops, something went wrong.