mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-30 15:27:57 +00:00
Contracts: Stabilize APIs (#3384)
Remove `#[unstable]` on `call_v2`, `instantiate_v2`, `lock_delegate_dependency` and `unlock_delegate_dependency`. See ink! integrations: - call_v2: https://github.com/paritytech/ink/pull/2077 - instantiate_v2: <TODO> - lock/unlock dependency: https://github.com/paritytech/ink/pull/2076
This commit is contained in:
@@ -5406,21 +5406,21 @@ fn delegate_call_indeterministic_code() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn add_remove_delegate_dependency_works() {
|
||||
fn locking_delegate_dependency_works() {
|
||||
// set hash lock up deposit to 30%, to test deposit calculation.
|
||||
CODE_HASH_LOCKUP_DEPOSIT_PERCENT.with(|c| *c.borrow_mut() = Perbill::from_percent(30));
|
||||
MAX_DELEGATE_DEPENDENCIES.with(|c| *c.borrow_mut() = 1);
|
||||
|
||||
let (wasm_caller, self_code_hash) =
|
||||
compile_module::<Test>("add_remove_delegate_dependency").unwrap();
|
||||
compile_module::<Test>("locking_delegate_dependency").unwrap();
|
||||
let (wasm_callee, code_hash) = compile_module::<Test>("dummy").unwrap();
|
||||
let (wasm_other, other_code_hash) = compile_module::<Test>("call").unwrap();
|
||||
|
||||
// Define inputs with various actions to test adding / removing delegate_dependencies.
|
||||
// Define inputs with various actions to test locking / unlocking delegate_dependencies.
|
||||
// See the contract for more details.
|
||||
let noop_input = (0u32, code_hash);
|
||||
let add_delegate_dependency_input = (1u32, code_hash);
|
||||
let remove_delegate_dependency_input = (2u32, code_hash);
|
||||
let lock_delegate_dependency_input = (1u32, code_hash);
|
||||
let unlock_delegate_dependency_input = (2u32, code_hash);
|
||||
let terminate_input = (3u32, code_hash);
|
||||
|
||||
// Instantiate the caller contract with the given input.
|
||||
@@ -5457,9 +5457,9 @@ fn add_remove_delegate_dependency_works() {
|
||||
ExtBuilder::default().existential_deposit(ED).build().execute_with(|| {
|
||||
let _ = Balances::set_balance(&ALICE, 1_000_000);
|
||||
|
||||
// Instantiate with add_delegate_dependency should fail since the code is not yet on chain.
|
||||
// Instantiate with lock_delegate_dependency should fail since the code is not yet on chain.
|
||||
assert_err!(
|
||||
instantiate(&add_delegate_dependency_input).result,
|
||||
instantiate(&lock_delegate_dependency_input).result,
|
||||
Error::<Test>::CodeNotFound
|
||||
);
|
||||
|
||||
@@ -5469,7 +5469,7 @@ fn add_remove_delegate_dependency_works() {
|
||||
.unwrap();
|
||||
|
||||
// Instantiate should now work.
|
||||
let addr_caller = instantiate(&add_delegate_dependency_input).result.unwrap().account_id;
|
||||
let addr_caller = instantiate(&lock_delegate_dependency_input).result.unwrap().account_id;
|
||||
|
||||
// There should be a dependency and a deposit.
|
||||
let contract = test_utils::get_contract(&addr_caller);
|
||||
@@ -5490,27 +5490,27 @@ fn add_remove_delegate_dependency_works() {
|
||||
<Error<Test>>::CodeInUse
|
||||
);
|
||||
|
||||
// Adding an already existing dependency should fail.
|
||||
// Locking an already existing dependency should fail.
|
||||
assert_err!(
|
||||
call(&addr_caller, &add_delegate_dependency_input).result,
|
||||
call(&addr_caller, &lock_delegate_dependency_input).result,
|
||||
Error::<Test>::DelegateDependencyAlreadyExists
|
||||
);
|
||||
|
||||
// Adding a dependency to self should fail.
|
||||
// Locking self should fail.
|
||||
assert_err!(
|
||||
call(&addr_caller, &(1u32, self_code_hash)).result,
|
||||
Error::<Test>::CannotAddSelfAsDelegateDependency
|
||||
);
|
||||
|
||||
// Adding more than the maximum allowed delegate_dependencies should fail.
|
||||
// Locking more than the maximum allowed delegate_dependencies should fail.
|
||||
Contracts::bare_upload_code(ALICE, wasm_other, None, Determinism::Enforced).unwrap();
|
||||
assert_err!(
|
||||
call(&addr_caller, &(1u32, other_code_hash)).result,
|
||||
Error::<Test>::MaxDelegateDependenciesReached
|
||||
);
|
||||
|
||||
// Removing dependency should work.
|
||||
assert_ok!(call(&addr_caller, &remove_delegate_dependency_input).result);
|
||||
// Unlocking dependency should work.
|
||||
assert_ok!(call(&addr_caller, &unlock_delegate_dependency_input).result);
|
||||
|
||||
// Dependency should be removed, and deposit should be returned.
|
||||
let contract = test_utils::get_contract(&addr_caller);
|
||||
@@ -5525,18 +5525,18 @@ fn add_remove_delegate_dependency_works() {
|
||||
|
||||
// Removing an unexisting dependency should fail.
|
||||
assert_err!(
|
||||
call(&addr_caller, &remove_delegate_dependency_input).result,
|
||||
call(&addr_caller, &unlock_delegate_dependency_input).result,
|
||||
Error::<Test>::DelegateDependencyNotFound
|
||||
);
|
||||
|
||||
// Adding a dependency with a storage limit too low should fail.
|
||||
// Locking a dependency with a storage limit too low should fail.
|
||||
DEFAULT_DEPOSIT_LIMIT.with(|c| *c.borrow_mut() = dependency_deposit - 1);
|
||||
assert_err!(
|
||||
call(&addr_caller, &add_delegate_dependency_input).result,
|
||||
call(&addr_caller, &lock_delegate_dependency_input).result,
|
||||
Error::<Test>::StorageDepositLimitExhausted
|
||||
);
|
||||
|
||||
// Since we removed the dependency we should now be able to remove the code.
|
||||
// Since we unlocked the dependency we should now be able to remove the code.
|
||||
assert_ok!(Contracts::remove_code(RuntimeOrigin::signed(ALICE), code_hash));
|
||||
|
||||
// Calling should fail since the delegated contract is not on chain anymore.
|
||||
@@ -5545,7 +5545,7 @@ fn add_remove_delegate_dependency_works() {
|
||||
// Restore initial deposit limit and add the dependency back.
|
||||
DEFAULT_DEPOSIT_LIMIT.with(|c| *c.borrow_mut() = 10_000_000);
|
||||
Contracts::bare_upload_code(ALICE, wasm_callee, None, Determinism::Enforced).unwrap();
|
||||
call(&addr_caller, &add_delegate_dependency_input).result.unwrap();
|
||||
call(&addr_caller, &lock_delegate_dependency_input).result.unwrap();
|
||||
|
||||
// Call terminate should work, and return the deposit.
|
||||
let balance_before = test_utils::get_balance(&ALICE);
|
||||
|
||||
Reference in New Issue
Block a user