cleanup rpc tests, use tx_utils

This commit is contained in:
Ethan Buchman
2015-05-22 18:22:57 -04:00
parent 8c3deb402f
commit c28614fca1
5 changed files with 158 additions and 138 deletions

View File

@ -3,6 +3,7 @@ package rpctest
import (
"bytes"
"fmt"
"github.com/tendermint/tendermint/account"
. "github.com/tendermint/tendermint/common"
"github.com/tendermint/tendermint/types"
"testing"
@ -32,34 +33,47 @@ func testGenPriv(t *testing.T, typ string) {
}
func testGetAccount(t *testing.T, typ string) {
acc := getAccount(t, typ, userByteAddr)
acc := getAccount(t, typ, user[0].Address)
if acc == nil {
t.Fatalf("Account was nil")
}
if bytes.Compare(acc.Address, userByteAddr) != 0 {
t.Fatalf("Failed to get correct account. Got %x, expected %x", acc.Address, userByteAddr)
if bytes.Compare(acc.Address, user[0].Address) != 0 {
t.Fatalf("Failed to get correct account. Got %x, expected %x", acc.Address, user[0].Address)
}
}
func testSignedTx(t *testing.T, typ string) {
amt := uint64(100)
toAddr := []byte{20, 143, 25, 63, 16, 177, 83, 29, 91, 91, 54, 23, 233, 46, 190, 121, 122, 34, 86, 54}
tx, priv := signTx(t, typ, userByteAddr, toAddr, nil, userBytePriv, amt, 0, 0)
checkTx(t, userByteAddr, priv, tx.(*types.SendTx))
testOneSignTx(t, typ, toAddr, amt)
toAddr = []byte{20, 143, 24, 63, 16, 17, 83, 29, 90, 91, 52, 2, 0, 41, 190, 121, 122, 34, 86, 54}
tx, priv = signTx(t, typ, userByteAddr, toAddr, nil, userBytePriv, amt, 0, 0)
checkTx(t, userByteAddr, priv, tx.(*types.SendTx))
testOneSignTx(t, typ, toAddr, amt)
toAddr = []byte{0, 0, 4, 0, 0, 4, 0, 0, 4, 91, 52, 2, 0, 41, 190, 121, 122, 34, 86, 54}
tx, priv = signTx(t, typ, userByteAddr, toAddr, nil, userBytePriv, amt, 0, 0)
checkTx(t, userByteAddr, priv, tx.(*types.SendTx))
testOneSignTx(t, typ, toAddr, amt)
}
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)
if bytes.Compare(txhash, tx2hash) != 0 {
t.Fatal("Got different signatures for signing via rpc vs tx_utils")
}
tx_ := signTx(t, typ, tx, user[0])
tx = tx_.(*types.SendTx)
checkTx(t, user[0].Address, user[0], tx)
}
func testBroadcastTx(t *testing.T, typ string) {
amt := uint64(100)
toAddr := []byte{20, 143, 25, 63, 16, 177, 83, 29, 91, 91, 54, 23, 233, 46, 190, 121, 122, 34, 86, 54}
tx, receipt := broadcastTx(t, typ, userByteAddr, toAddr, nil, userBytePriv, amt, 0, 0)
tx := makeDefaultSendTxSigned(t, typ, toAddr, amt)
receipt := broadcastTx(t, typ, tx)
if receipt.CreatesContract > 0 {
t.Fatal("This tx does not create a contract")
}
@ -90,9 +104,10 @@ func testGetStorage(t *testing.T, typ string) {
con.Close()
}()
amt := uint64(1100)
amt, gasLim, fee := uint64(1100), uint64(1000), uint64(1000)
code := []byte{0x60, 0x5, 0x60, 0x1, 0x55}
_, receipt := broadcastTx(t, typ, userByteAddr, nil, code, userBytePriv, amt, 1000, 1000)
tx := makeDefaultCallTx(t, typ, nil, code, amt, gasLim, fee)
receipt := broadcastTx(t, typ, tx)
if receipt.CreatesContract == 0 {
t.Fatal("This tx creates a contract")
}
@ -147,9 +162,11 @@ func testCall(t *testing.T, typ string) {
client := clients[typ]
// create the contract
amt := uint64(6969)
amt, gasLim, fee := uint64(6969), uint64(1000), uint64(1000)
code, _, _ := simpleContract()
_, receipt := broadcastTx(t, typ, userByteAddr, nil, code, userBytePriv, amt, 1000, 1000)
tx := makeDefaultCallTx(t, typ, nil, code, amt, gasLim, fee)
receipt := broadcastTx(t, typ, tx)
if receipt.CreatesContract == 0 {
t.Fatal("This tx creates a contract")
}