mirror of
https://github.com/fluencelabs/tendermint
synced 2025-04-25 06:42:16 +00:00
remove name fix
This commit is contained in:
parent
77ff09e173
commit
37a8a6cd65
@ -6,7 +6,6 @@ import (
|
||||
ctypes "github.com/tendermint/tendermint/rpc/core/types"
|
||||
)
|
||||
|
||||
// XXX: need we be careful about rendering bytes as string or is that their problem ?
|
||||
func NameRegEntry(name string) (*ctypes.ResponseNameRegEntry, error) {
|
||||
st := consensusState.GetState() // performs a copy
|
||||
entry := st.GetNameRegEntry(name)
|
||||
|
@ -245,7 +245,6 @@ func (cache *BlockCache) Sync() {
|
||||
|
||||
// Determine order for names
|
||||
// note names may be of any length less than some limit
|
||||
// and are arbitrary byte arrays...
|
||||
nameStrs := []string{}
|
||||
for nameStr := range cache.names {
|
||||
nameStrs = append(nameStrs, nameStr)
|
||||
@ -256,9 +255,9 @@ func (cache *BlockCache) Sync() {
|
||||
for _, nameStr := range nameStrs {
|
||||
entry, removed, dirty := cache.names[nameStr].unpack()
|
||||
if removed {
|
||||
removed := cache.backend.RemoveNameRegEntry(entry.Name)
|
||||
removed := cache.backend.RemoveNameRegEntry(nameStr)
|
||||
if !removed {
|
||||
panic(Fmt("Could not remove namereg entry to be removed: %X", entry.Name))
|
||||
panic(Fmt("Could not remove namereg entry to be removed: %s", nameStr))
|
||||
}
|
||||
} else {
|
||||
if entry == nil {
|
||||
|
@ -331,6 +331,44 @@ func TestNameTxs(t *testing.T) {
|
||||
entry = state.GetNameRegEntry(name)
|
||||
validateEntry(t, entry, name, data, privAccounts[1].Address, uint64(state.LastBlockHeight)+numDesiredBlocks)
|
||||
|
||||
// test removal
|
||||
amt = fee
|
||||
data = ""
|
||||
tx, _ = types.NewNameTx(state, privAccounts[1].PubKey, name, data, amt, fee)
|
||||
tx.Sign(privAccounts[1])
|
||||
if err := execTxWithStateNewBlock(state, tx, true); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
entry = state.GetNameRegEntry(name)
|
||||
if entry != nil {
|
||||
t.Fatal("Expected removed entry to be nil")
|
||||
}
|
||||
|
||||
// create entry by key0,
|
||||
// test removal by key1 after expiry
|
||||
name = "looking_good/karaoke_bar"
|
||||
data = "some data"
|
||||
amt = fee + numDesiredBlocks*types.NameCostPerByte*types.NameCostPerBlock*types.BaseEntryCost(name, data)
|
||||
tx, _ = types.NewNameTx(state, privAccounts[0].PubKey, name, data, amt, fee)
|
||||
tx.Sign(privAccounts[0])
|
||||
if err := execTxWithState(state, tx, true); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
entry = state.GetNameRegEntry(name)
|
||||
validateEntry(t, entry, name, data, privAccounts[0].Address, uint64(state.LastBlockHeight)+numDesiredBlocks)
|
||||
state.LastBlockHeight = uint(entry.Expires)
|
||||
|
||||
amt = fee
|
||||
data = ""
|
||||
tx, _ = types.NewNameTx(state, privAccounts[1].PubKey, name, data, amt, fee)
|
||||
tx.Sign(privAccounts[1])
|
||||
if err := execTxWithStateNewBlock(state, tx, true); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
entry = state.GetNameRegEntry(name)
|
||||
if entry != nil {
|
||||
t.Fatal("Expected removed entry to be nil")
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: test overflows.
|
||||
|
Loading…
x
Reference in New Issue
Block a user