Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add new platform user VC: daren market #2903

Merged
merged 5 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions bitacross-worker/docker/docker-compose.yml
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to change it - actually we should remove all data provider envs for bc-worker

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure. Let's do it in another PR to remove all unrelated entries.
P-935 : remove env entries

Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ services:
- KARAT_DAO_API_URL=http://localhost:19527/karat_dao/
- MAGIC_CRAFT_API_URL=http://localhost:19527/magic_craft/
- MAGIC_CRAFT_API_KEY=
- DAREN_MARKET_API_URL=http://localhost:19527/daren_market/
- DAREN_MARKET_API_KEY=
- MORALIS_API_KEY=
- NODEREAL_API_KEY=NODEREAL_API_KEY
- NODEREAL_API_URL=http://localhost:19527
Expand Down
4 changes: 4 additions & 0 deletions bitacross-worker/docker/multiworker-docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ services:
- KARAT_DAO_API_URL=http://localhost:19527/karat_dao/
- MAGIC_CRAFT_API_URL=http://localhost:19527/magic_craft/
- MAGIC_CRAFT_API_KEY=
- DAREN_MARKET_API_URL=http://localhost:19527/daren_market/
- DAREN_MARKET_API_KEY=
- MORALIS_API_KEY=
- NODEREAL_API_KEY=NODEREAL_API_KEY
- NODEREAL_API_URL=http://localhost:19527
Expand Down Expand Up @@ -193,6 +195,8 @@ services:
- KARAT_DAO_API_URL=http://localhost:19527/karat_dao/
- MAGIC_CRAFT_API_URL=http://localhost:19527/magic_craft/
- MAGIC_CRAFT_API_KEY=
- DAREN_MARKET_API_URL=http://localhost:19527/daren_market/
- DAREN_MARKET_API_KEY=
- MORALIS_API_KEY=
- NODEREAL_API_KEY=NODEREAL_API_KEY
- NODEREAL_API_URL=http://localhost:19527
Expand Down
2 changes: 2 additions & 0 deletions local-setup/.env.dev
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ NODEREAL_API_KEY=
GENIIDATA_API_KEY=
MORALIS_API_KEY=
MAGIC_CRAFT_API_KEY=
DAREN_MARKET_API_KEY=

# The followings are default value.
# Can be skipped; or overwrite within non-production mode.
Expand All @@ -61,4 +62,5 @@ MORALIS_API_URL=http://localhost:19527/moralis/
MORALIS_SOLANA_API_URL=http://localhost:19527/moralis_solana/
KARAT_DAO_API_URL=http://localhost:19527/karat_dao/
MAGIC_CRAFT_API_URL=http://localhost:19527/magic_craft/
DAREN_MARKET_API_URL=http://localhost:19527/daren_market/
BLOCKCHAIN_INFO_API_URL=http://localhost:19527/blockchain_info/
8 changes: 5 additions & 3 deletions primitives/core/src/assertion/platform_user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,17 @@ use crate::assertion::network::{all_evm_web3networks, Web3Network};
#[derive(Encode, Decode, Clone, Debug, PartialEq, Eq, MaxEncodedLen, TypeInfo)]
pub enum PlatformUserType {
#[codec(index = 0)]
KaratDaoUser,
KaratDao,
#[codec(index = 1)]
MagicCraftStakingUser,
MagicCraftStaking,
#[codec(index = 2)]
DarenMarket,
Comment on lines +28 to +30
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume this will be a breaking change for the SDK? @jonalvarezz

}

impl PlatformUserType {
pub fn get_supported_networks(&self) -> Vec<Web3Network> {
match self {
Self::KaratDaoUser | Self::MagicCraftStakingUser => all_evm_web3networks(),
Self::KaratDao | Self::MagicCraftStaking | Self::DarenMarket => all_evm_web3networks(),
}
}
}
4 changes: 4 additions & 0 deletions scripts/pre-commit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ function clean_up() {
cargo clean
cd "$root_dir/tee-worker/enclave-runtime"
cargo clean
cd "$root_dir/bitacross-worker"
cargo clean
cd "$root_dir/bitacross-worker/enclave-runtime"
cargo clean
}

