Skip to content

Commit

Permalink
Avoid create temporary keybase
Browse files Browse the repository at this point in the history
  • Loading branch information
Alessio Treglia committed Nov 7, 2019
1 parent 0b35127 commit c3f6d77
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 26 deletions.
21 changes: 6 additions & 15 deletions lcd_test/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand All @@ -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
Expand Down
22 changes: 11 additions & 11 deletions lcd_test/lcd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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))

Expand Down

0 comments on commit c3f6d77

Please sign in to comment.