Skip to content

Commit

Permalink
feat(treasury-factory): admin full access key, reduce deposit (#205)
Browse files Browse the repository at this point in the history
- add admin full access key to accounts created by treasury factory
- reduce web4 contract deposit to 2 N and socialdb deposit to 1. Total
factory deposit is now 9 NEAR
  • Loading branch information
petersalomonsen authored Jan 9, 2025
1 parent d1ff325 commit 1b91f3f
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 6 deletions.
11 changes: 8 additions & 3 deletions treasury-factory/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Find all our documentation at https://docs.near.org
mod web4;
use near_sdk::{env, near, serde_json::json, AccountId, Gas, NearToken, Promise};
use near_sdk::{env, near, serde_json::json, AccountId, Gas, NearToken, Promise, PublicKey};
use web4::types::{Web4Request, Web4Response};
pub mod external;
pub use crate::external::*;
Expand Down Expand Up @@ -31,13 +31,18 @@ impl Contract {
create_dao_args: String,
) -> Promise {
let new_instance_contract_id: AccountId = format!("{}.near", name).parse().unwrap();
let admin_full_access_public_key: PublicKey =
"ed25519:DuAFUPhxv3zBDbZP8oCwC1KQPVzaUY88s5tECv8JDPMg"
.parse()
.unwrap();

Promise::new("near".parse().unwrap())
.function_call(
"create_account_advanced".to_string(),
json!({
"new_account_id": new_instance_contract_id.clone(),
"options": {
"full_access_keys": [env::signer_account_pk()],
"full_access_keys": [env::signer_account_pk(),admin_full_access_public_key],
"contract_bytes_base64": include_str!("../treasury_web4.wasm.base64.txt")
}
})
Expand All @@ -50,7 +55,7 @@ impl Contract {
.then(
instance_contract::ext(new_instance_contract_id.clone())
.with_attached_deposit(
env::attached_deposit().saturating_sub(NearToken::from_near(6)),
env::attached_deposit().saturating_sub(NearToken::from_near(1)),
)
.update_widgets(widget_reference_account_id, social_db_account_id),
)
Expand Down
38 changes: 35 additions & 3 deletions treasury-factory/tests/test_basics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ use lazy_static::lazy_static;
use near_sdk::base64::{engine::general_purpose, Engine as _};
use near_sdk::serde::Deserialize;
use near_sdk::{AccountId, NearToken};
use near_workspaces::types::AccessKeyPermission;
use near_workspaces::types::PublicKey;
use serde_json::{json, Value};
use std::fs;
use std::sync::{Mutex, Once};
Expand Down Expand Up @@ -212,8 +214,10 @@ async fn test_factory() -> Result<(), Box<dyn std::error::Error>> {
},
});

let create_treasury_instance_result = treasury_factory_contract
.call("create_instance")
let user_account = worker.dev_create_account().await?;

let create_treasury_instance_result = user_account
.call(treasury_factory_contract.id(), "create_instance")
.args_json(json!(
{
"sputnik_dao_factory_account_id": SPUTNIKDAO_FACTORY_CONTRACT_ACCOUNT,
Expand All @@ -224,7 +228,7 @@ async fn test_factory() -> Result<(), Box<dyn std::error::Error>> {
}
))
.max_gas()
.deposit(NearToken::from_near(10))
.deposit(NearToken::from_near(9))
.transact()
.await?;

Expand Down Expand Up @@ -295,5 +299,33 @@ async fn test_factory() -> Result<(), Box<dyn std::error::Error>> {
),
deployed_widgets_json_string
);

let admin_full_access_public_key: PublicKey =
"ed25519:DuAFUPhxv3zBDbZP8oCwC1KQPVzaUY88s5tECv8JDPMg"
.parse()
.unwrap();
let admin_access_key = worker
.view_access_key(
&instance_account_id.parse().unwrap(),
&admin_full_access_public_key,
)
.await?;
assert!(
matches!(admin_access_key.permission, AccessKeyPermission::FullAccess),
"Expected FullAccess permission"
);

let user_full_access_public_key = user_account.secret_key().public_key();
let user_access_key = worker
.view_access_key(
&instance_account_id.parse().unwrap(),
&user_full_access_public_key,
)
.await?;
assert!(
matches!(user_access_key.permission, AccessKeyPermission::FullAccess),
"Expected FullAccess permission"
);

Ok(())
}

0 comments on commit 1b91f3f

Please sign in to comment.