rpc: fix tests to count mempool; copy responses to avoid data races
This commit is contained in:
parent
fb90d5bc92
commit
d30fc2fa43
|
@ -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})
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue