mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-26 19:21:44 +00:00
rpc: fix tests to count mempool; copy responses to avoid data races
This commit is contained in:
@ -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()
|
nFields := v.NumField()
|
||||||
for i := 0; i < nFields; i++ {
|
for i := 0; i < nFields; i++ {
|
||||||
field := v.FieldByIndex([]int{i})
|
field := v.FieldByIndex([]int{i})
|
||||||
|
@ -134,10 +134,11 @@ func TestHTTPBroadcastTx(t *testing.T) {
|
|||||||
}
|
}
|
||||||
pool := node.MempoolReactor().Mempool
|
pool := node.MempoolReactor().Mempool
|
||||||
txs := pool.GetProposalTxs()
|
txs := pool.GetProposalTxs()
|
||||||
if len(txs) != 1 {
|
if len(txs) != mempoolCount+1 {
|
||||||
t.Fatal("The mem pool has %d txs. Expected 1", len(txs))
|
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 {
|
if bytes.Compare(merkle.HashFromBinary(tx), merkle.HashFromBinary(tx2)) != 0 {
|
||||||
t.Fatal("inconsistent hashes for mempool tx and sent tx")
|
t.Fatal("inconsistent hashes for mempool tx and sent tx")
|
||||||
}
|
}
|
||||||
|
@ -155,10 +155,11 @@ func TestJSONBroadcastTx(t *testing.T) {
|
|||||||
}
|
}
|
||||||
pool := node.MempoolReactor().Mempool
|
pool := node.MempoolReactor().Mempool
|
||||||
txs := pool.GetProposalTxs()
|
txs := pool.GetProposalTxs()
|
||||||
if len(txs) != 1 {
|
if len(txs) != mempoolCount+1 {
|
||||||
t.Fatal("The mem pool has %d txs. Expected 1", len(txs))
|
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 {
|
if bytes.Compare(merkle.HashFromBinary(tx), merkle.HashFromBinary(tx2)) != 0 {
|
||||||
t.Fatal("inconsistent hashes for mempool tx and sent tx")
|
t.Fatal("inconsistent hashes for mempool tx and sent tx")
|
||||||
}
|
}
|
||||||
|
@ -22,8 +22,13 @@ import (
|
|||||||
var (
|
var (
|
||||||
rpcAddr = "127.0.0.1:8089"
|
rpcAddr = "127.0.0.1:8089"
|
||||||
requestAddr = "http://" + rpcAddr + "/"
|
requestAddr = "http://" + rpcAddr + "/"
|
||||||
|
|
||||||
chainId string
|
chainId string
|
||||||
|
|
||||||
node *daemon.Node
|
node *daemon.Node
|
||||||
|
|
||||||
|
mempoolCount = 0
|
||||||
|
|
||||||
userAddr = "D7DFF9806078899C8DA3FE3633CC0BF3C6C2B1BB"
|
userAddr = "D7DFF9806078899C8DA3FE3633CC0BF3C6C2B1BB"
|
||||||
userPriv = "FDE3BD94CB327D19464027BA668194C5EFA46AE83E8419D7542CFF41F00C81972239C21C81EA7173A6C489145490C015E05D4B97448933B708A7EC5B7B4921E3"
|
userPriv = "FDE3BD94CB327D19464027BA668194C5EFA46AE83E8419D7542CFF41F00C81972239C21C81EA7173A6C489145490C015E05D4B97448933B708A7EC5B7B4921E3"
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user