-
Notifications
You must be signed in to change notification settings - Fork 64
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 1 commit
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,53 @@ 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] | ||||||||||||||||||||||||||||||||||||||||||||||||||
| #[should_panic] // Should fail due to require_auth failure for non-admin | ||||||||||||||||||||||||||||||||||||||||||||||||||
| fn test_upgrade_version_non_admin() { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| let (env, client, _, _, _, _, _) = setup(); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| let non_admin = Address::generate(&env); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| env.as_contract(&client.address, || { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 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.