diff --git a/rpc/http_handlers.go b/rpc/http_handlers.go index e72e0430..6cb499b1 100644 --- a/rpc/http_handlers.go +++ b/rpc/http_handlers.go @@ -181,7 +181,8 @@ func returnsToResponse(funcInfo *FuncWrapper, returns []reflect.Value) (interfac } } - v := funcInfo.response.Elem() + // copy the response struct (New returns a pointer so we have to Elem() twice) + v := reflect.New(funcInfo.response.Elem().Type()).Elem() nFields := v.NumField() for i := 0; i < nFields; i++ { field := v.FieldByIndex([]int{i}) diff --git a/rpc/test/http_rpc_test.go b/rpc/test/http_rpc_test.go index 31e37b48..a6a5fb2f 100644 --- a/rpc/test/http_rpc_test.go +++ b/rpc/test/http_rpc_test.go @@ -134,10 +134,11 @@ func TestHTTPBroadcastTx(t *testing.T) { } pool := node.MempoolReactor().Mempool txs := pool.GetProposalTxs() - if len(txs) != 1 { - t.Fatal("The mem pool has %d txs. Expected 1", len(txs)) + if len(txs) != mempoolCount+1 { + t.Fatalf("The mem pool has %d txs. Expected %d", len(txs), mempoolCount+1) } - tx2 := txs[0].(*types.SendTx) + tx2 := txs[mempoolCount].(*types.SendTx) + mempoolCount += 1 if bytes.Compare(merkle.HashFromBinary(tx), merkle.HashFromBinary(tx2)) != 0 { t.Fatal("inconsistent hashes for mempool tx and sent tx") } diff --git a/rpc/test/json_rpc_test.go b/rpc/test/json_rpc_test.go index c8cafa30..d40f579f 100644 --- a/rpc/test/json_rpc_test.go +++ b/rpc/test/json_rpc_test.go @@ -155,10 +155,11 @@ func TestJSONBroadcastTx(t *testing.T) { } pool := node.MempoolReactor().Mempool txs := pool.GetProposalTxs() - if len(txs) != 1 { - t.Fatal("The mem pool has %d txs. Expected 1", len(txs)) + if len(txs) != mempoolCount+1 { + t.Fatalf("The mem pool has %d txs. Expected %d", len(txs), mempoolCount+1) } - tx2 := txs[0].(*types.SendTx) + tx2 := txs[mempoolCount].(*types.SendTx) + mempoolCount += 1 if bytes.Compare(merkle.HashFromBinary(tx), merkle.HashFromBinary(tx2)) != 0 { t.Fatal("inconsistent hashes for mempool tx and sent tx") } diff --git a/rpc/test/test.go b/rpc/test/test.go index 50a3ba0d..3057a8bf 100644 --- a/rpc/test/test.go +++ b/rpc/test/test.go @@ -22,10 +22,15 @@ import ( var ( rpcAddr = "127.0.0.1:8089" requestAddr = "http://" + rpcAddr + "/" - chainId string - node *daemon.Node - userAddr = "D7DFF9806078899C8DA3FE3633CC0BF3C6C2B1BB" - userPriv = "FDE3BD94CB327D19464027BA668194C5EFA46AE83E8419D7542CFF41F00C81972239C21C81EA7173A6C489145490C015E05D4B97448933B708A7EC5B7B4921E3" + + chainId string + + node *daemon.Node + + mempoolCount = 0 + + userAddr = "D7DFF9806078899C8DA3FE3633CC0BF3C6C2B1BB" + userPriv = "FDE3BD94CB327D19464027BA668194C5EFA46AE83E8419D7542CFF41F00C81972239C21C81EA7173A6C489145490C015E05D4B97448933B708A7EC5B7B4921E3" userPub = "2239C21C81EA7173A6C489145490C015E05D4B97448933B708A7EC5B7B4921E3" )