From d3466078b741a99201cf0161e48fa18705799363 Mon Sep 17 00:00:00 2001 From: Nathan Seva Date: Thu, 9 Nov 2023 09:43:44 -0500 Subject: [PATCH] fix transfer and roll edit fees, fix roll side (#838) --- internal/handler/wallet/rolls.go | 4 ++-- internal/handler/wallet/transfer.go | 4 ++-- internal/handler/wallet/transfer_test.go | 11 +++++++++++ 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/internal/handler/wallet/rolls.go b/internal/handler/wallet/rolls.go index 8d3725401..02da418f7 100644 --- a/internal/handler/wallet/rolls.go +++ b/internal/handler/wallet/rolls.go @@ -88,7 +88,7 @@ func (t *tradeRolls) Handle(params operations.TradeRollsParams) middleware.Respo password := output.Password - operation, err := doTradeRolls(acc, password, amount, fee, opType, t.massaClient) + operation, err := doTradeRolls(acc, password, amount, output.Fees, opType, t.massaClient) if err != nil { msg := fmt.Sprintf("error %sing rolls coin: %v", *params.Body.Side, err.Error()) @@ -115,7 +115,7 @@ func doTradeRolls( massaClient network.NodeFetcherInterface, ) (*sendOperation.OperationResponse, error) { var operation sendOperation.Operation - if opType == sellrolls.OpType { + if opType == buyrolls.OpType { operation = buyrolls.New(amount) } else { operation = sellrolls.New(amount) diff --git a/internal/handler/wallet/transfer.go b/internal/handler/wallet/transfer.go index 3ad4411d2..3f2ef7940 100644 --- a/internal/handler/wallet/transfer.go +++ b/internal/handler/wallet/transfer.go @@ -64,7 +64,7 @@ func (t *transferCoin) Handle(params operations.TransferCoinParams) middleware.R promptRequest := prompt.PromptRequest{ Action: walletapp.Sign, Data: PromptRequestSignData{ - Fees: string(params.Body.Fee), + Fees: strconv.FormatUint(fee, 10), WalletAddress: address, Nickname: acc.Nickname, OperationType: int(transaction.OpType), @@ -87,7 +87,7 @@ func (t *transferCoin) Handle(params operations.TransferCoinParams) middleware.R password := output.Password // create the transaction and send it to the network - operation, err := doTransfer(acc, password, amount, fee, *params.Body.RecipientAddress, t.massaClient) + operation, err := doTransfer(acc, password, amount, output.Fees, *params.Body.RecipientAddress, t.massaClient) if err != nil { msg := fmt.Sprintf("error transferring coin: %v", err.Error()) diff --git a/internal/handler/wallet/transfer_test.go b/internal/handler/wallet/transfer_test.go index ac11500d3..6f3877840 100644 --- a/internal/handler/wallet/transfer_test.go +++ b/internal/handler/wallet/transfer_test.go @@ -36,6 +36,17 @@ func Test_transfer_handler(t *testing.T) { assert.Equal(t, http.StatusNotFound, resp.Result().StatusCode) }) + t.Run("Transfer with invalid fee", func(t *testing.T) { + resp, err := handleHTTPRequest(handler, "POST", fmt.Sprintf("/api/accounts/%s/transfer", nickname), `{ + "fee": "none", + "amount": "5", + "recipientAddress": "AU1eQkRhZZBa5VNc24fCejxgFDpe1FHChpwiUksQB9StNb3rWm6i" + }`) + + assert.NoError(t, err) + assert.Equal(t, http.StatusBadRequest, resp.Result().StatusCode) + }) + t.Run("Transfer with invalid amount", func(t *testing.T) { resp, err := handleHTTPRequest(handler, "POST", fmt.Sprintf("/api/accounts/%s/transfer", nickname), `{ "fee": "1",