Merge PR #3523: Add tx/encode endpoint and CLI command
This commit is contained in:
committed by
Jack Zampolin
parent
d759bef4d1
commit
9348750eb4
@@ -1,6 +1,7 @@
|
||||
package lcd
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"net/http"
|
||||
@@ -423,6 +424,46 @@ func TestCoinSendGenerateSignAndBroadcast(t *testing.T) {
|
||||
require.Equal(t, gasEstimate, resultTx.GasWanted)
|
||||
}
|
||||
|
||||
func TestEncodeTx(t *testing.T) {
|
||||
// Setup
|
||||
kb, err := keys.NewKeyBaseFromDir(InitClientHome(t, ""))
|
||||
require.NoError(t, err)
|
||||
addr, seed := CreateAddr(t, name1, pw, kb)
|
||||
cleanup, _, _, port := InitializeTestLCD(t, 1, []sdk.AccAddress{addr}, true)
|
||||
defer cleanup()
|
||||
|
||||
// Make a transaction to test with
|
||||
res, body, _ := doTransferWithGas(t, port, seed, name1, memo, "", addr, "2", 1, false, true, fees)
|
||||
var tx auth.StdTx
|
||||
cdc.UnmarshalJSON([]byte(body), &tx)
|
||||
|
||||
// Build the request
|
||||
encodeReq := struct {
|
||||
Tx auth.StdTx `json:"tx"`
|
||||
}{Tx: tx}
|
||||
encodedJSON, _ := cdc.MarshalJSON(encodeReq)
|
||||
res, body = Request(t, port, "POST", "/tx/encode", encodedJSON)
|
||||
|
||||
// Make sure it came back ok, and that we can decode it back to the transaction
|
||||
// 200 response
|
||||
require.Equal(t, http.StatusOK, res.StatusCode, body)
|
||||
encodeResp := struct {
|
||||
Tx string `json:"tx"`
|
||||
}{}
|
||||
|
||||
// No error decoding the JSON
|
||||
require.Nil(t, cdc.UnmarshalJSON([]byte(body), &encodeResp))
|
||||
|
||||
// Check that the base64 decodes
|
||||
decodedBytes, err := base64.StdEncoding.DecodeString(encodeResp.Tx)
|
||||
require.Nil(t, err)
|
||||
|
||||
// Check that the transaction decodes as expected
|
||||
var decodedTx auth.StdTx
|
||||
require.Nil(t, cdc.UnmarshalBinaryLengthPrefixed(decodedBytes, &decodedTx))
|
||||
require.Equal(t, memo, decodedTx.Memo)
|
||||
}
|
||||
|
||||
func TestTxs(t *testing.T) {
|
||||
kb, err := keys.NewKeyBaseFromDir(InitClientHome(t, ""))
|
||||
require.NoError(t, err)
|
||||
|
||||
Vendored
+33
@@ -334,6 +334,39 @@ paths:
|
||||
description: The Tx was malformated
|
||||
500:
|
||||
description: Server internal error
|
||||
/tx/encode:
|
||||
post:
|
||||
tags:
|
||||
- ICS20
|
||||
summary: Encode a transaction to wire format
|
||||
description: Encode a transaction (signed or not) from JSON to base64-encoded Amino serialized bytes
|
||||
consumes:
|
||||
- application/json
|
||||
produces:
|
||||
- application/json
|
||||
parameters:
|
||||
- in: body
|
||||
name: tx
|
||||
description: The transaction to encode
|
||||
required: true
|
||||
schema:
|
||||
type: object
|
||||
properties:
|
||||
tx:
|
||||
$ref: "#/definitions/StdTx"
|
||||
responses:
|
||||
200:
|
||||
description: Transaction was successfully decoded and re-encoded
|
||||
schema:
|
||||
type: object
|
||||
properties:
|
||||
tx:
|
||||
type: string
|
||||
example: The base64-encoded Amino-serialized bytes for the transaction
|
||||
400:
|
||||
description: The Tx was malformated
|
||||
500:
|
||||
description: Server internal error
|
||||
/bank/balances/{address}:
|
||||
get:
|
||||
summary: Get the account balances
|
||||
|
||||
Reference in New Issue
Block a user