diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index e71301fab..935d0c975 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -3,7 +3,7 @@ on: [push, pull_request] name: E2E tests jobs: - run-e2e-test: + e2e-testing: strategy: fail-fast: false matrix: diff --git a/tests/deploy/deploy.sh b/tests/deploy/deploy.sh index 6529e7784..2ab19c0f0 100755 --- a/tests/deploy/deploy.sh +++ b/tests/deploy/deploy.sh @@ -5,6 +5,7 @@ set -xeuo pipefail script_dir="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)" data_dir="$script_dir/node-data" udt_init_dir="$script_dir/udt-init" +nodes_dir="$script_dir/../nodes" cd "$script_dir" || exit 1 miner_key_file="$data_dir/specs/miner.key" @@ -35,7 +36,7 @@ function deploy() { GENESIS_TX0="$(ckb -C "$data_dir" list-hashes | sed -n 's/tx_hash = "\(.*\)"/\1/p' | head -1)" sed "s/0x8f8c79eb6671709633fe6a46de93c0fedc9c1b8a6527a18d3983879542635c9f/$GENESIS_TX0/" "$TEMPLATE_FILE" >"$CONFIG_FILE" - ckb-cli deploy gen-txs --from-address ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqwgx292hnvmn68xf779vmzrshpmm6epn4c0cgwga \ + ckb-cli deploy gen-txs --from-address $(cat "$nodes_dir/deployer/ckb-chain/wallet") \ --fee-rate 100000 --deployment-config "$CONFIG_FILE" --info-file "$INFO_FILE" --migration-dir "$MIGRATION_DIR" ckb-cli deploy sign-txs --add-signatures --info-file "$INFO_FILE" --privkey-path "$miner_key_file" --output-format json | sed -n 's/: \("[^"]*"\)/: [\1]/p' @@ -58,6 +59,7 @@ deploy_and_generate_blocks() { run_udt_init() { export $(xargs <".env") + export NODES_DIR="$nodes_dir" ( cd "$udt_init_dir" || exit 1 cargo run -- "$@" diff --git a/tests/deploy/init-dev-chain.sh b/tests/deploy/init-dev-chain.sh index 4181ec58c..ba18a4873 100755 --- a/tests/deploy/init-dev-chain.sh +++ b/tests/deploy/init-dev-chain.sh @@ -16,6 +16,7 @@ check_deps ckb ckb-cli perl script_dir="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)" data_dir="$script_dir/node-data" +nodes_dir="$script_dir/../nodes" # If -f is used, we will remove old state data. Otherwise we will skip the initialization. while getopts "f" opt; do @@ -48,21 +49,21 @@ if ! [[ -d "$data_dir" ]]; then # Transfer some money to the node 1. # The address of node 1 can be seen with the following command: - # echo | HOME=/tmp ckb-cli account import --local-only --privkey-path "$script_dir/../nodes/1/ckb-chain/key" - ckb-cli wallet transfer --to-address ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqgx5lf4pczpamsfam48evs0c8nvwqqa59qapt46f --capacity 5000000000 --fee-rate 2000 --privkey-path "$script_dir/../nodes/deployer/ckb-chain/key" + # echo | HOME=/tmp ckb-cli account import --local-only --privkey-path "$$nodes_dir/1/ckb-chain/key" + ckb-cli wallet transfer --to-address $(cat "$nodes_dir/1/ckb-chain/wallet") --capacity 5000000000 --fee-rate 2000 --privkey-path "$nodes_dir/deployer/ckb-chain/key" sleep 1 "$script_dir/generate-blocks.sh" 6 sleep 1 # Transfer some money to the node 2. - ckb-cli wallet transfer --to-address ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqt4vqqyehpxn47deg5l6eeqtkfrt5kfkfchkwv62 --capacity 5000000000 --fee-rate 2000 --privkey-path "$script_dir/../nodes/deployer/ckb-chain/key" + ckb-cli wallet transfer --to-address $(cat "$nodes_dir/2/ckb-chain/wallet") --capacity 5000000000 --fee-rate 2000 --privkey-path "$nodes_dir/deployer/ckb-chain/key" sleep 1 "$script_dir/generate-blocks.sh" 6 sleep 1 # Transfer some money to the node 3. - ckb-cli wallet transfer --to-address ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqtrnd9f2lh5vlwlj23dedf7jje65cdj8qs7q4awr --capacity 5000000000 --fee-rate 2000 --privkey-path "$script_dir/../nodes/deployer/ckb-chain/key" + ckb-cli wallet transfer --to-address $(cat "$nodes_dir/3/ckb-chain/wallet") --capacity 5000000000 --fee-rate 2000 --privkey-path "$nodes_dir/deployer/ckb-chain/key" sleep 1 # Generate a few blocks so that above transaction is confirmed. echo "begin to generate blocks for wallet updating..." diff --git a/tests/deploy/udt-init/src/main.rs b/tests/deploy/udt-init/src/main.rs index f0afcf821..51cfd675d 100644 --- a/tests/deploy/udt-init/src/main.rs +++ b/tests/deploy/udt-init/src/main.rs @@ -78,16 +78,14 @@ fn generate_configuration( let mut configuration = TransactionBuilderConfiguration::new_devnet().expect("new devnet configuration"); - let sighash_handler = gen_dev_sighash_handler(); - configuration.register_script_handler(Box::new(sighash_handler)); - let sudt_handler = gen_dev_udt_handler(); - configuration.register_script_handler(Box::new(sudt_handler)); + configuration.register_script_handler(Box::new(gen_dev_sighash_handler())); + configuration.register_script_handler(Box::new(gen_dev_udt_handler())); return Ok((network_info, configuration)); } fn init_or_send_udt( issuer_address: &str, - sender_info: &(&str, H256), + sender_info: &(String, H256), receiver_address: Option<&str>, sudt_amount: u128, apply: bool, @@ -95,7 +93,7 @@ fn init_or_send_udt( let (network_info, configuration) = generate_configuration()?; let issuer = Address::from_str(issuer_address)?; - let sender = Address::from_str(sender_info.0)?; + let sender = Address::from_str(&sender_info.0)?; let receiver = if let Some(addr) = receiver_address { Address::from_str(addr)? } else { @@ -174,53 +172,60 @@ fn generate_udt_type_script(address: &str) -> ckb_types::packed::Script { res } -fn main() -> Result<(), Box> { - // The address is from - // ckb-cli account import --local-only --privkey-path tests/nodes/deployer/ckb-chain/key - let udt_owner = ("ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqwgx292hnvmn68xf779vmzrshpmm6epn4c0cgwga", h256!("0xd00c06bfd800d27397002dca6fb0993d5ba6399b4238b2f29ee9deb97593d2bc")); +fn get_nodes_info(node: &str) -> (String, H256) { + let nodes_dir = std::env::var("NODES_DIR").expect("env var"); + let node_dir = format!("{}/{}", nodes_dir, node); + let wallet = + std::fs::read_to_string(format!("{}/ckb-chain/wallet", node_dir)).expect("read failed"); + let key = std::fs::read_to_string(format!("{}/ckb-chain/key", node_dir)).expect("read failed"); + eprintln!("node {}: wallet: {}", node, wallet); + (wallet, H256::from_str(&key.trim()).expect("parse hex")) +} +fn main() -> Result<(), Box> { + let udt_owner = get_nodes_info("deployer"); let wallets = [ - ("ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqgx5lf4pczpamsfam48evs0c8nvwqqa59qapt46f", h256!("0xcccd5f7e693b60447623fb71a5983f15a426938c33699b1a81d1239cfa656cd1")), - ("ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqt4vqqyehpxn47deg5l6eeqtkfrt5kfkfchkwv62", h256!("0x85af6ff21ea891dbb384b771e02317427e7b66e84b4516c03d74ca4fd5ad0500")), - ("ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqtrnd9f2lh5vlwlj23dedf7jje65cdj8qs7q4awr", h256!("0xd00c06bfd800d27397002dca6fb0993d5ba6399b4238b2f29ee9deb975ffffff")), + get_nodes_info("1"), + get_nodes_info("2"), + get_nodes_info("3"), ]; - init_or_send_udt(udt_owner.0, &udt_owner, None, 1000000000000, true).expect("init udt"); + init_or_send_udt(&udt_owner.0, &udt_owner, None, 1000000000000, true).expect("init udt"); generate_blocks(4).expect("ok"); init_or_send_udt( - udt_owner.0, + &udt_owner.0, &udt_owner, - Some(wallets[0].0), + Some(&wallets[0].0), 200000000000, true, )?; generate_blocks(4).expect("ok"); init_or_send_udt( - udt_owner.0, + &udt_owner.0, &udt_owner, - Some(wallets[1].0), + Some(&wallets[1].0), 200000000000, true, )?; generate_blocks(4).expect("ok"); init_or_send_udt( - udt_owner.0, + &udt_owner.0, &udt_owner, - Some(wallets[2].0), + Some(&wallets[2].0), 200000000000, true, )?; generate_blocks(4).expect("ok"); - check_account(udt_owner.0, udt_owner.0)?; - check_account(wallets[0].0, udt_owner.0)?; - check_account(wallets[1].0, udt_owner.0)?; - check_account(wallets[2].0, udt_owner.0)?; + check_account(&udt_owner.0, &udt_owner.0)?; + check_account(&wallets[0].0, &udt_owner.0)?; + check_account(&wallets[1].0, &udt_owner.0)?; + check_account(&wallets[2].0, &udt_owner.0)?; - let script = generate_udt_type_script(udt_owner.0); + let script = generate_udt_type_script(&udt_owner.0); println!("initialized udt_type_script: {} ...", script); Ok(()) diff --git a/tests/nodes/1/ckb-chain/wallet b/tests/nodes/1/ckb-chain/wallet new file mode 100644 index 000000000..da733ced0 --- /dev/null +++ b/tests/nodes/1/ckb-chain/wallet @@ -0,0 +1 @@ +ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqgx5lf4pczpamsfam48evs0c8nvwqqa59qapt46f \ No newline at end of file diff --git a/tests/nodes/2/ckb-chain/key b/tests/nodes/2/ckb-chain/key index 98c013f65..648167695 100644 --- a/tests/nodes/2/ckb-chain/key +++ b/tests/nodes/2/ckb-chain/key @@ -1 +1 @@ -85af6ff21ea891dbb384b771e02317427e7b66e84b4516c03d74ca4fd5ad0500 +85af6ff21ea891dbb384b771e02317427e7b66e84b4516c03d74ca4fd5ad0500 \ No newline at end of file diff --git a/tests/nodes/2/ckb-chain/wallet b/tests/nodes/2/ckb-chain/wallet new file mode 100644 index 000000000..23badbbf5 --- /dev/null +++ b/tests/nodes/2/ckb-chain/wallet @@ -0,0 +1 @@ +ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqt4vqqyehpxn47deg5l6eeqtkfrt5kfkfchkwv62 \ No newline at end of file diff --git a/tests/nodes/3/ckb-chain/wallet b/tests/nodes/3/ckb-chain/wallet new file mode 100644 index 000000000..259dfe1d4 --- /dev/null +++ b/tests/nodes/3/ckb-chain/wallet @@ -0,0 +1 @@ +ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqtrnd9f2lh5vlwlj23dedf7jje65cdj8qs7q4awr \ No newline at end of file diff --git a/tests/nodes/deployer/ckb-chain/wallet b/tests/nodes/deployer/ckb-chain/wallet new file mode 100644 index 000000000..4328eb148 --- /dev/null +++ b/tests/nodes/deployer/ckb-chain/wallet @@ -0,0 +1 @@ +ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqwgx292hnvmn68xf779vmzrshpmm6epn4c0cgwga \ No newline at end of file