Browse Source

more cleanup rpc tests, testing namereg

pull/83/head
Ethan Buchman 10 years ago
parent
commit
02aedaaefb
6 changed files with 59 additions and 40 deletions
  1. +19
    -6
      config/tendermint_test/config.go
  2. +2
    -2
      rpc/test/client_ws_test.go
  3. +2
    -10
      rpc/test/helpers.go
  4. +34
    -21
      rpc/test/tests.go
  5. +1
    -1
      state/execution.go
  6. +1
    -0
      types/tx.go

+ 19
- 6
config/tendermint_test/config.go View File

@ -104,25 +104,38 @@ func defaultConfig(moniker string) (defaultConfig string) {
return
}
// priv keys generated deterministically eg rpc/tests/helpers.go
var defaultGenesis = `{
"chain_id" : "tendermint_test",
"accounts": [
{
"address": "1D7A91CB32F758A02EBB9BE1FB6F8DEE56F90D42",
"amount": 200000000
"address": "E9B5D87313356465FAE33C406CE2C2979DE60BCB",
"amount": 200000000
},
{
"address": "AC89A6DDF4C309A89A2C4078CE409A5A7B282270",
"amount": 200000000
"address": "DFE4AFFA4CEE17CD01CB9E061D77C3ECED29BD88",
"amount": 200000000
},
{
"address": "F60D30722E7B497FA532FB3207C3FB29C31B1992",
"amount": 200000000
},
{
"address": "336CB40A5EB92E496E19B74FDFF2BA017C877FD6",
"amount": 200000000
},
{
"address": "D218F0F439BF0384F6F5EF8D0F8B398D941BD1DC",
"amount": 200000000
}
],
"validators": [
{
"pub_key": [1, "06FBAC4E285285D1D91FCBC7E91C780ADA11516F67462340B3980CE2B94940E8"],
"pub_key": [1, "583779C3BFA3F6C7E23C7D830A9C3D023A216B55079AD38BFED1207B94A19548"],
"amount": 1000000,
"unbond_to": [
{
"address": "1D7A91CB32F758A02EBB9BE1FB6F8DEE56F90D42",
"address": "E9B5D87313356465FAE33C406CE2C2979DE60BCB",
"amount": 100000
}
]


+ 2
- 2
rpc/test/client_ws_test.go View File

@ -50,7 +50,7 @@ func TestWSBlockchainGrowth(t *testing.T) {
// send a transaction and validate the events from listening for both sender and receiver
func TestWSSend(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 := user[1].Address
amt := uint64(100)
con := newWSCon(t)
@ -80,7 +80,7 @@ func TestWSDoubleFire(t *testing.T) {
con.Close()
}()
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}
toAddr := user[1].Address
// broadcast the transaction, wait to hear about it
waitForEvent(t, con, eid, true, func() {
tx := makeDefaultSendTxSigned(t, wsTyp, toAddr, amt)


+ 2
- 10
rpc/test/helpers.go View File

@ -2,7 +2,6 @@ package rpctest
import (
"bytes"
"encoding/hex"
"strconv"
"testing"
"time"
@ -29,8 +28,7 @@ var (
mempoolCount = 0
// make keys
userPriv = "C453604BD6480D5538B4C6FD2E3E314B5BCE518D75ADE4DA3DA85AB8ADFD819606FBAC4E285285D1D91FCBC7E91C780ADA11516F67462340B3980CE2B94940E8"
user = makeUsers(2)
user = makeUsers(5)
chainID string
@ -40,6 +38,7 @@ var (
}
)
// deterministic account generation, synced with genesis file in config/tendermint_test/config.go
func makeUsers(n int) []*account.PrivAccount {
accounts := []*account.PrivAccount{}
for i := 0; i < n; i++ {
@ -47,13 +46,6 @@ func makeUsers(n int) []*account.PrivAccount {
user := account.GenPrivAccountFromSecret(secret)
accounts = append(accounts, user)
}
// include our validator
var byteKey [64]byte
userPrivByteSlice, _ := hex.DecodeString(userPriv)
copy(byteKey[:], userPrivByteSlice)
privAcc := account.GenPrivAccountFromKey(byteKey)
accounts[0] = privAcc
return accounts
}


+ 34
- 21
rpc/test/tests.go View File

@ -9,6 +9,8 @@ import (
"testing"
)
var doNothing = func(eid string, b []byte) error { return nil }
func testStatus(t *testing.T, typ string) {
client := clients[typ]
resp, err := client.Status()
@ -44,13 +46,13 @@ func testGetAccount(t *testing.T, typ string) {
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}
toAddr := user[1].Address
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}
toAddr = user[2].Address
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}
toAddr = user[3].Address
testOneSignTx(t, typ, toAddr, amt)
}
@ -71,7 +73,7 @@ func testOneSignTx(t *testing.T, typ string, addr []byte, amt uint64) {
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}
toAddr := user[1].Address
tx := makeDefaultSendTxSigned(t, typ, toAddr, amt)
receipt := broadcastTx(t, typ, tx)
if receipt.CreatesContract > 0 {
@ -120,10 +122,7 @@ func testGetStorage(t *testing.T, typ string) {
}
// allow it to get mined
waitForEvent(t, con, eid, true, func() {
}, func(eid string, b []byte) error {
return nil
})
waitForEvent(t, con, eid, true, func() {}, doNothing)
mempoolCount = 0
v := getStorage(t, typ, contractAddr, []byte{0x1})
@ -179,10 +178,7 @@ func testCall(t *testing.T, typ string) {
}
// allow it to get mined
waitForEvent(t, con, eid, true, func() {
}, func(eid string, b []byte) error {
return nil
})
waitForEvent(t, con, eid, true, func() {}, doNothing)
mempoolCount = 0
// run a call through the contract
@ -192,6 +188,7 @@ func testCall(t *testing.T, typ string) {
}
func testNameReg(t *testing.T, typ string) {
client := clients[typ]
con := newWSCon(t)
eid := types.EventStringNewBlock()
subscribe(t, con, eid)
@ -200,23 +197,39 @@ func testNameReg(t *testing.T, typ string) {
con.Close()
}()
// register a new name, check if its there
amt, fee := uint64(6969), uint64(1000)
// since entries ought to be unique and these run against different clients, we append the typ
name := "ye-old-domain-name-" + typ
data := "these are amongst the things I wish to bestow upon the youth of generations come: a safe supply of honey, and a better money. For what else shall they need?"
name := "ye_old_domain_name_" + typ
data := "these are amongst the things I wish to bestow upon the youth of generations come: a safe supply of honey, and a better money. For what else shall they need"
tx := makeDefaultNameTx(t, typ, name, data, amt, fee)
broadcastTx(t, typ, tx)
// allow it to get mined
waitForEvent(t, con, eid, true, func() {
}, func(eid string, b []byte) error {
return nil
})
waitForEvent(t, con, eid, true, func() {}, doNothing)
mempoolCount = 0
entry := getNameRegEntry(t, typ, name)
if entry.Data != data {
t.Fatal(fmt.Sprintf("Got %s, expected %s", entry.Data, data))
}
// update the data as the owner, make sure still there
data = "if not now, when"
tx = makeDefaultNameTx(t, typ, name, data, amt, fee)
broadcastTx(t, typ, tx)
waitForEvent(t, con, eid, true, func() {}, doNothing)
mempoolCount = 0
entry = getNameRegEntry(t, typ, name)
if entry.Data != data {
t.Fatal(fmt.Sprintf("Got %s, expected %s", entry.Data, data))
}
// try to update as non owner, should fail
nonce := getNonce(t, typ, user[1].Address)
data2 := "this is not my beautiful house"
tx = types.NewNameTxWithNonce(user[1].PubKey, name, data2, amt, fee, nonce)
tx.Sign(user[1])
_, err := client.BroadcastTx(tx)
if err == nil {
t.Fatal("Expected error on NameTx")
}
}

+ 1
- 1
state/execution.go View File

@ -527,7 +527,7 @@ func ExecTx(blockCache *BlockCache, tx_ types.Tx, runCall bool, evc events.Firea
// ensure we are owner
if bytes.Compare(entry.Owner, tx.Input.Address) != 0 {
log.Debug(Fmt("Sender %X is trying to update a name (%s) for which he is not owner", tx.Input.Address, tx.Name))
return types.ErrTxInvalidAddress // (?)
return types.ErrIncorrectOwner
}
} else {
expired = true


+ 1
- 0
types/tx.go View File

@ -20,6 +20,7 @@ var (
ErrTxInvalidPubKey = errors.New("Error invalid pubkey")
ErrTxInvalidSignature = errors.New("Error invalid signature")
ErrTxInvalidString = errors.New("Error invalid string")
ErrIncorrectOwner = errors.New("Error incorrect owner")
)
type ErrTxInvalidSequence struct {


Loading…
Cancel
Save