Skip to content

Commit

Permalink
add unittest cases, fix cicd
Browse files Browse the repository at this point in the history
  • Loading branch information
taokayan committed Oct 18, 2023
1 parent 0895889 commit 52aaab7
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .cicd/platforms/ubuntu22.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ RUN apt-get update && apt-get upgrade -y && \
git \
jq \
wget \
xxd
xxd \
libcurl4-gnutls-dev

#Install Node.js
#https://github.com/nodesource/distributions/blob/master/README.md#installation-instructions
Expand Down
2 changes: 1 addition & 1 deletion antelope_contracts/tests/erc20/erc20_tester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ void erc20_tester::open(name owner) { push_action(evm_account, "open"_n, owner,

transaction_trace_ptr erc20_tester::exec(const exec_input& input, const std::optional<exec_callback>& callback) {
auto binary_data = fc::raw::pack<exec_input, std::optional<exec_callback>>(input, callback);
return erc20_tester::push_action(evm_account, "exec"_n, evm_account, bytes{binary_data.begin(), binary_data.end()});
return erc20_tester::push_action(evm_account, "exec"_n, evm_account, bytes{binary_data.begin(), binary_data.end()}, DEFAULT_EXPIRATION_DELTA + (exec_count++) % 3500);
}

eosio::chain::action erc20_tester::get_action(account_name code, action_name acttype, std::vector<permission_level> auths,
Expand Down
3 changes: 2 additions & 1 deletion antelope_contracts/tests/erc20/erc20_tester.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ class erc20_tester : public eosio::testing::base_tester {
const eosio::chain::symbol native_symbol;
explicit erc20_tester(bool use_real_evm = false, std::string native_symbol_str = "4,EOS");

unsigned int exec_count = 0; // ensure uniqueness in exec

eosio::chain::asset make_asset(int64_t amount) const { return eosio::chain::asset(amount, native_symbol); }
eosio::chain::asset make_asset(int64_t amount, const eosio::chain::symbol& target_symbol) const { return eosio::chain::asset(amount, target_symbol); }
eosio::chain::transaction_trace_ptr transfer_token(eosio::chain::name token_account_name, eosio::chain::name from, eosio::chain::name to, eosio::chain::asset quantity, std::string memo = "");
Expand Down Expand Up @@ -187,7 +189,6 @@ class erc20_tester : public eosio::testing::base_tester {
const std::optional<asset> ingress_bridge_fee = std::nullopt,
const bool also_prepare_self_balance = true);


};


Expand Down
44 changes: 44 additions & 0 deletions antelope_contracts/tests/erc20/integrated_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,52 @@ try {
}
FC_LOG_AND_RETHROW()

BOOST_FIXTURE_TEST_CASE(it_unregtoken, 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();

// alice send 1.0000 USDT to evm1
transfer_token(token_account, "alice"_n, erc20_account, make_asset(10000, token_symbol), evm1.address_0x().c_str());

// evm1 has 0.990000 USDT
BOOST_REQUIRE(balanceOf(evm1.address_0x().c_str()) == 990000);

// alice has 9999.0000 USDT
BOOST_REQUIRE(9999'0000 == get_balance("alice"_n, token_account, symbol::from_string("4,USDT")).get_amount());

push_action(
erc20_account, "unregtoken"_n, erc20_account, mvo()("eos_contract_name", token_account)("token_symbol_code", (std::string)(token_symbol.name())));

BOOST_REQUIRE_EXCEPTION(
transfer_token(token_account, "alice"_n, erc20_account, make_asset(20000, token_symbol), evm1.address_0x().c_str()),
eosio_assert_message_exception,
eosio_assert_message_is("received unregistered token"));

// register token again (imply a different ERC-EVM address)
push_action(erc20_account, "regtoken"_n, erc20_account, mvo()("eos_contract_name",token_account.to_string())("evm_token_name","EVM USDT V2")("evm_token_symbol","WUSDT")("ingress_fee","0.0100 USDT")("egress_fee","0.0100 EOS")("erc20_precision",6));

transfer_token(token_account, "alice"_n, erc20_account, make_asset(20000, token_symbol), evm1.address_0x().c_str());

// alice has 9997.0000 USDT
BOOST_REQUIRE(9997'0000 == get_balance("alice"_n, token_account, symbol::from_string("4,USDT")).get_amount());

// evm1 has 0.990000 USDT under the original ERC-20 address
BOOST_REQUIRE(balanceOf(evm1.address_0x().c_str()) == 990000);
}
FC_LOG_AND_RETHROW()

BOOST_FIXTURE_TEST_CASE(it_eos_to_evm, it_tester)
try {
evm_eoa evm1;
Expand Down

0 comments on commit 52aaab7

Please sign in to comment.