Skip to content

Commit

Permalink
use precompile relayer to test ica callback
Browse files Browse the repository at this point in the history
  • Loading branch information
yihuang committed Nov 1, 2023
1 parent 8a3e3d4 commit 59f0a53
Showing 1 changed file with 88 additions and 3 deletions.
91 changes: 88 additions & 3 deletions integration_tests/test_ica_precompile.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import base64
import itertools
import json
from enum import IntEnum

import pytest
from hexbytes import HexBytes
from pystarport import cluster
from web3.datastructures import AttributeDict

from .ibc_utils import (
Expand Down Expand Up @@ -45,9 +48,15 @@ class Status(IntEnum):
@pytest.fixture(scope="module")
def ibc(request, tmp_path_factory):
"prepare-network"
name = "ibc"
name = "ibc_rly"
path = tmp_path_factory.mktemp(name)
yield from prepare_network(path, name, incentivized=False, connection_only=True)
yield from prepare_network(
path,
name,
incentivized=False,
connection_only=True,
relayer=cluster.Relayer.RLY.value,
)


def register_acc(cli, w3, register, query, data, addr, channel_id):
Expand Down Expand Up @@ -181,6 +190,7 @@ def test_sc_call(ibc):
cli_host = ibc.chainmain.cosmos_cli()
cli_controller = ibc.cronos.cosmos_cli()
w3 = ibc.cronos.w3
begin_block = w3.eth.block_number
contract = w3.eth.contract(address=CONTRACT, abi=contract_info)
jsonfile = CONTRACTS["TestICA"]
tcontract = deploy_contract(w3, jsonfile)
Expand Down Expand Up @@ -303,4 +313,79 @@ def submit_msgs_ro(func, str):
assert status == Status.FAIL
assert cli_host.balance(ica_address, denom=denom) == balance

print(tcontract.events.OnPacketResult.getLogs())
# check logs emitted in callback
logs = get_logs_since(w3, addr, begin_block)
assert_logs_equal(
logs,
[
{
"address": addr,
"topics": [
HexBytes(
"0xb58d968e02022e42ce2b8f5c494b724806ff73755eb957ff2be7a62947"
"8ac9f9"
)
],
"data": HexBytes(
"0x00000000000000000000000000000000000000000000000000000000000000"
"010000000000000000000000000000000000000000000000000000000000000001"
),
"transactionIndex": 1,
"logIndex": 0,
"removed": False,
},
{
"address": addr,
"topics": [
HexBytes(
"0xb58d968e02022e42ce2b8f5c494b724806ff73755eb957ff2be7a62947"
"8ac9f9"
)
],
"data": HexBytes(
"0x00000000000000000000000000000000000000000000000000000000000000"
"020000000000000000000000000000000000000000000000000000000000000001"
),
"transactionIndex": 1,
"logIndex": 0,
"removed": False,
},
{
"address": addr,
"topics": [
HexBytes(
"0xb58d968e02022e42ce2b8f5c494b724806ff73755eb957ff2be7a62947"
"8ac9f9"
)
],
"data": HexBytes(
"0x00000000000000000000000000000000000000000000000000000000000000"
"030000000000000000000000000000000000000000000000000000000000000002"
),
"transactionIndex": 1,
"logIndex": 0,
"removed": False,
},
{
"address": addr,
"topics": [
HexBytes(
"0xb58d968e02022e42ce2b8f5c494b724806ff73755eb957ff2be7a62947"
"8ac9f9"
)
],
"data": HexBytes(
"0x00000000000000000000000000000000000000000000000000000000000000"
"040000000000000000000000000000000000000000000000000000000000000002"
),
"transactionIndex": 1,
"logIndex": 0,
"removed": False,
},
],
)


def assert_logs_equal(logs, exp_logs):
for exp_log, log in itertools.zip_longest(exp_logs, logs):
assert exp_log.items() <= log.items()

0 comments on commit 59f0a53

Please sign in to comment.