Skip to content

Commit

Permalink
Fee should go to reveiver address.
Browse files Browse the repository at this point in the history
  • Loading branch information
yarkinwho committed Aug 31, 2023
1 parent 38078b7 commit 5e8268e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions src/actions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ void evm_contract::process_filtered_messages(const std::vector<silkworm::Filtere
eosio::check(value >= min_fee, "min_fee not covered");

balances balance_table(get_self(), get_self().value);
const balance& handler_account = balance_table.get(it->handler.value, "handler account is not open");
const balance& receiver_account = balance_table.get(receiver.value, "receiver account is not open");

action(std::vector<permission_level>{}, it->handler, "onbridgemsg"_n,
bridge_message{ bridge_message_v0 {
Expand All @@ -423,7 +423,7 @@ void evm_contract::process_filtered_messages(const std::vector<silkworm::Filtere
} }
).send();

balance_table.modify(handler_account, eosio::same_payer, [&](balance& row) {
balance_table.modify(receiver_account, eosio::same_payer, [&](balance& row) {
row.balance += value;
});

Expand Down Expand Up @@ -723,7 +723,7 @@ void evm_contract::bridgereg(eosio::name receiver, eosio::name handler, const eo
message_receivers.modify(*it, eosio::same_payer, update_row);
}

open(handler);
open(receiver);
}

void evm_contract::bridgeunreg(eosio::name receiver) {
Expand Down
16 changes: 8 additions & 8 deletions tests/bridge_message_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ BOOST_FIXTURE_TEST_CASE(test_bridge_errors, bridge_message_tester) try {
evmc::from_hex(data_str32(str_to_hex("abcd"))).value() +
evmc::from_hex(int_str32(4)).value() +
evmc::from_hex(data_str32(str_to_hex("data"))).value()),
eosio_assert_message_exception, eosio_assert_message_is("handler account is not open"));
eosio_assert_message_exception, eosio_assert_message_is("receiver account is not open"));
} FC_LOG_AND_RETHROW()

BOOST_FIXTURE_TEST_CASE(test_send_message_from_solidity, bridge_message_tester) try {
Expand Down Expand Up @@ -369,9 +369,9 @@ BOOST_FIXTURE_TEST_CASE(handler_tests, bridge_message_tester) try {
bridgereg("receiver"_n, "handler"_n, make_asset(1000'0000));


// Corner case: handler account is not open
// We can only test in this way because bridgereg will open handler.
close("handler"_n);
// Corner case: receiver account is not open
// We can only test in this way because bridgereg will open receiver.
close("receiver"_n);

BOOST_REQUIRE_EXCEPTION(send_raw_message(evm1, emv_reserved_address, 1000_ether,
evmc::from_hex(bridgeMsgV0_method_id).value() +
Expand All @@ -382,18 +382,18 @@ BOOST_FIXTURE_TEST_CASE(handler_tests, bridge_message_tester) try {
evmc::from_hex(data_str32(str_to_hex("receiver"))).value() +
evmc::from_hex(int_str32(4)).value() +
evmc::from_hex(data_str32(str_to_hex("data"))).value()),
eosio_assert_message_exception, eosio_assert_message_is("handler account is not open"));
eosio_assert_message_exception, eosio_assert_message_is("receiver account is not open"));
evm1.next_nonce--;
open("handler"_n);
open("receiver"_n);

// Check handler balance before sending the message
BOOST_REQUIRE(vault_balance("handler"_n) == (balance_and_dust{make_asset(0), 0}));
BOOST_REQUIRE(vault_balance("receiver"_n) == (balance_and_dust{make_asset(0), 0}));

// Emit message
auto res = send_bridge_message(evm1, "receiver", 1000_ether, "0102030405060708090a");

// Check handler balance after sending the message
BOOST_REQUIRE(vault_balance("handler"_n) == (balance_and_dust{make_asset(1000'0000), 0}));
BOOST_REQUIRE(vault_balance("receiver"_n) == (balance_and_dust{make_asset(1000'0000), 0}));

// Recover message form the return value of handler contract
// Make sure "handler" received a message sent to "receiver"
Expand Down

0 comments on commit 5e8268e

Please sign in to comment.