caelum_id/
lib.rs

1extern crate web3;
2extern crate rustc_hex;
3extern crate tiny_keccak;
4
5
6pub mod utils;
7pub mod controllers;
8pub mod models;
9
10/*
11#[cfg(test)]
12mod deployment_tests {
13    use crate::utils;
14    #[test]
15    fn it_deploys() {
16        let _gas_price = web3::types::U256::from("1000000000");
17        let _from = web3::types::Address::from("0x00a329c0648769a73afac7f9381e08fb43dbea72");
18        let (loop_hand ,_http) = web3::transports::Http::new("http://localhost:8545").expect("Not connected to an RPC Client."); 
19        utils::wallet::unlock_account(&_from, "", None, &_http);
20        let contract = utils::deploy::deploy_identity(&_from, &_from, &_gas_price, _http)
21        .expect("Failed to deploy indentity, Review the parameters.");
22        assert!(contract.address().to_string() != web3::types::Address::from("0000000000000000000000000000000000000000").to_string());
23    }
24    #[test]
25    fn it_generates_contract_at_addr() {
26        let _gas_price = web3::types::U256::from("1000000000");
27        let _from = web3::types::Address::from("0x00a329c0648769a73afac7f9381e08fb43dbea72");
28        let (loop_hand ,_http) = web3::transports::Http::new("http://localhost:8545").expect("Not connected to an RPC Client."); 
29        utils::wallet::unlock_account(&_from, "", None, &_http);
30        let deployed_contract = utils::deploy::deploy_identity(&_from, &_from, &_gas_price, _http.clone())
31        .expect("Failed to deploy indentity, Review the parameters.");
32        let instanciated_contract = utils::deploy::gen_identity_at_address(&web3::types::Address::from(utils::tools::string_to_static_str(deployed_contract.address().hex())), _http.clone());
33        assert_eq!(deployed_contract.address(), instanciated_contract.address());
34    }
35}
36
37#[cfg(test)]
38mod key_tests {
39    use crate::utils;
40    use crate::models;
41    use crate::controllers::keys;
42    use web3::types::{H256, Address, U256};
43    use crate::utils::tools;
44
45    #[test]
46    #[ignore]
47    fn it_gets_keys_bypurpose() {
48        let _gas_price = web3::types::U256::from("1000000000");
49        let _from = web3::types::Address::from("0x00a329c0648769a73afac7f9381e08fb43dbea72");
50        let purpose = web3::types::U256::from("1");
51        let (loop_hand ,_http) = web3::transports::Http::new("http://localhost:8545").expect("Not connected to an RPC Client."); 
52        utils::wallet::unlock_account(&_from, "", None, &_http);
53        let deployed_contract = utils::deploy::deploy_identity(&_from, &_from, &_gas_price, _http.clone())
54        .expect("Failed to deploy indentity, Review the parameters.");
55        let keys: Vec<H256> = keys::get_keys_by_purpose(&_from, &purpose, &deployed_contract).expect("Error on getting the keys");
56        let keccaked_key = utils::tools::keccak256(&H256::from(Address::from(_from)));
57        assert_eq!(keys[0], keccaked_key);
58    }
59
60    #[test]
61    #[ignore]
62    fn it_gets_keys() {
63        let _gas_price = web3::types::U256::from("1000000000");
64        let _from = web3::types::Address::from("0x00a329c0648769a73afac7f9381e08fb43dbea72");
65        let (loop_hand ,_http) = web3::transports::Http::new("http://localhost:8545").expect("Not connected to an RPC Client."); 
66        utils::wallet::unlock_account(&_from, "", None, &_http);
67        let deployed_contract = utils::deploy::deploy_identity(&_from, &_from, &_gas_price, _http.clone())
68        .expect("Failed to deploy indentity, Review the parameters.");
69        let _key: models::data_structs::Key = keys::get_key(&_from, H256::from([102, 98, 193, 58, 124, 52, 75, 143, 140, 12, 61, 118, 106, 139, 108, 166, 10, 18, 162, 92, 150, 32, 132, 83, 185, 187, 22, 61, 108, 142, 203, 86]), &deployed_contract).expect("Error getting the key");
70        assert_eq!(_key.key, H256::from([102, 98, 193, 58, 124, 52, 75, 143, 140, 12, 61, 118, 106, 139, 108, 166, 10, 18, 162, 92, 150, 32, 132, 83, 185, 187, 22, 61, 108, 142, 203, 86]));
71    }
72
73    #[test]
74    fn it_adds_key() {
75        let _gas_price = web3::types::U256::from("1000000000");
76        let _from = web3::types::Address::from("0x00a329c0648769a73afac7f9381e08fb43dbea72");
77        let (_ ,_http) = web3::transports::Http::new("http://localhost:8545").expect("Not connected to an RPC Client."); 
78        utils::wallet::unlock_account(&_from, "", None, &_http);
79        let deployed_contract = utils::deploy::deploy_identity(&_from, &_from, &_gas_price, _http.clone())
80        .expect("Failed to deploy indentity, Review the parameters.");
81        let _key = models::data_structs::Key {
82            key: H256::from([101, 98, 193, 58, 124, 52, 75, 143, 140, 12, 61, 118, 106, 139, 108, 166, 10, 18, 162, 92, 150, 32, 132, 83, 185, 187, 22, 61, 108, 142, 203, 86]),
83            purpose: U256::from("2"),
84            key_type: U256::from("2")
85        };
86        let added = keys::add_key(_key.clone(), &_gas_price, &_from, &deployed_contract).unwrap();
87        assert_ne!(added.0.key, H256::from(0));
88    }
89}
90
91#[cfg(test)]
92mod claim_tests {
93    use crate::utils;
94    use crate::models;
95    use crate::controllers::{claims, keys};
96    use ethereum_types::{H256, U256, Address};
97
98    #[test]
99    fn it_adds_claims() {
100        let _gas_price = web3::types::U256::from("1000000000");
101        let _from = web3::types::Address::from("0x00a329c0648769a73afac7f9381e08fb43dbea72");
102        let (loop_hand ,_http) = web3::transports::Http::new("http://localhost:8545").expect("Not connected to an RPC Client."); 
103        utils::wallet::unlock_account(&_from, "", None, &_http);
104        let deployed_contract = utils::deploy::deploy_identity(&_from, &_from, &_gas_price, _http.clone())
105        .expect("Failed to deploy indentity, Review the parameters.");
106
107        let _key = models::data_structs::Key {
108            key: H256::from(Address::from("0x00a329c0648769a73afac7f9381e08fb43dbea72")),//Always as bytes, &str not supported.
109            purpose: U256::from("3"),
110            key_type: U256::from("1")
111        };
112
113        keys::add_key(_key.clone(), &_gas_price, &_from, &deployed_contract);
114        //assert_eq!(added.unwrap(), true);
115        utils::wallet::unlock_account(&_from, "", None, &_http);
116        let _claim = models::data_structs::Claim {
117            id: H256::zero(),
118            topic: U256::from("50"),
119            scheme: U256::from("1"),
120            issuer: Address::zero(),
121            signature: H256::zero(),
122            data: H256::zero(),
123            uri: H256::zero()
124        }; 
125        match claims::add_claim(_claim, &_gas_price, &_from, &deployed_contract) {
126            None => panic!("Claim couldn't be added."),
127            Some(claim_id) =>  assert_ne!(claim_id, H256::zero())
128        };
129    }
130}
131*/