pass chainID through sign interfaces

This commit is contained in:
Ethan Buchman
2015-05-29 18:14:19 -04:00
parent 8a2d9525f0
commit 2045aee9cd
28 changed files with 122 additions and 110 deletions
+1 -1
View File
@@ -193,6 +193,6 @@ func TestWSCallCall(t *testing.T) {
waitForEvent(t, con, eid1, true, func() {
tx := makeDefaultCallTx(t, wsTyp, contractAddr2, nil, amt, gasLim, fee)
broadcastTx(t, wsTyp, tx)
*txid = account.HashSignBytes(tx)
*txid = account.HashSignBytes(chainID, tx)
}, unmarshalValidateCallCall(user[0].Address, returnVal, txid))
}
+8 -4
View File
@@ -32,6 +32,8 @@ var (
userPriv = "C453604BD6480D5538B4C6FD2E3E314B5BCE518D75ADE4DA3DA85AB8ADFD819606FBAC4E285285D1D91FCBC7E91C780ADA11516F67462340B3980CE2B94940E8"
user = makeUsers(2)
chainID string
clients = map[string]cclient.Client{
"JSONRPC": cclient.NewClient(requestAddr, "JSONRPC"),
"HTTP": cclient.NewClient(requestAddr, "HTTP"),
@@ -74,6 +76,8 @@ func newNode(ready chan struct{}) {
// initialize config and create new node
func init() {
chainID = config.GetString("chain_id")
// Save new priv_validator file.
priv := &state.PrivValidator{
Address: user[0].Address,
@@ -83,7 +87,7 @@ func init() {
priv.SetFile(config.GetString("priv_validator_file"))
priv.Save()
consensus.RoundDuration0 = 3 * time.Second
consensus.RoundDuration0 = 2 * time.Second
consensus.RoundDurationDelta = 1 * time.Second
// start a node
@@ -105,14 +109,14 @@ func makeDefaultSendTx(t *testing.T, typ string, addr []byte, amt uint64) *types
func makeDefaultSendTxSigned(t *testing.T, typ string, addr []byte, amt uint64) *types.SendTx {
tx := makeDefaultSendTx(t, typ, addr, amt)
tx.SignInput(0, user[0])
tx.SignInput(chainID, 0, user[0])
return tx
}
func makeDefaultCallTx(t *testing.T, typ string, addr, code []byte, amt, gasLim, fee uint64) *types.CallTx {
nonce := getNonce(t, typ, user[0].Address)
tx := types.NewCallTxWithNonce(user[0].PubKey, addr, code, amt, gasLim, fee, nonce)
tx.Sign(user[0])
tx.Sign(chainID, user[0])
return tx
}
@@ -214,7 +218,7 @@ func checkTx(t *testing.T, fromAddr []byte, priv *account.PrivAccount, tx *types
t.Fatal("Tx input addresses don't match!")
}
signBytes := account.SignBytes(tx)
signBytes := account.SignBytes(chainID, tx)
in := tx.Inputs[0] //(*types.SendTx).Inputs[0]
if err := in.ValidateBasic(); err != nil {
+7 -7
View File
@@ -15,9 +15,9 @@ func testStatus(t *testing.T, typ string) {
if err != nil {
t.Fatal(err)
}
if resp.ChainID != config.GetString("chain_id") {
if resp.ChainID != chainID {
t.Fatal(fmt.Errorf("ChainID mismatch: got %s expected %s",
resp.ChainID, config.Get("chain_id")))
resp.ChainID, chainID))
}
}
@@ -57,9 +57,9 @@ func testSignedTx(t *testing.T, typ string) {
func testOneSignTx(t *testing.T, typ string, addr []byte, amt uint64) {
tx := makeDefaultSendTx(t, typ, addr, amt)
tx2 := signTx(t, typ, tx, user[0])
tx2hash := account.HashSignBytes(tx2)
tx.SignInput(0, user[0])
txhash := account.HashSignBytes(tx)
tx2hash := account.HashSignBytes(chainID, tx2)
tx.SignInput(chainID, 0, user[0])
txhash := account.HashSignBytes(chainID, tx)
if bytes.Compare(txhash, tx2hash) != 0 {
t.Fatal("Got different signatures for signing via rpc vs tx_utils")
}
@@ -88,8 +88,8 @@ func testBroadcastTx(t *testing.T, typ string) {
tx2 := txs[mempoolCount-1].(*types.SendTx)
n, err := new(int64), new(error)
buf1, buf2 := new(bytes.Buffer), new(bytes.Buffer)
tx.WriteSignBytes(buf1, n, err)
tx2.WriteSignBytes(buf2, n, err)
tx.WriteSignBytes(chainID, buf1, n, err)
tx2.WriteSignBytes(chainID, buf2, n, err)
if bytes.Compare(buf1.Bytes(), buf2.Bytes()) != 0 {
t.Fatal("inconsistent hashes for mempool tx and sent tx")
}