-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pause Contract and Resume Contract (#779)
<!-- Thanks for submitting a pull request! Here are some helpful tips: * Always create branches on and target the `develop` branch. * Run all the tests locally and ensure that they are passing. * Run `make format` to ensure that the code is formatted. * Run `make check` to ensure that all checks passed successfully. * Small commits and contributions that attempt one single goal is preferable. * If the idea changes or adds anything functional which will affect users, an AIP discussion is required first on the Aurora forum: https://forum.aurora.dev/discussions/AIPs%20(Aurora%20Improvement%20Proposals). * Avoid breaking the public API (namely in engine/src/lib.rs) unless required. * If your PR is a WIP, ensure that you enable "draft" mode. * Your first PRs won't use the CI automatically unless a maintainer starts. If this is not your first PR, please do NOT abuse the CI resources. Checklist: - [ ] I have performed a self-review of my code - [ ] I have documented my code, particularly in the hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [ ] I have added tests to prove my fix or new feature is effective and works - [ ] Any dependent changes have been merged - [ ] The PR is targeting the `develop` branch and not `master` - [ ] I have pre-squashed my commits into a single commit and rebased. --> Feature to pause and resume the engine contract. We added two public methods to pause and resume the engine contract. Only DAO can use these functionalities. We use an Engine State field as a flag to indicate paused state. All existing contract public methods check this flat before proceeding, and fail if contract is paused. All public methods would need to read the Engine State now, but no impact on performance was visible. <!-- Performance regressions are not ideal, though we welcome performance improvements. Any PR must be completely mindful of any gas cost increases. The CI will fail if the gas costs change at all. Do update these tests to accommodate for the new gas changes. It is good to explain this change, if necessary. --> Added new tests to cover the DAO requirement and the feature effect. <!-- Please describe the tests that you ran to verify your changes. --> Please, take a look at the public methods on the contract: -All set methods should be affected by pausing. -All get methods should NOT be affected by pausing. This feature came as a necessity for the Aurora Hashchain integration. The decided strategy is to: 1. upgrade the engine with the Hashchain inactive. 2. pause the contract. 3. call a special contract method added by the Hashchain upgrade, to pass the seed computed Hashchain value for the block, and to activate the Hashchain. 4. resume the contract. 5. upgrade the engine to remove unnecessary code and the special method. There are more details about this but this is the general strategy. <!-- Include any additional information which you think should be in this PR, such as prior arts, future extensions, unresolved problems, or a TODO list which should be followed up. -->
- Loading branch information
1 parent
2146068
commit fa1be8e
Showing
12 changed files
with
287 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
use crate::test_utils; | ||
use aurora_engine::parameters::SetUpgradeDelayBlocksArgs; | ||
use borsh::BorshSerialize; | ||
|
||
#[test] | ||
fn test_pause_contract_require_owner() { | ||
let mut runner = test_utils::deploy_evm(); | ||
let aurora_account_id = runner.aurora_account_id.clone(); | ||
|
||
let result = runner.call("pause_contract", &aurora_account_id, vec![]); | ||
assert!(result.is_ok()); | ||
|
||
let result = runner.call("resume_contract", &aurora_account_id, vec![]); | ||
assert!(result.is_ok()); | ||
|
||
let result = runner.call("pause_contract", "new_owner.near", vec![]); | ||
assert!(result.is_err()); | ||
} | ||
|
||
#[test] | ||
fn test_resume_contract_require_owner() { | ||
let mut runner = test_utils::deploy_evm(); | ||
let aurora_account_id = runner.aurora_account_id.clone(); | ||
|
||
let result = runner.call("pause_contract", &aurora_account_id, vec![]); | ||
assert!(result.is_ok()); | ||
|
||
let result = runner.call("resume_contract", &aurora_account_id, vec![]); | ||
assert!(result.is_ok()); | ||
|
||
let result = runner.call("pause_contract", &aurora_account_id, vec![]); | ||
assert!(result.is_ok()); | ||
|
||
let result = runner.call("resume_contract", "new_owner.near", vec![]); | ||
assert!(result.is_err()); | ||
} | ||
|
||
#[test] | ||
fn test_pause_contract_require_running() { | ||
let mut runner = test_utils::deploy_evm(); | ||
let aurora_account_id = runner.aurora_account_id.clone(); | ||
|
||
let result = runner.call("pause_contract", &aurora_account_id, vec![]); | ||
assert!(result.is_ok()); | ||
|
||
let result = runner.call("pause_contract", &aurora_account_id, vec![]); | ||
assert!(result.is_err()); | ||
} | ||
|
||
#[test] | ||
fn test_resume_contract_require_paused() { | ||
let mut runner = test_utils::deploy_evm(); | ||
let aurora_account_id = runner.aurora_account_id.clone(); | ||
|
||
let result = runner.call("resume_contract", &aurora_account_id, vec![]); | ||
assert!(result.is_err()); | ||
|
||
let result = runner.call("pause_contract", &aurora_account_id, vec![]); | ||
assert!(result.is_ok()); | ||
|
||
let result = runner.call("resume_contract", &aurora_account_id, vec![]); | ||
assert!(result.is_ok()); | ||
} | ||
|
||
#[test] | ||
fn test_pause_contract() { | ||
let mut runner = test_utils::deploy_evm(); | ||
let aurora_account_id = runner.aurora_account_id.clone(); | ||
let set = SetUpgradeDelayBlocksArgs { | ||
upgrade_delay_blocks: 2, | ||
} | ||
.try_to_vec() | ||
.unwrap(); | ||
|
||
// contract is running by default, gets and sets should work | ||
let result = runner.call("get_upgrade_delay_blocks", &aurora_account_id, vec![]); | ||
assert!(result.is_ok()); | ||
|
||
let result = runner.call("set_upgrade_delay_blocks", &aurora_account_id, set.clone()); | ||
assert!(result.is_ok()); | ||
|
||
// pause contract | ||
let result = runner.call("pause_contract", &aurora_account_id, vec![]); | ||
assert!(result.is_ok()); | ||
|
||
// contract is paused, gets should still work but sets should fail | ||
let result = runner.call("get_upgrade_delay_blocks", &aurora_account_id, vec![]); | ||
assert!(result.is_ok()); | ||
|
||
let result = runner.call("set_upgrade_delay_blocks", &aurora_account_id, set); | ||
assert!(result.is_err()); | ||
} | ||
|
||
#[test] | ||
fn test_resume_contract() { | ||
let mut runner = test_utils::deploy_evm(); | ||
let aurora_account_id = runner.aurora_account_id.clone(); | ||
let set = SetUpgradeDelayBlocksArgs { | ||
upgrade_delay_blocks: 2, | ||
} | ||
.try_to_vec() | ||
.unwrap(); | ||
|
||
// pause contract | ||
let result = runner.call("pause_contract", &aurora_account_id, vec![]); | ||
assert!(result.is_ok()); | ||
|
||
// resume contract | ||
let result = runner.call("resume_contract", &aurora_account_id, vec![]); | ||
assert!(result.is_ok()); | ||
|
||
// contract is running again, gets and sets should work | ||
let result = runner.call("get_upgrade_delay_blocks", &aurora_account_id, vec![]); | ||
assert!(result.is_ok()); | ||
|
||
let result = runner.call("set_upgrade_delay_blocks", &aurora_account_id, set); | ||
assert!(result.is_ok()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.