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

Replace offchain metadata with IPFS CID #255

Merged
merged 10 commits into from
Apr 23, 2024
4 changes: 2 additions & 2 deletions integration-tests/src/tests/credentials.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use tests::defaults::*;

#[test]
fn test_jwt_for_create() {
let project = default_project_metadata(0, ISSUER.into());
let project = default_project_metadata(ISSUER.into());
PolitestNet::execute_with(|| {
let issuer = AccountId32::from(ISSUER);
assert_ok!(PolitestBalances::force_set_balance(PolitestOrigin::root(), issuer.into(), 10_000 * PLMC));
Expand All @@ -49,7 +49,7 @@ fn test_jwt_for_create() {

#[test]
fn test_jwt_verification() {
let project = default_project_metadata(0, ISSUER.into());
let project = default_project_metadata(ISSUER.into());
PolitestNet::execute_with(|| {
let issuer = AccountId32::from(ISSUER);
assert_ok!(PolitestBalances::force_set_balance(PolitestOrigin::root(), issuer.into(), 1000 * PLMC));
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/src/tests/ct_migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ fn create_settled_project() -> (ProjectId, Vec<AccountId>) {
let mut inst = IntegrationInstantiator::new(None);
PolitestNet::execute_with(|| {
let project_id = inst.create_finished_project(
default_project_metadata(0, ISSUER.into()),
default_project_metadata(ISSUER.into()),
ISSUER.into(),
default_evaluations(),
default_bids(),
Expand Down
27 changes: 8 additions & 19 deletions integration-tests/src/tests/defaults.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,12 @@ use pallet_funding::{
ProjectMetadataOf, TicketSize,
};
use sp_arithmetic::{FixedPointNumber, Percent};
use sp_core::H256;

use macros::generate_accounts;
use politest_runtime::AccountId;
use sp_runtime::{traits::ConstU32, Perquintill};

pub const METADATA: &str = r#"METADATA
{
"whitepaper":"ipfs_url",
"team_description":"ipfs_url",
"tokenomics":"ipfs_url",
"roadmap":"ipfs_url",
"usage_of_founds":"ipfs_url"
}"#;
pub const IPFS_CID: &str = "QmeuJ24ffwLAZppQcgcggJs3n689bewednYkuc8Bx5Gngz";
pub const ASSET_DECIMALS: u8 = 10;
pub const ASSET_UNIT: u128 = 10_u128.pow(10 as u32);
pub const PLMC: u128 = 10u128.pow(10);
Expand All @@ -45,9 +37,6 @@ pub type IntegrationInstantiator = pallet_funding::instantiator::Instantiator<
<PolitestRuntime as pallet_funding::Config>::AllPalletsWithoutSystem,
<PolitestRuntime as pallet_funding::Config>::RuntimeEvent,
>;
pub fn hashed(data: impl AsRef<[u8]>) -> sp_core::H256 {
<sp_runtime::traits::BlakeTwo256 as sp_runtime::traits::Hash>::hash(data.as_ref())
}

generate_accounts!(
ISSUER, EVAL_1, EVAL_2, EVAL_3, EVAL_4, BIDDER_1, BIDDER_2, BIDDER_3, BIDDER_4, BIDDER_5, BIDDER_6, BUYER_1,
Expand All @@ -60,8 +49,8 @@ pub fn bounded_name() -> BoundedVec<u8, ConstU32<64>> {
pub fn bounded_symbol() -> BoundedVec<u8, ConstU32<64>> {
BoundedVec::try_from("CTEST".as_bytes().to_vec()).unwrap()
}
pub fn metadata_hash(nonce: u32) -> H256 {
hashed(format!("{}-{}", METADATA, nonce))
pub fn ipfs_hash() -> BoundedVec<u8, ConstU32<64>> {
BoundedVec::try_from(IPFS_CID.as_bytes().to_vec()).unwrap()
}
pub fn default_weights() -> Vec<u8> {
vec![20u8, 15u8, 10u8, 25u8, 30u8]
Expand All @@ -73,7 +62,7 @@ pub fn default_contributor_multipliers() -> Vec<u8> {
vec![1u8, 1u8, 1u8, 1u8, 1u8]
}

pub fn default_project_metadata(nonce: u32, issuer: AccountId) -> ProjectMetadataOf<politest_runtime::Runtime> {
pub fn default_project_metadata(issuer: AccountId) -> ProjectMetadataOf<politest_runtime::Runtime> {
ProjectMetadata {
token_information: CurrencyMetadata {
name: bounded_name(),
Expand All @@ -97,7 +86,7 @@ pub fn default_project_metadata(nonce: u32, issuer: AccountId) -> ProjectMetadat
},
participation_currencies: vec![AcceptedFundingAsset::USDT].try_into().unwrap(),
funding_destination_account: issuer,
offchain_information_hash: Some(metadata_hash(nonce)),
policy_ipfs_cid: Some(ipfs_hash()),
}
}
pub fn default_evaluations() -> Vec<UserToUSDBalance<PolitestRuntime>> {
Expand All @@ -112,7 +101,7 @@ pub fn default_bidders() -> Vec<AccountId> {
}

pub fn default_bids() -> Vec<BidParams<PolitestRuntime>> {
let default_metadata = default_project_metadata(0u32, ISSUER.into());
let default_metadata = default_project_metadata(ISSUER.into());
let auction_allocation =
default_metadata.auction_round_allocation_percentage * default_metadata.total_allocation_size;
let auction_90_percent = Perquintill::from_percent(90) * auction_allocation;
Expand All @@ -128,7 +117,7 @@ pub fn default_bids() -> Vec<BidParams<PolitestRuntime>> {
}

pub fn default_community_contributions() -> Vec<ContributionParams<PolitestRuntime>> {
let default_metadata = default_project_metadata(0u32, ISSUER.into());
let default_metadata = default_project_metadata(ISSUER.into());

let auction_allocation =
default_metadata.auction_round_allocation_percentage * default_metadata.total_allocation_size;
Expand All @@ -147,7 +136,7 @@ pub fn default_community_contributions() -> Vec<ContributionParams<PolitestRunti
}

pub fn default_remainder_contributions() -> Vec<ContributionParams<PolitestRuntime>> {
let default_metadata = default_project_metadata(0u32, ISSUER.into());
let default_metadata = default_project_metadata(ISSUER.into());

let auction_allocation =
default_metadata.auction_round_allocation_percentage * default_metadata.total_allocation_size;
Expand Down
20 changes: 10 additions & 10 deletions integration-tests/src/tests/e2e.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ generate_accounts!(
JOEL, POLKA, MALIK, ALEXANDER, SOLOMUN, JOHNNY, GRINGO, JONAS, BUNDI, FELIX,
);

pub fn excel_project(nonce: u64) -> ProjectMetadataOf<PolitestRuntime> {
pub fn excel_project() -> ProjectMetadataOf<PolitestRuntime> {
let bounded_name = BoundedVec::try_from("Polimec".as_bytes().to_vec()).unwrap();
let bounded_symbol = BoundedVec::try_from("PLMC".as_bytes().to_vec()).unwrap();
let metadata_hash = hashed(format!("{}-{}", METADATA, nonce));
let metadata_hash = ipfs_hash();
ProjectMetadata {
token_information: CurrencyMetadata { name: bounded_name, symbol: bounded_symbol, decimals: 10 },
mainnet_token_max_supply: 10_000_000_0_000_000_000, // Made up, not in the Sheet.
Expand All @@ -61,7 +61,7 @@ pub fn excel_project(nonce: u64) -> ProjectMetadataOf<PolitestRuntime> {
},
participation_currencies: vec![AcceptedFundingAsset::USDT].try_into().unwrap(),
funding_destination_account: ISSUER.into(),
offchain_information_hash: Some(metadata_hash),
policy_ipfs_cid: Some(metadata_hash),
}
}

Expand Down Expand Up @@ -264,7 +264,7 @@ fn evaluation_round_completed() {
let mut inst = IntegrationInstantiator::new(None);

let issuer = ISSUER.into();
let project = excel_project(inst.get_new_nonce());
let project = excel_project();
let evaluations = excel_evaluators();

PolitestNet::execute_with(|| {
Expand All @@ -277,7 +277,7 @@ fn auction_round_completed() {
let mut inst = IntegrationInstantiator::new(None);

let issuer = ISSUER.into();
let project = excel_project(inst.get_new_nonce());
let project = excel_project();
let evaluations = excel_evaluators();
let bids = excel_bidders();

Expand Down Expand Up @@ -313,7 +313,7 @@ fn community_round_completed() {

PolitestNet::execute_with(|| {
let _ = inst.create_remainder_contributing_project(
excel_project(0),
excel_project(),
ISSUER.into(),
excel_evaluators(),
excel_bidders(),
Expand All @@ -338,7 +338,7 @@ fn remainder_round_completed() {

PolitestNet::execute_with(|| {
let project_id = inst.create_finished_project(
excel_project(0),
excel_project(),
ISSUER.into(),
excel_evaluators(),
excel_bidders(),
Expand Down Expand Up @@ -375,7 +375,7 @@ fn funds_raised() {

PolitestNet::execute_with(|| {
let project_id = inst.create_finished_project(
excel_project(0),
excel_project(),
ISSUER.into(),
excel_evaluators(),
excel_bidders(),
Expand All @@ -399,7 +399,7 @@ fn ct_minted() {

PolitestNet::execute_with(|| {
let project_id = inst.create_finished_project(
excel_project(0),
excel_project(),
ISSUER.into(),
excel_evaluators(),
excel_bidders(),
Expand All @@ -424,7 +424,7 @@ fn ct_migrated() {

let project_id = PolitestNet::execute_with(|| {
let project_id = inst.create_finished_project(
excel_project(0),
excel_project(),
ISSUER.into(),
excel_evaluators(),
excel_bidders(),
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/src/tests/oracle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ fn pallet_funding_works() {
assert_ok!(Oracle::feed_values(RuntimeOrigin::signed(charlie.clone()), values([4.84, 1.0, 1.0, 0.4])));

let _project_id = inst.create_finished_project(
default_project_metadata(0, ISSUER.into()),
default_project_metadata(ISSUER.into()),
ISSUER.into(),
default_evaluations(),
default_bids(),
Expand Down
39 changes: 14 additions & 25 deletions nodes/parachain/src/chain_spec/politest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,21 +294,13 @@ fn testnet_genesis(
mod testing_helpers {
use super::*;
pub use macros::generate_accounts;
pub use pallet_funding::{instantiator::UserToUSDBalance, AuctionPhase, ProjectStatus, *};
pub use sp_core::H256;
pub use pallet_funding::{instantiator::UserToUSDBalance, ProjectStatus, *};
pub use sp_runtime::{
traits::{ConstU32, Get, PhantomData},
BoundedVec, FixedPointNumber,
};

pub const METADATA: &str = r#"METADATA
{
"whitepaper":"ipfs_url",
"team_description":"ipfs_url",
"tokenomics":"ipfs_url",
"roadmap":"ipfs_url",
"usage_of_founds":"ipfs_url"
}"#;
pub const IPFS_CID: &str = "QmeuJ24ffwLAZppQcgcggJs3n689bewednYkuc8Bx5Gngz";
pub const ASSET_DECIMALS: u8 = 10;
pub const ASSET_UNIT: u128 = 10_u128.pow(10 as u32);

Expand All @@ -324,14 +316,14 @@ mod testing_helpers {
pub fn bounded_symbol() -> BoundedVec<u8, ConstU32<64>> {
BoundedVec::try_from("CTEST".as_bytes().to_vec()).unwrap()
}
pub fn metadata_hash(nonce: u32) -> H256 {
hashed(format!("{}-{}", METADATA, nonce))
pub fn ipfs_hash() -> BoundedVec<u8, ConstU32<64>> {
BoundedVec::try_from(IPFS_CID.as_bytes().to_vec()).unwrap()
}
pub fn default_weights() -> Vec<u8> {
vec![20u8, 15u8, 10u8, 25u8, 30u8]
}

pub fn project_metadata(issuer: AccountId, nonce: u32) -> ProjectMetadataOf<politest_runtime::Runtime> {
pub fn project_metadata(issuer: AccountId) -> ProjectMetadataOf<politest_runtime::Runtime> {
ProjectMetadata {
token_information: CurrencyMetadata {
name: bounded_name(),
Expand All @@ -355,7 +347,7 @@ mod testing_helpers {
},
participation_currencies: vec![AcceptedFundingAsset::USDT].try_into().unwrap(),
funding_destination_account: issuer,
offchain_information_hash: Some(metadata_hash(nonce)),
policy_ipfs_cid: Some(ipfs_hash()),
}
}
pub fn default_evaluations() -> Vec<UserToUSDBalance<politest_runtime::Runtime>> {
Expand Down Expand Up @@ -385,9 +377,6 @@ mod testing_helpers {
pub fn default_remainder_contributors() -> Vec<AccountId> {
vec![EVAL_1.into(), BIDDER_3.into(), BUYER_4.into(), BUYER_6.into(), BIDDER_6.into()]
}
pub fn hashed(data: impl AsRef<[u8]>) -> sp_core::H256 {
<sp_runtime::traits::BlakeTwo256 as sp_runtime::traits::Hash>::hash(data.as_ref())
}

use politest_runtime::Runtime as T;
pub type GenesisInstantiator = pallet_funding::instantiator::Instantiator<
Expand All @@ -410,13 +399,13 @@ fn testing_genesis(
use pallet_funding::instantiator::TestProjectParams;
use politest_runtime::{
BalancesConfig, CouncilConfig, ForeignAssetsConfig, ParachainInfoConfig, ParachainStakingConfig,
PolkadotXcmConfig, SessionConfig, SudoConfig, TechnicalCommitteeConfig,
PolkadotXcmConfig, SessionConfig, SudoConfig, TechnicalCommitteeConfig, EXISTENTIAL_DEPOSIT,
};
use sp_runtime::bounded_vec;
use testing_helpers::*;

// only used to generate some values, and not for chain interactions
let default_project_metadata = project_metadata(ISSUER.into(), 0u32);
let default_project_metadata = project_metadata(ISSUER.into());
let min_price = default_project_metadata.minimum_price;
let usdt_funding_amount =
default_project_metadata.minimum_price.checked_mul_int(default_project_metadata.total_allocation_size).unwrap();
Expand Down Expand Up @@ -461,7 +450,7 @@ fn testing_genesis(
starting_projects: vec![
TestProjectParams::<Runtime> {
expected_state: ProjectStatus::FundingSuccessful,
metadata: project_metadata(ISSUER_1.into(), 0u32),
metadata: project_metadata(ISSUER_1.into()),
issuer: ISSUER_1.into(),
evaluations: evaluations.clone(),
bids: bids.clone(),
Expand All @@ -470,7 +459,7 @@ fn testing_genesis(
},
TestProjectParams::<Runtime> {
expected_state: ProjectStatus::RemainderRound,
metadata: project_metadata(ISSUER_2.into(), 1u32),
metadata: project_metadata(ISSUER_2.into()),
issuer: ISSUER_2.into(),
evaluations: evaluations.clone(),
bids: bids.clone(),
Expand All @@ -479,7 +468,7 @@ fn testing_genesis(
},
TestProjectParams::<Runtime> {
expected_state: ProjectStatus::CommunityRound,
metadata: project_metadata(ISSUER_3.into(), 2u32),
metadata: project_metadata(ISSUER_3.into()),
issuer: ISSUER_3.into(),
evaluations: evaluations.clone(),
bids: bids.clone(),
Expand All @@ -488,7 +477,7 @@ fn testing_genesis(
},
TestProjectParams::<Runtime> {
expected_state: ProjectStatus::AuctionOpening,
metadata: project_metadata(ISSUER_4.into(), 3u32),
metadata: project_metadata(ISSUER_4.into()),
issuer: ISSUER_4.into(),
evaluations: evaluations.clone(),
bids: vec![],
Expand All @@ -497,7 +486,7 @@ fn testing_genesis(
},
TestProjectParams::<Runtime> {
expected_state: ProjectStatus::EvaluationRound,
metadata: project_metadata(ISSUER_5.into(), 4u32),
metadata: project_metadata(ISSUER_5.into()),
issuer: ISSUER_5.into(),
evaluations: vec![],
bids: vec![],
Expand All @@ -506,7 +495,7 @@ fn testing_genesis(
},
TestProjectParams::<Runtime> {
expected_state: ProjectStatus::Application,
metadata: project_metadata(ISSUER_6.into(), 5u32),
metadata: project_metadata(ISSUER_6.into()),
issuer: ISSUER_6.into(),
evaluations: vec![],
bids: vec![],
Expand Down
Loading