Skip to content

Commit

Permalink
chore: use enum for collection prefixes (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksuss authored Jan 30, 2024
1 parent a34e640 commit f924927
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 47 deletions.
21 changes: 17 additions & 4 deletions src/keys.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
pub const BLOBS_KEY: &[u8] = b"BLOBS";
pub const DEPLOYMENTS_KEY: &[u8] = b"DEPLOYMENTS";
pub const RELEASES_KEY: &[u8] = b"RELEASES";
pub const LATEST_KEY: &[u8] = b"LATEST";
use near_sdk::borsh::{self, BorshDeserialize, BorshSerialize};
use near_sdk::IntoStorageKey;

/// Prefixes for the `near-sdk` collections that are used in the smart contract.
#[derive(BorshSerialize, BorshDeserialize)]
pub enum Prefix {
Blobs,
Deployments,
Releases,
LatestRelease,
}

impl IntoStorageKey for Prefix {
fn into_storage_key(self) -> Vec<u8> {
self.try_to_vec().unwrap()
}
}
12 changes: 6 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ impl AuroraControllerFactory {
pub fn new(owner_id: AccountId) -> Self {
assert!(!env::state_exists(), "Already initialized");
let mut contract = Self {
releases: UnorderedMap::new(keys::RELEASES_KEY),
blobs: UnorderedMap::new(keys::BLOBS_KEY),
deployments: UnorderedMap::new(keys::DEPLOYMENTS_KEY),
latest: LazyOption::new(keys::LATEST_KEY, None),
releases: UnorderedMap::new(keys::Prefix::Releases),
blobs: UnorderedMap::new(keys::Prefix::Blobs),
deployments: UnorderedMap::new(keys::Prefix::Deployments),
latest: LazyOption::new(keys::Prefix::LatestRelease, None),
};

contract.owner_set(Some(owner_id));
Expand Down Expand Up @@ -134,8 +134,8 @@ impl AuroraControllerFactory {
promise.function_call(
action.function_name,
action.arguments.into(),
action.amount,
action.gas,
action.amount.into(),
Gas(action.gas.0),
)
})
}
Expand Down
32 changes: 1 addition & 31 deletions src/tests/sdk/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use crate::types::ReleaseInfo;
use crate::AuroraControllerFactory;
use near_plugins::AccessControllable;
use near_sdk::serde_json::Value;
use near_sdk::{AccountId, ONE_NEAR};
use near_sdk::AccountId;

#[macro_use]
mod macros;
Expand Down Expand Up @@ -96,35 +95,6 @@ fn test_adding_blob_without_adding_hash() {
contract.add_release_blob();
}

#[ignore]
#[test]
fn test_deploy_new_aurora_contract() {
set_env!(
predecessor_account_id: owner(),
attached_deposit: ONE_NEAR * 15,
input: include_bytes!("../../../res/aurora-mainnet-silo-3.4.0.wasm").to_vec(),
);
let mut contract = AuroraControllerFactory::new(owner());
assert!(contract.acl_grant_role("DAO".to_owned(), owner()).unwrap());

contract.add_release_info(
"05ed0185c7348ca8949727d7f0f20870cf24a768407b2870032e6ef3963990a7".to_string(),
"3.4.0".parse().unwrap(),
true,
None,
None,
);
contract.add_release_blob();
contract.deploy(
new_engine(),
"new".to_string(),
Value::default(),
Some("05ed0185c7348ca8949727d7f0f20870cf24a768407b2870032e6ef3963990a7".to_string()),
);

assert_eq!(contract.get_deployments().len(), 1);
}

#[test]
fn test_check_latest_release() {
set_env!(
Expand Down
4 changes: 2 additions & 2 deletions src/tests/workspace/delegate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ async fn test_delegate_execution() {
"actions": vec![FunctionCallArgs {
function_name: "set_owner".to_string(),
arguments: contract_id.try_to_vec().map(Into::into).unwrap(),
amount: 0,
gas: Gas::ONE_TERA * 5
amount: 0.into(),
gas: (Gas::ONE_TERA * 5).0.into()
}]
}))
.max_gas()
Expand Down
7 changes: 3 additions & 4 deletions src/types.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use near_sdk::borsh::{self, BorshDeserialize, BorshSerialize};
use near_sdk::json_types::Base64VecU8;
use near_sdk::json_types::{Base64VecU8, U128, U64};
use near_sdk::serde::{Deserialize, Serialize};
use near_sdk::{Balance, Gas};
use std::collections::BTreeMap;
use std::fmt::{Display, Formatter};
use std::io::Write;
Expand Down Expand Up @@ -94,8 +93,8 @@ impl Display for Version {
pub struct FunctionCallArgs {
pub function_name: String,
pub arguments: Base64VecU8,
pub amount: Balance,
pub gas: Gas,
pub amount: U128,
pub gas: U64,
}

#[test]
Expand Down

0 comments on commit f924927

Please sign in to comment.