From 9778a59ac0b694a8b357d3011de094fa0d42256b Mon Sep 17 00:00:00 2001 From: yarkin Date: Wed, 7 Aug 2024 10:46:37 +0800 Subject: [PATCH] After discussion, we decide that we should only keep the token address+symbol API --- .../contracts/erc20/include/erc20/erc20.hpp | 3 +- .../contracts/erc20/src/erc20.cpp | 19 +---- .../tests/erc20/integrated_tests.cpp | 84 +------------------ 3 files changed, 4 insertions(+), 102 deletions(-) diff --git a/antelope_contracts/contracts/erc20/include/erc20/erc20.hpp b/antelope_contracts/contracts/erc20/include/erc20/erc20.hpp index 984b77c..bf711e4 100644 --- a/antelope_contracts/contracts/erc20/include/erc20/erc20.hpp +++ b/antelope_contracts/contracts/erc20/include/erc20/erc20.hpp @@ -60,8 +60,7 @@ class [[eosio::contract]] erc20 : public contract { [[eosio::action]] void init(eosio::name evm_account, eosio::symbol gas_token_symbol, uint64_t gaslimit, uint64_t init_gaslimit); [[eosio::action]] void setgaslimit(std::optional gaslimit, std::optional init_gaslimit); - [[eosio::action]] void callupgaddr(std::string proxy_address); - [[eosio::action]] void callupgsym(eosio::name token_contract, eosio::symbol token_symbol); + [[eosio::action]] void callupgrade(eosio::name token_contract, eosio::symbol token_symbol); struct [[eosio::table("implcontract")]] impl_contract_t { uint64_t id = 0; diff --git a/antelope_contracts/contracts/erc20/src/erc20.cpp b/antelope_contracts/contracts/erc20/src/erc20.cpp index 0f70b53..05bf401 100644 --- a/antelope_contracts/contracts/erc20/src/erc20.cpp +++ b/antelope_contracts/contracts/erc20/src/erc20.cpp @@ -477,24 +477,7 @@ inline eosio::name erc20::receiver_account()const { return get_self(); } -void erc20::callupgaddr(std::string proxy_address){ - require_auth(get_self()); - - auto address_bytes = from_hex(proxy_address); - eosio::check(!!address_bytes, "token address must be valid 0x EVM address"); - eosio::check(address_bytes->size() == kAddressLength, "invalid length of token address"); - - checksum256 addr_key = make_key(*address_bytes); - token_table_t token_table(_self, _self.value); - auto index = token_table.get_index<"by.address"_n>(); - auto token_table_iter = index.find(addr_key); - - check(token_table_iter != index.end() && token_table_iter->address == address_bytes, "ERC-20 token not registerred"); - - handle_call_upgrade(token_table_iter->address); -} - -void erc20::callupgsym(eosio::name token_contract, eosio::symbol token_symbol){ +void erc20::callupgrade(eosio::name token_contract, eosio::symbol token_symbol){ require_auth(get_self()); token_table_t token_table(_self, _self.value); diff --git a/antelope_contracts/tests/erc20/integrated_tests.cpp b/antelope_contracts/tests/erc20/integrated_tests.cpp index 456e57a..fb2e08a 100644 --- a/antelope_contracts/tests/erc20/integrated_tests.cpp +++ b/antelope_contracts/tests/erc20/integrated_tests.cpp @@ -274,87 +274,7 @@ try { } FC_LOG_AND_RETHROW() -BOOST_FIXTURE_TEST_CASE(it_upgrade_addr, it_tester) -try { - evm_eoa evm1; - auto addr_alice = silkworm::make_reserved_address("alice"_n.to_uint64_t()); - - // Give evm1 some EOS - transfer_token(eos_token_account, "alice"_n, evm_account, make_asset(1000000, eos_token_symbol), evm1.address_0x().c_str()); - produce_block(); - - - // USDT balance should be zero - auto bal = balanceOf(evm1.address_0x().c_str()); - BOOST_REQUIRE(bal == 0); - - produce_block(); - - transfer_token(token_account, "alice"_n, erc20_account, make_asset(10000, token_symbol), evm1.address_0x().c_str()); - - bal = balanceOf(evm1.address_0x().c_str()); - BOOST_REQUIRE(bal == 990000); - BOOST_REQUIRE(99990000 == get_balance("alice"_n, token_account, symbol::from_string("4,USDT")).get_amount()); - auto tokenInfo = getRegistedTokenInfo(); - BOOST_REQUIRE(tokenInfo.balance == make_asset(9900, token_symbol)); - BOOST_REQUIRE(tokenInfo.fee_balance == make_asset(100, token_symbol)); - - produce_block(); - - auto fee = egressFee(); - // received = 1000/1e6*1e4 = 10 - bridgeTransferERC20(evm1, addr_alice, 1000, "aaa", fee); - produce_block(); - - bal = balanceOf(evm1.address_0x().c_str()); - - BOOST_REQUIRE(bal == 989000); - bal = get_balance("alice"_n, token_account, symbol::from_string("4,USDT")).get_amount(); - - BOOST_REQUIRE(99990010 == get_balance("alice"_n, token_account, symbol::from_string("4,USDT")).get_amount()); - - // upgrade - - evm_eoa deployer; - evmc::address impl_addr = silkworm::create_address(deployer.address, deployer.next_nonce); - - transfer_token(eos_token_account, faucet_account_name, evmin_account, make_asset(1000000, eos_token_symbol), deployer.address_0x().c_str()); - - auto txn = prepare_deploy_contract_tx(solidity::erc20::bytecode, sizeof(solidity::erc20::bytecode), 10'000'000); - - deployer.sign(txn); - pushtx(txn); - produce_block(); - - push_action(erc20_account, "upgradeto"_n, erc20_account, mvo()("impl_address",fc::variant(impl_addr).as_string())); - - produce_block(); - - push_action(erc20_account, "callupgaddr"_n, erc20_account, mvo()("proxy_address",evm_address.substr(2))); - - produce_block(); - - // Perform some basic tests again - - transfer_token(token_account, "alice"_n, erc20_account, make_asset(10000, token_symbol), evm1.address_0x().c_str()); - - bal = balanceOf(evm1.address_0x().c_str()); - - BOOST_REQUIRE(bal == 989000 + 990000); - - fee = egressFee(); - // received = 1000/1e6*1e4 = 10 - bridgeTransferERC20(evm1, addr_alice, 1000, "aaa", fee); - produce_block(); - - bal = balanceOf(evm1.address_0x().c_str()); - - BOOST_REQUIRE(bal == 989000 * 2); - -} -FC_LOG_AND_RETHROW() - -BOOST_FIXTURE_TEST_CASE(it_upgrade_symbol, it_tester) +BOOST_FIXTURE_TEST_CASE(it_upgrade, it_tester) try { @@ -413,7 +333,7 @@ try { produce_block(); - push_action(erc20_account, "callupgsym"_n, erc20_account, mvo()("token_contract",token_account)("token_symbol",symbol::from_string("4,USDT"))); + push_action(erc20_account, "callupgrade"_n, erc20_account, mvo()("token_contract",token_account)("token_symbol",symbol::from_string("4,USDT"))); produce_block();