Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/devnet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"rust-analyzer.showUnlinkedFileNotification": false
}
15 changes: 3 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion contracts/spore/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
2 changes: 1 addition & 1 deletion tests/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
76 changes: 73 additions & 3 deletions tests/src/tests/mutant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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");
}
25 changes: 21 additions & 4 deletions tests/src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,21 +211,38 @@ pub fn build_agent_materials(

pub fn build_spore_output_materials(
context: &mut Context,
normal_input: &CellInput,
content: Vec<u8>,
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<u8>,
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(
Expand Down