Skip to content

Commit

Permalink
refactor: finalise draft PR
Browse files Browse the repository at this point in the history
  • Loading branch information
Daanvdplas committed Jun 20, 2024
1 parent e1f67a8 commit 874218f
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 23 deletions.
2 changes: 1 addition & 1 deletion pop-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub mod primitives;
pub mod v0;

type AccountId = AccountId32;
// TODO: do the same as above and check expanded code.
// TODO: do the same as above and check expanded macro code.
type Balance = <Environment as ink::env::Environment>::Balance;
type BlockNumber = <Environment as ink::env::Environment>::BlockNumber;
type StringLimit = u32;
Expand Down
3 changes: 2 additions & 1 deletion pop-api/src/v0/assets/pallets/assets.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// TODO: what to put in this file?
#![allow(dead_code)]

use crate::{Balance, RuntimeCall, *};
Expand Down Expand Up @@ -412,6 +411,8 @@ pub(crate) enum AssetsCall {
Block { id: AssetIdParameter, who: MultiAddress<AccountId, ()> },
}

// TODO: do we want add this. Not being used atm but necessary if we want to provide access to the
// rest of the pallet.
#[derive(Debug, Copy, Clone, PartialEq, Eq, Encode, scale::Decode)]
#[cfg_attr(feature = "std", derive(scale_info::TypeInfo))]
pub enum AssetsError {
Expand Down
3 changes: 2 additions & 1 deletion pop-api/src/v0/balances.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// TODO: what to put in this file?
use crate::{dispatch, error::PopApiError, primitives::MultiAddress, v0::RuntimeCall, AccountId};

type Result<T> = core::result::Result<T, PopApiError>;
Expand All @@ -24,6 +23,8 @@ pub enum BalancesCall {
},
}

// TODO: do we want add this. Not being used atm but necessary if we want to provide access to the
// rest of the pallet.
#[derive(Debug, Copy, Clone, PartialEq, Eq, scale::Encode, scale::Decode)]
#[cfg_attr(feature = "std", derive(scale_info::TypeInfo))]
pub enum BalancesError {
Expand Down
5 changes: 0 additions & 5 deletions primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ scale-decode = { version = "0.10.0", default-features = false, features = ["deri
scale-encode = { version = "0.5.0", default-features = false, features = ["derive"], optional = true }
scale-info = { version = "2.6", default-features = false, features = ["derive"], optional = true }

#scale = { workspace = true, features = ["max-encoded-len"] }
#scale-decode = { workspace = true, features = ["derive"], optional = true }
#scale-encode = { workspace = true, features = ["derive"], optional = true }
#scale-info = { workspace = true, features = ["derive"], optional = true }

[features]
default = ["std"]
std = [
Expand Down
22 changes: 8 additions & 14 deletions runtime/devnet/src/tests/local_fungibles.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
// Todo - errors:
// - Badorigin: contract is always signed
// - Lookup: is a valid AccountId due to the contract
// - Many errors can occur from calling a dispatchable. As of now, most of the DispatchErrors are
// handled by the pop api but not all of them are tested. How should I approach this? I.e.:
// - Arithmetic errors
// - Token errors
// - others (besides Module errors) that I might haven't found yet.
#![cfg(test)]

use super::*;
Expand Down Expand Up @@ -251,16 +259,6 @@ fn asset_exists_works() {
});
}

// Todo - errors:
// - Badorigin: contract is always signed
// - Lookup: is a valid AccountId due to the contract
// - reserve(): Overflow, LiquidityRestrictions; frozen
// - Callback
// - StorageDepositLimitExhausted
// todo: errors:
// - TokenErrors
// - Arithmetic
// - https://github.com/paritytech/polkadot-sdk/blob/3977f389cce4a00fd7100f95262e0563622b9aa4/substrate/frame/assets/src/functions.rs#L125
#[test]
#[ignore]
fn create_works() {
Expand Down Expand Up @@ -407,10 +405,6 @@ fn transfer_from_mint_works() {
});
}

// Todo: error:
// - https://github.com/paritytech/polkadot-sdk/blob/2460cddf57660a88844d201f769eb17a7accce5a/substrate/frame/assets/src/functions.rs#L161
// - ArithmeticError: Underflow, Overflow
// - https://github.com/paritytech/polkadot-sdk/blob/master/substrate/frame/assets/src/functions.rs#L125
#[test]
#[ignore]
fn transfer_works() {
Expand Down
5 changes: 4 additions & 1 deletion runtime/testnet/src/extensions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ impl TryFrom<u16> for v0::FuncId {
0x1 => Self::ReadState,
_ => {
log::error!("called an unregistered `func_id`: {:}", func_id);
// TODO: Other error.
return Err(DispatchError::Other("unimplemented func_id"));
},
};
Expand Down Expand Up @@ -206,6 +207,7 @@ where
RuntimeStateKeys::ParachainSystem(key) => {
read_parachain_system_state::<T, E>(key, &mut env)
},
_ => Err(DispatchError::Other("Unknown state keys")),
}?
.encode();

Expand All @@ -215,7 +217,8 @@ where
);
env.write(&result, false, None).map_err(|e| {
log::trace!(target: LOG_TARGET, "{:?}", e);
DispatchError::Other("unable to write results to contract memory")
// TODO: Other error.
DispatchError::Other("Unable to write results to contract memory")
})
}

Expand Down

0 comments on commit 874218f

Please sign in to comment.