root_dir=$(git rev-parse --show-toplevel)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,9 @@ pub enum TokenHoldingAmountCommand {

#[derive(Subcommand, Debug)]
pub enum PlatformUserCommand {
KaratDaoUser,
MagicCraftStakingUser,
KaratDao,
MagicCraftStaking,
DarenMarket,
}

#[derive(Subcommand, Debug)]
Expand Down Expand Up @@ -652,9 +653,10 @@ impl Command {
TokenHoldingAmountCommand::Tuna => TokenHoldingAmount(Web3TokenType::Tuna),
}),
Command::PlatformUser(arg) => Ok(match arg {
PlatformUserCommand::KaratDaoUser => PlatformUser(PlatformUserType::KaratDaoUser),
PlatformUserCommand::MagicCraftStakingUser =>
PlatformUser(PlatformUserType::MagicCraftStakingUser),
PlatformUserCommand::KaratDao => PlatformUser(PlatformUserType::KaratDao),
PlatformUserCommand::MagicCraftStaking =>
PlatformUser(PlatformUserType::MagicCraftStaking),
PlatformUserCommand::DarenMarket => PlatformUser(PlatformUserType::DarenMarket),
}),
Command::NftHolder(arg) => Ok(match arg {
NftHolderCommand::WeirdoGhostGang => NftHolder(Web3NftType::WeirdoGhostGang),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ export default {
},
// PlatformUserType
PlatformUserType: {
_enum: ["KaratDaoUser", "MagicCraftStakingUser"],
_enum: ["KaratDao", "MagicCraftStaking", "DarenMarket"],
},
Comment on lines -245 to 246
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we will need to update client-api, but not a breaking change for client-sdk nor clients in general.

// Web3NftType
Web3NftType: {
Expand Down
2 changes: 2 additions & 0 deletions tee-worker/docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ services:
- KARAT_DAO_API_URL=http://localhost:19527/karat_dao/
- MAGIC_CRAFT_API_URL=http://localhost:19527/magic_craft/
- MAGIC_CRAFT_API_KEY=
- DAREN_MARKET_API_URL=http://localhost:19527/daren_market/
- DAREN_MARKET_API_KEY=
- MORALIS_API_KEY=
- NODEREAL_API_KEY=NODEREAL_API_KEY
- NODEREAL_API_URL=http://localhost:19527
Expand Down
6 changes: 6 additions & 0 deletions tee-worker/docker/multiworker-docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ services:
- KARAT_DAO_API_URL=http://localhost:19527/karat_dao/
- MAGIC_CRAFT_API_URL=http://localhost:19527/magic_craft/
- MAGIC_CRAFT_API_KEY=
- DAREN_MARKET_API_URL=http://localhost:19527/daren_market/
- DAREN_MARKET_API_KEY=
- MORALIS_API_KEY=
- NODEREAL_API_KEY=NODEREAL_API_KEY
- NODEREAL_API_URL=http://localhost:19527
Expand Down Expand Up @@ -203,6 +205,8 @@ services:
- KARAT_DAO_API_URL=http://localhost:19527/karat_dao/
- MAGIC_CRAFT_API_URL=http://localhost:19527/magic_craft/
- MAGIC_CRAFT_API_KEY=
- DAREN_MARKET_API_URL=http://localhost:19527/daren_market/
- DAREN_MARKET_API_KEY=
- MORALIS_API_KEY=
- NODEREAL_API_KEY=NODEREAL_API_KEY
- NODEREAL_API_URL=http://localhost:19527
Expand Down Expand Up @@ -267,6 +271,8 @@ services:
- KARAT_DAO_API_URL=http://localhost:19527/karat_dao/
- MAGIC_CRAFT_API_URL=http://localhost:19527/magic_craft/
- MAGIC_CRAFT_API_KEY=
- DAREN_MARKET_API_URL=http://localhost:19527/daren_market/
- DAREN_MARKET_API_KEY=
- MORALIS_API_KEY=
- NODEREAL_API_KEY=NODEREAL_API_KEY
- NODEREAL_API_URL=http://localhost:19527
Expand Down
103 changes: 94 additions & 9 deletions tee-worker/litentry/core/assertion-build-v2/src/platform_user/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,26 @@ mod tests {
use litentry_hex_utils::decode_hex;
use litentry_primitives::{Identity, IdentityNetworkTuple};

fn init() -> DataProviderConfig {
fn init(platform_user_type: PlatformUserType) -> DataProviderConfig {
let _ = env_logger::builder().is_test(true).try_init();
let url = run(0).unwrap() + "/karat_dao/";

let mut config = DataProviderConfig::new().unwrap();
config.set_karat_dao_api_url(url).unwrap();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm so we never set magic_craft? How did it work before? 🤔

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously magic_craft was not tested.


match platform_user_type {
PlatformUserType::KaratDao => {
let url = run(0).unwrap() + "/karat_dao/";
config.set_karat_dao_api_url(url).unwrap();
},
PlatformUserType::MagicCraftStaking => {
let url = run(0).unwrap() + "/magic_craft/";
config.set_magic_craft_api_url(url).unwrap();
},
PlatformUserType::DarenMarket => {
let url = run(0).unwrap() + "/daren_market/";
config.set_daren_market_api_url(url).unwrap();
},
};

config
}

Expand Down Expand Up @@ -129,11 +143,11 @@ mod tests {
assertion_value: bool,
data_provider_config: &DataProviderConfig,
) {
let req = crate_assertion_build_request(PlatformUserType::KaratDaoUser, identities);
let req = crate_assertion_build_request(platform_user_type.clone(), identities);

match build(&req, platform_user_type.clone(), &data_provider_config) {
Ok(credential) => {
log::info!("build karat dao user done");
log::info!("build platform user: {:?} done", platform_user_type);
assert_eq!(
*(credential.credential_subject.assertions.first().unwrap()),
AssertionLogic::And {
Expand All @@ -150,14 +164,85 @@ mod tests {
);
},
Err(e) => {
panic!("build karat dao user failed with error {:?}", e);
panic!("build platform user: {:?} failed with error {:?}", platform_user_type, e);
},
}
}

#[test]
fn build_karat_dao_user_works() {
let data_provider_config = init();
let data_provider_config = init(PlatformUserType::KaratDao);

let mut address =
decode_hex("0x49ad262c49c7aa708cc2df262ed53b64a17dd5ee".as_bytes().to_vec())
.unwrap()
.as_slice()
.try_into()
.unwrap();
let mut identities: Vec<IdentityNetworkTuple> =
vec![(Identity::Evm(address), vec![Web3Network::Ethereum])];

build_and_assert_result(
identities,
PlatformUserType::KaratDao,
true,
&data_provider_config,
);

address = decode_hex("0x75438d34c9125839c8b08d21b7f3167281659e7c".as_bytes().to_vec())
.unwrap()
.as_slice()
.try_into()
.unwrap();
identities = vec![(Identity::Evm(address), vec![Web3Network::Bsc, Web3Network::Ethereum])];

build_and_assert_result(
identities,
PlatformUserType::KaratDao,
false,
&data_provider_config,
);
}

#[test]
fn build_magic_craft_staking_user_works() {
let data_provider_config = init(PlatformUserType::MagicCraftStaking);

let mut address =
decode_hex("0x49ad262c49c7aa708cc2df262ed53b64a17dd5ee".as_bytes().to_vec())
.unwrap()
.as_slice()
.try_into()
.unwrap();
let mut identities: Vec<IdentityNetworkTuple> =
vec![(Identity::Evm(address), vec![Web3Network::Ethereum])];

build_and_assert_result(
identities,
PlatformUserType::MagicCraftStaking,
true,
&data_provider_config,
);

address = decode_hex("0x75438d34c9125839c8b08d21b7f3167281659e7c".as_bytes().to_vec())
.unwrap()
.as_slice()
.try_into()
.unwrap();
identities = vec![(Identity::Evm(address), vec![Web3Network::Bsc, Web3Network::Ethereum])];

build_and_assert_result(
identities,
PlatformUserType::MagicCraftStaking,
false,
&data_provider_config,
);
}

#[test]
fn build_daren_market_user_works() {
let data_provider_config = init(PlatformUserType::DarenMarket);

let mut address =
decode_hex("0x49ad262c49c7aa708cc2df262ed53b64a17dd5ee".as_bytes().to_vec())
.unwrap()
Expand All @@ -169,7 +254,7 @@ mod tests {

build_and_assert_result(
identities,
PlatformUserType::KaratDaoUser,
PlatformUserType::DarenMarket,
true,
&data_provider_config,
);
Expand All @@ -183,7 +268,7 @@ mod tests {

build_and_assert_result(
identities,
PlatformUserType::KaratDaoUser,
PlatformUserType::DarenMarket,
false,
&data_provider_config,
);
Expand Down
5 changes: 3 additions & 2 deletions tee-worker/litentry/core/common/src/platform_user/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ pub trait PlatformName {
impl PlatformName for PlatformUserType {
fn get_platform_name(&self) -> &'static str {
match self {
Self::KaratDaoUser => "KaratDao",
Self::MagicCraftStakingUser => "MagicCraft",
Self::KaratDao => "KaratDao",
Self::MagicCraftStaking => "MagicCraft",
Self::DarenMarket => "DarenMarket",
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ pub fn get_schema_url(assertion: &Assertion) -> Option<String> {

Assertion::CryptoSummary => Some(format!("{BASE_URL}/23-crypto-summary/1-1-0.json")),

Assertion::PlatformUser(_) => Some(format!("{BASE_URL}/24-platform-user/1-1-1.json")),
Assertion::PlatformUser(_) => Some(format!("{BASE_URL}/24-platform-user/1-1-2.json")),

Assertion::NftHolder(_) => Some(format!("{BASE_URL}/26-nft-holder/1-1-2.json")),

Expand Down
Loading