Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ All notable changes to this project will be documented in this file.
- Add on-chain validation to reject CloseAccountDevice when device has active references (reference_count > 0)
- Allow contributor owner to update ops manager key
- Add new arguments on create interface cli command
- Serviceability: enforce that resume instructions for locations, exchanges, contributors, devices, links, and users only succeed when the account status is `Suspended`, returning `InvalidStatus` otherwise, and add tests to cover the new behavior.
- RequestBanUser: only allow requests when user.status is Activated or Suspended; otherwise return InvalidStatus
- Serviceability: require device interfaces to be in `Pending` status before they can be rejected, and add tests to cover the new status check
- Add ResourceExtension to track IP/ID allocations. Foundation instructions added to create/allocate/deallocate.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ pub fn process_resume_contributor(
}

let mut contributor: Contributor = Contributor::try_from(contributor_account)?;

// Only resume contributors that are currently Suspended
if contributor.status != ContributorStatus::Suspended {
return Err(DoubleZeroError::InvalidStatus.into());
}

contributor.status = ContributorStatus::Activated;

try_acc_write(&contributor, contributor_account, payer_account, accounts)?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ pub fn process_resume_device(
}

let mut device: Device = Device::try_from(device_account)?;

// Only resume devices that are currently Suspended
if device.status != DeviceStatus::Suspended {
return Err(DoubleZeroError::InvalidStatus.into());
}

device.status = DeviceStatus::Activated;

try_acc_write(&device, device_account, payer_account, accounts)?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ pub fn process_resume_exchange(
return Err(DoubleZeroError::NotAllowed.into());
}

// Only resume exchanges that are currently Suspended
if exchange.status != ExchangeStatus::Suspended {
return Err(DoubleZeroError::InvalidStatus.into());
}

exchange.status = ExchangeStatus::Activated;

try_acc_write(&exchange, exchange_account, payer_account, accounts)?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ pub fn process_resume_location(
}

let mut location: Location = Location::try_from(location_account)?;

// Only resume locations that are currently Suspended
if location.status != LocationStatus::Suspended {
return Err(DoubleZeroError::InvalidStatus.into());
}

location.status = LocationStatus::Activated;

try_acc_write(&location, location_account, payer_account, accounts)?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ pub fn process_resume_user(
return Err(DoubleZeroError::NotAllowed.into());
}

// Only resume users that are currently Suspended
if user.status != UserStatus::Suspended {
return Err(DoubleZeroError::InvalidStatus.into());
}

