Repository navigation
fix: extend the token, verifier and compliance ttl #246
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b8f30ed
fix(token): extend the instance on every call
hpmaxi 5c63d44
fix(verifier): extend the instance on every call
hpmaxi 170dd3f
fix(compliance): extend the instance on hooks
hpmaxi c88ace4
docs: list the instance ttl tests
hpmaxi 9f7fbac
Merge branch 'feat/shared-timelock-crate' into feat/instance-ttl
hpmaxi 306666d
Merge branch 'feat/shared-timelock-crate' into feat/instance-ttl
hpmaxi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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,73 @@ | ||
| use soroban_sdk::{ | ||
| testutils::{storage::Instance as _, Address as _, Ledger as _}, | ||
| Address, Env, | ||
| }; | ||
| use storage::INSTANCE_EXTEND_AMOUNT; | ||
|
|
||
| use crate::{Compliance, ComplianceClient}; | ||
|
|
||
| const TWO_DAYS_IN_LEDGERS: u32 = 2 * 17_280; | ||
|
|
||
| fn instance_ttl(e: &Env, id: &Address) -> u32 { | ||
| e.as_contract(id, || e.storage().instance().get_ttl()) | ||
| } | ||
|
|
||
| fn age(e: &Env) { | ||
| e.ledger() | ||
| .with_mut(|l| l.sequence_number += TWO_DAYS_IN_LEDGERS); | ||
| } | ||
|
|
||
| /// A compliance contract with one bound token, its instance decayed past the | ||
| /// extend threshold. | ||
| fn decayed(e: &Env) -> (ComplianceClient<'_>, Address) { | ||
| e.mock_all_auths(); | ||
| let admin = Address::generate(e); | ||
| let token = Address::generate(e); | ||
| let client = ComplianceClient::new(e, &e.register(Compliance, (admin.clone(),))); | ||
| client.bind_token(&token, &admin); | ||
| age(e); | ||
| assert!(instance_ttl(e, &client.address) < INSTANCE_EXTEND_AMOUNT); | ||
| (client, token) | ||
| } | ||
|
|
||
| #[test] | ||
| fn construction_writes_the_instance_with_the_full_ttl() { | ||
| let e = Env::default(); | ||
| let id = e.register(Compliance, (Address::generate(&e),)); | ||
|
|
||
| assert_eq!(instance_ttl(&e, &id), INSTANCE_EXTEND_AMOUNT); | ||
| } | ||
|
|
||
| #[test] | ||
| fn the_checks_a_token_runs_before_moving_shares_restore_the_instance_ttl() { | ||
| let e = Env::default(); | ||
| let (client, token) = decayed(&e); | ||
| let holder = Address::generate(&e); | ||
| let other = Address::generate(&e); | ||
|
|
||
| assert!(client.can_create(&holder, &1, &token)); | ||
| assert_eq!(instance_ttl(&e, &client.address), INSTANCE_EXTEND_AMOUNT); | ||
|
|
||
| age(&e); | ||
| assert!(client.can_transfer(&holder, &other, &1, &token)); | ||
| assert_eq!(instance_ttl(&e, &client.address), INSTANCE_EXTEND_AMOUNT); | ||
| } | ||
|
|
||
| #[test] | ||
| fn the_hooks_a_token_calls_after_moving_shares_restore_the_instance_ttl() { | ||
| let e = Env::default(); | ||
| let (client, token) = decayed(&e); | ||
| let holder = Address::generate(&e); | ||
| let other = Address::generate(&e); | ||
|
|
||
| client.created(&holder, &1, &token); | ||
| assert_eq!(instance_ttl(&e, &client.address), INSTANCE_EXTEND_AMOUNT); | ||
|
|
||
| age(&e); | ||
| client.transferred(&holder, &other, &1, &token); | ||
| assert_eq!(instance_ttl(&e, &client.address), INSTANCE_EXTEND_AMOUNT); | ||
|
|
||
| age(&e); | ||
| client.destroyed(&other, &1, &token); | ||
| assert_eq!(instance_ttl(&e, &client.address), INSTANCE_EXTEND_AMOUNT); | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe also extend in
balanceandtotal_supply? A later wind-down claim only readsbalance, so a quiet wind-down could still let the instance lapse.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added in #276 (9516c95):
balanceandtotal_supplynow extend the token's instance before they read, so a wind-down that only reads balances keeps the token alive. A test lets the instance fall below its threshold and checks that abalanceread brings it back to the full 30 days.