MCPcopy Create free account
hub / github.com/canopy-network/canopy / test_plugin_transactions

Function test_plugin_transactions

plugin/python/tutorial/rpc_test.py:368–505  ·  view source on GitHub ↗

Main test function.

()

Source from the content-addressed store, hash-verified

366
367
368def test_plugin_transactions() -> None:
369 """Main test function."""
370 print("=== Python Plugin RPC Test ===\n")
371
372 # Step 1: Create two new accounts in the keystore
373 print("Step 1: Creating two accounts in keystore...")
374
375 suffix = random_suffix()
376 account1_addr = keystore_new_key(ADMIN_RPC_URL, f"test_faucet_1_{suffix}", TEST_PASSWORD)
377 print(f"Created account 1: {account1_addr}")
378
379 account2_addr = keystore_new_key(ADMIN_RPC_URL, f"test_faucet_2_{suffix}", TEST_PASSWORD)
380 print(f"Created account 2: {account2_addr}")
381
382 # Get current height for transaction
383 height = get_height(QUERY_RPC_URL)
384 print(f"Current height: {height}")
385
386 # Get account 1's key for signing
387 account1_key = keystore_get_key(ADMIN_RPC_URL, account1_addr, TEST_PASSWORD)
388
389 # Step 2: Use faucet to add balance to account 1
390 print("\nStep 2: Using faucet to add balance to account 1...")
391
392 faucet_amount = 1000000000 # 1000 tokens
393 faucet_fee = 10000
394
395 faucet_tx_hash = send_faucet_tx(
396 QUERY_RPC_URL,
397 account1_key,
398 account1_addr,
399 faucet_amount,
400 faucet_fee,
401 NETWORK_ID,
402 CHAIN_ID,
403 height
404 )
405 print(f"Faucet transaction sent: {faucet_tx_hash}")
406
407 # Wait for faucet transaction to be included in a block
408 print("Waiting for faucet transaction to be confirmed...")
409 faucet_included = wait_for_tx_inclusion(QUERY_RPC_URL, account1_addr, faucet_tx_hash, 30)
410 if not faucet_included:
411 raise Exception("Faucet transaction not included within timeout")
412 print("Faucet transaction confirmed!")
413
414 # Verify no failed transactions
415 failed_count1 = check_tx_not_failed(QUERY_RPC_URL, account1_addr)
416 if failed_count1 > 0:
417 raise Exception(f"Account 1 has {failed_count1} failed transactions")
418
419 # Print balances after faucet
420 bal1_after_faucet = get_account_balance(QUERY_RPC_URL, account1_addr)
421 bal2_after_faucet = get_account_balance(QUERY_RPC_URL, account2_addr)
422 print(f"Balances after faucet - Account 1: {bal1_after_faucet}, Account 2: {bal2_after_faucet}")
423
424 # Step 3: Send tokens from account 1 to account 2
425 print("\nStep 3: Sending tokens from account 1 to account 2...")

Callers 1

rpc_test.pyFile · 0.85

Calls 10

random_suffixFunction · 0.85
keystore_new_keyFunction · 0.85
get_heightFunction · 0.85
keystore_get_keyFunction · 0.85
send_faucet_txFunction · 0.85
wait_for_tx_inclusionFunction · 0.85
check_tx_not_failedFunction · 0.85
get_account_balanceFunction · 0.85
send_send_txFunction · 0.85
send_reward_txFunction · 0.85

Tested by

no test coverage detected