Skip to content

Commit

Permalink
fix: adjust inactive name owner table (#767)
Browse files Browse the repository at this point in the history
  • Loading branch information
jyeshe committed Jul 5, 2022
1 parent 18c6e3b commit f9825d6
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/ae_mdw/names.ex
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ defmodule AeMdw.Names do
@table_active_owner Model.ActiveNameOwner
@table_inactive Model.InactiveName
@table_inactive_expiration Model.InactiveNameExpiration
@table_inactive_owner Model.InactiveNameowner
@table_inactive_owner Model.InactiveNameOwner

@pagination_params ~w(limit cursor rev direction scope)
@states ~w(active inactive)
Expand Down
67 changes: 67 additions & 0 deletions test/ae_mdw_web/controllers/name_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ defmodule AeMdwWeb.NameControllerTest do
alias AeMdw.Db.Model.AuctionBid
alias AeMdw.Db.Model.AuctionExpiration
alias AeMdw.Db.Model.InactiveName
alias AeMdw.Db.Model.InactiveNameOwner
alias AeMdw.Db.Model.InactiveNameExpiration
alias AeMdw.Db.Model.Tx
alias AeMdw.Db.Name
Expand Down Expand Up @@ -769,6 +770,72 @@ defmodule AeMdwWeb.NameControllerTest do
end
end

test "get inactive names for given account/owner", %{conn: conn} do
owner_id = "ak_2VMBcnJQgzQQeQa6SgCgufYiRqgvoY9dXHR11ixqygWnWGfSah"
owner_pk = Validate.id!(owner_id)
other_pk = :crypto.strong_rand_bytes(32)
limit = 2
first_name = TS.plain_name(4)
not_owned_name = "o2#{first_name}"
second_name = "o1#{first_name}"

m_name =
Model.name(
index: first_name,
active: false,
expire: 3,
claims: [{{2, 0}, 0}],
updates: [],
transfers: [],
revoke: nil,
owner: owner_pk,
auction_timeout: 1
)

Database.dirty_write(InactiveName, m_name)
Database.dirty_write(InactiveName, Model.name(m_name, index: second_name))

Database.dirty_write(
InactiveName,
Model.name(m_name, index: not_owned_name, owner: other_pk)
)

Database.dirty_write(InactiveNameOwner, Model.owner(index: {owner_pk, first_name}))
Database.dirty_write(InactiveNameOwner, Model.owner(index: {owner_pk, second_name}))
Database.dirty_write(InactiveNameOwner, Model.owner(index: {other_pk, not_owned_name}))

with_mocks [
{Txs, [],
[
fetch!: fn _state, _hash -> %{"tx" => %{"account_id" => <<>>}} end
]},
{Name, [],
[
pointers: fn _state, _mnme -> %{} end,
ownership: fn _state, _mname ->
orig = {:id, :account, owner_pk}
%{current: orig, original: orig}
end
]}
] do
assert %{"data" => owned_names} =
conn
|> get("/names",
owned_by: owner_id,
by: "name",
state: "inactive",
limit: limit
)
|> json_response(200)

assert length(owned_names) == limit

assert Enum.all?(owned_names, fn %{"name" => plain_name} ->
plain_name in [first_name, second_name]
end)
end
end

test "renders error when parameter by is invalid", %{conn: conn} do
by = "invalid_by"
error = "invalid query: by=#{by}"
Expand Down

0 comments on commit f9825d6

Please sign in to comment.