diff --git a/.github/workflows/devnet.yaml b/.github/workflows/devnet.yaml index 9abcb3c..897ce6a 100644 --- a/.github/workflows/devnet.yaml +++ b/.github/workflows/devnet.yaml @@ -76,6 +76,7 @@ jobs: env: VITE_ACCOUNT_CHARLIE: ${{ secrets.ACCOUNT_CHARLIE }} VITE_ACCOUNT_ALICE: ${{ secrets.ACCOUNT_ALICE }} + VITE_ACCOUNT_BOB: ${{ secrets.ACCOUNT_BOB }} - name: Prepare spore-sdk working-directory: spore-sdk @@ -87,4 +88,5 @@ jobs: env: VITE_ACCOUNT_CHARLIE: ${{ secrets.ACCOUNT_CHARLIE }} VITE_ACCOUNT_ALICE: ${{ secrets.ACCOUNT_ALICE }} + VITE_ACCOUNT_BOB: ${{ secrets.ACCOUNT_BOB }} VITE_NETWORK: devnet diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..8e619a4 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "rust-analyzer.showUnlinkedFileNotification": false +} diff --git a/Cargo.lock b/Cargo.lock index 84cd821..602b25a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -26,12 +26,9 @@ checksum = "1f0d2da64a6a895d5a7e0724882825d50f83c13396b1b9f1878e19a024bab395" [[package]] name = "cc" -version = "1.0.83" +version = "1.0.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0" -dependencies = [ - "libc", -] +checksum = "2678b2e3449475e95b0aa6f9b506a28e61b3dc8996592b983695e8ebb58a8b41" [[package]] name = "cfg-if" @@ -84,7 +81,7 @@ dependencies = [ [[package]] name = "ckb-transaction-cobuild" version = "0.1.0" -source = "git+https://github.com/cryptape/ckb-transaction-cobuild-poc?rev=bdb0c74#bdb0c745a76c1aa349a0e881ad4ccdd4af286723" +source = "git+https://github.com/cryptape/ckb-transaction-cobuild-poc?rev=e29514f#bdb0c745a76c1aa349a0e881ad4ccdd4af286723" dependencies = [ "blake2b-ref", "ckb-gen-types", @@ -175,12 +172,6 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "131bddab59a64213cc1e9f0c5be010d7eb485951358ab7e52017888dec482028" -[[package]] -name = "libc" -version = "0.2.151" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "302d7ab3130588088d277783b1e2d2e10c9e9e4a16dd9050e6ec93fb3e7048f4" - [[package]] name = "memchr" version = "2.7.1" diff --git a/contracts/spore/Cargo.toml b/contracts/spore/Cargo.toml index d85096a..8340638 100644 --- a/contracts/spore/Cargo.toml +++ b/contracts/spore/Cargo.toml @@ -12,7 +12,7 @@ spore-types = { path = "../../lib/types" } spore-utils = { path = "../../lib/utils" } spore-errors = { path = "../../lib/errors" } kmp = { version = "0.1.1" } -ckb-transaction-cobuild = { git = "https://github.com/cryptape/ckb-transaction-cobuild-poc", rev = "bdb0c74" } +ckb-transaction-cobuild = { git = "https://github.com/cryptape/ckb-transaction-cobuild-poc", rev = "e29514f" } [build-dependencies] ckb-hash = "0.112.1" diff --git a/lib/utils/Cargo.toml b/lib/utils/Cargo.toml index c7cd0a1..3ac639c 100644 --- a/lib/utils/Cargo.toml +++ b/lib/utils/Cargo.toml @@ -9,4 +9,4 @@ edition = "2021" ckb-std = "0.14.0" spore-types = { path = "../types" } spore-errors = { path = "../errors" } -ckb-transaction-cobuild = { git = "https://github.com/cryptape/ckb-transaction-cobuild-poc", rev = "bdb0c74" } +ckb-transaction-cobuild = { git = "https://github.com/cryptape/ckb-transaction-cobuild-poc", rev = "e29514f" } diff --git a/tests/Cargo.lock b/tests/Cargo.lock index 5d46b9c..937145d 100644 --- a/tests/Cargo.lock +++ b/tests/Cargo.lock @@ -560,7 +560,7 @@ dependencies = [ [[package]] name = "ckb-transaction-cobuild" version = "0.1.0" -source = "git+https://github.com/cryptape/ckb-transaction-cobuild-poc?rev=bdb0c74#bdb0c745a76c1aa349a0e881ad4ccdd4af286723" +source = "git+https://github.com/cryptape/ckb-transaction-cobuild-poc?rev=e29514f#bdb0c745a76c1aa349a0e881ad4ccdd4af286723" dependencies = [ "blake2b-ref", "ckb-gen-types", diff --git a/tests/Cargo.toml b/tests/Cargo.toml index eedc990..f0ecc97 100644 --- a/tests/Cargo.toml +++ b/tests/Cargo.toml @@ -6,7 +6,7 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -ckb-testtool = "0.10.0" +ckb-testtool = "=0.10.0" ckb-sdk = "3.0.1" hex = { version = "0.4.3" } serde_json = "1.0" diff --git a/tests/src/tests/mutant.rs b/tests/src/tests/mutant.rs index 43b645d..80ce040 100644 --- a/tests/src/tests/mutant.rs +++ b/tests/src/tests/mutant.rs @@ -47,13 +47,15 @@ fn test_simple_mutant_mint() { fn test_simple_mutant_spore_mint_without_cluster() { let mut context = Context::default(); - let lua_code = "print('hello world')"; + let lua_code = "print('hello world with spore_ext_mode = ' .. spore_ext_mode)"; let (tx, mutant_id) = build_single_mutant_celldep_tx(&mut context, lua_code, 1); + let normal_input = build_normal_input(&mut context); println!("mutant_id: {mutant_id:?}"); - let content_type = format!("plain/test;mutant[]={}", hex::encode(mutant_id)); - let (output_data, normal_input, spore_output, spore_celldep) = build_spore_output_materials( + let content_type = format!("plain/text;mutant[]={}", hex::encode(mutant_id)); + let (output_data, spore_output, spore_celldep) = build_spore_output_materials( &mut context, + &normal_input, "mutant spore".as_bytes().to_vec(), &content_type, 0, @@ -73,3 +75,71 @@ fn test_simple_mutant_spore_mint_without_cluster() { .verify_tx(&tx, MAX_CYCLES) .expect("test mint mutant spore cell (no cluster)"); } + +#[test] +fn test_simple_mutant_spore_transfer() { + let mut context = Context::default(); + + let lua_code = "print('hello world with spore_ext_mode = ' .. spore_ext_mode)"; + let (tx, mutant_id) = build_single_mutant_celldep_tx(&mut context, lua_code, 1); + let normal_input = &build_normal_input(&mut context); + + let content_type = format!("plain/text;mutant[]={}", hex::encode(mutant_id)); + let content = "mutant spore".as_bytes().to_vec(); + + // build spore in output + let (output_data, spore_output, spore_celldep) = build_spore_output_materials( + &mut context, + &normal_input, + content.clone(), + &content_type, + 0, + None, + ); + + // build spore in input + let (_, spore_input, _) = + build_spore_input_materials(&mut context, &normal_input, content, &content_type, 0, None); + + // build tx + let tx = tx + .as_advanced_builder() + .input(spore_input) + .output(spore_output) + .output_data(output_data.as_bytes().pack()) + .cell_dep(spore_celldep) + .build(); + let tx = context.complete_tx(tx); + + context + .verify_tx(&tx, MAX_CYCLES) + .expect("test transfer mutant spore cell"); +} + +#[test] +fn test_simple_mutant_spore_burn() { + let mut context = Context::default(); + + let lua_code = "print('hello world with spore_ext_mode = ' .. spore_ext_mode)"; + let (tx, mutant_id) = build_single_mutant_celldep_tx(&mut context, lua_code, 1); + let normal_input = &build_normal_input(&mut context); + + let content_type = format!("plain/text;mutant[]={}", hex::encode(mutant_id)); + let content = "mutant spore".as_bytes().to_vec(); + + // build spore in input + let (_, spore_input, spore_celldep) = + build_spore_input_materials(&mut context, &normal_input, content, &content_type, 0, None); + + // build tx + let tx = tx + .as_advanced_builder() + .input(spore_input) + .cell_dep(spore_celldep) + .build(); + let tx = context.complete_tx(tx); + + context + .verify_tx(&tx, MAX_CYCLES) + .expect("test burn mutant spore cell"); +} diff --git a/tests/src/utils/mod.rs b/tests/src/utils/mod.rs index fe01cc1..fa1c174 100644 --- a/tests/src/utils/mod.rs +++ b/tests/src/utils/mod.rs @@ -211,21 +211,38 @@ pub fn build_agent_materials( pub fn build_spore_output_materials( context: &mut Context, + normal_input: &CellInput, content: Vec, content_type: &str, out_index: usize, cluster_id: Option<[u8; 32]>, -) -> (SporeData, CellInput, CellOutput, CellDep) { +) -> (SporeData, CellOutput, CellDep) { let (spore_out_point, spore_script_dep) = build_spore_contract_materials(context, "spore"); let output_data = build_serialized_spore_data(content, content_type, cluster_id.map(|v| v.to_vec())); - let normal_input = build_normal_input(context); - let type_id = build_type_id(&normal_input, out_index); + let type_id = build_type_id(normal_input, out_index); let spore_type = build_spore_type_script(context, &spore_out_point, type_id.to_vec().into()); let spore_output = build_normal_output_cell_with_type(context, spore_type.clone()); - (output_data, normal_input, spore_output, spore_script_dep) + (output_data, spore_output, spore_script_dep) +} + +pub fn build_spore_input_materials( + context: &mut Context, + normal_input: &CellInput, + content: Vec, + content_type: &str, + out_index: usize, + cluster_id: Option<[u8; 32]>, +) -> (SporeData, CellInput, CellDep) { + let (spore_out_point, spore_script_dep) = build_spore_contract_materials(context, "spore"); + let type_id = build_type_id(&normal_input, out_index); + let spore_data = + build_serialized_spore_data(content, &content_type, cluster_id.map(|v| v.to_vec())); + let spore_type = build_spore_type_script(context, &spore_out_point, type_id.to_vec().into()); + let spore_input = build_spore_input(context, spore_type.clone(), spore_data.clone()); + (spore_data, spore_input, spore_script_dep) } pub fn build_single_spore_mint_tx_with_extra_action(