Skip to content

Commit

Permalink
fix: removed unused imports & lint
Browse files Browse the repository at this point in the history
  • Loading branch information
alenmestrov committed Dec 2, 2024
1 parent 1fd6bf8 commit 7703289
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 45 deletions.
5 changes: 2 additions & 3 deletions contracts/icp/proxy-contract/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::{cell::RefCell, collections::{BTreeMap, BTreeSet, HashMap}};
use std::cell::RefCell;
use std::collections::{BTreeMap, BTreeSet, HashMap};

use candid::{CandidType, Principal};
use serde::{Deserialize, Serialize};
Expand All @@ -13,7 +14,6 @@ pub mod mutate;
pub mod query;
pub mod types;


#[derive(CandidType, Serialize, Deserialize, Default)]
pub struct ICProxyContract {
pub context_id: ICContextId,
Expand Down Expand Up @@ -43,7 +43,6 @@ impl ICProxyContract {
}
}


thread_local! {
static PROXY_CONTRACT: RefCell<ICProxyContract> = RefCell::new(ICProxyContract::default());
}
Expand Down
42 changes: 14 additions & 28 deletions contracts/icp/proxy-contract/src/mutate.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,10 @@
use std::collections::BTreeSet;

use candid::decode_one;
use candid::Principal;
use ic_ledger_types::AccountIdentifier;
use ic_ledger_types::BlockIndex;
use ic_ledger_types::Memo;
use ic_ledger_types::Subaccount;
use ic_ledger_types::Tokens;
use ic_ledger_types::TransferArgs;
use ic_ledger_types::TransferError;
use ic_ledger_types::TransferResult;
use ic_ledger_types::{AccountIdentifier, Memo, Subaccount, Tokens, TransferArgs, TransferError};

use crate::types::*;
use crate::ICProxyContract;
use crate::PROXY_CONTRACT;
use crate::{ICProxyContract, PROXY_CONTRACT};

async fn check_member(_signer_id: &ICSignerId) -> Result<bool, String> {
// let context_canister_id = PROXY_CONTRACT.with(|contract| {
Expand Down Expand Up @@ -52,9 +43,7 @@ async fn mutate(
}

match request.kind {
ICRequestKind::Propose { proposal } => {
internal_create_proposal(proposal)
}
ICRequestKind::Propose { proposal } => internal_create_proposal(proposal),
ICRequestKind::Approve { approval } => {
internal_approve_proposal(
approval.signer_id,
Expand Down Expand Up @@ -135,22 +124,21 @@ async fn execute_proposal(proposal_id: &ICProposalId) -> Result<(), String> {

let transfer_args = TransferArgs {
memo: Memo(0),
amount: Tokens::from_e8s(amount.try_into().map_err(|e| format!("Amount conversion error: {}", e))?),
fee: Tokens::from_e8s(10_000), // Standard fee is 0.0001 ICP
amount: Tokens::from_e8s(
amount
.try_into()
.map_err(|e| format!("Amount conversion error: {}", e))?,
),
fee: Tokens::from_e8s(10_000), // Standard fee is 0.0001 ICP
from_subaccount: None,
to: AccountIdentifier::new(&receiver_id, &Subaccount([0; 32])),
created_at_time: None,
};

let _: (Result<u64, TransferError>,) = ic_cdk::call(
Principal::from(ledger_id),
"transfer",
(transfer_args,)
)
.await
.map_err(|e| {
format!("Transfer failed: {:?}", e)
})?;
let _: (Result<u64, TransferError>,) =
ic_cdk::call(Principal::from(ledger_id), "transfer", (transfer_args,))
.await
.map_err(|e| format!("Transfer failed: {:?}", e))?;
}
ICProposalAction::SetNumApprovals { num_approvals } => {
PROXY_CONTRACT.with(|contract| {
Expand Down Expand Up @@ -210,9 +198,7 @@ fn internal_create_proposal(
// Store proposal
let proposal_id = proposal.id;
let author_id = proposal.author_id;
contract
.proposals
.insert(proposal_id, proposal);
contract.proposals.insert(proposal_id, proposal);

// Initialize approvals set with author's approval
let approvals = BTreeSet::from([author_id]);
Expand Down
8 changes: 6 additions & 2 deletions contracts/icp/proxy-contract/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ impl ReprBytes for Identity {
}
}

#[derive(CandidType, Serialize, Deserialize, Clone, Debug, Hash, Eq, PartialEq, Copy, Ord, PartialOrd)]
#[derive(
CandidType, Serialize, Deserialize, Clone, Debug, Hash, Eq, PartialEq, Copy, Ord, PartialOrd,
)]
pub struct ICSignerId(Identity);

impl ICSignerId {
Expand Down Expand Up @@ -108,7 +110,9 @@ impl Default for ICContextId {
}
}

#[derive(CandidType, Serialize, Deserialize, Copy, Clone, Debug, Hash, Eq, PartialEq, Ord, PartialOrd)]
#[derive(
CandidType, Serialize, Deserialize, Copy, Clone, Debug, Hash, Eq, PartialEq, Ord, PartialOrd,
)]
pub struct ICProposalId(pub [u8; 32]);

impl ICProposalId {
Expand Down
26 changes: 14 additions & 12 deletions contracts/icp/proxy-contract/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,7 @@ mod tests {
let result: Result<Option<ICProposalWithApprovals>, String> =
candid::decode_one(&bytes).expect("Failed to decode response");
match result {
Ok(Some(proposal_with_approvals)) => {}
Ok(Some(_proposal_with_approvals)) => {}
Ok(None) => {
// Proposal was executed and removed
// Verify proposal no longer exists
Expand Down Expand Up @@ -769,18 +769,20 @@ mod tests {
account: AccountIdentifier::new(&Principal::anonymous(), &Subaccount([0; 32])),
};

let response = pic.query_call(
mock_ledger,
Principal::anonymous(),
"account_balance",
candid::encode_one(args).unwrap(),
).expect("Failed to query balance");

let response = pic
.query_call(
mock_ledger,
Principal::anonymous(),
"account_balance",
candid::encode_one(args).unwrap(),
)
.expect("Failed to query balance");

match response {
WasmResult::Reply(bytes) => {
let balance: Tokens = candid::decode_one(&bytes).expect("Failed to decode balance");
let final_balance = balance.e8s();
// Verify the transfer was executed
// Verify the transfer was executed
assert_eq!(
final_balance,
initial_balance
Expand Down Expand Up @@ -917,10 +919,10 @@ mod tests {
let calls: Vec<Vec<u8>> =
candid::decode_one(&bytes).expect("Failed to decode calls");
assert_eq!(calls.len(), 1, "Should have exactly one call");

// Decode the Candid-encoded argument
let received_args: String = candid::decode_one(&calls[0])
.expect("Failed to decode call arguments");
let received_args: String =
candid::decode_one(&calls[0]).expect("Failed to decode call arguments");
assert_eq!(received_args, test_args, "Call arguments should match");
}
_ => panic!("Unexpected response type"),
Expand Down

0 comments on commit 7703289

Please sign in to comment.