Skip to content

Commit 3802591

Browse files
vstam1JuaniRioslrazovic
authored
Feature/split contributions (#176)
* new test for plmc and usdt return on final price being lower post wap calculation Signed-off-by: Juan Ignacio Rios <juani.rios.99@gmail.com> * Cargo check passes!!!! Signed-off-by: Juan Ignacio Rios <juani.rios.99@gmail.com> * trying to fix test Signed-off-by: Juan Ignacio Rios <juani.rios.99@gmail.com> * save Signed-off-by: Juan Ignacio Rios <juani.rios.99@gmail.com> * save Signed-off-by: Juan Ignacio Rios <juani.rios.99@gmail.com> * test for fn written. fails :( Signed-off-by: Juan Ignacio Rios <juani.rios.99@gmail.com> * instantiator helper function working in unit test and in a funding test Signed-off-by: Juan Ignacio Rios <juani.rios.99@gmail.com> * fixing functions Signed-off-by: Juan Ignacio Rios <juani.rios.99@gmail.com> * fixed test Signed-off-by: Juan Ignacio Rios <juani.rios.99@gmail.com> * holy shit all tests passing :O Signed-off-by: Juan Ignacio Rios <juani.rios.99@gmail.com> * fmt Signed-off-by: Juan Ignacio Rios <juani.rios.99@gmail.com> * most tests fixed, including benchmarks ;D Signed-off-by: Juan Ignacio Rios <juani.rios.99@gmail.com> * split contribution in 2 functions + simplify benchmarking * ALL TESTS PASSING INCL. BENCHMARKS Signed-off-by: Juan Ignacio Rios <juani.rios.99@gmail.com> * fix tests * integration test fixes Signed-off-by: Juan Ignacio Rios <juani.rios.99@gmail.com> * deleting repeated tests Signed-off-by: Juan Ignacio Rios <juani.rios.99@gmail.com> * tests cleaning, 3 are failing Signed-off-by: Juan Ignacio Rios <juani.rios.99@gmail.com> * fix tests syntax err Signed-off-by: Juan Ignacio Rios <juani.rios.99@gmail.com> * 2 tests remaining to pass Signed-off-by: Juan Ignacio Rios <juani.rios.99@gmail.com> * all tests passing Signed-off-by: Juan Ignacio Rios <juani.rios.99@gmail.com> * post merge fixes Signed-off-by: Juan Ignacio Rios <juani.rios.99@gmail.com> * rollback toolchain Signed-off-by: Juan Ignacio Rios <juani.rios.99@gmail.com> * fmt and check for winning bid in community contribute Signed-off-by: Juan Ignacio Rios <juani.rios.99@gmail.com> * fmt Signed-off-by: Juan Ignacio Rios <juani.rios.99@gmail.com> * save Signed-off-by: Juan Ignacio Rios <juani.rios.99@gmail.com> * save Signed-off-by: Juan Ignacio Rios <juani.rios.99@gmail.com> * fixed integration tests on my machine by using nightly and stopped using sccache + sold linker Signed-off-by: Juan Ignacio Rios <juani.rios.99@gmail.com> * fixes in integration-tests Signed-off-by: Juan Ignacio Rios <juani.rios.99@gmail.com> * fmt Signed-off-by: Juan Ignacio Rios <juani.rios.99@gmail.com> * Update rust-toolchain.toml Co-authored-by: Leonardo Razovic <4128940+lrazovic@users.noreply.github.com> * Update integration-tests/src/tests/mod.rs Co-authored-by: Leonardo Razovic <4128940+lrazovic@users.noreply.github.com> * remove old weights Signed-off-by: Juan Ignacio Rios <juani.rios.99@gmail.com> * uncomment Signed-off-by: Juan Ignacio Rios <juani.rios.99@gmail.com> * unused fn Signed-off-by: Juan Ignacio Rios <juani.rios.99@gmail.com> --------- Signed-off-by: Juan Ignacio Rios <juani.rios.99@gmail.com> Co-authored-by: Juan Ignacio Rios <juani.rios.99@gmail.com> Co-authored-by: Juan Ignacio Rios <54085674+JuaniRios@users.noreply.github.com> Co-authored-by: Leonardo Razovic <4128940+lrazovic@users.noreply.github.com>
1 parent df49898 commit 3802591

File tree

11 files changed

+384
-1155
lines changed

11 files changed

+384
-1155
lines changed

Cargo.lock

+176-176
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

integration-tests/src/tests/basic_comms.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ use crate::*;
1919

2020
const MAX_REF_TIME: u64 = 300_000_000;
2121
const MAX_PROOF_SIZE: u64 = 10_000;
22-
2322
// Ignored for now as we are not allowing "Transact" execution on our parachain
2423
#[ignore]
2524
#[test]
@@ -59,6 +58,7 @@ fn dmp() {
5958
});
6059
}
6160

