-
Notifications
You must be signed in to change notification settings - Fork 63
feat: implement on-chain contract version tracking for split-escrow #252
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,4 +12,5 @@ pub enum Error { | |
| SplitNotPending = 7, | ||
| SplitNotReady = 8, | ||
| TreasuryNotSet = 9, | ||
| InvalidVersion = 10, | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -29,7 +29,7 @@ fn setup() -> ( | |||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| let contract_id = env.register_contract(None, SplitEscrowContract); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| let client = SplitEscrowContractClient::new(&env, &contract_id); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| client.initialize(&admin, &token); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| client.initialize(&admin, &token, &String::from_str(&env, "1.0.0")); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| token_admin_client.mint(&participant, &1_000_000); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -117,3 +117,79 @@ fn test_fees_collected_event_emitted() { | |||||||||||||||||||||||||||||||||||||||||||||||||
| let after_len = env.events().all().len(); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| assert!(after_len > before_len); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| #[test] | ||||||||||||||||||||||||||||||||||||||||||||||||||
| fn test_get_version() { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| let (env, client, _, _, _, _, _) = setup(); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| assert_eq!(client.get_version(), String::from_str(&env, "1.0.0")); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| #[test] | ||||||||||||||||||||||||||||||||||||||||||||||||||
| fn test_upgrade_version_success() { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| let (env, client, admin, _, _, _, _) = setup(); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| // Auth is mocked in setup, but we can explicitly test it if needed. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| // Here we just test the functionality. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| let new_version = String::from_str(&env, "1.1.0"); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| client.upgrade_version(&new_version); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| assert_eq!(client.get_version(), new_version); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| #[test] | ||||||||||||||||||||||||||||||||||||||||||||||||||
| #[should_panic(expected = "HostError: Error(Contract, #10)")] | ||||||||||||||||||||||||||||||||||||||||||||||||||
| fn test_upgrade_version_invalid_format() { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| let (env, client, _, _, _, _, _) = setup(); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| let invalid_version = String::from_str(&env, "one.zero.zero"); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| client.upgrade_version(&invalid_version); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| #[test] | ||||||||||||||||||||||||||||||||||||||||||||||||||
| fn test_release_funds_works_without_treasury_when_fee_is_zero() { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| let (env, client, _admin, creator, participant, token_client, _) = setup(); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| // Fee is 0% by default after init. Treasury is NOT set. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| let split_id = client.create_split(&creator, &String::from_str(&env, "No Fee"), &1_000); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| client.deposit(&split_id, &participant, &1_000); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| // This should NOT panic now, even without treasury set. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| client.release_funds(&split_id); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| assert_eq!(token_client.balance(&creator), 1_000); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| let split = client.get_split(&split_id); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| assert_eq!(split.status, SplitStatus::Released); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| #[test] | ||||||||||||||||||||||||||||||||||||||||||||||||||
| #[should_panic] | ||||||||||||||||||||||||||||||||||||||||||||||||||
| fn test_upgrade_version_non_admin() { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| let env = Env::default(); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| // We don't call mock_all_auths() here. | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| let admin = Address::generate(&env); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| let token = Address::generate(&env); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| let contract_id = env.register_contract(None, SplitEscrowContract); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| let client = SplitEscrowContractClient::new(&env, &contract_id); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| client.initialize(&admin, &token, &String::from_str(&env, "1.0.0")); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| let non_admin = Address::generate(&env); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| // This should panic because non_admin is not the stored admin and we didn't mock auth. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| // However, since Soroban verification requires the caller to be authorized, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| // calling this as non_admin without mocking admin's auth will fail. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| env.as_contract(&non_admin, || { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| client.upgrade_version(&String::from_str(&env, "2.0.0")); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| #[test] | ||||||||||||||||||||||||||||||||||||||||||||||||||
| fn test_semver_validation_at_init() { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| let env = Env::default(); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| let admin = Address::generate(&env); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| let token = Address::generate(&env); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| let contract_id = env.register_contract(None, SplitEscrowContract); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| let client = SplitEscrowContractClient::new(&env, &contract_id); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| // Valid | ||||||||||||||||||||||||||||||||||||||||||||||||||
| client.initialize(&admin, &token, &String::from_str(&env, "0.1.0")); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| assert_eq!(client.get_version(), String::from_str(&env, "0.1.0")); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+184
to
+194
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing The 🐛 Proposed fix #[test]
fn test_semver_validation_at_init() {
let env = Env::default();
+ env.mock_all_auths();
let admin = Address::generate(&env);
let token = Address::generate(&env);
let contract_id = env.register_contract(None, SplitEscrowContract);
let client = SplitEscrowContractClient::new(&env, &contract_id);
// Valid
client.initialize(&admin, &token, &String::from_str(&env, "0.1.0"));
assert_eq!(client.get_version(), String::from_str(&env, "0.1.0"));
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.