diff --git a/rpc/core/names.go b/rpc/core/names.go index b73662d2..5c238b44 100644 --- a/rpc/core/names.go +++ b/rpc/core/names.go @@ -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) diff --git a/state/block_cache.go b/state/block_cache.go index 53278aa1..8cc4ccb0 100644 --- a/state/block_cache.go +++ b/state/block_cache.go @@ -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 { diff --git a/state/state_test.go b/state/state_test.go index 0a562f7f..7e8ccc2d 100644 --- a/state/state_test.go +++ b/state/state_test.go @@ -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.