Skip to content

Commit

Permalink
fix error gen
Browse files Browse the repository at this point in the history
  • Loading branch information
leighmcculloch committed Jul 24, 2024
1 parent 0f2798a commit 033daeb
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 24 deletions.
23 changes: 2 additions & 21 deletions services/friendbot/internal/friendbot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
6 changes: 4 additions & 2 deletions services/friendbot/internal/minion.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
5 changes: 4 additions & 1 deletion services/friendbot/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ type Config struct {
}

func main() {

rootCmd := &cobra.Command{
Use: "friendbot",
Short: "friendbot for the Stellar Test Network",
Expand Down Expand Up @@ -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)
}

0 comments on commit 033daeb

Please sign in to comment.