Skip to content

Commit 926fc9f

Browse files
authored
Fix wrong from_date and to_date in assertions (#1342)
* add upate holder * add tests * update 4/7/10 * update test case
1 parent 45c1cf6 commit 926fc9f

File tree

6 files changed

+165
-58
lines changed

6 files changed

+165
-58
lines changed

tee-worker/litentry/core/assertion-build/src/a10.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,23 @@ pub fn build(
4848
let q_min_balance: f64 = (min_balance / (10 ^ 8)) as f64;
4949

5050
let mut client = GraphQLClient::new();
51-
let mut flag = false;
51+
let mut found = false;
52+
let mut from_date_index = 0_usize;
5253

5354
for id in identities {
55+
if found {
56+
break
57+
}
58+
5459
if let Identity::Evm { network, address } = id {
5560
if matches!(network, EvmNetwork::Ethereum) {
5661
if let Ok(addr) = from_utf8(address.as_ref()) {
5762
let addresses = vec![addr.to_string()];
5863

59-
for from_date in ASSERTION_FROM_DATE.iter() {
60-
// if flag is true, no need to check it continually
61-
if flag {
64+
for (index, from_date) in ASSERTION_FROM_DATE.iter().enumerate() {
65+
// if found is true, no need to check it continually
66+
if found {
67+
from_date_index = index + 1;
6268
break
6369
}
6470
let credentials = VerifiedCredentialsIsHodlerIn::new(
@@ -73,7 +79,7 @@ pub fn build(
7379
.check_verified_credentials_is_hodler(credentials)
7480
.map_err(from_data_provider_error)?;
7581
for hodler in is_hodler_out.verified_credentials_is_hodler.iter() {
76-
flag = flag || hodler.is_hodler;
82+
found = found || hodler.is_hodler;
7783
}
7884
}
7985
};
@@ -84,8 +90,7 @@ pub fn build(
8490
let a10 = Assertion::A10(min_balance);
8591
match Credential::generate_unsigned_credential(&a10, who, &shard.clone(), bn) {
8692
Ok(mut credential_unsigned) => {
87-
credential_unsigned.credential_subject.values.push(flag);
88-
93+
credential_unsigned.update_holder(from_date_index, min_balance);
8994
return Ok(credential_unsigned)
9095
},
9196
Err(e) => {

tee-worker/litentry/core/assertion-build/src/a11.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,23 @@ pub fn build(
4949
let q_min_balance: f64 = (min_balance / (10 ^ 18)) as f64;
5050

5151
let mut client = GraphQLClient::new();
52-
let mut flag = false;
52+
let mut found = false;
53+
let mut from_date_index = 0_usize;
5354

5455
for id in identities {
56+
if found {
57+
break
58+
}
59+
5560
if let Identity::Evm { network, address } = id {
5661
if matches!(network, EvmNetwork::Ethereum) {
5762
let address = from_utf8(address.as_ref()).unwrap().to_string();
5863
let addresses = vec![address];
5964

60-
for from_date in ASSERTION_FROM_DATE.iter() {
61-
// if flag is true, no need to check it continually
62-
if flag {
65+
for (index, from_date) in ASSERTION_FROM_DATE.iter().enumerate() {
66+
// if found is true, no need to check it continually
67+
if found {
68+
from_date_index = index + 1;
6369
break
6470
}
6571

@@ -74,7 +80,7 @@ pub fn build(
7480
.check_verified_credentials_is_hodler(credentials)
7581
.map_err(from_data_provider_error)?;
7682
for hodler in is_hodler_out.verified_credentials_is_hodler.iter() {
77-
flag = flag || hodler.is_hodler;
83+
found = found || hodler.is_hodler;
7884
}
7985
}
8086
}
@@ -84,8 +90,7 @@ pub fn build(
8490
let a11 = Assertion::A11(min_balance);
8591
match Credential::generate_unsigned_credential(&a11, who, &shard.clone(), bn) {
8692
Ok(mut credential_unsigned) => {
87-
credential_unsigned.credential_subject.values.push(flag);
88-
93+
credential_unsigned.update_holder(from_date_index, min_balance);
8994
return Ok(credential_unsigned)
9095
},
9196
Err(e) => {

tee-worker/litentry/core/assertion-build/src/a4.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,14 @@ pub fn build(
4949
bn: ParentchainBlockNumber,
5050
) -> Result<Credential> {
5151
let mut client = GraphQLClient::new();
52-
let mut flag = false;
52+
let mut found = false;
53+
let mut from_date_index = 0_usize;
5354

5455
for identity in identities.iter() {
56+
if found {
57+
break
58+
}
59+
5560
let mut verified_network = VerifiedCredentialsNetwork::Polkadot;
5661
if identity.is_web3() {
5762
match identity {
@@ -88,9 +93,10 @@ pub fn build(
8893
tmp_token_addr = LIT_TOKEN_ADDRESS.to_string();
8994
}
9095

91-
for from_date in ASSERTION_FROM_DATE.iter() {
92-
// if flag is true, no need to check it continually
93-
if flag {
96+
for (index, from_date) in ASSERTION_FROM_DATE.iter().enumerate() {
97+
// if found is true, no need to check it continually
98+
if found {
99+
from_date_index = index + 1;
94100
break
95101
}
96102

@@ -106,7 +112,7 @@ pub fn build(
106112
.map_err(from_data_provider_error)?;
107113

108114
for holder in is_hodler_out.verified_credentials_is_hodler.iter() {
109-
flag = flag || holder.is_hodler;
115+
found = found || holder.is_hodler;
110116
}
111117
}
112118
}
@@ -115,7 +121,7 @@ pub fn build(
115121
let a4 = Assertion::A4(min_balance);
116122
match Credential::generate_unsigned_credential(&a4, who, &shard.clone(), bn) {
117123
Ok(mut credential_unsigned) => {
118-
credential_unsigned.credential_subject.values.push(flag);
124+
credential_unsigned.update_holder(from_date_index, min_balance);
119125
return Ok(credential_unsigned)
120126
},
121127
Err(e) => {

tee-worker/litentry/core/assertion-build/src/a7.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,23 @@ pub fn build(
4848
let q_min_balance: f64 = (min_balance / (10 ^ 12)) as f64;
4949

5050
let mut client = GraphQLClient::new();
51-
let mut flag = false;
51+
let mut found = false;
52+
let mut from_date_index = 0_usize;
5253

5354
for id in identities {
55+
if found {
56+
break
57+
}
58+
5459
if let Identity::Substrate { network, address } = id {
5560
if matches!(network, SubstrateNetwork::Polkadot) {
5661
let address = from_utf8(address.as_ref()).unwrap().to_string();
5762
let addresses = vec![address];
5863

59-
for from_date in ASSERTION_FROM_DATE.iter() {
60-
// if flag is true, no need to check it continually
61-
if flag {
64+
for (index, from_date) in ASSERTION_FROM_DATE.iter().enumerate() {
65+
// if found is true, no need to check it continually
66+
if found {
67+
from_date_index = index + 1;
6268
break
6369
}
6470

@@ -73,7 +79,7 @@ pub fn build(
7379
.check_verified_credentials_is_hodler(credentials)
7480
.map_err(from_data_provider_error)?;
7581
for hodler in is_hodler_out.verified_credentials_is_hodler.iter() {
76-
flag = flag || hodler.is_hodler;
82+
found = found || hodler.is_hodler;
7783
}
7884
}
7985
}
@@ -83,8 +89,7 @@ pub fn build(
8389
let a7 = Assertion::A7(min_balance);
8490
match Credential::generate_unsigned_credential(&a7, who, &shard.clone(), bn) {
8591
Ok(mut credential_unsigned) => {
86-
credential_unsigned.credential_subject.values.push(flag);
87-
92+
credential_unsigned.update_holder(from_date_index, min_balance);
8893
return Ok(credential_unsigned)
8994
},
9095
Err(e) => {

0 commit comments

Comments
 (0)