From c3f6d77f373370fea521edabe60c532c676cd9a6 Mon Sep 17 00:00:00 2001 From: Alessio Treglia Date: Thu, 7 Nov 2019 06:26:08 +0000 Subject: [PATCH] Avoid create temporary keybase --- lcd_test/helpers_test.go | 21 ++++++--------------- lcd_test/lcd_test.go | 22 +++++++++++----------- 2 files changed, 17 insertions(+), 26 deletions(-) diff --git a/lcd_test/helpers_test.go b/lcd_test/helpers_test.go index 6e1afd7d481..604afaf66d2 100644 --- a/lcd_test/helpers_test.go +++ b/lcd_test/helpers_test.go @@ -291,14 +291,14 @@ func doTransfer( kb crkeys.Keybase, ) (sdk.AccAddress, sdk.TxResponse) { - resp, body, recvAddr := doTransferWithGas(t, port, seed, name, memo, addr, "", 1.0, false, true, fees, kb) + resp, body := doTransferWithGas(t, port, seed, name, memo, addr, "", 1.0, false, true, fees, kb) require.Equal(t, http.StatusOK, resp.StatusCode, body) var txResp sdk.TxResponse err := cdc.UnmarshalJSON([]byte(body), &txResp) require.NoError(t, err) - return recvAddr, txResp + return addr, txResp } // doTransferWithGas performs a balance transfer with a specified gas value. The @@ -309,17 +309,8 @@ func doTransferWithGas( t *testing.T, port, seed, name, memo string, addr sdk.AccAddress, gas string, gasAdjustment float64, simulate, broadcast bool, fees sdk.Coins, kb crkeys.Keybase, -) (resp *http.Response, body string, receiveAddr sdk.AccAddress) { - - // create receive address - kb2 := crkeys.NewInMemory() - - receiveInfo, _, err := kb2.CreateMnemonic( - "receive_address", crkeys.English, client.DefaultKeyPass, crkeys.SigningAlgo("secp256k1"), - ) - require.Nil(t, err) +) (resp *http.Response, body string) { - receiveAddr = sdk.AccAddress(receiveInfo.GetPubKey().Address()) acc := getAccount(t, port, addr) accnum := acc.GetAccountNumber() sequence := acc.GetSequence() @@ -339,14 +330,14 @@ func doTransferWithGas( require.NoError(t, err) // generate tx - resp, body = Request(t, port, "POST", fmt.Sprintf("/bank/accounts/%s/transfers", receiveAddr), req) + resp, body = Request(t, port, "POST", fmt.Sprintf("/bank/accounts/%s/transfers", addr), req) if !broadcast { - return resp, body, receiveAddr + return resp, body } // sign and broadcast resp, body = signAndBroadcastGenTx(t, port, name, body, acc, gasAdjustment, simulate, kb) - return resp, body, receiveAddr + return resp, body } // doTransferWithGasAccAuto is similar to doTransferWithGas except that it diff --git a/lcd_test/lcd_test.go b/lcd_test/lcd_test.go index 8a3a4dbaf7b..edbbd683e4b 100644 --- a/lcd_test/lcd_test.go +++ b/lcd_test/lcd_test.go @@ -119,28 +119,28 @@ func TestCoinSend(t *testing.T) { require.Equal(t, int64(1), coins2[0].Amount.Int64()) // test failure with too little gas - res, body, _ = doTransferWithGas(t, port, seed, name1, memo, addr, "100", 0, false, true, fees, kb) + res, body = doTransferWithGas(t, port, seed, name1, memo, addr, "100", 0, false, true, fees, kb) require.Equal(t, http.StatusOK, res.StatusCode, body) require.Nil(t, err) // test failure with negative gas - res, body, _ = doTransferWithGas(t, port, seed, name1, memo, addr, "-200", 0, false, false, fees, kb) + res, body = doTransferWithGas(t, port, seed, name1, memo, addr, "-200", 0, false, false, fees, kb) require.Equal(t, http.StatusBadRequest, res.StatusCode, body) // test failure with negative adjustment - res, body, _ = doTransferWithGas(t, port, seed, name1, memo, addr, "10000", -0.1, true, false, fees, kb) + res, body = doTransferWithGas(t, port, seed, name1, memo, addr, "10000", -0.1, true, false, fees, kb) require.Equal(t, http.StatusBadRequest, res.StatusCode, body) // test failure with 0 gas - res, body, _ = doTransferWithGas(t, port, seed, name1, memo, addr, "0", 0, false, true, fees, kb) + res, body = doTransferWithGas(t, port, seed, name1, memo, addr, "0", 0, false, true, fees, kb) require.Equal(t, http.StatusOK, res.StatusCode, body) // test failure with wrong adjustment - res, body, _ = doTransferWithGas(t, port, seed, name1, memo, addr, client.GasFlagAuto, 0.1, false, true, fees, kb) + res, body = doTransferWithGas(t, port, seed, name1, memo, addr, client.GasFlagAuto, 0.1, false, true, fees, kb) require.Equal(t, http.StatusOK, res.StatusCode, body) // run simulation and test success with estimated gas - res, body, _ = doTransferWithGas(t, port, seed, name1, memo, addr, "10000", 1.0, true, false, fees, kb) + res, body = doTransferWithGas(t, port, seed, name1, memo, addr, "10000", 1.0, true, false, fees, kb) require.Equal(t, http.StatusOK, res.StatusCode, body) var gasEstResp rest.GasEstimateResponse @@ -152,7 +152,7 @@ func TestCoinSend(t *testing.T) { // run successful tx gas := fmt.Sprintf("%d", gasEstResp.GasEstimate) - res, body, _ = doTransferWithGas(t, port, seed, name1, memo, addr, gas, 1.0, false, true, fees, kb) + res, body = doTransferWithGas(t, port, seed, name1, memo, addr, gas, 1.0, false, true, fees, kb) require.Equal(t, http.StatusOK, res.StatusCode, body) err = cdc.UnmarshalJSON([]byte(body), &resultTx) @@ -203,7 +203,7 @@ func TestCoinMultiSendGenerateOnly(t *testing.T) { defer cleanup() // generate only - res, body, _ := doTransferWithGas(t, port, seed, "", memo, addr, "200000", 1, false, false, fees, kb) + res, body := doTransferWithGas(t, port, seed, "", memo, addr, "200000", 1, false, false, fees, kb) require.Equal(t, http.StatusOK, res.StatusCode, body) var stdTx auth.StdTx @@ -229,7 +229,7 @@ func TestCoinSendGenerateSignAndBroadcast(t *testing.T) { acc := getAccount(t, port, addr) // simulate tx - res, body, _ := doTransferWithGas(t, port, seed, name1, memo, addr, client.GasFlagAuto, 1.0, true, false, fees, kb) + res, body := doTransferWithGas(t, port, seed, name1, memo, addr, client.GasFlagAuto, 1.0, true, false, fees, kb) require.Equal(t, http.StatusOK, res.StatusCode, body) var gasEstResp rest.GasEstimateResponse @@ -238,7 +238,7 @@ func TestCoinSendGenerateSignAndBroadcast(t *testing.T) { // generate tx gas := fmt.Sprintf("%d", gasEstResp.GasEstimate) - res, body, _ = doTransferWithGas(t, port, seed, name1, memo, addr, gas, 1, false, false, fees, kb) + res, body = doTransferWithGas(t, port, seed, name1, memo, addr, gas, 1, false, false, fees, kb) require.Equal(t, http.StatusOK, res.StatusCode, body) var tx auth.StdTx @@ -269,7 +269,7 @@ func TestEncodeTx(t *testing.T) { require.NoError(t, err) defer cleanup() - res, body, _ := doTransferWithGas(t, port, seed, name1, memo, addr, "2", 1, false, false, fees, kb) + res, body := doTransferWithGas(t, port, seed, name1, memo, addr, "2", 1, false, false, fees, kb) var tx auth.StdTx require.Nil(t, cdc.UnmarshalJSON([]byte(body), &tx))