Skip to content
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

feat(treasury-factory): admin full access key, reduce deposit #205

Merged
merged 2 commits into from
Jan 9, 2025
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
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(())
}
Loading