Skip to content

Commit

Permalink
add legacy send_to_ibc test
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-nguy committed Sep 6, 2022
1 parent 6af41e5 commit c30dff3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
12 changes: 11 additions & 1 deletion integration_tests/contracts/contracts/TestERC21Source.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ contract TestERC21Source is ERC20 {
string denom;
bool isSource;

event __CronosSendToIbc(address sender, string recipient, uint256 amount);
event __CronosSendToIbc(address sender, string recipient, uint256 amount, string channel_id, bytes extraData);
event __CronosSendToEvmChain(address sender, address recipient, uint256 chain_id, uint256 amount, uint256 bridge_fee, bytes extraData);
event __CronosCancelSendToEvmChain(address sender, uint256 id);
Expand Down Expand Up @@ -57,7 +58,16 @@ contract TestERC21Source is ERC20 {
**/

// send an "amount" of the contract token to recipient through IBC
function send_to_ibc(string memory recipient, uint amount, string memory channel_id, bytes memory extraData) public {
function send_to_ibc(string memory recipient, uint amount) public {
if (isSource) {
transfer(module_address, amount);
} else {
unsafe_burn(msg.sender, amount);
}
emit __CronosSendToIbc(msg.sender, recipient, amount);
}

function send_to_ibc_v2(string memory recipient, uint amount, string memory channel_id, bytes memory extraData) public {
if (isSource) {
transfer(module_address, amount);
} else {
Expand Down
12 changes: 11 additions & 1 deletion integration_tests/test_ibc.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ def test_cronos_transfer_source_tokens(ibc):
assert chainmain_receiver_balance == 0

# send to ibc
tx = contract.functions.send_to_ibc(chainmain_receiver, amount, '', b'').buildTransaction(
tx = contract.functions.send_to_ibc_v2(chainmain_receiver, amount, '', b'').buildTransaction(
{"from": ADDRS["validator"]}
)
txreceipt = send_transaction(w3, tx)
Expand All @@ -291,6 +291,16 @@ def check_chainmain_balance_change():
wait_for_fn("check balance change", check_chainmain_balance_change)
assert chainmain_receiver_new_balance == amount

# check legacy send to ibc
tx = contract.functions.send_to_ibc(chainmain_receiver, 1).buildTransaction(
{"from": ADDRS["validator"]}
)
txreceipt = send_transaction(w3, tx)
assert txreceipt.status == 1, "should success"
chainmain_receiver_balance = amount
wait_for_fn("check balance change", check_chainmain_balance_change)
assert chainmain_receiver_new_balance == amount + 1

# send back the token to cronos
# check receiver balance
cronos_balance_before_send = contract.caller.balanceOf(ADDRS["signer2"])
Expand Down

0 comments on commit c30dff3

Please sign in to comment.