mirror of
https://github.com/tendermint/tendermint.git
synced 2026-09-19 06:31:57 +00:00
namereg rpc and tests
This commit is contained in:
@@ -40,6 +40,10 @@ func TestHTTPCallContract(t *testing.T) {
|
||||
testCall(t, "HTTP")
|
||||
}
|
||||
|
||||
func TestHTTPNameReg(t *testing.T) {
|
||||
testNameReg(t, "HTTP")
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------
|
||||
// Test the JSONRPC client
|
||||
|
||||
@@ -74,3 +78,7 @@ func TestJSONCallCode(t *testing.T) {
|
||||
func TestJSONCallContract(t *testing.T) {
|
||||
testCall(t, "JSONRPC")
|
||||
}
|
||||
|
||||
func TestJSONNameReg(t *testing.T) {
|
||||
testNameReg(t, "JSONRPC")
|
||||
}
|
||||
|
||||
@@ -120,6 +120,13 @@ func makeDefaultCallTx(t *testing.T, typ string, addr, code []byte, amt, gasLim,
|
||||
return tx
|
||||
}
|
||||
|
||||
func makeDefaultNameTx(t *testing.T, typ string, name, value []byte, amt, fee uint64) *types.NameTx {
|
||||
nonce := getNonce(t, typ, user[0].Address)
|
||||
tx := types.NewNameTxWithNonce(user[0].PubKey, name, value, amt, fee, nonce)
|
||||
tx.Sign(user[0])
|
||||
return tx
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------
|
||||
// rpc call wrappers (fail on err)
|
||||
|
||||
@@ -210,6 +217,16 @@ func callContract(t *testing.T, client cclient.Client, address, data, expected [
|
||||
}
|
||||
}
|
||||
|
||||
// get the namereg entry
|
||||
func getNameRegEntry(t *testing.T, typ string, name []byte) *types.NameRegEntry {
|
||||
client := clients[typ]
|
||||
r, err := client.NameRegEntry(name)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return r.Entry
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------
|
||||
// utility verification function
|
||||
|
||||
|
||||
@@ -190,3 +190,33 @@ func testCall(t *testing.T, typ string) {
|
||||
expected := []byte{0xb}
|
||||
callContract(t, client, contractAddr, data, expected)
|
||||
}
|
||||
|
||||
func testNameReg(t *testing.T, typ string) {
|
||||
con := newWSCon(t)
|
||||
eid := types.EventStringNewBlock()
|
||||
subscribe(t, con, eid)
|
||||
defer func() {
|
||||
unsubscribe(t, con, eid)
|
||||
con.Close()
|
||||
}()
|
||||
|
||||
amt, fee := uint64(6969), uint64(1000)
|
||||
// since entries ought to be unique and these run against different clients, we append the typ
|
||||
name := []byte("ye-old-domain-name-" + typ)
|
||||
data := []byte("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
|
||||
})
|
||||
|
||||
entry := getNameRegEntry(t, typ, name)
|
||||
|
||||
if bytes.Compare(entry.Data, data) != 0 {
|
||||
t.Fatal(fmt.Sprintf("Got %s, expected %s", entry.Data, data))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user