diff --git a/Cargo.toml b/Cargo.toml index 2398c9e5..5517c982 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -106,35 +106,35 @@ triomphe = "0.1.9" # Note: the BEGIN and END comments below are required for external tooling. Do not remove. # BEGIN MOVE DEPENDENCIES -# move-abigen = { git = "https://github.com/initia-labs/move.git", rev = "f9e116fbfd9c4c5eaa4b39ee5da83715f0c99367" } -# move-bytecode-utils = { git = "https://github.com/initia-labs/move.git", rev = "f9e116fbfd9c4c5eaa4b39ee5da83715f0c99367" } -# move-errmapgen = { git = "https://github.com/initia-labs/move.git", rev = "f9e116fbfd9c4c5eaa4b39ee5da83715f0c99367" } -# move-ir-compiler = { git = "https://github.com/initia-labs/move.git", rev = "f9e116fbfd9c4c5eaa4b39ee5da83715f0c99367" } -# move-prover-test-utils = { git = "https://github.com/initia-labs/move.git", rev = "f9e116fbfd9c4c5eaa4b39ee5da83715f0c99367" } -# move-stackless-bytecode-interpreter = { git = "https://github.com/initia-labs/move.git", rev = "f9e116fbfd9c4c5eaa4b39ee5da83715f0c99367" } -# move-transactional-test-runner = { git = "https://github.com/initia-labs/move.git", rev = "f9e116fbfd9c4c5eaa4b39ee5da83715f0c99367" } -# read-write-set = { git = "https://github.com/initia-labs/move.git", rev = "f9e116fbfd9c4c5eaa4b39ee5da83715f0c99367" } -# read-write-set-dynamic = { git = "https://github.com/initia-labs/move.git", rev = "f9e116fbfd9c4c5eaa4b39ee5da83715f0c99367" } -move-binary-format = { git = "https://github.com/initia-labs/move.git", rev = "f9e116fbfd9c4c5eaa4b39ee5da83715f0c99367" } -move-bytecode-verifier = { git = "https://github.com/initia-labs/move.git", rev = "f9e116fbfd9c4c5eaa4b39ee5da83715f0c99367" } -move-cli = { git = "https://github.com/initia-labs/move.git", rev = "f9e116fbfd9c4c5eaa4b39ee5da83715f0c99367" } -move-command-line-common = { git = "https://github.com/initia-labs/move.git", rev = "f9e116fbfd9c4c5eaa4b39ee5da83715f0c99367" } -move-compiler = { git = "https://github.com/initia-labs/move.git", rev = "f9e116fbfd9c4c5eaa4b39ee5da83715f0c99367" } -move-core-types = { git = "https://github.com/initia-labs/move.git", rev = "f9e116fbfd9c4c5eaa4b39ee5da83715f0c99367" } -move-docgen = { git = "https://github.com/initia-labs/move.git", rev = "f9e116fbfd9c4c5eaa4b39ee5da83715f0c99367" } -move-model = { git = "https://github.com/initia-labs/move.git", rev = "f9e116fbfd9c4c5eaa4b39ee5da83715f0c99367" } -move-package = { git = "https://github.com/initia-labs/move.git", rev = "f9e116fbfd9c4c5eaa4b39ee5da83715f0c99367" } -move-prover = { git = "https://github.com/initia-labs/move.git", rev = "f9e116fbfd9c4c5eaa4b39ee5da83715f0c99367" } -move-prover-boogie-backend = { git = "https://github.com/initia-labs/move.git", rev = "f9e116fbfd9c4c5eaa4b39ee5da83715f0c99367" } -move-prover-bytecode-pipeline = { git = "https://github.com/initia-labs/move.git", rev = "f9e116fbfd9c4c5eaa4b39ee5da83715f0c99367" } -move-resource-viewer = { git = "https://github.com/initia-labs/move.git", rev = "f9e116fbfd9c4c5eaa4b39ee5da83715f0c99367" } -move-stackless-bytecode = { git = "https://github.com/initia-labs/move.git", rev = "f9e116fbfd9c4c5eaa4b39ee5da83715f0c99367" } -move-stdlib = { git = "https://github.com/initia-labs/move.git", rev = "f9e116fbfd9c4c5eaa4b39ee5da83715f0c99367" } -move-symbol-pool = { git = "https://github.com/initia-labs/move.git", rev = "f9e116fbfd9c4c5eaa4b39ee5da83715f0c99367" } -move-unit-test = { git = "https://github.com/initia-labs/move.git", rev = "f9e116fbfd9c4c5eaa4b39ee5da83715f0c99367" } -move-vm-runtime = { git = "https://github.com/initia-labs/move.git", rev = "f9e116fbfd9c4c5eaa4b39ee5da83715f0c99367" } -move-vm-test-utils = { git = "https://github.com/initia-labs/move.git", rev = "f9e116fbfd9c4c5eaa4b39ee5da83715f0c99367" } -move-vm-types = { git = "https://github.com/initia-labs/move.git", rev = "f9e116fbfd9c4c5eaa4b39ee5da83715f0c99367" } +# move-abigen = { git = "https://github.com/initia-labs/move.git", rev = "2b55388a528d222ae93b24672e15424d445d7b9e" } +# move-bytecode-utils = { git = "https://github.com/initia-labs/move.git", rev = "2b55388a528d222ae93b24672e15424d445d7b9e" } +# move-errmapgen = { git = "https://github.com/initia-labs/move.git", rev = "2b55388a528d222ae93b24672e15424d445d7b9e" } +# move-ir-compiler = { git = "https://github.com/initia-labs/move.git", rev = "2b55388a528d222ae93b24672e15424d445d7b9e" } +# move-prover-test-utils = { git = "https://github.com/initia-labs/move.git", rev = "2b55388a528d222ae93b24672e15424d445d7b9e" } +# move-stackless-bytecode-interpreter = { git = "https://github.com/initia-labs/move.git", rev = "2b55388a528d222ae93b24672e15424d445d7b9e" } +# move-transactional-test-runner = { git = "https://github.com/initia-labs/move.git", rev = "2b55388a528d222ae93b24672e15424d445d7b9e" } +# read-write-set = { git = "https://github.com/initia-labs/move.git", rev = "2b55388a528d222ae93b24672e15424d445d7b9e" } +# read-write-set-dynamic = { git = "https://github.com/initia-labs/move.git", rev = "2b55388a528d222ae93b24672e15424d445d7b9e" } +move-binary-format = { git = "https://github.com/initia-labs/move.git", rev = "2b55388a528d222ae93b24672e15424d445d7b9e" } +move-bytecode-verifier = { git = "https://github.com/initia-labs/move.git", rev = "2b55388a528d222ae93b24672e15424d445d7b9e" } +move-cli = { git = "https://github.com/initia-labs/move.git", rev = "2b55388a528d222ae93b24672e15424d445d7b9e" } +move-command-line-common = { git = "https://github.com/initia-labs/move.git", rev = "2b55388a528d222ae93b24672e15424d445d7b9e" } +move-compiler = { git = "https://github.com/initia-labs/move.git", rev = "2b55388a528d222ae93b24672e15424d445d7b9e" } +move-core-types = { git = "https://github.com/initia-labs/move.git", rev = "2b55388a528d222ae93b24672e15424d445d7b9e" } +move-docgen = { git = "https://github.com/initia-labs/move.git", rev = "2b55388a528d222ae93b24672e15424d445d7b9e" } +move-model = { git = "https://github.com/initia-labs/move.git", rev = "2b55388a528d222ae93b24672e15424d445d7b9e" } +move-package = { git = "https://github.com/initia-labs/move.git", rev = "2b55388a528d222ae93b24672e15424d445d7b9e" } +move-prover = { git = "https://github.com/initia-labs/move.git", rev = "2b55388a528d222ae93b24672e15424d445d7b9e" } +move-prover-boogie-backend = { git = "https://github.com/initia-labs/move.git", rev = "2b55388a528d222ae93b24672e15424d445d7b9e" } +move-prover-bytecode-pipeline = { git = "https://github.com/initia-labs/move.git", rev = "2b55388a528d222ae93b24672e15424d445d7b9e" } +move-resource-viewer = { git = "https://github.com/initia-labs/move.git", rev = "2b55388a528d222ae93b24672e15424d445d7b9e" } +move-stackless-bytecode = { git = "https://github.com/initia-labs/move.git", rev = "2b55388a528d222ae93b24672e15424d445d7b9e" } +move-stdlib = { git = "https://github.com/initia-labs/move.git", rev = "2b55388a528d222ae93b24672e15424d445d7b9e" } +move-symbol-pool = { git = "https://github.com/initia-labs/move.git", rev = "2b55388a528d222ae93b24672e15424d445d7b9e" } +move-unit-test = { git = "https://github.com/initia-labs/move.git", rev = "2b55388a528d222ae93b24672e15424d445d7b9e" } +move-vm-runtime = { git = "https://github.com/initia-labs/move.git", rev = "2b55388a528d222ae93b24672e15424d445d7b9e" } +move-vm-test-utils = { git = "https://github.com/initia-labs/move.git", rev = "2b55388a528d222ae93b24672e15424d445d7b9e" } +move-vm-types = { git = "https://github.com/initia-labs/move.git", rev = "2b55388a528d222ae93b24672e15424d445d7b9e" } # END MOVE DEPENDENCIES diff --git a/crates/e2e-move-tests/src/tests/table.data/pack/sources/TableTestData.move b/crates/e2e-move-tests/src/tests/table.data/pack/sources/TableTestData.move index d3daba79..682ebc90 100644 --- a/crates/e2e-move-tests/src/tests/table.data/pack/sources/TableTestData.move +++ b/crates/e2e-move-tests/src/tests/table.data/pack/sources/TableTestData.move @@ -49,8 +49,8 @@ module 0x2::TableTestData { let keys = vector::empty(); let vals = vector::empty(); - while(T::prepare(&mut iter)) { - let (key, value) = T::next(&mut iter); + while(T::prepare(iter)) { + let (key, value) = T::next(iter); vector::push_back(&mut keys, key); vector::push_back(&mut vals, *value); @@ -83,27 +83,27 @@ module 0x2::TableTestData { let i = 1; while(i < 11) { - assert!(T::prepare(&mut iter), 101); - let (key, value) = T::next(&mut iter); + assert!(T::prepare(iter), 101); + let (key, value) = T::next(iter); assert!(key == i, 101); assert!(value == &i, 101); i = i + 1; }; - assert!(!T::prepare(&mut iter), 101); + assert!(!T::prepare(iter), 101); let iter = T::iter(t_ref, option::some(2), option::some(5), 1); let i = 2; while(i < 5) { - assert!(T::prepare(&mut iter), 102); - let (key, value) = T::next(&mut iter); + assert!(T::prepare(iter), 102); + let (key, value) = T::next(iter); assert!(key == i, 102); assert!(value == &i, 102); i = i + 1; }; - assert!(!T::prepare(&mut iter), 102); + assert!(!T::prepare(iter), 102); } public entry fun iterate_descending(acc: address) acquires S { @@ -113,26 +113,26 @@ module 0x2::TableTestData { let i = 10; while(i > 0) { - assert!(T::prepare(&mut iter), 101); - let (key, value) = T::next(&mut iter); + assert!(T::prepare(iter), 101); + let (key, value) = T::next(iter); assert!(key == i, 101); assert!(value == &i, 101); i = i - 1; }; - assert!(!T::prepare(&mut iter), 101); + assert!(!T::prepare(iter), 101); let iter = T::iter(t_ref, option::some(2), option::some(5), 2); let i = 4; while(i > 1) { - assert!(T::prepare(&mut iter), 102); - let (key, value) = T::next(&mut iter); + assert!(T::prepare(iter), 102); + let (key, value) = T::next(iter); assert!(key == i, 102); assert!(value == &i, 102); i = i - 1; }; - assert!(!T::prepare(&mut iter), 102); + assert!(!T::prepare(iter), 102); } } diff --git a/crates/natives/src/table.rs b/crates/natives/src/table.rs index e4f4ce46..0275e68e 100644 --- a/crates/natives/src/table.rs +++ b/crates/natives/src/table.rs @@ -620,7 +620,7 @@ fn native_new_table_iter( order, }); - Ok(smallvec![Value::u64(context_iterator_id as u64)]) + Ok(smallvec![Value::iter_reference(context_iterator_id as u64)]) } /// Check the `next_key` exist or not and store @@ -683,9 +683,10 @@ fn native_next_box( let table_context = context.extensions().get::(); let mut iterators = table_context.iterators.borrow_mut(); let iterator = iterators.get_mut(iterator_id).unwrap(); - let (key, value) = iterator.next.take().ok_or_else(|| { - partial_extension_error("next_box called without prepare_box") - })?; + let (key, value) = iterator + .next + .take() + .ok_or_else(|| partial_extension_error("next_box called without prepare_box"))?; iterator.next = None; diff --git a/precompile/binaries/minlib/collection.mv b/precompile/binaries/minlib/collection.mv index b8034094..85dc856e 100644 Binary files a/precompile/binaries/minlib/collection.mv and b/precompile/binaries/minlib/collection.mv differ diff --git a/precompile/binaries/minlib/dex.mv b/precompile/binaries/minlib/dex.mv index 7b3fe819..a9dd6325 100644 Binary files a/precompile/binaries/minlib/dex.mv and b/precompile/binaries/minlib/dex.mv differ diff --git a/precompile/binaries/minlib/multisig.mv b/precompile/binaries/minlib/multisig.mv index 3fe247dd..712167ba 100644 Binary files a/precompile/binaries/minlib/multisig.mv and b/precompile/binaries/minlib/multisig.mv differ diff --git a/precompile/binaries/minlib/primary_fungible_store.mv b/precompile/binaries/minlib/primary_fungible_store.mv index bfef4e41..b6e049ad 100644 Binary files a/precompile/binaries/minlib/primary_fungible_store.mv and b/precompile/binaries/minlib/primary_fungible_store.mv differ diff --git a/precompile/binaries/minlib/table.mv b/precompile/binaries/minlib/table.mv index 7d25c8cd..43827596 100644 Binary files a/precompile/binaries/minlib/table.mv and b/precompile/binaries/minlib/table.mv differ diff --git a/precompile/binaries/stdlib/collection.mv b/precompile/binaries/stdlib/collection.mv index b8034094..85dc856e 100644 Binary files a/precompile/binaries/stdlib/collection.mv and b/precompile/binaries/stdlib/collection.mv differ diff --git a/precompile/binaries/stdlib/dex.mv b/precompile/binaries/stdlib/dex.mv index cf01e356..a9dd6325 100644 Binary files a/precompile/binaries/stdlib/dex.mv and b/precompile/binaries/stdlib/dex.mv differ diff --git a/precompile/binaries/stdlib/multisig.mv b/precompile/binaries/stdlib/multisig.mv index 3fe247dd..712167ba 100644 Binary files a/precompile/binaries/stdlib/multisig.mv and b/precompile/binaries/stdlib/multisig.mv differ diff --git a/precompile/binaries/stdlib/primary_fungible_store.mv b/precompile/binaries/stdlib/primary_fungible_store.mv index bfef4e41..b6e049ad 100644 Binary files a/precompile/binaries/stdlib/primary_fungible_store.mv and b/precompile/binaries/stdlib/primary_fungible_store.mv differ diff --git a/precompile/binaries/stdlib/stableswap.mv b/precompile/binaries/stdlib/stableswap.mv index 819a8566..8b5877fd 100644 Binary files a/precompile/binaries/stdlib/stableswap.mv and b/precompile/binaries/stdlib/stableswap.mv differ diff --git a/precompile/binaries/stdlib/staking.mv b/precompile/binaries/stdlib/staking.mv index 543496a9..9b3177cc 100644 Binary files a/precompile/binaries/stdlib/staking.mv and b/precompile/binaries/stdlib/staking.mv differ diff --git a/precompile/binaries/stdlib/table.mv b/precompile/binaries/stdlib/table.mv index 7d25c8cd..43827596 100644 Binary files a/precompile/binaries/stdlib/table.mv and b/precompile/binaries/stdlib/table.mv differ diff --git a/precompile/binaries/stdlib/vip.mv b/precompile/binaries/stdlib/vip.mv index f7d9d360..1a9acabd 100644 Binary files a/precompile/binaries/stdlib/vip.mv and b/precompile/binaries/stdlib/vip.mv differ diff --git a/precompile/binaries/stdlib/vip_vesting.mv b/precompile/binaries/stdlib/vip_vesting.mv index 2d62ecf7..fbc6aae1 100644 Binary files a/precompile/binaries/stdlib/vip_vesting.mv and b/precompile/binaries/stdlib/vip_vesting.mv differ diff --git a/precompile/modules/initia_stdlib/sources/dex.move b/precompile/modules/initia_stdlib/sources/dex.move index cfd90759..0c748529 100644 --- a/precompile/modules/initia_stdlib/sources/dex.move +++ b/precompile/modules/initia_stdlib/sources/dex.move @@ -467,8 +467,8 @@ module initia_std::dex { 1, ); - while (vector::length(&res) < (limit as u64) && table::prepare(&mut pairs_iter)) { - let (key, value) = table::next(&mut pairs_iter); + while (vector::length(&res) < (limit as u64) && table::prepare(pairs_iter)) { + let (key, value) = table::next(pairs_iter); if (&key != option::borrow(&start_after)) { vector::push_back(&mut res, *value) } @@ -523,8 +523,8 @@ module initia_std::dex { 1, ); - while (vector::length(&res) < (limit as u64) && table::prepare(&mut pairs_iter)) { - let (key, value) = table::next(&mut pairs_iter); + while (vector::length(&res) < (limit as u64) && table::prepare(pairs_iter)) { + let (key, value) = table::next(pairs_iter); if (&key != option::borrow(&start_after)) { vector::push_back(&mut res, PairByDenomResponse { coin_a: coin::metadata_to_denom(object::address_to_object(value.coin_a)), @@ -576,8 +576,8 @@ module initia_std::dex { 1, ); - while (vector::length(&res) < (limit as u64) && table::prepare(&mut pairs_iter)) { - let (key, value) = table::next(&mut pairs_iter); + while (vector::length(&res) < (limit as u64) && table::prepare(pairs_iter)) { + let (key, value) = table::next(pairs_iter); if (coin_a != key.coin_a || coin_b != key.coin_b) break; if (&key != option::borrow(&start_after)) { vector::push_back(&mut res, *value) diff --git a/precompile/modules/initia_stdlib/sources/fa/primary_fungible_store.move b/precompile/modules/initia_stdlib/sources/fa/primary_fungible_store.move index ae006618..b059591a 100644 --- a/precompile/modules/initia_stdlib/sources/fa/primary_fungible_store.move +++ b/precompile/modules/initia_stdlib/sources/fa/primary_fungible_store.move @@ -198,8 +198,8 @@ module initia_std::primary_fungible_store { let metadata_vec: vector> = vector[]; let balance_vec: vector = vector[]; - while (table::prepare(&mut iter) && vector::length(&balance_vec) < (limit as u64)) { - let (metadata_addr, store_addr) = table::next(&mut iter); + while (table::prepare(iter) && vector::length(&balance_vec) < (limit as u64)) { + let (metadata_addr, store_addr) = table::next(iter); let metadata = object::address_to_object(metadata_addr); let store = object::address_to_object(*store_addr); diff --git a/precompile/modules/initia_stdlib/sources/multisig.move b/precompile/modules/initia_stdlib/sources/multisig.move index f653bc09..95d8f358 100644 --- a/precompile/modules/initia_stdlib/sources/multisig.move +++ b/precompile/modules/initia_stdlib/sources/multisig.move @@ -159,8 +159,8 @@ module initia_std::multisig { let multisig_wallet = borrow_global(multisig_addr); let iter = table::iter(&multisig_wallet.proposals, option::none(), start_after, 2); - while (vector::length(&res) < (limit as u64) && table::prepare(&mut iter)) { - let (proposal_id, proposal) = table::next(&mut iter); + while (vector::length(&res) < (limit as u64) && table::prepare(iter)) { + let (proposal_id, proposal) = table::next(iter); vector::push_back(&mut res, proposal_to_proposal_response(multisig_wallet, multisig_addr, proposal_id, proposal)); }; diff --git a/precompile/modules/initia_stdlib/sources/stableswap.move b/precompile/modules/initia_stdlib/sources/stableswap.move index a1023b60..0275e3c3 100644 --- a/precompile/modules/initia_stdlib/sources/stableswap.move +++ b/precompile/modules/initia_stdlib/sources/stableswap.move @@ -208,8 +208,8 @@ module initia_std::stableswap { 2, ); - while (vector::length(&res) < (limit as u64) && table::prepare(&mut pools_iter)) { - let (key, _) = table::next(&mut pools_iter); + while (vector::length(&res) < (limit as u64) && table::prepare(pools_iter)) { + let (key, _) = table::next(pools_iter); let pool_response = get_pool(object::address_to_object(key)); vector::push_back(&mut res, pool_response) }; diff --git a/precompile/modules/initia_stdlib/sources/staking.move b/precompile/modules/initia_stdlib/sources/staking.move index 6d7c9595..ec16cf55 100644 --- a/precompile/modules/initia_stdlib/sources/staking.move +++ b/precompile/modules/initia_stdlib/sources/staking.move @@ -341,10 +341,10 @@ module initia_std::staking { 2, ); - let prepare = table::prepare(&mut delegations_iter); + let prepare = table::prepare(delegations_iter); let res: vector = vector[]; while (vector::length(&res) < (limit as u64) && prepare) { - let (validator, delegation) = table::next(&mut delegations_iter); + let (validator, delegation) = table::next(delegations_iter); let state = table::borrow(staking_states, validator); let reward = calculate_reward(delegation, state); vector::push_back( @@ -356,7 +356,7 @@ module initia_std::staking { unclaimed_reward: reward, }, ); - prepare = table::prepare(&mut delegations_iter); + prepare = table::prepare(delegations_iter); }; res @@ -431,10 +431,8 @@ module initia_std::staking { ); let res: vector = vector[]; - while (vector::length(&res) < (limit as u64) && table::prepare( - &mut unbondings_iter - )) { - let (_, unbonding) = table::next(&mut unbondings_iter); + while (vector::length(&res) < (limit as u64) && table::prepare(unbondings_iter)) { + let (_, unbonding) = table::next(unbondings_iter); let unbonding_amount = get_unbonding_amount_from_unbonding(unbonding); vector::push_back( &mut res, diff --git a/precompile/modules/initia_stdlib/sources/table.move b/precompile/modules/initia_stdlib/sources/table.move index 2b4be13c..25ed256b 100644 --- a/precompile/modules/initia_stdlib/sources/table.move +++ b/precompile/modules/initia_stdlib/sources/table.move @@ -23,11 +23,6 @@ module initia_std::table { iterator_id: u64, } - /// Type of mutable table iterators - struct TableIterMut has drop { - iterator_id: u64, - } - /// Create a new Table. public fun new(): Table { let handle = new_table_handle(); @@ -151,7 +146,7 @@ module initia_std::table { start: Option, /* inclusive */ end: Option, /* exclusive */ order: u8 /* 1: Ascending, 2: Descending */, - ): TableIter { + ): &TableIter { let start_bytes: vector = if (option::is_some(&start)) { bcs::to_bytes(&option::extract(&mut start)) } else { @@ -164,17 +159,14 @@ module initia_std::table { vector::empty() }; - let iterator_id = new_table_iter>(table, start_bytes, end_bytes, order); - TableIter { - iterator_id, - } + new_table_iter>(table, start_bytes, end_bytes, order) } - public fun prepare(table_iter: &mut TableIter): bool { + public fun prepare(table_iter: &TableIter): bool { prepare_box>(table_iter) } - public fun next(table_iter: &mut TableIter): (K, &V) { + public fun next(table_iter: &TableIter): (K, &V) { let (key, box) = next_box>(table_iter); (key, &box.val) } @@ -201,7 +193,7 @@ module initia_std::table { start: Option, /* inclusive */ end: Option, /* exclusive */ order: u8 /* 1: Ascending, 2: Descending */, - ): TableIterMut { + ): &mut TableIter { let start_bytes: vector = if (option::is_some(&start)) { bcs::to_bytes(&option::extract(&mut start)) } else { @@ -214,17 +206,14 @@ module initia_std::table { vector::empty() }; - let iterator_id = new_table_iter_mut>(table, start_bytes, end_bytes, order); - TableIterMut { - iterator_id, - } + new_table_iter_mut>(table, start_bytes, end_bytes, order) } - public fun prepare_mut(table_iter: &mut TableIterMut): bool { + public fun prepare_mut(table_iter: &mut TableIter): bool { prepare_box_mut>(table_iter) } - public fun next_mut(table_iter: &mut TableIterMut): (K, &mut V) { + public fun next_mut(table_iter: &mut TableIter): (K, &mut V) { let (key, box) = next_box_mut>(table_iter); (key, &mut box.val) } @@ -260,22 +249,22 @@ module initia_std::table { start: vector, end: vector, order: u8 - ): u64; + ): &TableIter; native fun new_table_iter_mut( table: &mut Table, start: vector, end: vector, order: u8 - ): u64; + ): &mut TableIter; - native fun next_box(table_iter: &mut TableIter): (K, &mut Box); + native fun next_box(table_iter: &TableIter): (K, &Box); - native fun prepare_box(table_iter: &mut TableIter): bool; + native fun prepare_box(table_iter: &TableIter): bool; - native fun next_box_mut(table_iter: &mut TableIterMut): (K, &mut Box); + native fun next_box_mut(table_iter: &mut TableIter): (K, &mut Box); - native fun prepare_box_mut(table_iter: &mut TableIterMut): bool; + native fun prepare_box_mut(table_iter: &mut TableIter): bool; // ====================================================================================================== // Tests @@ -311,4 +300,21 @@ module initia_std::table { move_to(&account, TableHolder{ t }); } + + #[test(account = @0x1)] + fun test_iterator(account: &signer) { + let t = new(); + add(&mut t, 1, 1); + add(&mut t, 2, 2); + + let iter = iter(&t, option::none(), option::none(), 1); + let iter2 = iter(&t, option::none(), option::none(), 1); + assert!(iter.iterator_id == 0, 1); + assert!(iter2.iterator_id == 1, 1); + prepare(iter); + let (key, value) = next(iter); + assert!(key == 1 && *value == 1, 1); + + move_to(account, TableHolder { t }); + } } diff --git a/precompile/modules/initia_stdlib/sources/token/collection.move b/precompile/modules/initia_stdlib/sources/token/collection.move index 100d315f..8bf13ca2 100644 --- a/precompile/modules/initia_stdlib/sources/token/collection.move +++ b/precompile/modules/initia_stdlib/sources/token/collection.move @@ -396,8 +396,8 @@ module initia_std::collection { let res: vector = vector[]; - while (table::prepare(&mut nfts_iter) && vector::length(&res) < (limit as u64)) { - let (token_id, nft) = table::next(&mut nfts_iter); + while (table::prepare(nfts_iter) && vector::length(&res) < (limit as u64)) { + let (token_id, nft) = table::next(nfts_iter); vector::push_back( &mut res, diff --git a/precompile/modules/initia_stdlib/sources/vip/vesting.move b/precompile/modules/initia_stdlib/sources/vip/vesting.move index e430a1b1..786c0c8e 100644 --- a/precompile/modules/initia_stdlib/sources/vip/vesting.move +++ b/precompile/modules/initia_stdlib/sources/vip/vesting.move @@ -180,19 +180,6 @@ module initia_std::vip_vesting { table::add(&mut vesting_store.vestings, table_key::encode_u64(stage), vesting); } - fun finalize_vesting( - account_addr: address, - bridge_id: u64, - stage: u64, - ) acquires VestingStore { - let vesting_store_addr = get_vesting_store_address(account_addr, bridge_id); - let vesting_store = borrow_global_mut>(vesting_store_addr); - assert!(table::contains(&vesting_store.claimed_stages, table_key::encode_u64(stage)), error::unavailable(EVESTING_NOT_CLAIMED)); - - let vesting = table::remove(&mut vesting_store.vestings, table_key::encode_u64(stage)); - table::add(&mut vesting_store.vestings_finalized, table_key::encode_u64(stage), vesting); - } - fun create_vesting_store_address(account: address, bridge_id: u64): address { let seed = generate_vesting_store_seed(bridge_id); object::create_object_address(account, seed) @@ -276,10 +263,10 @@ module initia_std::vip_vesting { let vesting_store = borrow_global_mut>(vesting_store_addr); let iter = table::iter(&mut vesting_store.claimed_stages, option::none(), option::none(), 2); - if (!table::prepare, bool>(&mut iter)) { + if (!table::prepare, bool>(iter)) { return 0 }; - let (key, _) = table::next, bool>(&mut iter); + let (key, _) = table::next, bool>(iter); table_key::decode_u64(key) } @@ -290,16 +277,18 @@ module initia_std::vip_vesting { l2_score: u64, ) : (u64, vector) acquires VestingStore { let vested_reward = 0u64; + + let finalized_vestings = vector::empty(); let vesting_changes = vector::empty(); let vesting_store_addr = get_vesting_store_address(account_addr, bridge_id); let vesting_store = borrow_global_mut>(vesting_store_addr); let iter = table::iter_mut(&mut vesting_store.vestings, option::none(), option::none(), 1); loop { - if (!table::prepare_mut, UserVesting>(&mut iter)) { + if (!table::prepare_mut, UserVesting>(iter)) { break }; - let (_, value) = table::next_mut, UserVesting>(&mut iter); + let (_, value) = table::next_mut, UserVesting>(iter); // move vesting if end stage is over or the left reward is empty if ( stage > value.end_stage || value.remaining_reward == 0) { @@ -311,7 +300,8 @@ module initia_std::vip_vesting { remaining_reward: value.remaining_reward, } ); - finalize_vesting(account_addr, bridge_id, value.start_stage); + + vector::push_back(&mut finalized_vestings, value.start_stage); continue }; @@ -327,6 +317,14 @@ module initia_std::vip_vesting { }); }; + // cleanup finalized vestings + vector::for_each_ref(&finalized_vestings, |stage| { + assert!(table::contains(&vesting_store.claimed_stages, table_key::encode_u64(*stage)), error::unavailable(EVESTING_NOT_CLAIMED)); + + let vesting = table::remove(&mut vesting_store.vestings, table_key::encode_u64(*stage)); + table::add(&mut vesting_store.vestings_finalized, table_key::encode_u64(*stage), vesting); + }); + (vested_reward, vesting_changes) } @@ -336,16 +334,18 @@ module initia_std::vip_vesting { stage: u64, ) : (u64, vector) acquires VestingStore { let vested_reward = 0u64; + + let finalized_vestings = vector::empty(); let vesting_changes = vector::empty(); let vesting_store_addr = get_vesting_store_address(account_addr, bridge_id); let vesting_store = borrow_global_mut>(vesting_store_addr); let iter = table::iter_mut(&mut vesting_store.vestings, option::none(), option::none(), 1); loop { - if (!table::prepare_mut, OperatorVesting>(&mut iter)) { + if (!table::prepare_mut, OperatorVesting>(iter)) { break }; - let (_, value) = table::next_mut, OperatorVesting>(&mut iter); + let (_, value) = table::next_mut, OperatorVesting>(iter); // move vesting if end stage is over or the left reward is empty if ( stage > value.end_stage || value.remaining_reward == 0) { @@ -357,7 +357,8 @@ module initia_std::vip_vesting { remaining_reward: value.remaining_reward, } ); - finalize_vesting(account_addr, bridge_id, value.start_stage); + + vector::push_back(&mut finalized_vestings, value.start_stage); continue }; @@ -373,6 +374,14 @@ module initia_std::vip_vesting { }); }; + // cleanup finalized vestings + vector::for_each_ref(&finalized_vestings, |stage| { + assert!(table::contains(&vesting_store.claimed_stages, table_key::encode_u64(*stage)), error::unavailable(EVESTING_NOT_CLAIMED)); + + let vesting = table::remove(&mut vesting_store.vestings, table_key::encode_u64(*stage)); + table::add(&mut vesting_store.vestings_finalized, table_key::encode_u64(*stage), vesting); + }); + (vested_reward, vesting_changes) } @@ -688,11 +697,11 @@ module initia_std::vip_vesting { let vesting_store = borrow_global_mut>(vesting_store_addr); let iter = table::iter(&mut vesting_store.claimed_stages, option::none(), option::none(), 1); loop { - if (!table::prepare, bool>(&mut iter)) { + if (!table::prepare, bool>(iter)) { break }; - let (key, _) = table::next, bool>(&mut iter); + let (key, _) = table::next, bool>(iter); vector::push_back(&mut claimed_stages, table_key::decode_u64(key)); }; claimed_stages @@ -723,11 +732,11 @@ module initia_std::vip_vesting { let vesting_store = borrow_global_mut>(vesting_store_addr); let iter = table::iter(&mut vesting_store.vestings, option::none(), option::some(table_key::encode_u64(stage + 1)), 1); loop { - if (!table::prepare, UserVesting>(&mut iter)) { + if (!table::prepare, UserVesting>(iter)) { break }; - let (_, value) = table::next, UserVesting>(&mut iter); + let (_, value) = table::next, UserVesting>(iter); locked_reward = locked_reward + value.remaining_reward; }; @@ -741,11 +750,11 @@ module initia_std::vip_vesting { let vesting_store = borrow_global_mut>(vesting_store_addr); let iter = table::iter_mut(&mut vesting_store.vestings, option::none(), option::some(table_key::encode_u64(stage)), 1); loop { - if (!table::prepare_mut, UserVesting>(&mut iter)) { + if (!table::prepare_mut, UserVesting>(iter)) { break }; - let (_, value) = table::next_mut, UserVesting>(&mut iter); + let (_, value) = table::next_mut, UserVesting>(iter); let vest_amount = calculate_user_vest(value, l2_score); vested_reward = vested_reward + vest_amount; @@ -796,11 +805,11 @@ module initia_std::vip_vesting { let vesting_store = borrow_global_mut>(vesting_store_addr); let iter = table::iter(&mut vesting_store.claimed_stages, option::none(), option::none(), 1); loop { - if (!table::prepare, bool>(&mut iter)) { + if (!table::prepare, bool>(iter)) { break }; - let (key, _) = table::next, bool>(&mut iter); + let (key, _) = table::next, bool>(iter); vector::push_back(&mut claimed_stages, table_key::decode_u64(key)); }; claimed_stages @@ -831,11 +840,11 @@ module initia_std::vip_vesting { let vesting_store = borrow_global_mut>(vesting_store_addr); let iter = table::iter(&mut vesting_store.vestings, option::none(), option::some(table_key::encode_u64(stage + 1)), 1); loop { - if (!table::prepare, OperatorVesting>(&mut iter)) { + if (!table::prepare, OperatorVesting>(iter)) { break }; - let (_, value) = table::next, OperatorVesting>(&mut iter); + let (_, value) = table::next, OperatorVesting>(iter); locked_reward = locked_reward + value.remaining_reward; }; @@ -849,11 +858,11 @@ module initia_std::vip_vesting { let vesting_store = borrow_global_mut>(vesting_store_addr); let iter = table::iter_mut(&mut vesting_store.vestings, option::none(), option::some(table_key::encode_u64(stage)), 1); loop { - if (!table::prepare_mut, OperatorVesting>(&mut iter)) { + if (!table::prepare_mut, OperatorVesting>(iter)) { break }; - let (_, value) = table::next_mut, OperatorVesting>(&mut iter); + let (_, value) = table::next_mut, OperatorVesting>(iter); let vest_amount = calculate_operator_vest(value); vested_reward = vested_reward + vest_amount; diff --git a/precompile/modules/initia_stdlib/sources/vip/vip.move b/precompile/modules/initia_stdlib/sources/vip/vip.move index 19c9733f..99906055 100644 --- a/precompile/modules/initia_stdlib/sources/vip/vip.move +++ b/precompile/modules/initia_stdlib/sources/vip/vip.move @@ -408,11 +408,11 @@ module initia_std::vip { let index = 0; let iter = table::iter(&module_store.bridges, option::none(), option::none(), 1); loop { - if (!table::prepare, Bridge>(&mut iter)){ + if (!table::prepare, Bridge>(iter)){ break }; - let (bridge_id_vec, bridge) = table::next, Bridge>(&mut iter); + let (bridge_id_vec, bridge) = table::next, Bridge>(iter); let bridge_id = table_key::decode_u64(bridge_id_vec); let balance_reward = split_reward_with_share( balance_shares, @@ -552,10 +552,10 @@ module initia_std::vip { let iter = table::iter(&module_store.bridges, option::none(), option::none(), 1); loop { - if (!table::prepare, Bridge>(&mut iter)){ + if (!table::prepare, Bridge>(iter)){ break }; - let (bridge_id_vec, bridge) = table::next, Bridge>(&mut iter); + let (bridge_id_vec, bridge) = table::next, Bridge>(iter); let bridge_id = table_key::decode_u64(bridge_id_vec); let bridge_balance = primary_fungible_store::balance(bridge.bridge_addr, vip_reward::reward_metadata()); @@ -582,10 +582,10 @@ module initia_std::vip { let iter = table::iter(&module_store.bridges, option::none(), option::none(), 1); loop { - if (!table::prepare, Bridge>(&mut iter)){ + if (!table::prepare, Bridge>(iter)){ break }; - let (bridge_id_vec, bridge) = table::next, Bridge>(&mut iter); + let (bridge_id_vec, bridge) = table::next, Bridge>(iter); let bridge_id = table_key::decode_u64(bridge_id_vec); let bridge_balance = primary_fungible_store::balance(bridge.bridge_addr, vip_reward::reward_metadata()); @@ -1078,11 +1078,11 @@ module initia_std::vip { let iter = table::iter(&module_store.stage_data, option::none(), option::none(), 2); loop { - if (!table::prepare, StageData>(&mut iter)) { + if (!table::prepare, StageData>(iter)) { break }; - let (key, value) = table::next, StageData>(&mut iter); + let (key, value) = table::next, StageData>(iter); if (table::contains(&value.snapshots, table_key::encode_u64(bridge_id))) { return table_key::decode_u64(key) + 1 }; diff --git a/precompile/modules/minitia_stdlib/sources/dex.move b/precompile/modules/minitia_stdlib/sources/dex.move index 8abff336..dcc5c3d5 100644 --- a/precompile/modules/minitia_stdlib/sources/dex.move +++ b/precompile/modules/minitia_stdlib/sources/dex.move @@ -204,8 +204,12 @@ module minitia_std::dex { /// All start_after must be provided or not const ESTART_AFTER: u64 = 17; + // Cannot create pair with the same coin type const ESAME_COIN_TYPE: u64 = 19; + /// Zero amount in the swap simulation is not allowed + const EZERO_AMOUNT_IN: u64 = 20; + // Constants const MAX_LIMIT: u8 = 30; @@ -463,8 +467,8 @@ module minitia_std::dex { 1, ); - while (vector::length(&res) < (limit as u64) && table::prepare(&mut pairs_iter)) { - let (key, value) = table::next(&mut pairs_iter); + while (vector::length(&res) < (limit as u64) && table::prepare(pairs_iter)) { + let (key, value) = table::next(pairs_iter); if (&key != option::borrow(&start_after)) { vector::push_back(&mut res, *value) } @@ -519,8 +523,8 @@ module minitia_std::dex { 1, ); - while (vector::length(&res) < (limit as u64) && table::prepare(&mut pairs_iter)) { - let (key, value) = table::next(&mut pairs_iter); + while (vector::length(&res) < (limit as u64) && table::prepare(pairs_iter)) { + let (key, value) = table::next(pairs_iter); if (&key != option::borrow(&start_after)) { vector::push_back(&mut res, PairByDenomResponse { coin_a: coin::metadata_to_denom(object::address_to_object(value.coin_a)), @@ -572,8 +576,8 @@ module minitia_std::dex { 1, ); - while (vector::length(&res) < (limit as u64) && table::prepare(&mut pairs_iter)) { - let (key, value) = table::next(&mut pairs_iter); + while (vector::length(&res) < (limit as u64) && table::prepare(pairs_iter)) { + let (key, value) = table::next(pairs_iter); if (coin_a != key.coin_a || coin_b != key.coin_b) break; if (&key != option::borrow(&start_after)) { vector::push_back(&mut res, *value) @@ -1359,9 +1363,17 @@ module minitia_std::dex { amount_in: u64, swap_fee_rate: Decimal128, ): (u64, u64) { + assert!(amount_in > 0, error::invalid_argument(EZERO_AMOUNT_IN)); + let one = decimal128::one(); let exp = decimal128::from_ratio(decimal128::val(&weight_in), decimal128::val(&weight_out)); + + // avoid zero fee amount to prevent fee bypass attack let fee_amount = decimal128::mul_u64(&swap_fee_rate, amount_in); + if (fee_amount == 0) { + fee_amount = 1; + }; + let adjusted_amount_in = amount_in - fee_amount; let base = decimal128::from_ratio_u64(pool_amount_in, pool_amount_in + adjusted_amount_in); let sub_amount = pow(&base, &exp); diff --git a/precompile/modules/minitia_stdlib/sources/fa/primary_fungible_store.move b/precompile/modules/minitia_stdlib/sources/fa/primary_fungible_store.move index a6843b14..a428065c 100644 --- a/precompile/modules/minitia_stdlib/sources/fa/primary_fungible_store.move +++ b/precompile/modules/minitia_stdlib/sources/fa/primary_fungible_store.move @@ -198,8 +198,8 @@ module minitia_std::primary_fungible_store { let metadata_vec: vector> = vector[]; let balance_vec: vector = vector[]; - while (table::prepare(&mut iter) && vector::length(&balance_vec) < (limit as u64)) { - let (metadata_addr, store_addr) = table::next(&mut iter); + while (table::prepare(iter) && vector::length(&balance_vec) < (limit as u64)) { + let (metadata_addr, store_addr) = table::next(iter); let metadata = object::address_to_object(metadata_addr); let store = object::address_to_object(*store_addr); diff --git a/precompile/modules/minitia_stdlib/sources/multisig.move b/precompile/modules/minitia_stdlib/sources/multisig.move index e2bca6cf..8fb29ff2 100644 --- a/precompile/modules/minitia_stdlib/sources/multisig.move +++ b/precompile/modules/minitia_stdlib/sources/multisig.move @@ -159,8 +159,8 @@ module minitia_std::multisig { let multisig_wallet = borrow_global(multisig_addr); let iter = table::iter(&multisig_wallet.proposals, option::none(), start_after, 2); - while (vector::length(&res) < (limit as u64) && table::prepare(&mut iter)) { - let (proposal_id, proposal) = table::next(&mut iter); + while (vector::length(&res) < (limit as u64) && table::prepare(iter)) { + let (proposal_id, proposal) = table::next(iter); vector::push_back(&mut res, proposal_to_proposal_response(multisig_wallet, multisig_addr, proposal_id, proposal)); }; diff --git a/precompile/modules/minitia_stdlib/sources/table.move b/precompile/modules/minitia_stdlib/sources/table.move index 4b516733..398b561f 100644 --- a/precompile/modules/minitia_stdlib/sources/table.move +++ b/precompile/modules/minitia_stdlib/sources/table.move @@ -23,11 +23,6 @@ module minitia_std::table { iterator_id: u64, } - /// Type of mutable table iterators - struct TableIterMut has drop { - iterator_id: u64, - } - /// Create a new Table. public fun new(): Table { let handle = new_table_handle(); @@ -151,7 +146,7 @@ module minitia_std::table { start: Option, /* inclusive */ end: Option, /* exclusive */ order: u8 /* 1: Ascending, 2: Descending */, - ): TableIter { + ): &TableIter { let start_bytes: vector = if (option::is_some(&start)) { bcs::to_bytes(&option::extract(&mut start)) } else { @@ -164,17 +159,14 @@ module minitia_std::table { vector::empty() }; - let iterator_id = new_table_iter>(table, start_bytes, end_bytes, order); - TableIter { - iterator_id, - } + new_table_iter>(table, start_bytes, end_bytes, order) } - public fun prepare(table_iter: &mut TableIter): bool { + public fun prepare(table_iter: &TableIter): bool { prepare_box>(table_iter) } - public fun next(table_iter: &mut TableIter): (K, &V) { + public fun next(table_iter: &TableIter): (K, &V) { let (key, box) = next_box>(table_iter); (key, &box.val) } @@ -201,7 +193,7 @@ module minitia_std::table { start: Option, /* inclusive */ end: Option, /* exclusive */ order: u8 /* 1: Ascending, 2: Descending */, - ): TableIterMut { + ): &mut TableIter { let start_bytes: vector = if (option::is_some(&start)) { bcs::to_bytes(&option::extract(&mut start)) } else { @@ -214,17 +206,14 @@ module minitia_std::table { vector::empty() }; - let iterator_id = new_table_iter_mut>(table, start_bytes, end_bytes, order); - TableIterMut { - iterator_id, - } + new_table_iter_mut>(table, start_bytes, end_bytes, order) } - public fun prepare_mut(table_iter: &mut TableIterMut): bool { + public fun prepare_mut(table_iter: &mut TableIter): bool { prepare_box_mut>(table_iter) } - public fun next_mut(table_iter: &mut TableIterMut): (K, &mut V) { + public fun next_mut(table_iter: &mut TableIter): (K, &mut V) { let (key, box) = next_box_mut>(table_iter); (key, &mut box.val) } @@ -260,22 +249,22 @@ module minitia_std::table { start: vector, end: vector, order: u8 - ): u64; + ): &TableIter; native fun new_table_iter_mut( table: &mut Table, start: vector, end: vector, order: u8 - ): u64; + ): &mut TableIter; - native fun next_box(table_iter: &mut TableIter): (K, &mut Box); + native fun next_box(table_iter: &TableIter): (K, &Box); - native fun prepare_box(table_iter: &mut TableIter): bool; + native fun prepare_box(table_iter: &TableIter): bool; - native fun next_box_mut(table_iter: &mut TableIterMut): (K, &mut Box); + native fun next_box_mut(table_iter: &mut TableIter): (K, &mut Box); - native fun prepare_box_mut(table_iter: &mut TableIterMut): bool; + native fun prepare_box_mut(table_iter: &mut TableIter): bool; // ====================================================================================================== // Tests @@ -311,4 +300,21 @@ module minitia_std::table { move_to(&account, TableHolder{ t }); } + + #[test(account = @0x1)] + fun test_iterator(account: &signer) { + let t = new(); + add(&mut t, 1, 1); + add(&mut t, 2, 2); + + let iter = iter(&t, option::none(), option::none(), 1); + let iter2 = iter(&t, option::none(), option::none(), 1); + assert!(iter.iterator_id == 0, 1); + assert!(iter2.iterator_id == 1, 1); + prepare(iter); + let (key, value) = next(iter); + assert!(key == 1 && *value == 1, 1); + + move_to(account, TableHolder { t }); + } } diff --git a/precompile/modules/minitia_stdlib/sources/token/collection.move b/precompile/modules/minitia_stdlib/sources/token/collection.move index 23acc0aa..dfef1719 100644 --- a/precompile/modules/minitia_stdlib/sources/token/collection.move +++ b/precompile/modules/minitia_stdlib/sources/token/collection.move @@ -396,8 +396,8 @@ module minitia_std::collection { let res: vector = vector[]; - while (table::prepare(&mut nfts_iter) && vector::length(&res) < (limit as u64)) { - let (token_id, nft) = table::next(&mut nfts_iter); + while (table::prepare(nfts_iter) && vector::length(&res) < (limit as u64)) { + let (token_id, nft) = table::next(nfts_iter); vector::push_back( &mut res, diff --git a/precompile/modules/tests/sources/TableTestData.move b/precompile/modules/tests/sources/TableTestData.move index d91f58c8..6e0971bf 100644 --- a/precompile/modules/tests/sources/TableTestData.move +++ b/precompile/modules/tests/sources/TableTestData.move @@ -31,27 +31,27 @@ module TestAccount::TableTestData { let i = 1; while(i < 11) { - assert!(T::prepare(&mut iter), 101); - let (key, value) = T::next(&mut iter); + assert!(T::prepare(iter), 101); + let (key, value) = T::next(iter); assert!(key == i, 101); assert!(value == &i, 101); i = i + 1; }; - assert!(!T::prepare(&mut iter), 101); + assert!(!T::prepare(iter), 101); let iter = T::iter(t_ref, option::some(2), option::some(5), 1); let i = 2; while(i < 5) { - assert!(T::prepare(&mut iter), 102); - let (key, value) = T::next(&mut iter); + assert!(T::prepare(iter), 102); + let (key, value) = T::next(iter); assert!(key == i, 102); assert!(value == &i, 102); i = i + 1; }; - assert!(!T::prepare(&mut iter), 102); + assert!(!T::prepare(iter), 102); } public entry fun iterate_descending(acc: address) acquires S { let t_ref = &borrow_global>(acc).t; @@ -60,26 +60,26 @@ module TestAccount::TableTestData { let i = 10; while(i > 0) { - assert!(T::prepare(&mut iter), 101); - let (key, value) = T::next(&mut iter); + assert!(T::prepare(iter), 101); + let (key, value) = T::next(iter); assert!(key == i, 101); assert!(value == &i, 101); i = i - 1; }; - assert!(!T::prepare(&mut iter), 101); + assert!(!T::prepare(iter), 101); let iter = T::iter(t_ref, option::some(2), option::some(5), 2); let i = 4; while(i > 1) { - assert!(T::prepare(&mut iter), 102); - let (key, value) = T::next(&mut iter); + assert!(T::prepare(iter), 102); + let (key, value) = T::next(iter); assert!(key == i, 102); assert!(value == &i, 102); i = i - 1; }; - assert!(!T::prepare(&mut iter), 102); + assert!(!T::prepare(iter), 102); } } diff --git a/precompile/modules/tests/sources/TableUnitTests.move b/precompile/modules/tests/sources/TableUnitTests.move index 431821bb..f388f970 100644 --- a/precompile/modules/tests/sources/TableUnitTests.move +++ b/precompile/modules/tests/sources/TableUnitTests.move @@ -276,27 +276,27 @@ module TestAccount::TableUnitTests { let iter = T::iter(&t, option::some(1), option::some(5), 1); - assert!(T::prepare(&mut iter), 101); - let (key, value) = T::next(&mut iter); + assert!(T::prepare(iter), 101); + let (key, value) = T::next(iter); assert!(key == 1, 101); assert!(value == &1, 101); - assert!(T::prepare(&mut iter), 102); - let (key, value) = T::next(&mut iter); + assert!(T::prepare(iter), 102); + let (key, value) = T::next(iter); assert!(key == 2, 102); assert!(value == &2, 102); - assert!(T::prepare(&mut iter), 103); - let (key, value) = T::next(&mut iter); + assert!(T::prepare(iter), 103); + let (key, value) = T::next(iter); assert!(key == 3, 103); assert!(value == &3, 103); - assert!(T::prepare(&mut iter), 104); - let (key, value) = T::next(&mut iter); + assert!(T::prepare(iter), 104); + let (key, value) = T::next(iter); assert!(key == 4, 104); assert!(value == &4, 104); - assert!(!T::prepare(&mut iter), 105); + assert!(!T::prepare(iter), 105); // clear T::remove(&mut t, 1);