Skip to content

Commit

Permalink
integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
yihuang committed Dec 18, 2024
1 parent e699e40 commit 59d59b6
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 10 deletions.
10 changes: 10 additions & 0 deletions integration_tests/contracts/contracts/TestERC20Owner.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
pragma solidity 0.8.21;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

// An utility erc20 contract that has a fancy method
contract TestERC20Owner is ERC20 {
constructor(address owner) public ERC20("Fancy", "FNY") {
_mint(owner, 100000000000000000000000000);
}
}

30 changes: 21 additions & 9 deletions integration_tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
RevertTestContract,
assert_gov_params,
build_batch_tx,
build_batch_tx_signed,
contract_address,
contract_path,
deploy_contract,
Expand Down Expand Up @@ -677,24 +678,34 @@ def test_batch_tx(cronos):
"send multiple eth txs in single cosmos tx"
w3 = cronos.w3
cli = cronos.cosmos_cli()
sender = ADDRS["validator"]
deployer = ADDRS["validator"]
sender = ADDRS["signer1"]
recipient = ADDRS["community"]
deployer_nonce = w3.eth.get_transaction_count(deployer)
nonce = w3.eth.get_transaction_count(sender)
info = json.loads(CONTRACTS["TestERC20Utility"].read_text())
info = json.loads(CONTRACTS["TestERC20Owner"].read_text())
contract = w3.eth.contract(abi=info["abi"], bytecode=info["bytecode"])
deploy_tx = contract.constructor().build_transaction(
{"from": sender, "nonce": nonce}
deploy_tx = contract.constructor(sender).build_transaction(
{"from": deployer, "nonce": deployer_nonce}
)
contract = w3.eth.contract(
address=contract_address(deployer, deployer_nonce), abi=info["abi"]
)
contract = w3.eth.contract(address=contract_address(sender, nonce), abi=info["abi"])
transfer_tx1 = contract.functions.transfer(recipient, 1000).build_transaction(
{"from": sender, "nonce": nonce + 1, "gas": 200000}
{"from": sender, "nonce": nonce, "gas": 200000}
)
transfer_tx2 = contract.functions.transfer(recipient, 1000).build_transaction(
{"from": sender, "nonce": nonce + 2, "gas": 200000}
{"from": sender, "nonce": nonce + 1, "gas": 200000}
)

cosmos_tx, tx_hashes = build_batch_tx(
w3, cli, [deploy_tx, transfer_tx1, transfer_tx2]
cosmos_tx, tx_hashes = build_batch_tx_signed(
w3,
cli,
[
sign_transaction(w3, deploy_tx, KEYS["validator"]),
sign_transaction(w3, transfer_tx1, KEYS["signer1"]),
sign_transaction(w3, transfer_tx2, KEYS["signer1"]),
],
)
rsp = cli.broadcast_tx_json(cosmos_tx)
assert rsp["code"] == 0, rsp["raw_log"]
Expand Down Expand Up @@ -814,6 +825,7 @@ def test_log0(cluster):
w3,
Path(__file__).parent
/ "contracts/artifacts/contracts/TestERC20Utility.sol/TestERC20Utility.json",
args=(ADDRS["validator"],),
)
tx = contract.functions.test_log0().build_transaction({"from": ADDRS["validator"]})
receipt = send_transaction(w3, tx, KEYS["validator"])
Expand Down
6 changes: 5 additions & 1 deletion integration_tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
"TestICA": "TestICA.sol",
"Random": "Random.sol",
"TestRelayer": "TestRelayer.sol",
"TestERC20Owner": "TestERC20Owner.sol",
}


Expand Down Expand Up @@ -548,7 +549,10 @@ def modify_command_in_supervisor_config(ini: Path, fn, **kwargs):

def build_batch_tx(w3, cli, txs, key=KEYS["validator"]):
"return cosmos batch tx and eth tx hashes"
signed_txs = [sign_transaction(w3, tx, key) for tx in txs]
return build_batch_tx_signed([sign_transaction(w3, tx, key) for tx in txs])


def build_batch_tx_signed(w3, cli, signed_txs):
tmp_txs = [cli.build_evm_tx(signed.rawTransaction.hex()) for signed in signed_txs]

msgs = [tx["body"]["messages"][0] for tx in tmp_txs]
Expand Down

0 comments on commit 59d59b6

Please sign in to comment.