-
Notifications
You must be signed in to change notification settings - Fork 1
feat(cheatcodes): base implementation of cheatcode system #58
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
Merged
Merged
Changes from all commits
Commits
Show all changes
48 commits
Select commit
Hold shift + click to select a range
939cc75
feat(builtins): upgrade builtins dep
tchataigner a8d80e4
feat(builtins): updated way to retrieve builtin code
tchataigner 3f92a49
fix(builtins): bump helix lib & builtins lob
tchataigner 1354bbf
cli: rename read_actor and log the reason it failed to read.
jxs f3a3ed3
common: separate constructor and set_up functions
jxs 4901439
lib: execute Constructor and SetUp first
jxs a75839f
feat(builtins): integrating builtins deployment
tchataigner 4e191ab
feat(builtins): chainsafe builtins dep
tchataigner fa10194
feat(builtins): stable channel for rust toolchain
tchataigner ce8334d
feat(builtins): setup all builtins
tchataigner e46769c
lib: address Thomas review
jxs 5f0f338
feat(builtins): builtins tests
tchataigner b122876
feat(lib): testing flow
tchataigner ee34622
feat(builtins): testing builtins deployment
tchataigner c0683e8
fix(builtins): changing Chainsafe dep to be based on crates.io
tchataigner 7cffa99
fix(builtins): merge develop
tchataigner b893074
lib: extract executor into it's own mod
jxs ab0ebd8
Update test_actors/actors/builtins_test_actor/src/actor.rs
tchataigner 84177e2
Update lib/tests/lib.rs
tchataigner 089d096
fix(builtins): refactor test code
tchataigner 409e736
fix(builtins): fixed typo in variable
tchataigner 86bd74e
Merge branch 'develop' into feature/builtins-genesis
PhilippeMts 7502afa
Merge branch 'develop' into feature/builtins-genesis
tchataigner 1011b1e
Merge branch 'feature/builtins-genesis' of github.com:polyphene/kythe…
tchataigner 039b80b
lib: address Thomas review
jxs 10a7b28
Merge branch 'develop' of github.com:polyphene/kythera into feat/pars…
jxs 97a2639
feat(cheatcodes): started cheatcodes testing ground
tchataigner 8f9063c
lib: address Thomas review
jxs 7fa89f1
fix(cheatcodes): merge feat/parse-constructor-setup
tchataigner 4511d80
fix(cheatcodes): sanitize actor compilation at runtime
tchataigner d8f27b6
fix(cheatcodes): merge develop
tchataigner 1a70fad
feat(cheatcodes): WIP trying to implement a persistent context for ou…
tchataigner af435a5
feat(cheatcodes): cheatcodes for Kythera
tchataigner 2e318ae
fix(cheatcodes): merge develop
tchataigner 309c054
Update lib/src/state_tree.rs
tchataigner 45c431a
Update cli/src/utils/search.rs
tchataigner e508ce8
Update cli/src/utils/search.rs
tchataigner 92f89f8
Update cli/src/utils/search.rs
tchataigner f8216ce
fix(cheatcodes): address jxs review
tchataigner 0661191
fix(cheatcodes): jxs review addressed
tchataigner def912e
fix(cheatcodes): typo
tchataigner baa541d
fix(cheatcodes): typo
tchataigner 4b2866c
fix(cheatcodes): typo
tchataigner cc43577
Merge branch 'feature/cheatcodes-foundation' of github.com:polyphene/…
tchataigner 0054791
Update lib/src/state_tree.rs
tchataigner 9c98ad7
fix(cheatcodes): typo in comments + comment on deploy_actor_from_bin_…
tchataigner 2f0a6ef
fix(cheatcodes): merge develop
tchataigner 427afcd
fix(cheatcodes): remove unused feature
tchataigner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,12 @@ | ||
| [package] | ||
| name = "kythera_test_actors" | ||
| name = "kythera-actors" | ||
| description = "Kythera FVM WASM actor builder" | ||
| version = "0.1.0" | ||
| edition = "2021" | ||
| license = "MIT OR Apache-2.0" | ||
| authors = ["Polyphene"] | ||
| publish = false | ||
|
|
||
| [features] | ||
| default=[] | ||
| testing=[] |
This file contains hidden or 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
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| ## Cheatcodes Test Actor | ||
|
|
||
| This is the actor embedded in our `kythera-fvm` to expose the cheatcodes interface. | ||
|
|
||
| ### Cheatcodes | ||
|
|
||
| The following cheatcodes are exposed through the actor: | ||
| - `Epoch`: Set the `NetworkContext::epoch` | ||
| - `Warp`: Set the `NetworkContext::timestamp` | ||
| - `Fee`: Set the `NetworkContext::fee` | ||
| - `ChaindId`: Set the `NetworkContext::chain_id` | ||
| - `Prank`: Sets the **next implicit message**'s `MessageContext::caller` to be the input address | ||
| - `Trick`: Sets the **next implicit message and its sub-implicit messages**' `MessageContext::origin` to be the input address |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| // Copyright 2023 Polyphene. | ||
| // SPDX-License-Identifier: Apache-2.0, MIT | ||
|
|
||
| use frc42_dispatch::match_method; | ||
| use fvm_ipld_encoding::{de::DeserializeOwned, RawBytes}; | ||
| use fvm_sdk::NO_DATA_BLOCK_ID; | ||
| use fvm_shared::address::Address; | ||
| use fvm_shared::error::ExitCode; | ||
|
|
||
| /// Deserialize message parameters into given struct. | ||
| pub fn deserialize_params<D: DeserializeOwned>(params: u32) -> D { | ||
| let params = fvm_sdk::message::params_raw(params) | ||
| .expect("Could not get message parameters") | ||
| .expect("Expected message parameters but got none"); | ||
|
|
||
| let params = RawBytes::new(params.data); | ||
|
|
||
| params | ||
| .deserialize() | ||
| .expect("Should be able to deserialize message params into arguments of called method") | ||
| } | ||
|
|
||
| #[no_mangle] | ||
| fn invoke(input: u32) -> u32 { | ||
| let method_num = fvm_sdk::message::method_number(); | ||
| match_method!( | ||
| method_num, | ||
| { | ||
| "Warp" => { | ||
| // Ensure that the message params can be deserialized. | ||
| let new_timestamp: u64 = deserialize_params(input); | ||
|
|
||
| Warp(new_timestamp); | ||
|
|
||
| NO_DATA_BLOCK_ID | ||
| }, | ||
| "Epoch" => { | ||
| // Ensure that the message params can be deserialized. | ||
| let new_epoch: i64 = deserialize_params(input); | ||
|
|
||
| Epoch(new_epoch); | ||
|
|
||
| NO_DATA_BLOCK_ID | ||
| }, | ||
| "Fee" => { | ||
| // Ensure that the message params can be deserialized. | ||
| let (lo, hi): (u64, u64) = deserialize_params(input); | ||
|
|
||
| Fee( | ||
| fvm_shared::sys::TokenAmount { | ||
| lo, | ||
| hi | ||
| } | ||
| ); | ||
|
|
||
| NO_DATA_BLOCK_ID | ||
| }, | ||
| "ChainId" => { | ||
| // Ensure that the message params can be deserialized. | ||
| let new_chain_id: u64 = deserialize_params(input); | ||
|
|
||
| ChainId(new_chain_id); | ||
|
|
||
| NO_DATA_BLOCK_ID | ||
| }, | ||
| "Prank" => { | ||
| // Ensure that the message params can be deserialized. | ||
| let new_caller: Address = deserialize_params(input); | ||
|
|
||
| Prank(new_caller); | ||
|
|
||
| NO_DATA_BLOCK_ID | ||
| }, | ||
| "Trick" => { | ||
| // Ensure that the message params can be deserialized. | ||
| let new_origin: Address = deserialize_params(input); | ||
|
|
||
| Trick(new_origin); | ||
|
|
||
| NO_DATA_BLOCK_ID | ||
| }, | ||
| _ => { | ||
| fvm_sdk::vm::abort( | ||
| ExitCode::USR_UNHANDLED_MESSAGE.value(), | ||
| Some("Unknown method number"), | ||
| ); | ||
| } | ||
| } | ||
| ) | ||
| } | ||
|
|
||
| /// Warp the machine context to a given timestamp. | ||
| #[allow(non_snake_case)] | ||
| fn Warp(_new_timestamp: u64) {} | ||
|
|
||
| /// Update the machine context to a given epoch. | ||
| #[allow(non_snake_case)] | ||
| fn Epoch(_new_epoch: i64) {} | ||
|
|
||
| /// Update the base fee that's in effect when the machine runs. | ||
| #[allow(non_snake_case)] | ||
| fn Fee(_new_fee: fvm_shared::sys::TokenAmount) {} | ||
|
|
||
| /// Set a new chain Id in the machine context. | ||
| #[allow(non_snake_case)] | ||
| fn ChainId(_new_chain_id: u64) {} | ||
|
|
||
| /// Prank the call manager to set a pre-determined caller for the next message sent. | ||
| #[allow(non_snake_case)] | ||
| fn Prank(_new_caller: Address) {} | ||
|
|
||
| /// Trick the call manager to set a pre-determined origin for the next message sent. | ||
| #[allow(non_snake_case)] | ||
| fn Trick(_new_origin: Address) {} |
File renamed without changes.
This file contains hidden or 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
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| This crate contains the necessary logic to build some testing actors for our Kythera toolset. | ||
| This crate contains the necessary logic to build actors for our Kythera toolset. | ||
|
|
||
| It was heavily inspired and copied from the implementation [over the `ref-fvm`](https://github.com/filecoin-project/ref-fvm/tree/37643fc02f0342256afecff5158c43693b5ee4f0/testing/test_actors) | ||
| done by @fridrik01. |
File renamed without changes.
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| // Copyright 2023 Polyphene. | ||
| // SPDX-License-Identifier: Apache-2.0, MIT | ||
| // Constants for wasm build artifacts. | ||
|
|
||
| macro_rules! wasm_bin { | ||
| ($x: expr) => { | ||
| concat!( | ||
| env!("OUT_DIR"), | ||
| "/bundle/wasm32-unknown-unknown/wasm/", | ||
| $x, | ||
| ".wasm" | ||
| ) | ||
| }; | ||
| } | ||
|
|
||
| pub const CHEATCODES_ACTOR_BINARY: &[u8] = include_bytes!(wasm_bin!("cheatcodes_actor")); | ||
|
|
||
| #[cfg(feature = "testing")] | ||
| pub mod test_actors { | ||
| // Integration tests actors. | ||
| pub const BASIC_TEST_ACTOR_BINARY: &[u8] = include_bytes!(wasm_bin!("basic_test_actor")); | ||
| pub const BASIC_TARGET_ACTOR_BINARY: &[u8] = include_bytes!(wasm_bin!("basic_target_actor")); | ||
| pub const BUILTINS_TEST_ACTOR_BINARY: &[u8] = include_bytes!(wasm_bin!("builtins_test_actor")); | ||
| pub const CHEATCODES_TEST_ACTOR_BINARY: &[u8] = | ||
| include_bytes!(wasm_bin!("cheatcodes_test_actor")); | ||
| pub const CONSTRUCTOR_SETUP_TEST_ACTOR_BINARY: &[u8] = | ||
| include_bytes!(wasm_bin!("constructor_setup_test_actor")); | ||
| } |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| [package] | ||
| name = "basic-target-actor" | ||
| version = "0.1.0" | ||
| edition = "2021" | ||
| publish=false | ||
|
|
||
| [target.'cfg(target_arch = "wasm32")'.dependencies] | ||
| frc42_dispatch = "3.1.0" | ||
| fvm_sdk = { version = "3.0.0" } | ||
| fvm_shared = { version = "3.1.0" } | ||
| fvm_ipld_encoding = { version = "0.3.3" } | ||
| serde = { version = "1.0.136", features = ["derive"] } | ||
| thiserror = { version = "1.0.31" } | ||
|
|
||
| [lib] | ||
| crate-type = ["cdylib"] |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| ## Basic Target Actor | ||
|
|
||
| This is a basic actor that serves as a target actor in some of our tests for Kythera. It is the target actor used against | ||
| our `cheatcodes_test_actor` for example. Its entrypoints are: | ||
| - `Caller`: Method that returns the value of the `MessageContext.caller` | ||
| - `Origin`: Method that returns the value of the `MessageContext.origin` |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| // Copyright 2023 Polyphene. | ||
| // SPDX-License-Identifier: Apache-2.0, MIT | ||
|
|
||
| use frc42_dispatch::match_method; | ||
| use fvm_ipld_encoding::DAG_CBOR; | ||
| use fvm_sdk as sdk; | ||
| use fvm_shared::error::ExitCode; | ||
| use sdk::sys::ErrorNumber; | ||
| use serde::ser; | ||
| use thiserror::Error; | ||
|
|
||
| #[derive(Error, Debug)] | ||
| enum IpldError { | ||
| #[error("ipld encoding error: {0}")] | ||
| Encoding(#[from] fvm_ipld_encoding::Error), | ||
| #[error("ipld blockstore error: {0}")] | ||
| Blockstore(#[from] ErrorNumber), | ||
| } | ||
|
|
||
| fn return_ipld<T>(value: &T) -> std::result::Result<u32, IpldError> | ||
| where | ||
| T: ser::Serialize + ?Sized, | ||
| { | ||
| let bytes = fvm_ipld_encoding::to_vec(value)?; | ||
| Ok(sdk::ipld::put_block(DAG_CBOR, bytes.as_slice())?) | ||
| } | ||
|
|
||
| #[no_mangle] | ||
| fn invoke(_input: u32) -> u32 { | ||
| let method_num = fvm_sdk::message::method_number(); | ||
| match_method!( | ||
| method_num, | ||
| { | ||
| "Caller" => { | ||
| let mc_caller: u64 = unsafe { fvm_sdk::sys::vm::message_context().unwrap().caller }; | ||
|
|
||
| return_ipld(&mc_caller).unwrap() | ||
| }, | ||
| "Origin" => { | ||
| let mc_origin: u64 = unsafe { fvm_sdk::sys::vm::message_context().unwrap().origin }; | ||
|
|
||
| return_ipld(&mc_origin).unwrap() | ||
| }, | ||
| _ => { | ||
| fvm_sdk::vm::abort( | ||
| ExitCode::USR_UNHANDLED_MESSAGE.value(), | ||
| Some("Unknown method number"), | ||
| ); | ||
| } | ||
| } | ||
| ) | ||
| } |
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...actors/actors/basic_test_actor/Cargo.toml → ...s/test_actors/basic_test_actor/Cargo.toml
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| [package] | ||
| name = "basic_test_actor" | ||
| name = "basic-test-actor" | ||
| version = "0.1.0" | ||
| edition = "2021" | ||
| publish=false | ||
|
|
||
File renamed without changes.
This file contains hidden or 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
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...ors/actors/builtins_test_actor/Cargo.toml → ...est_actors/builtins_test_actor/Cargo.toml
This file contains hidden or 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
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.