|
@ -9,6 +9,8 @@ import ( |
|
|
"github.com/tendermint/tendermint/types" |
|
|
"github.com/tendermint/tendermint/types" |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
var wsTyp = "JSONRPC" |
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------
|
|
|
//--------------------------------------------------------------------------------
|
|
|
// Test the websocket service
|
|
|
// Test the websocket service
|
|
|
|
|
|
|
|
@ -52,7 +54,7 @@ func TestWSSend(t *testing.T) { |
|
|
amt := uint64(100) |
|
|
amt := uint64(100) |
|
|
|
|
|
|
|
|
con := newWSCon(t) |
|
|
con := newWSCon(t) |
|
|
eidInput := types.EventStringAccInput(userByteAddr) |
|
|
|
|
|
|
|
|
eidInput := types.EventStringAccInput(user[0].Address) |
|
|
eidOutput := types.EventStringAccOutput(toAddr) |
|
|
eidOutput := types.EventStringAccOutput(toAddr) |
|
|
subscribe(t, con, eidInput) |
|
|
subscribe(t, con, eidInput) |
|
|
subscribe(t, con, eidOutput) |
|
|
subscribe(t, con, eidOutput) |
|
@ -62,7 +64,8 @@ func TestWSSend(t *testing.T) { |
|
|
con.Close() |
|
|
con.Close() |
|
|
}() |
|
|
}() |
|
|
waitForEvent(t, con, eidInput, true, func() { |
|
|
waitForEvent(t, con, eidInput, true, func() { |
|
|
broadcastTx(t, "JSONRPC", userByteAddr, toAddr, nil, userBytePriv, amt, 0, 0) |
|
|
|
|
|
|
|
|
tx := makeDefaultSendTxSigned(t, wsTyp, toAddr, amt) |
|
|
|
|
|
broadcastTx(t, wsTyp, tx) |
|
|
}, unmarshalValidateSend(amt, toAddr)) |
|
|
}, unmarshalValidateSend(amt, toAddr)) |
|
|
waitForEvent(t, con, eidOutput, true, func() {}, unmarshalValidateSend(amt, toAddr)) |
|
|
waitForEvent(t, con, eidOutput, true, func() {}, unmarshalValidateSend(amt, toAddr)) |
|
|
} |
|
|
} |
|
@ -70,7 +73,7 @@ func TestWSSend(t *testing.T) { |
|
|
// ensure events are only fired once for a given transaction
|
|
|
// ensure events are only fired once for a given transaction
|
|
|
func TestWSDoubleFire(t *testing.T) { |
|
|
func TestWSDoubleFire(t *testing.T) { |
|
|
con := newWSCon(t) |
|
|
con := newWSCon(t) |
|
|
eid := types.EventStringAccInput(userByteAddr) |
|
|
|
|
|
|
|
|
eid := types.EventStringAccInput(user[0].Address) |
|
|
subscribe(t, con, eid) |
|
|
subscribe(t, con, eid) |
|
|
defer func() { |
|
|
defer func() { |
|
|
unsubscribe(t, con, eid) |
|
|
unsubscribe(t, con, eid) |
|
@ -80,7 +83,8 @@ func TestWSDoubleFire(t *testing.T) { |
|
|
toAddr := []byte{20, 143, 25, 63, 16, 177, 83, 29, 91, 91, 54, 23, 233, 46, 190, 121, 122, 34, 86, 54} |
|
|
toAddr := []byte{20, 143, 25, 63, 16, 177, 83, 29, 91, 91, 54, 23, 233, 46, 190, 121, 122, 34, 86, 54} |
|
|
// broadcast the transaction, wait to hear about it
|
|
|
// broadcast the transaction, wait to hear about it
|
|
|
waitForEvent(t, con, eid, true, func() { |
|
|
waitForEvent(t, con, eid, true, func() { |
|
|
broadcastTx(t, "JSONRPC", userByteAddr, toAddr, nil, userBytePriv, amt, 0, 0) |
|
|
|
|
|
|
|
|
tx := makeDefaultSendTxSigned(t, wsTyp, toAddr, amt) |
|
|
|
|
|
broadcastTx(t, wsTyp, tx) |
|
|
}, func(eid string, b []byte) error { |
|
|
}, func(eid string, b []byte) error { |
|
|
return nil |
|
|
return nil |
|
|
}) |
|
|
}) |
|
@ -94,18 +98,19 @@ func TestWSDoubleFire(t *testing.T) { |
|
|
// create a contract, wait for the event, and send it a msg, validate the return
|
|
|
// create a contract, wait for the event, and send it a msg, validate the return
|
|
|
func TestWSCallWait(t *testing.T) { |
|
|
func TestWSCallWait(t *testing.T) { |
|
|
con := newWSCon(t) |
|
|
con := newWSCon(t) |
|
|
eid1 := types.EventStringAccInput(userByteAddr) |
|
|
|
|
|
|
|
|
eid1 := types.EventStringAccInput(user[0].Address) |
|
|
subscribe(t, con, eid1) |
|
|
subscribe(t, con, eid1) |
|
|
defer func() { |
|
|
defer func() { |
|
|
unsubscribe(t, con, eid1) |
|
|
unsubscribe(t, con, eid1) |
|
|
con.Close() |
|
|
con.Close() |
|
|
}() |
|
|
}() |
|
|
amt := uint64(10000) |
|
|
|
|
|
|
|
|
amt, gasLim, fee := uint64(10000), uint64(1000), uint64(1000) |
|
|
code, returnCode, returnVal := simpleContract() |
|
|
code, returnCode, returnVal := simpleContract() |
|
|
var contractAddr []byte |
|
|
var contractAddr []byte |
|
|
// wait for the contract to be created
|
|
|
// wait for the contract to be created
|
|
|
waitForEvent(t, con, eid1, true, func() { |
|
|
waitForEvent(t, con, eid1, true, func() { |
|
|
_, receipt := broadcastTx(t, "JSONRPC", userByteAddr, nil, code, userBytePriv, amt, 1000, 1000) |
|
|
|
|
|
|
|
|
tx := makeDefaultCallTx(t, wsTyp, nil, code, amt, gasLim, fee) |
|
|
|
|
|
receipt := broadcastTx(t, wsTyp, tx) |
|
|
contractAddr = receipt.ContractAddr |
|
|
contractAddr = receipt.ContractAddr |
|
|
}, unmarshalValidateCall(amt, returnCode)) |
|
|
}, unmarshalValidateCall(amt, returnCode)) |
|
|
|
|
|
|
|
@ -117,9 +122,11 @@ func TestWSCallWait(t *testing.T) { |
|
|
unsubscribe(t, con, eid2) |
|
|
unsubscribe(t, con, eid2) |
|
|
}() |
|
|
}() |
|
|
// get the return value from a call
|
|
|
// get the return value from a call
|
|
|
data := []byte{0x1} // just needs to be non empty for this to be a CallTx
|
|
|
|
|
|
|
|
|
data := []byte{0x1} |
|
|
waitForEvent(t, con, eid2, true, func() { |
|
|
waitForEvent(t, con, eid2, true, func() { |
|
|
broadcastTx(t, "JSONRPC", userByteAddr, contractAddr, data, userBytePriv, amt, 1000, 1000) |
|
|
|
|
|
|
|
|
tx := makeDefaultCallTx(t, wsTyp, contractAddr, data, amt, gasLim, fee) |
|
|
|
|
|
receipt := broadcastTx(t, wsTyp, tx) |
|
|
|
|
|
contractAddr = receipt.ContractAddr |
|
|
}, unmarshalValidateCall(amt, returnVal)) |
|
|
}, unmarshalValidateCall(amt, returnVal)) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -127,10 +134,11 @@ func TestWSCallWait(t *testing.T) { |
|
|
// and validate return
|
|
|
// and validate return
|
|
|
func TestWSCallNoWait(t *testing.T) { |
|
|
func TestWSCallNoWait(t *testing.T) { |
|
|
con := newWSCon(t) |
|
|
con := newWSCon(t) |
|
|
amt := uint64(10000) |
|
|
|
|
|
|
|
|
amt, gasLim, fee := uint64(10000), uint64(1000), uint64(1000) |
|
|
code, _, returnVal := simpleContract() |
|
|
code, _, returnVal := simpleContract() |
|
|
|
|
|
|
|
|
_, receipt := broadcastTx(t, "JSONRPC", userByteAddr, nil, code, userBytePriv, amt, 1000, 1000) |
|
|
|
|
|
|
|
|
tx := makeDefaultCallTx(t, wsTyp, nil, code, amt, gasLim, fee) |
|
|
|
|
|
receipt := broadcastTx(t, wsTyp, tx) |
|
|
contractAddr := receipt.ContractAddr |
|
|
contractAddr := receipt.ContractAddr |
|
|
|
|
|
|
|
|
// susbscribe to the new contract
|
|
|
// susbscribe to the new contract
|
|
@ -142,24 +150,28 @@ func TestWSCallNoWait(t *testing.T) { |
|
|
con.Close() |
|
|
con.Close() |
|
|
}() |
|
|
}() |
|
|
// get the return value from a call
|
|
|
// get the return value from a call
|
|
|
data := []byte{0x1} // just needs to be non empty for this to be a CallTx
|
|
|
|
|
|
|
|
|
data := []byte{0x1} |
|
|
waitForEvent(t, con, eid, true, func() { |
|
|
waitForEvent(t, con, eid, true, func() { |
|
|
broadcastTx(t, "JSONRPC", userByteAddr, contractAddr, data, userBytePriv, amt, 1000, 1000) |
|
|
|
|
|
|
|
|
tx := makeDefaultCallTx(t, wsTyp, contractAddr, data, amt, gasLim, fee) |
|
|
|
|
|
broadcastTx(t, wsTyp, tx) |
|
|
}, unmarshalValidateCall(amt, returnVal)) |
|
|
}, unmarshalValidateCall(amt, returnVal)) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// create two contracts, one of which calls the other
|
|
|
// create two contracts, one of which calls the other
|
|
|
func TestWSCallCall(t *testing.T) { |
|
|
func TestWSCallCall(t *testing.T) { |
|
|
con := newWSCon(t) |
|
|
con := newWSCon(t) |
|
|
amt := uint64(10000) |
|
|
|
|
|
|
|
|
amt, gasLim, fee := uint64(10000), uint64(1000), uint64(1000) |
|
|
code, _, returnVal := simpleContract() |
|
|
code, _, returnVal := simpleContract() |
|
|
txid := new([]byte) |
|
|
txid := new([]byte) |
|
|
|
|
|
|
|
|
// deploy the two contracts
|
|
|
// deploy the two contracts
|
|
|
_, receipt := broadcastTx(t, "JSONRPC", userByteAddr, nil, code, userBytePriv, amt, 1000, 1000) |
|
|
|
|
|
|
|
|
tx := makeDefaultCallTx(t, wsTyp, nil, code, amt, gasLim, fee) |
|
|
|
|
|
receipt := broadcastTx(t, wsTyp, tx) |
|
|
contractAddr1 := receipt.ContractAddr |
|
|
contractAddr1 := receipt.ContractAddr |
|
|
|
|
|
|
|
|
code, _, _ = simpleCallContract(contractAddr1) |
|
|
code, _, _ = simpleCallContract(contractAddr1) |
|
|
_, receipt = broadcastTx(t, "JSONRPC", userByteAddr, nil, code, userBytePriv, amt, 1000, 1000) |
|
|
|
|
|
|
|
|
tx = makeDefaultCallTx(t, wsTyp, nil, code, amt, gasLim, fee) |
|
|
|
|
|
receipt = broadcastTx(t, wsTyp, tx) |
|
|
contractAddr2 := receipt.ContractAddr |
|
|
contractAddr2 := receipt.ContractAddr |
|
|
|
|
|
|
|
|
// susbscribe to the new contracts
|
|
|
// susbscribe to the new contracts
|
|
@ -171,7 +183,6 @@ func TestWSCallCall(t *testing.T) { |
|
|
con.Close() |
|
|
con.Close() |
|
|
}() |
|
|
}() |
|
|
// call contract2, which should call contract1, and wait for ev1
|
|
|
// call contract2, which should call contract1, and wait for ev1
|
|
|
data := []byte{0x1} // just needs to be non empty for this to be a CallTx
|
|
|
|
|
|
|
|
|
|
|
|
// let the contract get created first
|
|
|
// let the contract get created first
|
|
|
waitForEvent(t, con, eid1, true, func() { |
|
|
waitForEvent(t, con, eid1, true, func() { |
|
@ -180,7 +191,8 @@ func TestWSCallCall(t *testing.T) { |
|
|
}) |
|
|
}) |
|
|
// call it
|
|
|
// call it
|
|
|
waitForEvent(t, con, eid1, true, func() { |
|
|
waitForEvent(t, con, eid1, true, func() { |
|
|
tx, _ := broadcastTx(t, "JSONRPC", userByteAddr, contractAddr2, data, userBytePriv, amt, 1000, 1000) |
|
|
|
|
|
|
|
|
tx := makeDefaultCallTx(t, wsTyp, contractAddr2, nil, amt, gasLim, fee) |
|
|
|
|
|
broadcastTx(t, wsTyp, tx) |
|
|
*txid = account.HashSignBytes(tx) |
|
|
*txid = account.HashSignBytes(tx) |
|
|
}, unmarshalValidateCallCall(userByteAddr, returnVal, txid)) |
|
|
|
|
|
|
|
|
}, unmarshalValidateCallCall(user[0].Address, returnVal, txid)) |
|
|
} |
|
|
} |