61+
#[ignore]
6262
#[test]
6363
fn ump() {
6464
use polkadot_runtime_parachains::inclusion::{AggregateMessageOrigin, UmpQueueId};

integration-tests/src/tests/ct_migration.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ fn migration_is_sent() {
323323
(sp_runtime::FixedU128::from_float(1.0).checked_mul_int(100_000 * ASSET_UNIT).unwrap()),
324324
sp_runtime::FixedU128::from_float(1.0),
325325
default_weights(),
326-
vec![EVAL_1.into(), BUYER_1.into(), BUYER_2.into(), BUYER_3.into(), BUYER_4.into()],
326+
vec![EVAL_2.into(), BUYER_1.into(), BUYER_2.into(), BUYER_3.into(), BUYER_4.into()],
327327
default_contributor_multipliers(),
328328
),
329329
vec![],
@@ -368,7 +368,7 @@ fn migration_is_executed_on_project_and_confirmed_on_polimec() {
368368
(sp_runtime::FixedU128::from_float(1.0).checked_mul_int(100_000 * ASSET_UNIT).unwrap()),
369369
sp_runtime::FixedU128::from_float(1.0),
370370
default_weights(),
371-
vec![EVAL_1.into(), BUYER_2.into(), BUYER_3.into(), BUYER_4.into(), BUYER_5.into()],
371+
vec![EVAL_2.into(), BUYER_2.into(), BUYER_3.into(), BUYER_4.into(), BUYER_5.into()],
372372
default_contributor_multipliers(),
373373
),
374374
vec![],
@@ -391,7 +391,7 @@ fn migration_is_executed_on_project_and_confirmed_on_polimec() {
391391
#[test]
392392
fn vesting_over_several_blocks_on_project() {
393393
let mut inst = IntegrationInstantiator::new(None);
394-
let participants = vec![EVAL_1, EVAL_2, EVAL_3, BIDDER_1, BIDDER_2, BUYER_1, BUYER_2, BUYER_3]
394+
let participants = vec![EVAL_1, EVAL_2, EVAL_3, BIDDER_1, BIDDER_2, BUYER_1, BUYER_2]
395395
.into_iter()
396396
.map(|x| AccountId::from(x))
397397
.collect::<Vec<_>>();
@@ -413,7 +413,7 @@ fn vesting_over_several_blocks_on_project() {
413413
asset: AcceptedFundingAsset::USDT,
414414
});
415415
bids.push(BidParams {
416-
bidder: BIDDER_2.into(),
416+
bidder: EVAL_2.into(),
417417
amount: 12_000 * ASSET_UNIT,
418418
multiplier: MultiplierOf::<PolimecRuntime>::try_from(7u8).unwrap(),
419419
asset: AcceptedFundingAsset::USDT,
@@ -432,7 +432,7 @@ fn vesting_over_several_blocks_on_project() {
432432
asset: AcceptedFundingAsset::USDT,
433433
});
434434
community_contributions.push(ContributionParams {
435-
contributor: BUYER_3.into(),
435+
contributor: EVAL_1.into(),
436436
amount: 30000 * ASSET_UNIT,
437437
multiplier: MultiplierOf::<PolimecRuntime>::try_from(3u8).unwrap(),
438438
asset: AcceptedFundingAsset::USDT,

integration-tests/src/tests/defaults.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use macros::generate_accounts;
2626
use polimec_parachain_runtime::AccountId;
2727
use sp_runtime::{traits::ConstU32, Perquintill};
2828
use xcm_emulator::TestExt;
29-
29+
// //42555945525f3300000000000000000000000000000000000000000000000000
3030
pub const METADATA: &str = r#"METADATA
3131
{
3232
"whitepaper":"ipfs_url",

pallets/funding/src/benchmarking.rs

+4-225
Original file line numberDiff line numberDiff line change
@@ -1334,191 +1334,10 @@ mod benchmarks {
13341334
);
13351335
}
13361336

1337-
// - We know how many iterations it does in storage
1338-
// - We know it requires no CT deposit (remainder round only)
1339-
// - We know that it does not require to unbond the lowest contribution
1340-
// - We know it doesn't end the round
1341-
#[benchmark]
1342-
fn first_contribution_with_ct_deposit() {
1343-
// How many other contributions the user did for that same project
1344-
let x = 0;
1345-
let ends_round = None;
1346-
1347-
let (
1348-
inst,
1349-
project_id,
1350-
project_metadata,
1351-
extrinsic_contribution,
1352-
total_free_plmc,
1353-
total_plmc_bonded,
1354-
total_free_usdt,
1355-
total_usdt_locked,
1356-
total_ct_sold,
1357-
) = contribution_setup::<T>(x, ends_round);
1358-
1359-
#[extrinsic_call]
1360-
contribute(
1361-
RawOrigin::Signed(extrinsic_contribution.contributor.clone()),
1362-
project_id,
1363-
extrinsic_contribution.amount,
1364-
extrinsic_contribution.multiplier,
1365-
extrinsic_contribution.asset,
1366-
);
1367-
1368-
contribution_verification::<T>(
1369-
inst,
1370-
project_id,
1371-
project_metadata,
1372-
extrinsic_contribution,
1373-
total_free_plmc,
1374-
total_plmc_bonded,
1375-
total_free_usdt,
1376-
total_usdt_locked,
1377-
total_ct_sold,
1378-
);
1379-
}
1380-
1381-
// - We know how many iterations it does in storage
1382-
// - We know it requires a CT deposit
1383-
// - We know that it does not require to unbond the lowest contribution
1384-
// - We know it doesn't end the round
13851337
#[benchmark]
1386-
fn first_contribution_no_ct_deposit() {
1338+
fn contribution(
13871339
// How many other contributions the user did for that same project
1388-
let x = 0;
1389-
let ends_round = None;
1390-
1391-
let (
1392-
inst,
1393-
project_id,
1394-
project_metadata,
1395-
extrinsic_contribution,
1396-
total_free_plmc,
1397-
total_plmc_bonded,
1398-
total_free_usdt,
1399-
total_usdt_locked,
1400-
total_ct_sold,
1401-
) = contribution_setup::<T>(x, ends_round);
1402-
1403-
let _new_plmc_minted = make_ct_deposit_for::<T>(extrinsic_contribution.contributor.clone(), project_id);
1404-
1405-
#[extrinsic_call]
1406-
contribute(
1407-
RawOrigin::Signed(extrinsic_contribution.contributor.clone()),
1408-
project_id,
1409-
extrinsic_contribution.amount,
1410-
extrinsic_contribution.multiplier,
1411-
extrinsic_contribution.asset,
1412-
);
1413-
1414-
contribution_verification::<T>(
1415-
inst,
1416-
project_id,
1417-
project_metadata,
1418-
extrinsic_contribution,
1419-
total_free_plmc,
1420-
total_plmc_bonded,
1421-
total_free_usdt,
1422-
total_usdt_locked,
1423-
total_ct_sold,
1424-
);
1425-
}
1426-
#[benchmark]
1427-
fn first_contribution_ends_round_with_ct_deposit(
1428-
// Insertion attempts in add_to_update_store. Total amount of storage items iterated through in `ProjectsToUpdate`. Leave one free to make the extrinsic pass
1429-
y: Linear<1, { <T as Config>::MaxProjectsToUpdateInsertionAttempts::get() - 1 }>,
1430-
// Total amount of storage items iterated through in `ProjectsToUpdate` when trying to remove our project in `remove_from_update_store`.
1431-
// Upper bound is assumed to be enough
1432-
z: Linear<1, 10_000>,
1433-
) {
1434-
// How many other contributions the user did for that same project
1435-
let x = 0;
1436-
let ends_round = Some((y, z));
1437-
let (
1438-
inst,
1439-
project_id,
1440-
project_metadata,
1441-
extrinsic_contribution,
1442-
total_free_plmc,
1443-
total_plmc_bonded,
1444-
total_free_usdt,
1445-
total_usdt_locked,
1446-
total_ct_sold,
1447-
) = contribution_setup::<T>(x, ends_round);
1448-
1449-
#[extrinsic_call]
1450-
contribute(
1451-
RawOrigin::Signed(extrinsic_contribution.contributor.clone()),
1452-
project_id,
1453-
extrinsic_contribution.amount,
1454-
extrinsic_contribution.multiplier,
1455-
extrinsic_contribution.asset,
1456-
);
1457-
1458-
contribution_verification::<T>(
1459-
inst,
1460-
project_id,
1461-
project_metadata,
1462-
extrinsic_contribution,
1463-
total_free_plmc,
1464-
total_plmc_bonded,
1465-
total_free_usdt,
1466-
total_usdt_locked,
1467-
total_ct_sold,
1468-
);
1469-
}
1470-
1471-
#[benchmark]
1472-
fn first_contribution_ends_round_no_ct_deposit(
1473-
// Insertion attempts in add_to_update_store. Total amount of storage items iterated through in `ProjectsToUpdate`. Leave one free to make the extrinsic pass
1474-
y: Linear<1, { <T as Config>::MaxProjectsToUpdateInsertionAttempts::get() - 1 }>,
1475-
// Total amount of storage items iterated through in `ProjectsToUpdate` when trying to remove our project in `remove_from_update_store`.
1476-
// Upper bound is assumed to be enough
1477-
z: Linear<1, 10_000>,
1478-
) {
1479-
// How many other contributions the user did for that same project
1480-
let x = 0;
1481-
let ends_round = Some((y, z));
1482-
let (
1483-
inst,
1484-
project_id,
1485-
project_metadata,
1486-
extrinsic_contribution,
1487-
total_free_plmc,
1488-
total_plmc_bonded,
1489-
total_free_usdt,
1490-
total_usdt_locked,
1491-
total_ct_sold,
1492-
) = contribution_setup::<T>(x, ends_round);
1493-
1494-
let _new_plmc_minter = make_ct_deposit_for::<T>(extrinsic_contribution.contributor.clone(), project_id);
1495-
1496-
#[extrinsic_call]
1497-
contribute(
1498-
RawOrigin::Signed(extrinsic_contribution.contributor.clone()),
1499-
project_id,
1500-
extrinsic_contribution.amount,
1501-
extrinsic_contribution.multiplier,
1502-
extrinsic_contribution.asset,
1503-
);
1504-
1505-
contribution_verification::<T>(
1506-
inst,
1507-
project_id,
1508-
project_metadata,
1509-
extrinsic_contribution,
1510-
total_free_plmc,
1511-
total_plmc_bonded,
1512-
total_free_usdt,
1513-
total_usdt_locked,
1514-
total_ct_sold,
1515-
);
1516-
}
1517-
1518-
#[benchmark]
1519-
fn second_to_limit_contribution(
1520-
// How many other contributions the user did for that same project
1521-
x: Linear<1, { T::MaxContributionsPerUser::get() - 1 }>,
1340+
x: Linear<0, { T::MaxContributionsPerUser::get() - 1 }>,
15221341
) {
15231342
let ends_round = None;
15241343

@@ -1557,9 +1376,9 @@ mod benchmarks {
15571376
}
15581377

15591378
#[benchmark]
1560-
fn second_to_limit_contribution_ends_round(
1379+
fn contribution_ends_round(
15611380
// How many other contributions the user did for that same project
1562-
x: Linear<1, { T::MaxContributionsPerUser::get() - 1 }>,
1381+
x: Linear<0, { T::MaxContributionsPerUser::get() - 1 }>,
15631382
// Insertion attempts in add_to_update_store. Total amount of storage items iterated through in `ProjectsToUpdate`. Leave one free to make the extrinsic pass
15641383
y: Linear<1, { <T as Config>::MaxProjectsToUpdateInsertionAttempts::get() - 1 }>,
15651384
// Total amount of storage items iterated through in `ProjectsToUpdate` when trying to remove our project in `remove_from_update_store`.
@@ -1602,46 +1421,6 @@ mod benchmarks {
16021421
);
16031422
}
16041423

1605-
#[benchmark]
1606-
fn contribution_over_limit() {
1607-
// How many other contributions the user did for that same project
1608-
let x = <T as Config>::MaxContributionsPerUser::get();
1609-
let ends_round = None;
1610-
1611-
let (
1612-
inst,
1613-
project_id,
1614-
project_metadata,
1615-
extrinsic_contribution,
1616-
total_free_plmc,
1617-
total_plmc_bonded,
1618-
total_free_usdt,
1619-
total_usdt_locked,
1620-
total_ct_sold,
1621-
) = contribution_setup::<T>(x, ends_round);
1622-
1623-
#[extrinsic_call]
1624-
contribute(
1625-
RawOrigin::Signed(extrinsic_contribution.contributor.clone()),
1626-
project_id,
1627-
extrinsic_contribution.amount,
1628-
extrinsic_contribution.multiplier,
1629-
extrinsic_contribution.asset,
1630-
);
1631-
1632-
contribution_verification::<T>(
1633-
inst,
1634-
project_id,
1635-
project_metadata,
1636-
extrinsic_contribution,
1637-
total_free_plmc,
1638-
total_plmc_bonded,
1639-
total_free_usdt,
1640-
total_usdt_locked,
1641-
total_ct_sold,
1642-
);
1643-
}
1644-
16451424
#[benchmark]
16461425
fn evaluation_unbond_for() {
16471426
// setup

0 commit comments

Comments
 (0)