From d113ea82fdd41b844bcef380b0288946ac3679be Mon Sep 17 00:00:00 2001 From: alfred-mk Date: Thu, 24 Oct 2024 20:21:28 +0300 Subject: [PATCH] Add dynamic send_amount and session_id --- menutraversal_test/menu_traversal_test.go | 22 +++++++++++++++++----- menutraversal_test/test_setup.json | 8 ++++---- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/menutraversal_test/menu_traversal_test.go b/menutraversal_test/menu_traversal_test.go index 2b2a093..900ebcc 100644 --- a/menutraversal_test/menu_traversal_test.go +++ b/menutraversal_test/menu_traversal_test.go @@ -56,11 +56,22 @@ func extractBalance(response []byte) string { // Extracts the Maximum amount value from the engine response. func extractMaxAmount(response []byte) string { - // Regex to match "Maximum amount: " followed by a newline - re := regexp.MustCompile(`(?m)^Maximum amount:\s+(\d+(\.\d+)?)\s+([A-Z]+)`) + // Regex to match "Maximum amount: " followed by a newline + re := regexp.MustCompile(`(?m)^Maximum amount:\s+(\d+(\.\d+)?)`) match := re.FindSubmatch(response) if match != nil { - return string(match[1]) + " " + string(match[3]) // " " + return string(match[1]) // "" + } + return "" +} + +// Extracts the send amount value from the engine response. +func extractSendAmount(response []byte) string { + // Regex to match the pattern "will receive X.XX SYM from" + re := regexp.MustCompile(`will receive (\d+\.\d{2}\s+[A-Z]+) from`) + match := re.FindSubmatch(response) + if match != nil { + return string(match[1]) // Returns "X.XX SYM" } return "" } @@ -304,12 +315,13 @@ func TestMainMenuSend(t *testing.T) { b := w.Bytes() balance := extractBalance(b) max_amount := extractMaxAmount(b) - publicKey := extractPublicKey(b) + send_amount := extractSendAmount(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) + expectedContent = bytes.Replace(expectedContent, []byte("{send_amount}"), []byte(send_amount), -1) + expectedContent = bytes.Replace(expectedContent, []byte("{session_id}"), []byte(sessionID), -1) step.ExpectedContent = string(expectedContent) match, err := step.MatchesExpectedContent(b) diff --git a/menutraversal_test/test_setup.json b/menutraversal_test/test_setup.json index 736d4de..13166a4 100644 --- a/menutraversal_test/test_setup.json +++ b/menutraversal_test/test_setup.json @@ -84,8 +84,8 @@ "expectedContent": "{max_amount}\nEnter amount:\n0:Back" }, { - "input": "0.001", - "expectedContent": "065656 will receive 0.001 from {public_key}\nPlease enter your PIN to confirm:\n0:Back\n9:Quit" + "input": "1.00", + "expectedContent": "065656 will receive {send_amount} from {session_id}\nPlease enter your PIN to confirm:\n0:Back\n9:Quit" }, { "input": "1222", @@ -93,11 +93,11 @@ }, { "input": "1", - "expectedContent": "065656 will receive 0.001 from {public_key}\nPlease enter your PIN to confirm:\n0:Back\n9:Quit" + "expectedContent": "065656 will receive {send_amount} from {session_id}\nPlease enter your PIN to confirm:\n0:Back\n9:Quit" }, { "input": "1234", - "expectedContent": "Your request has been sent. 065656 will receive 0.001 from {public_key}." + "expectedContent": "Your request has been sent. 065656 will receive {send_amount} from {session_id}." } ] },