diff --git a/crates/rooch-framework-tests/tests/cases/account_storage/exists_and_move_from.exp b/crates/rooch-framework-tests/tests/cases/account_storage/exists_and_move_from.exp new file mode 100644 index 000000000..45fae8392 --- /dev/null +++ b/crates/rooch-framework-tests/tests/cases/account_storage/exists_and_move_from.exp @@ -0,0 +1,7 @@ +processed 3 tasks + +task 1 'publish'. lines 3-34: +status EXECUTED + +task 2 'run'. lines 36-44: +status EXECUTED diff --git a/crates/rooch-framework-tests/tests/cases/account_storage/exists_and_move_from.move b/crates/rooch-framework-tests/tests/cases/account_storage/exists_and_move_from.move new file mode 100644 index 000000000..861d0a061 --- /dev/null +++ b/crates/rooch-framework-tests/tests/cases/account_storage/exists_and_move_from.move @@ -0,0 +1,44 @@ +//# init --addresses test=0x42 + +//# publish +module test::m { + use std::signer; + use moveos_std::storage_context::{StorageContext}; + use moveos_std::account_storage; + + struct Test has key{ + addr: address, + version: u64 + } + + fun init(ctx: &mut StorageContext, sender: &signer) { + let sender_addr = signer::address_of(sender); + account_storage::global_move_to(ctx, sender, Test{ + addr: sender_addr, + version: 0, + }); + } + + public fun test_exists_and_move_from(ctx: &mut StorageContext, sender:&signer){ + let sender_addr = signer::address_of(sender); + let test_exists = account_storage::global_exists(ctx, sender_addr); + assert!(test_exists, 1); + let test = account_storage::global_move_from(ctx, sender_addr); + let test_exists = account_storage::global_exists(ctx, sender_addr); + assert!(!test_exists, 2); + let Test{ + addr: _, + version: _ + } = test; + } +} + +//# run --signers test +script { + use moveos_std::storage_context::{StorageContext}; + use test::m; + + fun main(ctx: &mut StorageContext, sender: signer) { + m::test_exists_and_move_from(ctx, &sender); + } +} diff --git a/crates/rooch-framework-tests/tests/cases/account_storage/basic.exp b/crates/rooch-framework-tests/tests/cases/account_storage/module_exists.exp similarity index 100% rename from crates/rooch-framework-tests/tests/cases/account_storage/basic.exp rename to crates/rooch-framework-tests/tests/cases/account_storage/module_exists.exp diff --git a/crates/rooch-framework-tests/tests/cases/account_storage/basic.move b/crates/rooch-framework-tests/tests/cases/account_storage/module_exists.move similarity index 100% rename from crates/rooch-framework-tests/tests/cases/account_storage/basic.move rename to crates/rooch-framework-tests/tests/cases/account_storage/module_exists.move diff --git a/examples/complex_struct/sources/complex_struct.move b/examples/complex_struct/sources/complex_struct.move index 9c87688d1..a5cea1644 100644 --- a/examples/complex_struct/sources/complex_struct.move +++ b/examples/complex_struct/sources/complex_struct.move @@ -107,16 +107,6 @@ module rooch_examples::complex_struct { fun init(ctx: &mut StorageContext, sender: signer) { let addr = signer::address_of(&sender); - //When we try to re publish the modules, the `ComplexStruct` already inited - //so we need to remove it first. - //There some bugs in the global_exists| global_move_from | global_move_to - //Seam like the VM think the resource after move_from still exists. - //FIXME - // if (account_storage::global_exists(ctx, addr)){ - // let old_struct = account_storage::global_move_from(ctx, addr); - // drop(old_struct); - // }; - let object_id = { let tx_ctx = storage_context::tx_context_mut(ctx); tx_context::fresh_object_id(tx_ctx) diff --git a/moveos/moveos-stdlib/move-stdlib/doc/error.md b/moveos/moveos-stdlib/move-stdlib/doc/error.md index 991ffee53..eb2890523 100644 --- a/moveos/moveos-stdlib/move-stdlib/doc/error.md +++ b/moveos/moveos-stdlib/move-stdlib/doc/error.md @@ -198,7 +198,7 @@ Construct a canonical error code from a category and a reason.
public fun canonical(category: u64, reason: u64): u64 {
-  (category * 10000) + reason
+  (category << 16) + reason
 }
 
diff --git a/moveos/moveos-stdlib/moveos-stdlib/sources/account_storage.move b/moveos/moveos-stdlib/moveos-stdlib/sources/account_storage.move index 347ea3e2b..44d8ed803 100644 --- a/moveos/moveos-stdlib/moveos-stdlib/sources/account_storage.move +++ b/moveos/moveos-stdlib/moveos-stdlib/sources/account_storage.move @@ -354,4 +354,26 @@ module moveos_std::account_storage { assert!(exist_account_storage(&ctx , sender_addr), 1); storage_context::drop_test_context(ctx); } + + #[test(sender=@0x42)] + fun test_ensure_move_from_and_exists(sender: signer){ + let sender_addr = signer::address_of(&sender); + let ctx = storage_context::new_test_context(sender_addr); + let test_exists = global_exists(&ctx, sender_addr); + assert!(!test_exists, 1); + global_move_to(&mut ctx, &sender, Test{ + addr: sender_addr, + version: 1, + }); + let test_exists = global_exists(&ctx, sender_addr); + assert!(test_exists, 2); + let test = global_move_from(&mut ctx, sender_addr); + let test_exists = global_exists(&ctx, sender_addr); + assert!(!test_exists, 3); + let Test{ + addr: _, + version: _ + } = test; + storage_context::drop_test_context(ctx); + } } \ No newline at end of file