Skip to content
This repository has been archived by the owner on May 16, 2024. It is now read-only.

Commit

Permalink
chore(lib): checking for unused variables
Browse files Browse the repository at this point in the history
  • Loading branch information
yahortsaryk committed Jun 29, 2023
1 parent b123746 commit c50afa9
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 42 deletions.
12 changes: 4 additions & 8 deletions bucket/ddc_bucket/tests/test_cdn_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ fn cdn_node_create_ok() {

let new_cdn_node_key = AccountId::from([0xc4, 0xcd, 0xaa, 0xfa, 0xf1, 0x30, 0x7d, 0x23, 0xf4, 0x99, 0x84, 0x71, 0xdf, 0x78, 0x59, 0xce, 0x06, 0x3d, 0xce, 0x78, 0x59, 0xc4, 0x3a, 0xe8, 0xef, 0x12, 0x0a, 0xbc, 0x43, 0xc4, 0x84, 0x31]);
let new_cdn_node_params = CdnNodeParams::from("{\"url\":\"https://ddc-1.cere.network/cdn/new\"}");
let new_cdn_node_capacity = 100;
let new_cdn_node_rent_per_month: Balance = 10 * TOKEN;

set_caller_value(new_provider_id, CONTRACT_FEE_LIMIT);
ctx.contract.cdn_node_create(
Expand All @@ -50,13 +48,14 @@ fn cdn_node_create_ok() {
);

let cdn_node_info = ctx.contract.cdn_node_get(new_cdn_node_key)?;
assert!(matches!(cdn_node_info.cdn_node, CdnNode {
let _expected_cdn_node = CdnNode {
provider_id: new_provider_id,
undistributed_payment: 0,
cdn_node_params,
cdn_node_params: new_cdn_node_params,
cluster_id: None,
status_in_cluster: None,
}));
};
assert!(matches!(cdn_node_info.cdn_node, _expected_cdn_node));

}

Expand Down Expand Up @@ -170,7 +169,6 @@ fn cdn_node_get_err_if_node_does_not_exist() {
fn node_get_ok() {
let ctx = setup_cluster();

let v_nodes1_len : u32 = ctx.v_nodes1.len().try_into().unwrap();
assert_eq!(
ctx.contract.cdn_node_get(ctx.cdn_node_key1),
Ok({
Expand All @@ -196,7 +194,6 @@ fn node_list_ok() {
let cdn_node_info = ctx.contract.cdn_node_get(ctx.cdn_node_key1)?;
assert_eq!(ctx.provider_id1, cdn_node_info.cdn_node.provider_id.clone());

let v_nodes1_len : u32 = ctx.v_nodes1.len().try_into().unwrap();
let cdn_node1 = CdnNodeInfo {
cdn_node_key: ctx.cdn_node_key1,
cdn_node: CdnNode {
Expand All @@ -208,7 +205,6 @@ fn node_list_ok() {
},
};

let v_nodes2_len : u32 = ctx.v_nodes2.len().try_into().unwrap();
let cdn_node2 = CdnNodeInfo {
cdn_node_key: ctx.cdn_node_key2,
cdn_node: CdnNode {
Expand Down
63 changes: 32 additions & 31 deletions bucket/ddc_bucket/tests/test_cluster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,14 +400,14 @@ fn cluster_add_node_ok() {
})
);

let nodes_keys = vec![
let _nodes_keys = vec![
ctx.node_key0,
ctx.node_key1,
ctx.node_key2,
new_node_key,
];

let cluster_v_nodes = vec![
let _cluster_v_nodes = vec![
ctx.v_nodes0,
ctx.v_nodes1,
ctx.v_nodes2,
Expand All @@ -416,11 +416,11 @@ fn cluster_add_node_ok() {

let mut cluster_info = ctx.contract.cluster_get(ctx.cluster_id)?;
cluster_info.cluster_v_nodes.sort();
assert!(matches!(cluster_info.cluster.nodes_keys, nodes_keys));
assert!(matches!(cluster_info.cluster_v_nodes, cluster_v_nodes));
assert!(matches!(cluster_info.cluster.nodes_keys, _nodes_keys));
assert!(matches!(cluster_info.cluster_v_nodes, _cluster_v_nodes));

let node_info = ctx.contract.node_get(new_node_key)?;
let expected_node_info = NodeInfo {
let _expected_node_info = NodeInfo {
node_key: new_node_key,
node: Node {
provider_id: new_provider_id,
Expand All @@ -432,7 +432,7 @@ fn cluster_add_node_ok() {
},
v_nodes: new_v_nodes
};
assert!(matches!(node_info, expected_node_info));
assert!(matches!(node_info, _expected_node_info));
}


Expand Down Expand Up @@ -500,23 +500,23 @@ fn cluster_remove_node_ok_if_node_provider() {
})
);

let nodes_keys = vec![
let _nodes_keys = vec![
ctx.node_key0,
ctx.node_key2,
];

let cluster_v_nodes = vec![
let _cluster_v_nodes = vec![
ctx.v_nodes0,
ctx.v_nodes2,
];

let mut cluster_info = ctx.contract.cluster_get(ctx.cluster_id)?;
cluster_info.cluster_v_nodes.sort();
assert!(matches!(cluster_info.cluster.nodes_keys, nodes_keys));
assert!(matches!(cluster_info.cluster_v_nodes, cluster_v_nodes));
assert!(matches!(cluster_info.cluster.nodes_keys, _nodes_keys));
assert!(matches!(cluster_info.cluster_v_nodes, _cluster_v_nodes));

let node_info = ctx.contract.node_get(ctx.node_key1)?;
let expected_node_info = NodeInfo {
let _expected_node_info = NodeInfo {
node_key: ctx.node_key1,
node: Node {
provider_id: ctx.provider_id1,
Expand All @@ -528,7 +528,7 @@ fn cluster_remove_node_ok_if_node_provider() {
},
v_nodes: Vec::new()
};
assert!(matches!(node_info, expected_node_info));
assert!(matches!(node_info, _expected_node_info));

}

Expand All @@ -551,23 +551,24 @@ fn cluster_remove_node_ok_if_cluster_manager() {
})
);

let nodes_keys = vec![
let _nodes_keys = vec![
ctx.node_key0,
ctx.node_key1,
];

let cluster_v_nodes = vec![
let _cluster_v_nodes = vec![
ctx.v_nodes0,
ctx.v_nodes1,
];

let mut cluster_info = ctx.contract.cluster_get(ctx.cluster_id)?;
cluster_info.cluster_v_nodes.sort();
assert!(matches!(cluster_info.cluster.nodes_keys, nodes_keys));
assert!(matches!(cluster_info.cluster_v_nodes, cluster_v_nodes));
assert!(matches!(cluster_info.cluster.nodes_keys, _nodes_keys));
assert!(matches!(cluster_info.cluster_v_nodes, _cluster_v_nodes
));

let node_info = ctx.contract.node_get(ctx.node_key2)?;
let expected_node_info = NodeInfo {
let _expected_node_info = NodeInfo {
node_key: ctx.node_key2,
node: Node {
provider_id: ctx.provider_id2,
Expand All @@ -579,7 +580,7 @@ fn cluster_remove_node_ok_if_cluster_manager() {
},
v_nodes: Vec::new()
};
assert!(matches!(node_info, expected_node_info));
assert!(matches!(node_info, _expected_node_info));

}

Expand Down Expand Up @@ -620,7 +621,7 @@ fn cluster_add_cdn_node_err_if_not_trusted_manager() {
let new_cdn_node_key = AccountId::from([0xc4, 0xcd, 0xaa, 0xfa, 0xf1, 0x30, 0x7d, 0x23, 0xf4, 0x99, 0x84, 0x71, 0xdf, 0x78, 0x59, 0xce, 0x06, 0x3d, 0xce, 0x78, 0x59, 0xc4, 0x3a, 0xe8, 0xef, 0x12, 0x0a, 0xbc, 0x43, 0xc4, 0x84, 0x31]);

set_caller_value(new_provider_id, CONTRACT_FEE_LIMIT);
let new_node_key = ctx.contract.cdn_node_create(
ctx.contract.cdn_node_create(
new_cdn_node_key,
CdnNodeParams::from("new_cdn_node"),
)?;
Expand Down Expand Up @@ -727,18 +728,18 @@ fn cluster_add_cdn_node_ok() {
})
);

let cdn_nodes_keys = vec![
let _cdn_nodes_keys = vec![
ctx.cdn_node_key0,
ctx.cdn_node_key1,
ctx.cdn_node_key2,
new_cdn_node_key,
];

let cluster_info = ctx.contract.cluster_get(ctx.cluster_id)?;
assert!(matches!(cluster_info.cluster.cdn_nodes_keys, cdn_nodes_keys));
assert!(matches!(cluster_info.cluster.cdn_nodes_keys, _cdn_nodes_keys));

let cdn_node_info = ctx.contract.cdn_node_get(new_cdn_node_key)?;
let expected_cdn_node_info = CdnNodeInfo {
let _expected_cdn_node_info = CdnNodeInfo {
cdn_node_key: new_cdn_node_key,
cdn_node: CdnNode {
provider_id: new_provider_id,
Expand All @@ -748,7 +749,7 @@ fn cluster_add_cdn_node_ok() {
status_in_cluster: Some(NodeStatusInCluster::ADDING)
},
};
assert!(matches!(cdn_node_info, expected_cdn_node_info));
assert!(matches!(cdn_node_info, _expected_cdn_node_info));
}


Expand Down Expand Up @@ -814,16 +815,16 @@ fn cluster_remove_cdn_node_ok_if_cdn_node_provider() {
})
);

let cdn_nodes_keys = vec![
let _cdn_nodes_keys = vec![
ctx.cdn_node_key0,
ctx.cdn_node_key2,
];

let cluster_info = ctx.contract.cluster_get(ctx.cluster_id)?;
assert!(matches!(cluster_info.cluster.cdn_nodes_keys, cdn_nodes_keys));
assert!(matches!(cluster_info.cluster.cdn_nodes_keys, _cdn_nodes_keys));

let cdn_node_info = ctx.contract.cdn_node_get(ctx.cdn_node_key1)?;
let expected_cdn_node_info = CdnNodeInfo {
let _expected_cdn_node_info = CdnNodeInfo {
cdn_node_key: ctx.cdn_node_key1,
cdn_node: CdnNode {
provider_id: ctx.provider_id1,
Expand All @@ -833,7 +834,7 @@ fn cluster_remove_cdn_node_ok_if_cdn_node_provider() {
status_in_cluster: None
},
};
assert!(matches!(cdn_node_info, expected_cdn_node_info));
assert!(matches!(cdn_node_info, _expected_cdn_node_info));

}

Expand All @@ -856,16 +857,16 @@ fn cluster_remove_cdn_node_ok_if_cluster_manager() {
})
);

let cdn_nodes_keys = vec![
let _cdn_nodes_keys = vec![
ctx.cdn_node_key0,
ctx.cdn_node_key1,
];

let cluster_info = ctx.contract.cluster_get(ctx.cluster_id)?;
assert!(matches!(cluster_info.cluster.cdn_nodes_keys, cdn_nodes_keys));
assert!(matches!(cluster_info.cluster.cdn_nodes_keys, _cdn_nodes_keys));

let cdn_node_info = ctx.contract.cdn_node_get(ctx.cdn_node_key2)?;
let expected_cdn_node_info = CdnNodeInfo {
let _expected_cdn_node_info = CdnNodeInfo {
cdn_node_key: ctx.cdn_node_key2,
cdn_node: CdnNode {
provider_id: ctx.provider_id2,
Expand All @@ -875,7 +876,7 @@ fn cluster_remove_cdn_node_ok_if_cluster_manager() {
status_in_cluster: None
},
};
assert!(matches!(cdn_node_info, expected_cdn_node_info));
assert!(matches!(cdn_node_info, _expected_cdn_node_info));
}


Expand Down
5 changes: 3 additions & 2 deletions bucket/ddc_bucket/tests/test_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,15 @@ fn node_create_ok() {
);

let node_info = ctx.contract.node_get(new_node_key)?;
assert!(matches!(node_info.node, Node {
let _expected_node_info = Node {
provider_id: new_provider_id,
rent_per_month: new_node_rent_per_month,
free_resource: new_node_capacity,
node_params: new_node_params,
cluster_id: None,
status_in_cluster: None,
}));
};
assert!(matches!(node_info.node, _expected_node_info));

}

Expand Down
2 changes: 1 addition & 1 deletion bucket/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#![cfg_attr(not(feature = "std"), no_std)]
#![feature(proc_macro_hygiene)] // for tests in a separate file
// #![deny(unused_must_use, unused_variables)]
#![deny(unused_must_use, unused_variables)]

use ink_lang as ink;

Expand Down

0 comments on commit c50afa9

Please sign in to comment.