Skip to content

Commit

Permalink
fmt and taplo
Browse files Browse the repository at this point in the history
  • Loading branch information
jakehemmerle committed May 16, 2023
1 parent 4a9d51d commit e7e7f8d
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 57 deletions.
5 changes: 1 addition & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
[workspace]
members = [
"constraints",
"core",
]
members = ["constraints", "core"]
28 changes: 14 additions & 14 deletions constraints/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
[package]
name ="ec-constraints"
version="0.1.0"
edition="2021"
name = "ec-constraints"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
thiserror="1.0"
thiserror = "1.0"

# parsing
serde ={ version="1.0.147", default-features=false, features=["derive"] }
serde_json ={ version="1.0", default-features=false, features=["alloc"] }
ec-core ={ path="../core", default-features=false }
sp-core ={ git="https://github.com/paritytech/substrate", branch="polkadot-v0.9.31", default-features=false }
serde = { version = "1.0.147", default-features = false, features = ["derive"] }
serde_json = { version = "1.0", default-features = false, features = ["alloc"] }
ec-core = { path = "../core", default-features = false }
sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.31", default-features = false }

# EVM
ethers-core={ version="0.13.0", default-features=false }
rlp={ version="0.5.2", default-features=false }
hex="0.4.3"
primitive-types={ version="0.11.1", default-features=false, features=[
ethers-core = { version = "0.13.0", default-features = false }
rlp = { version = "0.5.2", default-features = false }
hex = "0.4.3"
primitive-types = { version = "0.11.1", default-features = false, features = [
"scale-info",
"serde_no_std",
] }

[features]
default=["std"]
std=[
default = ["std"]
std = [
"serde/std",
"serde_json/std",
"ec-core/std",
Expand Down
14 changes: 10 additions & 4 deletions constraints/src/architectures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ pub mod evm {
}

impl GetSender<Evm> for <Evm as Architecture>::TransactionRequest {
fn sender(&self) -> Option<<Evm as Architecture>::Address> { self.from }
fn sender(&self) -> Option<<Evm as Architecture>::Address> {
self.from
}
}

impl GetReceiver<Evm> for <Evm as Architecture>::TransactionRequest {
Expand All @@ -76,7 +78,9 @@ pub mod evm {
}

impl GetArch for <Evm as Architecture>::TransactionRequest {
fn arch() -> Arch { Arch::Evm }
fn arch() -> Arch {
Arch::Evm
}
}

impl Parse<Evm> for <Evm as Architecture>::TransactionRequest {
Expand All @@ -96,8 +100,10 @@ pub mod evm {
)),
_ => Ok(tx),
},
Err(e) =>
Err(Error::InvalidTransactionRequest(format!("Unable to decode string: {}", e))),
Err(e) => Err(Error::InvalidTransactionRequest(format!(
"Unable to decode string: {}",
e
))),
}
}
}
Expand Down
7 changes: 5 additions & 2 deletions constraints/src/constraints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ impl Evaluate<Evm> for Acl<[u8; 20]> {
};
}

let converted_addresses: Vec<NameOrAddress> =
self.addresses.into_iter().map(|a| NameOrAddress::Address(H160::from(a))).collect();
let converted_addresses: Vec<NameOrAddress> = self
.addresses
.into_iter()
.map(|a| NameOrAddress::Address(H160::from(a)))
.collect();

