Skip to content

Commit e614d51

Browse files
committed
test setegress fee, unregtoken
1 parent 58a2f4a commit e614d51

File tree

3 files changed

+49
-4
lines changed

3 files changed

+49
-4
lines changed

antelope_contracts/contracts/erc20/include/erc20/erc20.hpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ class [[eosio::contract]] erc20 : public contract {
107107
eosio::asset balance; // total amount in EVM side, only valid for native->evm tokens
108108
eosio::asset fee_balance;
109109
uint8_t erc20_precision = 0;
110-
eosio::binary_extension<bool> _is_evm_to_native{false};
110+
eosio::binary_extension<bool> from_evm_to_native{false};
111111

112112
uint64_t primary_key() const {
113113
return id;
@@ -122,11 +122,11 @@ class [[eosio::contract]] erc20 : public contract {
122122
return make_key(address);
123123
}
124124
bool is_evm_to_native() const {
125-
if (_is_evm_to_native.has_value()) return _is_evm_to_native.value();
125+
if (from_evm_to_native.has_value()) return from_evm_to_native.value();
126126
return false;
127127
}
128128

129-
EOSLIB_SERIALIZE(token_t, (id)(token_contract)(address)(ingress_fee)(balance)(fee_balance)(erc20_precision)(_is_evm_to_native));
129+
EOSLIB_SERIALIZE(token_t, (id)(token_contract)(address)(ingress_fee)(balance)(fee_balance)(erc20_precision)(from_evm_to_native));
130130
};
131131
typedef eosio::multi_index<"tokens"_n, token_t,
132132
indexed_by<"by.symbol"_n, const_mem_fun<token_t, uint128_t, &token_t::by_contract_symbol> >,

antelope_contracts/contracts/erc20/src/erc20.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ void erc20::regevm2nat(std::string erc20_token_address,
345345
v.balance.amount = 0;
346346
v.fee_balance = v.balance;
347347
v.erc20_precision = erc20_precision;
348-
v._is_evm_to_native = true;
348+
v.from_evm_to_native = true;
349349
});
350350
}
351351

antelope_contracts/tests/erc20/integrated_tests.cpp

+45
Original file line numberDiff line numberDiff line change
@@ -1055,6 +1055,51 @@ try {
10551055
evm_address = gold_evm_acc->address_0x();
10561056
bal = balanceOf(evm2.address_0x().c_str());
10571057
BOOST_REQUIRE(bal == 634'000'000'000'000'000);
1058+
1059+
// set egress fee to 0.5 EOS
1060+
constexpr intx::uint256 minimum_natively_representable = intx::exp(10_u256, intx::uint256(18 - 4));
1061+
evm_address = proxy_address;
1062+
push_action(erc20_account, "setegressfee"_n, erc20_account,
1063+
mvo()("token_contract", gold_token_account_name)("token_symbol_code", "GOLD")("egress_fee", make_asset(5000)));
1064+
BOOST_REQUIRE(5000 * minimum_natively_representable == egressFee());
1065+
1066+
// EVM -> native with old fee, should not work
1067+
evm_address = proxy_address;
1068+
bridgeTransferERC20(evm2, addr_alice, (uint64_t)100'000'000'000'000'000, "hello world", fee);
1069+
produce_block();
1070+
1071+
evm_address = gold_evm_acc->address_0x();
1072+
bal = balanceOf(evm2.address_0x().c_str());
1073+
BOOST_REQUIRE(bal == 634'000'000'000'000'000);
1074+
1075+
// EVM -> native with new fee, should work
1076+
evm_address = proxy_address;
1077+
fee = egressFee();
1078+
bridgeTransferERC20(evm2, addr_alice, (uint64_t)100'000'000'000'000'000, "hello world", fee);
1079+
produce_block();
1080+
1081+
evm_address = gold_evm_acc->address_0x();
1082+
bal = balanceOf(evm2.address_0x().c_str());
1083+
BOOST_REQUIRE(bal == 534'000'000'000'000'000);
1084+
1085+
// unregtoken
1086+
push_action(
1087+
erc20_account, "unregtoken"_n, erc20_account, mvo()("eos_contract_name", gold_token_account_name)("token_symbol_code", "GOLD"));
1088+
1089+
// EOS->EVM not allowed after unregtoken
1090+
BOOST_REQUIRE_EXCEPTION(
1091+
transfer_token(gold_token_account_name, "alice"_n, erc20_account, make_asset(2000, symbol::from_string("4,GOLD")), evm2.address_0x().c_str()),
1092+
eosio_assert_message_exception,
1093+
eosio_assert_message_is("received unregistered token"));
1094+
1095+
// EVM -> native not allowed
1096+
evm_address = proxy_address;
1097+
fee = egressFee();
1098+
BOOST_REQUIRE_EXCEPTION(
1099+
bridgeTransferERC20(evm2, addr_alice, (uint64_t)100'000'000'000'000'000, "hello world", fee),
1100+
eosio_assert_message_exception,
1101+
eosio_assert_message_is("ERC-20 token not registerred"));
1102+
10581103
}
10591104
FC_LOG_AND_RETHROW()
10601105

0 commit comments

Comments
 (0)