Skip to content

Commit

Permalink
add test for pemanent area and bitcoin plants
Browse files Browse the repository at this point in the history
  • Loading branch information
pause125 committed Apr 23, 2024
1 parent 1655ece commit 2f79837
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 15 deletions.
7 changes: 5 additions & 2 deletions examples/bitcoin_plants/sources/plants.move
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ module bitcoin_plants::plants {

// Check if the Inscription is already planted
assert!(!ord::contains_permanent_state<Plant>(seed), ErrorAlreadyPlanted);

// TODO: init the Plant from seed attributes
let plant = Plant {
variety: 0,
Expand Down Expand Up @@ -162,8 +161,12 @@ module bitcoin_plants::plants {
#[test_only]
use std::option;

#[test_only]
use rooch_framework::genesis;

#[test]
fun test() {
genesis::init_for_test();
let inscription_obj = ord::new_inscription_object_for_test(
@0x3232423,
0,
Expand Down Expand Up @@ -195,7 +198,7 @@ module bitcoin_plants::plants {

let plant = ord::remove_permanent_state<Plant>(&mut inscription_obj);
let Plant { variety: _, growth_value: _, health: _, last_watering_time: _, pickable_fruits: _, picked_fruits: _ } = plant;

ord::destroy_permanent_area(&mut inscription_obj);
ord::drop_inscription_object_for_test(inscription_obj);
}
}
12 changes: 0 additions & 12 deletions frameworks/bitcoin-move/doc/utxo.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
- [Resource `BitcoinUTXOStore`](#0x4_utxo_BitcoinUTXOStore)
- [Struct `CreatingUTXOEvent`](#0x4_utxo_CreatingUTXOEvent)
- [Struct `RemovingUTXOEvent`](#0x4_utxo_RemovingUTXOEvent)
- [Struct `TempState`](#0x4_utxo_TempState)
- [Constants](#@Constants_0)
- [Function `genesis_init`](#0x4_utxo_genesis_init)
- [Function `borrow_utxo_store`](#0x4_utxo_borrow_utxo_store)
Expand Down Expand Up @@ -110,17 +109,6 @@ Event for remove UTXO



<a name="0x4_utxo_TempState"></a>

## Struct `TempState`



<pre><code><b>struct</b> <a href="utxo.md#0x4_utxo_TempState">TempState</a> <b>has</b> <b>copy</b>, drop, store
</code></pre>



<a name="@Constants_0"></a>

## Constants
Expand Down
47 changes: 46 additions & 1 deletion frameworks/bitcoin-move/sources/ord.move
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module bitcoin_move::ord {
use moveos_std::json;
use moveos_std::table_vec::{Self, TableVec};
use moveos_std::type_info;
use moveos_std::bag;
use moveos_std::bag::{Self, Bag};
use rooch_framework::address_mapping;
use rooch_framework::multichain_address;
use rooch_framework::bitcoin_address::BitcoinAddress;
Expand Down Expand Up @@ -668,6 +668,13 @@ module bitcoin_move::ord {
bag::remove(bag, name)
}

// TODO: remove #[test_only]?
#[test_only]
public fun destroy_permanent_area(inscription: &mut Object<Inscription>){
let bag: Bag = object::remove_field(inscription, PERMANENT_AREA);
bag::destroy_empty(bag);
}

#[test_only]
public fun new_inscription_object_for_test(
txid: address,
Expand Down Expand Up @@ -716,4 +723,42 @@ module bitcoin_move::ord {
pointer: _,
} = inscription;
}

#[test_only]
struct PermanentState has store {
value: u64,
}

#[test]
fun test_permanent_state(){
// genesis_init();
let txid = @0x77dfc2fe598419b00641c296181a96cf16943697f573480b023b77cce82ada21;
let inscription_obj = new_inscription_object_for_test(
txid,
0,
0,
0,
vector[],
option::none(),
option::none(),
vector[],
option::none(),
option::none(),
option::none(),
);
add_permanent_state(&mut inscription_obj, PermanentState{value: 10});
assert!(contains_permanent_state<PermanentState>(&inscription_obj), 1);
assert!(borrow_permanent_state<PermanentState>(&inscription_obj).value == 10, 2);
{
let state = borrow_mut_permanent_state<PermanentState>(&mut inscription_obj);
state.value = 20;
};
let state = remove_permanent_state<PermanentState>(&mut inscription_obj);
assert!(state.value == 20, 1);
assert!(!contains_permanent_state<PermanentState>(&inscription_obj), 3);

let PermanentState { value: _ } = state;
destroy_permanent_area(&mut inscription_obj);
drop_inscription_object_for_test(inscription_obj);
}
}
1 change: 1 addition & 0 deletions frameworks/bitcoin-move/sources/utxo.move
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ module bitcoin_move::utxo{
simple_multimap::drop(seals);
}

#[test_only]
struct TempState has store, copy, drop {
value: u64,
}
Expand Down

0 comments on commit 2f79837

Please sign in to comment.