Skip to content

Commit

Permalink
😎 Runtime APIs (#354)
Browse files Browse the repository at this point in the history
## What?
- Add pallet-funding runtime APIs as requested in https://linear.app/polimec/issue/PLMC-582/runtime-api-to-have-less-logic-in-the-ui
- Add and modify instantiator functions to make the testing easier

## Why?
Complex querying and calculations are done better in Rust with the full on-chain data and types than in Javascript on the front-end

## Testing?
- New file inside test folder "runtime_api.rs"

## Anything Else?
To get an overview of the main changes, check out runtime_api.rs on /src and on /tests folders, as well as the new tests.rs file on the instantiator, where I test the new functions.

The rest of the changed files should be more about reflecting the changes of the instantiator functions
  • Loading branch information
JuaniRios authored Jul 22, 2024
1 parent a899c98 commit 79eaafd
Show file tree
Hide file tree
Showing 29 changed files with 1,976 additions and 180 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions integration-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ std = [
"polimec-common/std",
"polimec-receiver/std",
"polimec-runtime/std",
"polimec-xcm-executor/std",
"polkadot-core-primitives/std",
"polkadot-parachain-primitives/std",
"polkadot-primitives/std",
Expand Down
18 changes: 15 additions & 3 deletions integration-tests/penpal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,9 @@ assets-common = { version = "0.7.0", default-features = false }
snowbridge-rococo-common = { version = "0.1.0", default-features = false }

[features]
default = ["std"]
default = [ "std" ]
std = [
"assets-common/std",
"parity-scale-codec/std",
"cumulus-pallet-aura-ext/std",
"cumulus-pallet-dmp-queue/std",
"cumulus-pallet-parachain-system/std",
Expand Down Expand Up @@ -119,12 +118,17 @@ std = [
"pallet-timestamp/std",
"pallet-transaction-payment-rpc-runtime-api/std",
"pallet-transaction-payment/std",
"pallet-vesting/std",
"pallet-xcm/std",
"parachain-info/std",
"parachains-common/std",
"parity-scale-codec/std",
"polimec-common/std",
"polimec-receiver/std",
"polkadot-parachain-primitives/std",
"polkadot-primitives/std",
"polkadot-runtime-common/std",
"polkadot-runtime-parachains/std",
"scale-info/std",
"snowbridge-rococo-common/std",
"sp-api/std",
Expand Down Expand Up @@ -166,11 +170,15 @@ runtime-benchmarks = [
"pallet-message-queue/runtime-benchmarks",
"pallet-sudo/runtime-benchmarks",
"pallet-timestamp/runtime-benchmarks",
"pallet-vesting/runtime-benchmarks",
"pallet-xcm/runtime-benchmarks",
"parachains-common/runtime-benchmarks",
"polimec-common/runtime-benchmarks",
"polimec-receiver/runtime-benchmarks",
"polkadot-parachain-primitives/runtime-benchmarks",
"polkadot-primitives/runtime-benchmarks",
"polkadot-runtime-common/runtime-benchmarks",
"polkadot-runtime-parachains/runtime-benchmarks",
"snowbridge-rococo-common/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
"xcm-builder/runtime-benchmarks",
Expand Down Expand Up @@ -198,10 +206,14 @@ try-runtime = [
"pallet-sudo/try-runtime",
"pallet-timestamp/try-runtime",
"pallet-transaction-payment/try-runtime",
"pallet-vesting/try-runtime",
"pallet-xcm/try-runtime",
"parachain-info/try-runtime",
"polimec-common/try-runtime",
"polimec-receiver/try-runtime",
"polkadot-runtime-common/try-runtime",
"polkadot-runtime-parachains/try-runtime",
"sp-runtime/try-runtime",
]

experimental = ["pallet-aura/experimental"]
experimental = [ "pallet-aura/experimental" ]
2 changes: 2 additions & 0 deletions integration-tests/src/tests/ct_migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ fn create_settled_project() -> (ProjectId, Vec<AccountId>) {
let project_id = inst.create_finished_project(
default_project_metadata(ISSUER.into()),
ISSUER.into(),
None,
default_evaluations(),
default_bids(),
default_community_contributions(),
Expand Down Expand Up @@ -221,6 +222,7 @@ fn create_project_with_unsettled_participation(participation_type: Participation
let project_id = inst.create_finished_project(
default_project_metadata(ISSUER.into()),
ISSUER.into(),
None,
default_evaluations(),
default_bids(),
default_community_contributions(),
Expand Down
9 changes: 7 additions & 2 deletions integration-tests/src/tests/e2e.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ fn evaluation_round_completed() {
let evaluations = excel_evaluators();

PolimecNet::execute_with(|| {
inst.create_auctioning_project(project, issuer, evaluations);
inst.create_auctioning_project(project, issuer, None, evaluations);
});
}

Expand All @@ -296,7 +296,7 @@ fn auction_round_completed() {
let bids = excel_bidders();

PolimecNet::execute_with(|| {
let project_id = inst.create_community_contributing_project(project, issuer, evaluations, bids);
let project_id = inst.create_community_contributing_project(project, issuer, None, evaluations, bids);
let excel_wap_fixed = FixedU128::from_float(10.202357561f64);
let excel_wap_usd = excel_wap_fixed.saturating_mul_int(USD_UNIT);

Expand Down Expand Up @@ -334,6 +334,7 @@ fn community_round_completed() {
let _ = inst.create_remainder_contributing_project(
excel_project(),
ISSUER.into(),
None,
excel_evaluators(),
excel_bidders(),
excel_contributions(),
Expand All @@ -360,6 +361,7 @@ fn remainder_round_completed() {
inst.create_finished_project(
excel_project(),
ISSUER.into(),
None,
excel_evaluators(),
excel_bidders(),
excel_contributions(),
Expand Down Expand Up @@ -393,6 +395,7 @@ fn funds_raised() {
let project_id = inst.create_finished_project(
excel_project(),
ISSUER.into(),
None,
excel_evaluators(),
excel_bidders(),
excel_contributions(),
Expand Down Expand Up @@ -424,6 +427,7 @@ fn ct_minted() {
let project_id = inst.create_finished_project(
excel_project(),
ISSUER.into(),
None,
excel_evaluators(),
excel_bidders(),
excel_contributions(),
Expand Down Expand Up @@ -452,6 +456,7 @@ fn ct_migrated() {
let project_id = inst.create_finished_project(
excel_project(),
ISSUER.into(),
None,
excel_evaluators(),
excel_bidders(),
excel_contributions(),
Expand Down
1 change: 1 addition & 0 deletions integration-tests/src/tests/oracle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ fn pallet_funding_works() {
let _project_id = inst.create_finished_project(
default_project_metadata(ISSUER.into()),
ISSUER.into(),
None,
default_evaluations(),
default_bids(),
default_community_contributions(),
Expand Down
2 changes: 2 additions & 0 deletions pallets/funding/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ pallet-xcm.workspace = true
polkadot-parachain-primitives.workspace = true
polimec-common-test-utils = { workspace = true, optional = true }
frame-benchmarking = { workspace = true, optional = true }
sp-api.workspace = true

# Used in the instantiator.
itertools.workspace = true
Expand Down Expand Up @@ -76,6 +77,7 @@ std = [
"polkadot-parachain-primitives/std",
"scale-info/std",
"serde/std",
"sp-api/std",
"sp-arithmetic/std",
"sp-core/std",
"sp-io/std",
Expand Down
Loading

0 comments on commit 79eaafd

Please sign in to comment.