Created
January 17, 2024 14:20
-
-
Save sgerodes/97c5c37d2cbf98f561264e4f6728d703 to your computer and use it in GitHub Desktop.
Asignment 3, What to ttest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# test ideas | |
//! - Only signed extrinsics are accepted, so you will learn signature verification. | |
//! - Basic calls for testing/learning, mainly represented in [`shared::RuntimeCall::System`]. | |
//! - Basic currency system. | |
//! - Basic staking/reserving system. | |
//! - Nonce system, to prevent replay attacks and similar issues. | |
//! - Tipping, which is there to mimic transaction fee payment. | |
//! Checks that must happen in apply phase are those that are mandatory to make sure a blockchain is | |
//! sound and safe. These include: | |
//! | |
//! - Signature verification | |
//! - Payment of any fees and tips. | |
//! - Nonce check. | |
//! Contrary, a dispatch error means that the extrinsic *is worth keeping in the block*, but | |
//! whatever it wished to do may have failed. This is represented by `ApplyExtrinsicResult` being | |
//! `Ok(Err(_))`. | |
//! | |
//! Use this information to return the correct `ApplyExtrinsicResult` in `do_apply_extrinsic`. | |
//! - **Proper signature check**. You need to look into `UncheckedExtrinsic.signature`, ensure it is | |
//! `Some`, and only accept those that are properly signed. The signing payload should be the | |
//! entire `UncheckedExtrinsic.function` (ignore `Extra`, which is `()`). Since | |
//! `UncheckedExtrinsic` is the type that is used in all substrate-based chains, you can look at | |
//! the methods and traits implemented for this type for inspiration. For example, look into `impl | |
//! Checkable for UncheckedExtrinsic`. | |
//! - **Implement `SystemCall`**. Once you verify the signature, you can get a signer `AccountId` | |
//! out of the extrinsic. Use this to implement [`shared::SystemCall`] dispatchables, such as | |
//! `SetValue`. | |
//! | |
//! The above two steps should both be implemented as a part of `apply_extrinsic`. | |
//! | |
//! - **Root calculation**: Once you have successful transactions processed by your runtime you need | |
//! to make sure your state and extrinsic root are correct. | |
//! - After each successful `apply_extrinsic`, if the transaction passes all the checks to be | |
//! apply-able, note the encoded extrinsic in `EXTRINSICS_KEY`. | |
//! - In `finalize_block`, compute the extrinsics root from the above. | |
//! - Flush the `EXTRINSICS_KEY` at the beginning of the next block authoring's | |
//! `initialize_block`. | |
//! Lastly, you need to update `validate_transaction` to make sure transactions with bad signature | |
//! are rejected. | |
//! #### Apply Errors | |
//! | |
//! [`sp_runtime::transaction_validity::InvalidTransaction::BadProof`] if the extrinsic has an | |
//! invalid signature. | |
//! | |
//! #### Transaction Pool Validation Errors | |
//! | |
//! [`sp_runtime::transaction_validity::InvalidTransaction::BadProof`] if the extrinsic has an | |
//! invalid signature. | |
//! **Paying the tip must not cause an account's existence to change. Specifically, an account | |
//! cannot be destroyed due to the tip**. This is because tip payment happens prior to dispatch, and | |
//! the dispatch logic of the runtime assumes all accounts start at an "existing" state. | |
//! #### Apply Errors | |
//! | |
//! [`sp_runtime::transaction_validity::InvalidTransaction::Payment`] if the extrinsic cannot pay | |
//! for its declared tip. | |
//! | |
//! #### Transaction Pool Validation Errors | |
//! | |
//! [`sp_runtime::transaction_validity::InvalidTransaction::Payment`] if the extrinsic cannot pay | |
//! for its declared tip. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment