From 033daeb7fb8e38e0f8bd2d80fa5238dd20176894 Mon Sep 17 00:00:00 2001 From: Leigh McCulloch <351529+leighmcculloch@users.noreply.github.com> Date: Wed, 24 Jul 2024 13:36:43 +1000 Subject: [PATCH] fix error gen --- services/friendbot/internal/friendbot_test.go | 23 ++----------------- services/friendbot/internal/minion.go | 6 +++-- services/friendbot/main.go | 5 +++- 3 files changed, 10 insertions(+), 24 deletions(-) diff --git a/services/friendbot/internal/friendbot_test.go b/services/friendbot/internal/friendbot_test.go index 73d1908baf..6313dd52dc 100644 --- a/services/friendbot/internal/friendbot_test.go +++ b/services/friendbot/internal/friendbot_test.go @@ -190,25 +190,6 @@ func TestFriendbot_Pay_accountExistsAlreadyFunded(t *testing.T) { fb := &Bot{Minions: []Minion{minion}} recipientAddress := "GDJIN6W6PLTPKLLM57UW65ZH4BITUXUMYQHIMAZFYXF45PZVAWDBI77Z" - txSuccess, err := fb.Pay(recipientAddress) - if !assert.NoError(t, err) { - return - } - expectedTxn := "AAAAAgAAAAD4Az3jKU6lbzq/L5HG9/GzBT+FYusOz71oyYMbZkP+GAAAAGQAAAAAAAAAAgAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAABAAAAAPXQ8gjyrVHa47a6JDPkVHwPPDKxNRE2QBcamA4JvlOGAAAAAQAAAADShvreeub1LWzv6W93J+BROl6MxA6GAyXFy86/NQWGFAAAAAAAAAAXSHboAAAAAAAAAAACZkP+GAAAAEBAwm/hWuu/ZHHQWRD9oF/cnSwQyTZpHQoTlPlVSFH4g12HR2nbzOI9wC5Z5bt0ueXny4UNFS5QhUvnzdb2FMsDCb5ThgAAAED1HzWPW6lKBxBi6MTSwM/POytPSfL87taiarpTIk5naoqXPLpM0YBBaf5uH8de5Id1KSCP/g8tdeCxvrT053kJ" - assert.Equal(t, expectedTxn, txSuccess.EnvelopeXdr) - - // Don't assert on tx values below, since the completion order is unknown. - var wg sync.WaitGroup - wg.Add(2) - go func() { - _, err := fb.Pay(recipientAddress) - assert.NoError(t, err) - wg.Done() - }() - go func() { - _, err := fb.Pay(recipientAddress) - assert.NoError(t, err) - wg.Done() - }() - wg.Wait() + _, err = fb.Pay(recipientAddress) + assert.ErrorIs(t, err, ErrAccountFunded) } diff --git a/services/friendbot/internal/minion.go b/services/friendbot/internal/minion.go index 5dd455036d..a1da2a0e72 100644 --- a/services/friendbot/internal/minion.go +++ b/services/friendbot/internal/minion.go @@ -15,6 +15,8 @@ const createAccountAlreadyExistXDR = "AAAAAAAAAGT/////AAAAAQAAAAAAAAAA/////AAAAA var ErrAccountExists error = errors.New(fmt.Sprintf("createAccountAlreadyExist (%s)", createAccountAlreadyExistXDR)) +var ErrAccountFunded error = errors.New("account already funded to starting balance") + // Minion contains a Stellar channel account and Go channels to communicate with friendbot. type Minion struct { Account Account @@ -164,8 +166,8 @@ func (minion *Minion) checkBalance(balance string) error { if err != nil { return errors.Wrap(err, "cannot parse starting balance") } - if bal > starting { - return errors.New("account already funded up to the starting balance") + if bal >= starting { + return ErrAccountFunded } return nil } diff --git a/services/friendbot/main.go b/services/friendbot/main.go index 22e7d4c44d..c5933c2fc3 100644 --- a/services/friendbot/main.go +++ b/services/friendbot/main.go @@ -34,7 +34,6 @@ type Config struct { } func main() { - rootCmd := &cobra.Command{ Use: "friendbot", Short: "friendbot for the Stellar Test Network", @@ -114,4 +113,8 @@ func registerProblems() { accountExistsProblem := problem.BadRequest accountExistsProblem.Detail = internal.ErrAccountExists.Error() problem.RegisterError(internal.ErrAccountExists, accountExistsProblem) + + accountFundedProblem := problem.BadRequest + accountFundedProblem.Detail = internal.ErrAccountFunded.Error() + problem.RegisterError(internal.ErrAccountFunded, accountFundedProblem) }