Skip to content

Commit

Permalink
fix: add test for contract_pk transfer field
Browse files Browse the repository at this point in the history
  • Loading branch information
jyeshe committed Aug 31, 2022
1 parent c6abf11 commit 8fb32ef
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
15 changes: 10 additions & 5 deletions lib/ae_mdw/db/contract.ex
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ defmodule AeMdw.Db.Contract do

cond do
is_aexn_transfer?(evt_hash) and aex9_contract_pk != nil ->
write_aexn_transfer(state3, :aex9, txi, i, args)
write_aexn_transfer(state3, :aex9, aex9_contract_pk, txi, i, args)

is_aexn_transfer?(evt_hash) and State.exists?(state3, Model.AexnContract, {:aex141, addr}) ->
write_aex141_records(state3, addr, txi, i, args)
Expand Down Expand Up @@ -331,7 +331,7 @@ defmodule AeMdw.Db.Contract do
state2 =
state
|> State.put(Model.NftOwnership, m_ownership)
|> write_aexn_transfer(:aex141, txi, i, args)
|> write_aexn_transfer(:aex141, contract_pk, txi, i, args)

if State.exists?(state2, Model.NftOwnership, {from_pk, contract_pk, token_id}) do
State.delete(state2, Model.NftOwnership, {from_pk, contract_pk, token_id})
Expand All @@ -342,12 +342,17 @@ defmodule AeMdw.Db.Contract do

defp write_aex141_records(state, _pk, _txi, _i, _args), do: state

defp write_aexn_transfer(state, aexn_type, txi, i, [
defp write_aexn_transfer(state, aexn_type, contract_pk, txi, i, [
<<_pk1::256>> = from_pk,
<<_pk2::256>> = to_pk,
<<value::256>>
]) do
m_transfer = Model.aexn_transfer(index: {aexn_type, from_pk, txi, to_pk, value, i})
m_transfer =
Model.aexn_transfer(
index: {aexn_type, from_pk, txi, to_pk, value, i},
contract_pk: contract_pk
)

m_rev_transfer = Model.rev_aexn_transfer(index: {aexn_type, to_pk, txi, from_pk, value, i})
m_pair_transfer = Model.aexn_pair_transfer(index: {aexn_type, from_pk, to_pk, txi, value, i})

Expand All @@ -357,7 +362,7 @@ defmodule AeMdw.Db.Contract do
|> State.put(Model.AexnPairTransfer, m_pair_transfer)
end

defp write_aexn_transfer(state, _type, _txi, _i, _args), do: state
defp write_aexn_transfer(state, _contract_pk, _type, _txi, _i, _args), do: state

defp fetch_aex9_balance_or_new(state, contract_pk, account_pk) do
case State.get(state, Model.Aex9Balance, {contract_pk, account_pk}) do
Expand Down
9 changes: 4 additions & 5 deletions test/ae_mdw/db/contract_call_mutation_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -279,11 +279,10 @@ defmodule AeMdw.Db.ContractCallMutationTest do
assert State.exists?(state, Model.NftOwnership, {to_pk, contract_pk, token_id})
refute State.exists?(state, Model.NftOwnership, {from_pk, contract_pk, token_id})

assert State.exists?(
state,
Model.AexnTransfer,
{:aex141, from_pk, call_txi, to_pk, token_id, 0}
)
key = {:aex141, from_pk, call_txi, to_pk, token_id, 0}

assert Model.aexn_transfer(index: ^key, contract_pk: contract_pk) =
State.fetch!(state, Model.AexnTransfer, key)

assert State.exists?(
state,
Expand Down

0 comments on commit 8fb32ef

Please sign in to comment.