let mut accesspass = AccessPass::try_from(accesspass_account)?;
assert_eq!(accesspass.user_payer, user.owner, "Invalid AccessPass");
if !accesspass.allow_multiple_ip() && accesspass.client_ip != user.client_ip {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,27 @@ async fn test_contributor() {
assert_eq!(contributor.status, ContributorStatus::Activated);

println!("✅ Contributor resumed");
let result = try_execute_transaction(
&mut banks_client,
recent_blockhash,
program_id,
DoubleZeroInstruction::ResumeContributor(ContributorResumeArgs {}),
vec![
AccountMeta::new(contributor_pubkey, false),
AccountMeta::new(globalstate_pubkey, false),
],
&payer,
)
.await;

assert!(result.is_err());
let error = result.unwrap_err();
let error_string = format!("{:?}", error);
assert!(
error_string.contains("Custom(7)"),
"Expected error to contain 'Custom(7)' (InvalidStatus), but got: {}",
error_string
);
/*****************************************************************************************************************************************************/
println!("Testing Contributor update...");
let ops_manager_pk = Pubkey::new_unique();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,28 @@ async fn test_device() {
assert_eq!(device.status, DeviceStatus::Activated);

println!("✅ Device resumed");
let result = try_execute_transaction(
&mut banks_client,
recent_blockhash,
program_id,
DoubleZeroInstruction::ResumeDevice(DeviceResumeArgs {}),
vec![
AccountMeta::new(device_pubkey, false),
AccountMeta::new(contributor_pubkey, false),
AccountMeta::new(globalstate_pubkey, false),
],
&payer,
)
.await;

assert!(result.is_err());
let error = result.unwrap_err();
let error_string = format!("{:?}", error);
assert!(
error_string.contains("Custom(7)"),
"Expected error to contain 'Custom(7)' (InvalidStatus), but got: {}",
error_string
);
/*****************************************************************************************************************************************************/
println!("🟢 10. Update Device...");
execute_transaction(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,27 @@ async fn test_exchange() {
assert_eq!(exchange.status, ExchangeStatus::Activated);

println!("✅ Exchange resumed");
let result = try_execute_transaction(
&mut banks_client,
recent_blockhash,
program_id,
DoubleZeroInstruction::ResumeExchange(ExchangeResumeArgs {}),
vec![
AccountMeta::new(exchange_pubkey, false),
AccountMeta::new(globalstate_pubkey, false),
],
&payer,
)
.await;

assert!(result.is_err());
let error = result.unwrap_err();
let error_string = format!("{:?}", error);
assert!(
error_string.contains("Custom(7)"),
"Expected error to contain 'Custom(7)' (InvalidStatus), but got: {}",
error_string
);
/*****************************************************************************************************************************************************/
println!("Testing Exchange update...");
execute_transaction(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,28 @@ async fn test_dzx_link() {
assert_eq!(link.status, LinkStatus::Activated);

println!("✅ Link resumed");
let result = try_execute_transaction(
&mut banks_client,
recent_blockhash,
program_id,
DoubleZeroInstruction::ResumeLink(LinkResumeArgs {}),
vec![
AccountMeta::new(link_dzx_pubkey, false),
AccountMeta::new(contributor1_pubkey, false),
AccountMeta::new(globalstate_pubkey, false),
],
&payer,
)
.await;

assert!(result.is_err());
let error = result.unwrap_err();
let error_string = format!("{:?}", error);
assert!(
error_string.contains("Custom(7)"),
"Expected error to contain 'Custom(7)' (InvalidStatus), but got: {}",
error_string
);
/*****************************************************************************************************************************************************/
println!("🟢 13. Update Link...");
execute_transaction(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,28 @@ async fn test_wan_link() {
assert_eq!(link.status, LinkStatus::Activated);

println!("✅ Link resumed");
let result = try_execute_transaction(
&mut banks_client,
recent_blockhash,
program_id,
DoubleZeroInstruction::ResumeLink(LinkResumeArgs {}),
vec![
AccountMeta::new(tunnel_pubkey, false),
AccountMeta::new(contributor_pubkey, false),
AccountMeta::new(globalstate_pubkey, false),
],
&payer,
)
.await;

assert!(result.is_err());
let error = result.unwrap_err();
let error_string = format!("{:?}", error);
assert!(
error_string.contains("Custom(7)"),
"Expected error to contain 'Custom(7)' (InvalidStatus), but got: {}",
error_string
);
/*****************************************************************************************************************************************************/
println!("🟢 11. Update Link...");
execute_transaction(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,27 @@ async fn test_location() {
assert_eq!(location.status, LocationStatus::Activated);

println!("✅ Location resumed");
let result = try_execute_transaction(
&mut banks_client,
recent_blockhash,
program_id,
DoubleZeroInstruction::ResumeLocation(LocationResumeArgs {}),
vec![
AccountMeta::new(location_pubkey, false),
AccountMeta::new(globalstate_pubkey, false),
],
&payer,
)
.await;

assert!(result.is_err());
let error = result.unwrap_err();
let error_string = format!("{:?}", error);
assert!(
error_string.contains("Custom(7)"),
"Expected error to contain 'Custom(7)' (InvalidStatus), but got: {}",
error_string
);
/*****************************************************************************************************************************************************/
println!("Testing Location update...");
execute_transaction(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,27 @@ async fn test_old_user() {
assert_eq!(user.status, UserStatus::Activated);

println!("✅ User resumed");
let result = try_execute_transaction(
&mut banks_client,
recent_blockhash,
program_id,
DoubleZeroInstruction::ResumeUser(UserResumeArgs {}),
vec![
AccountMeta::new(user_pubkey, false),
AccountMeta::new(accesspass_pubkey, false),
],
&payer,
)
.await;

assert!(result.is_err());
let error = result.unwrap_err();
let error_string = format!("{:?}", error);
assert!(
error_string.contains("Custom(7)"),
"Expected error to contain 'Custom(7)' (InvalidStatus), but got: {}",
error_string
);
/*****************************************************************************************************************************************************/
println!("🟢 11a. Testing User update...");
execute_transaction(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,27 @@ async fn test_user() {
assert_eq!(user.status, UserStatus::Activated);

println!("✅ User resumed");
let result = try_execute_transaction(
&mut banks_client,
recent_blockhash,
program_id,
DoubleZeroInstruction::ResumeUser(UserResumeArgs {}),
vec![
AccountMeta::new(user_pubkey, false),
AccountMeta::new(accesspass_pubkey, false),
],
&payer,
)
.await;

assert!(result.is_err());
let error = result.unwrap_err();
let error_string = format!("{:?}", error);
assert!(
error_string.contains("Custom(7)"),
"Expected error to contain 'Custom(7)' (InvalidStatus), but got: {}",
error_string
);
/*****************************************************************************************************************************************************/
println!("🟢 11a. Testing User update...");
execute_transaction(
Expand Down
Loading