match (converted_addresses.contains(&tx.to.unwrap()), self.kind) {
(true, AclKind::Allow) => Ok(()),
Expand Down
74 changes: 57 additions & 17 deletions constraints/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,34 @@ fn test_acl_functions_properly() {
to: Some(NameOrAddress::Address(H160::from(evm_address_3))),
..Default::default()
};
let to_null_recipient_tx = TransactionRequest { to: None, ..Default::default() };
let to_null_recipient_tx = TransactionRequest {
to: None,
..Default::default()
};

let allowlisted_acl = Acl::<[u8; 20]> { addresses: vec![evm_address_1], ..Default::default() };
let allowlisted_acl = Acl::<[u8; 20]> {
addresses: vec![evm_address_1],
..Default::default()
};

// should only let allowlisted_tx through
assert!(allowlisted_acl.clone().eval(to_address_1_tx.clone()).is_ok());

assert!(allowlisted_acl.clone().eval(to_address_2_tx.clone()).is_err());
assert!(allowlisted_acl.clone().eval(to_address_3_tx.clone()).is_err());
assert!(allowlisted_acl.clone().eval(to_null_recipient_tx.clone()).is_err());
assert!(allowlisted_acl
.clone()
.eval(to_address_1_tx.clone())
.is_ok());

assert!(allowlisted_acl
.clone()
.eval(to_address_2_tx.clone())
.is_err());
assert!(allowlisted_acl
.clone()
.eval(to_address_3_tx.clone())
.is_err());
assert!(allowlisted_acl
.clone()
.eval(to_null_recipient_tx.clone())
.is_err());

let denylisted_acl = Acl::<[u8; 20]> {
addresses: vec![evm_address_1],
Expand All @@ -54,11 +72,22 @@ fn test_acl_functions_properly() {
};

// should only let allowlisted_tx and null recipient txs through
assert!(allowlisted_acl_with_null_recipient.clone().eval(to_address_1_tx.clone()).is_ok());
assert!(allowlisted_acl_with_null_recipient.clone().eval(to_null_recipient_tx.clone()).is_ok());

assert!(allowlisted_acl_with_null_recipient.clone().eval(to_address_2_tx.clone()).is_err());
assert!(allowlisted_acl_with_null_recipient.eval(to_address_3_tx.clone()).is_err());
assert!(allowlisted_acl_with_null_recipient
.clone()
.eval(to_address_1_tx.clone())
.is_ok());
assert!(allowlisted_acl_with_null_recipient
.clone()
.eval(to_null_recipient_tx.clone())
.is_ok());

assert!(allowlisted_acl_with_null_recipient
.clone()
.eval(to_address_2_tx.clone())
.is_err());
assert!(allowlisted_acl_with_null_recipient
.eval(to_address_3_tx.clone())
.is_err());

let denylisted_acl_with_null_recipient = Acl::<[u8; 20]> {
addresses: vec![evm_address_1],
Expand All @@ -67,11 +96,22 @@ fn test_acl_functions_properly() {
};

// should only block whitelisted
assert!(denylisted_acl_with_null_recipient.clone().eval(to_address_2_tx.clone()).is_ok());
assert!(denylisted_acl_with_null_recipient.clone().eval(to_address_3_tx.clone()).is_ok());
assert!(denylisted_acl_with_null_recipient.clone().eval(to_null_recipient_tx.clone()).is_ok());

assert!(denylisted_acl_with_null_recipient.eval(to_address_1_tx.clone()).is_err());
assert!(denylisted_acl_with_null_recipient
.clone()
.eval(to_address_2_tx.clone())
.is_ok());
assert!(denylisted_acl_with_null_recipient
.clone()
.eval(to_address_3_tx.clone())
.is_ok());
assert!(denylisted_acl_with_null_recipient
.clone()
.eval(to_null_recipient_tx.clone())
.is_ok());

assert!(denylisted_acl_with_null_recipient
.eval(to_address_1_tx.clone())
.is_err());

let empty_acl = Acl::<[u8; 20]>::default();

Expand Down
34 changes: 21 additions & 13 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
[package]
name ="ec-core"
version="0.1.0"
edition="2021"
name = "ec-core"
version = "0.1.0"
edition = "2021"

[dependencies]
codec ={ package="parity-scale-codec", version="3.0.0", default-features=false }
scale-info ={ version='2.0.1', default-features=false, features=['derive'] }
serde ={ version="1.0", default-features=false, features=["derive"] }
serde_derive ="1.0.147"
sp-core ={ package="sp-core", git="https://github.com/paritytech/substrate", branch="polkadot-v0.9.31", default-features=false }
sp-std ={ package="sp-std", git="https://github.com/paritytech/substrate", branch="polkadot-v0.9.31", default-features=false }
frame-support ={ package="frame-support", git="https://github.com/paritytech/substrate", branch="polkadot-v0.9.31", default-features=false }
node-primitives={ version="2.0.0", default-features=false, git='https://github.com/paritytech/substrate.git', branch="polkadot-v0.9.31" }
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false }
scale-info = { version = '2.0.1', default-features = false, features = [
'derive',
] }
serde = { version = "1.0", default-features = false, features = ["derive"] }
serde_derive = "1.0.147"
sp-core = { package = "sp-core", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.31", default-features = false }
sp-std = { package = "sp-std", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.31", default-features = false }
frame-support = { package = "frame-support", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.31", default-features = false }
node-primitives = { version = "2.0.0", default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = "polkadot-v0.9.31" }

[features]
default=["std"]
std =["scale-info/std", "serde/std", "frame-support/std", "sp-core/std", "sp-std/std"]
default = ["std"]
std = [
"scale-info/std",
"serde/std",
"frame-support/std",
"sp-core/std",
"sp-std/std",
]
10 changes: 7 additions & 3 deletions core/src/constraints.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use core::fmt::Debug;
use alloc::vec::Vec;
use core::fmt::Debug;

pub use acl::*;
use codec::{Decode, Encode};
use codec::MaxEncodedLen;
use codec::{Decode, Encode};
use scale_info::TypeInfo;
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -45,7 +45,11 @@ mod acl {
impl<A: Default> Default for Acl<A> {
fn default() -> Self {
let addresses = Vec::<A>::default();
Self { addresses, kind: AclKind::Allow, allow_null_recipient: false }
Self {
addresses,
kind: AclKind::Allow,
allow_null_recipient: false,
}
}
}
}

0 comments on commit e7e7f8d

Please sign in to comment.