added send menu test with dynamic max_amount
This commit is contained in:
parent
02cb75f97a
commit
0547bc7e5f
@ -54,6 +54,17 @@ func extractBalance(response []byte) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
// Extracts the Maximum amount value from the engine response.
|
||||
func extractMaxAmount(response []byte) string {
|
||||
// Regex to match "Maximum amount: <amount> <symbol>" followed by a newline
|
||||
re := regexp.MustCompile(`(?m)^Maximum amount:\s+(\d+(\.\d+)?)\s+([A-Z]+)`)
|
||||
match := re.FindSubmatch(response)
|
||||
if match != nil && len(match) > 0 {
|
||||
return string(match[1]) + " " + string(match[3]) // "<amount> <symbol>"
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
sessionID = GenerateSessionId()
|
||||
defer func() {
|
||||
@ -268,6 +279,52 @@ func TestMyAccount_MyAddress(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestMainMenuSend(t *testing.T) {
|
||||
en, fn, _ := testutil.TestEngine(sessionID)
|
||||
defer fn()
|
||||
ctx := context.Background()
|
||||
sessions := testData
|
||||
for _, session := range sessions {
|
||||
groups := driver.FilterGroupsByName(session.Groups, "send_with_invalid_inputs")
|
||||
for _, group := range groups {
|
||||
for _, step := range group.Steps {
|
||||
cont, err := en.Exec(ctx, []byte(step.Input))
|
||||
if err != nil {
|
||||
t.Fatalf("Test case '%s' failed at input '%s': %v", group.Name, step.Input, err)
|
||||
return
|
||||
}
|
||||
if !cont {
|
||||
break
|
||||
}
|
||||
w := bytes.NewBuffer(nil)
|
||||
if _, err := en.Flush(ctx, w); err != nil {
|
||||
t.Fatalf("Test case '%s' failed during Flush: %v", group.Name, err)
|
||||
}
|
||||
|
||||
b := w.Bytes()
|
||||
balance := extractBalance(b)
|
||||
max_amount := extractMaxAmount(b)
|
||||
publicKey := extractPublicKey(b)
|
||||
|
||||
expectedContent := []byte(step.ExpectedContent)
|
||||
expectedContent = bytes.Replace(expectedContent, []byte("{balance}"), []byte(balance), -1)
|
||||
expectedContent = bytes.Replace(expectedContent, []byte("{max_amount}"), []byte(max_amount), -1)
|
||||
expectedContent = bytes.Replace(expectedContent, []byte("{public_key}"), []byte(publicKey), -1)
|
||||
|
||||
step.ExpectedContent = string(expectedContent)
|
||||
match, err := step.MatchesExpectedContent(b)
|
||||
if err != nil {
|
||||
t.Fatalf("Error compiling regex for step '%s': %v", step.Input, err)
|
||||
}
|
||||
if !match {
|
||||
t.Fatalf("expected:\n\t%s\ngot:\n\t%s\n", step.ExpectedContent, b)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func TestGroups(t *testing.T) {
|
||||
groups, err := driver.LoadTestGroups(groupTestFile)
|
||||
if err != nil {
|
||||
|
@ -73,15 +73,15 @@
|
||||
},
|
||||
{
|
||||
"input": "065656",
|
||||
"expectedContent": "Maximum amount: 0.003 CELO\nEnter amount:\n0:Back"
|
||||
"expectedContent": "{max_amount}\nEnter amount:\n0:Back"
|
||||
},
|
||||
{
|
||||
"input": "0.1",
|
||||
"expectedContent": "Amount 0.1 is invalid, please try again:\n1:retry\n9:Quit"
|
||||
"input": "10000000",
|
||||
"expectedContent": "Amount 10000000 is invalid, please try again:\n1:retry\n9:Quit"
|
||||
},
|
||||
{
|
||||
"input": "1",
|
||||
"expectedContent": "Maximum amount: 0.003 CELO\nEnter amount:\n0:Back"
|
||||
"expectedContent": "{max_amount}\nEnter amount:\n0:Back"
|
||||
},
|
||||
{
|
||||
"input": "0.001",
|
||||
|
Loading…
Reference in New Issue
Block a user