From 939cc750668dd262cd6c6dca814b12266dfcecef Mon Sep 17 00:00:00 2001 From: Thomas Chataigner Date: Mon, 3 Apr 2023 14:39:14 +0200 Subject: [PATCH 01/38] feat(builtins): upgrade builtins dep * Upgrade builtins dependencies to revision for release 10.0 (M2.1 of FVM) --- Cargo.lock | 172 +++++++++++++++++++++---------------------------- lib/Cargo.toml | 16 ++++- 2 files changed, 87 insertions(+), 101 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0a9326c..daccb54 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -83,9 +83,6 @@ name = "arrayvec" version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6" -dependencies = [ - "serde", -] [[package]] name = "async-channel" @@ -477,9 +474,6 @@ name = "bytes" version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "89b2fd2a0dcf38d7971e2194b6b6eebab45ae01067456a7fd93d5547a61b70be" -dependencies = [ - "serde", -] [[package]] name = "castaway" @@ -1200,8 +1194,8 @@ dependencies = [ [[package]] name = "fil_actor_account" -version = "10.0.0-alpha.1" -source = "git+https://github.com/filecoin-project/builtin-actors?rev=c5cbd5b#c5cbd5bc25b26958b83d43ecabed782132e43773" +version = "10.0.0" +source = "git+https://github.com/filecoin-project/builtin-actors?rev=89dc63d#89dc63dfc9473d7db42525bf59bb0e679d8c9c41" dependencies = [ "anyhow", "fil_actors_runtime", @@ -1236,8 +1230,8 @@ dependencies = [ [[package]] name = "fil_actor_cron" -version = "10.0.0-alpha.1" -source = "git+https://github.com/filecoin-project/builtin-actors?rev=c5cbd5b#c5cbd5bc25b26958b83d43ecabed782132e43773" +version = "10.0.0" +source = "git+https://github.com/filecoin-project/builtin-actors?rev=89dc63d#89dc63dfc9473d7db42525bf59bb0e679d8c9c41" dependencies = [ "fil_actors_runtime", "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1251,8 +1245,8 @@ dependencies = [ [[package]] name = "fil_actor_datacap" -version = "10.0.0-alpha.1" -source = "git+https://github.com/filecoin-project/builtin-actors?rev=c5cbd5b#c5cbd5bc25b26958b83d43ecabed782132e43773" +version = "10.0.0" +source = "git+https://github.com/filecoin-project/builtin-actors?rev=89dc63d#89dc63dfc9473d7db42525bf59bb0e679d8c9c41" dependencies = [ "cid", "fil_actors_runtime", @@ -1270,10 +1264,32 @@ dependencies = [ "serde", ] +[[package]] +name = "fil_actor_eam" +version = "10.0.0" +source = "git+https://github.com/filecoin-project/builtin-actors?rev=89dc63d#89dc63dfc9473d7db42525bf59bb0e679d8c9c41" +dependencies = [ + "anyhow", + "cid", + "fil_actors_evm_shared", + "fil_actors_runtime", + "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_shared 3.0.0", + "hex-literal", + "log", + "multihash", + "num-derive", + "num-traits", + "rlp", + "serde", + "serde_tuple", +] + [[package]] name = "fil_actor_ethaccount" -version = "10.0.0-alpha.1" -source = "git+https://github.com/filecoin-project/builtin-actors?rev=c5cbd5b#c5cbd5bc25b26958b83d43ecabed782132e43773" +version = "10.0.0" +source = "git+https://github.com/filecoin-project/builtin-actors?rev=89dc63d#89dc63dfc9473d7db42525bf59bb0e679d8c9c41" dependencies = [ "fil_actors_runtime", "frc42_dispatch", @@ -1288,17 +1304,13 @@ dependencies = [ [[package]] name = "fil_actor_evm" -version = "10.0.0-alpha.1" -source = "git+https://github.com/filecoin-project/builtin-actors?rev=c5cbd5b#c5cbd5bc25b26958b83d43ecabed782132e43773" +version = "10.0.0" +source = "git+https://github.com/filecoin-project/builtin-actors?rev=89dc63d#89dc63dfc9473d7db42525bf59bb0e679d8c9c41" dependencies = [ "anyhow", - "arrayvec 0.7.2", - "bytes", "cid", - "derive_more", "fil_actors_evm_shared", "fil_actors_runtime", - "fixed-hash", "frc42_dispatch", "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1306,26 +1318,19 @@ dependencies = [ "fvm_shared 3.0.0", "hex", "hex-literal", - "impl-serde", - "lazy_static", "log", "multihash", - "near-blake2", "num-derive", "num-traits", - "once_cell", - "rlp", "serde", "serde_tuple", - "strum", - "strum_macros", "substrate-bn", ] [[package]] name = "fil_actor_init" -version = "10.0.0-alpha.1" -source = "git+https://github.com/filecoin-project/builtin-actors?rev=c5cbd5b#c5cbd5bc25b26958b83d43ecabed782132e43773" +version = "10.0.0" +source = "git+https://github.com/filecoin-project/builtin-actors?rev=89dc63d#89dc63dfc9473d7db42525bf59bb0e679d8c9c41" dependencies = [ "anyhow", "cid", @@ -1343,8 +1348,8 @@ dependencies = [ [[package]] name = "fil_actor_market" -version = "10.0.0-alpha.1" -source = "git+https://github.com/filecoin-project/builtin-actors?rev=c5cbd5b#c5cbd5bc25b26958b83d43ecabed782132e43773" +version = "10.0.0" +source = "git+https://github.com/filecoin-project/builtin-actors?rev=89dc63d#89dc63dfc9473d7db42525bf59bb0e679d8c9c41" dependencies = [ "anyhow", "cid", @@ -1366,8 +1371,8 @@ dependencies = [ [[package]] name = "fil_actor_miner" -version = "10.0.0-alpha.1" -source = "git+https://github.com/filecoin-project/builtin-actors?rev=c5cbd5b#c5cbd5bc25b26958b83d43ecabed782132e43773" +version = "10.0.0" +source = "git+https://github.com/filecoin-project/builtin-actors?rev=89dc63d#89dc63dfc9473d7db42525bf59bb0e679d8c9c41" dependencies = [ "anyhow", "byteorder", @@ -1391,8 +1396,8 @@ dependencies = [ [[package]] name = "fil_actor_multisig" -version = "10.0.0-alpha.1" -source = "git+https://github.com/filecoin-project/builtin-actors?rev=c5cbd5b#c5cbd5bc25b26958b83d43ecabed782132e43773" +version = "10.0.0" +source = "git+https://github.com/filecoin-project/builtin-actors?rev=89dc63d#89dc63dfc9473d7db42525bf59bb0e679d8c9c41" dependencies = [ "anyhow", "cid", @@ -1412,8 +1417,8 @@ dependencies = [ [[package]] name = "fil_actor_paych" -version = "10.0.0-alpha.1" -source = "git+https://github.com/filecoin-project/builtin-actors?rev=c5cbd5b#c5cbd5bc25b26958b83d43ecabed782132e43773" +version = "10.0.0" +source = "git+https://github.com/filecoin-project/builtin-actors?rev=89dc63d#89dc63dfc9473d7db42525bf59bb0e679d8c9c41" dependencies = [ "anyhow", "cid", @@ -1429,13 +1434,13 @@ dependencies = [ [[package]] name = "fil_actor_placeholder" -version = "10.0.0-alpha.1" -source = "git+https://github.com/filecoin-project/builtin-actors?rev=c5cbd5b#c5cbd5bc25b26958b83d43ecabed782132e43773" +version = "10.0.0" +source = "git+https://github.com/filecoin-project/builtin-actors?rev=89dc63d#89dc63dfc9473d7db42525bf59bb0e679d8c9c41" [[package]] name = "fil_actor_power" -version = "10.0.0-alpha.1" -source = "git+https://github.com/filecoin-project/builtin-actors?rev=c5cbd5b#c5cbd5bc25b26958b83d43ecabed782132e43773" +version = "10.0.0" +source = "git+https://github.com/filecoin-project/builtin-actors?rev=89dc63d#89dc63dfc9473d7db42525bf59bb0e679d8c9c41" dependencies = [ "anyhow", "cid", @@ -1456,8 +1461,8 @@ dependencies = [ [[package]] name = "fil_actor_reward" -version = "10.0.0-alpha.1" -source = "git+https://github.com/filecoin-project/builtin-actors?rev=c5cbd5b#c5cbd5bc25b26958b83d43ecabed782132e43773" +version = "10.0.0" +source = "git+https://github.com/filecoin-project/builtin-actors?rev=89dc63d#89dc63dfc9473d7db42525bf59bb0e679d8c9c41" dependencies = [ "fil_actors_runtime", "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1472,8 +1477,8 @@ dependencies = [ [[package]] name = "fil_actor_system" -version = "10.0.0-alpha.1" -source = "git+https://github.com/filecoin-project/builtin-actors?rev=c5cbd5b#c5cbd5bc25b26958b83d43ecabed782132e43773" +version = "10.0.0" +source = "git+https://github.com/filecoin-project/builtin-actors?rev=89dc63d#89dc63dfc9473d7db42525bf59bb0e679d8c9c41" dependencies = [ "anyhow", "cid", @@ -1488,8 +1493,8 @@ dependencies = [ [[package]] name = "fil_actor_verifreg" -version = "10.0.0-alpha.1" -source = "git+https://github.com/filecoin-project/builtin-actors?rev=c5cbd5b#c5cbd5bc25b26958b83d43ecabed782132e43773" +version = "10.0.0" +source = "git+https://github.com/filecoin-project/builtin-actors?rev=89dc63d#89dc63dfc9473d7db42525bf59bb0e679d8c9c41" dependencies = [ "anyhow", "cid", @@ -1510,8 +1515,8 @@ dependencies = [ [[package]] name = "fil_actors_evm_shared" -version = "10.0.0-alpha.1" -source = "git+https://github.com/filecoin-project/builtin-actors?rev=c5cbd5b#c5cbd5bc25b26958b83d43ecabed782132e43773" +version = "10.0.0" +source = "git+https://github.com/filecoin-project/builtin-actors?rev=89dc63d#89dc63dfc9473d7db42525bf59bb0e679d8c9c41" dependencies = [ "fil_actors_runtime", "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1523,8 +1528,8 @@ dependencies = [ [[package]] name = "fil_actors_runtime" -version = "10.0.0-alpha.1" -source = "git+https://github.com/filecoin-project/builtin-actors?rev=c5cbd5b#c5cbd5bc25b26958b83d43ecabed782132e43773" +version = "10.0.0" +source = "git+https://github.com/filecoin-project/builtin-actors?rev=89dc63d#89dc63dfc9473d7db42525bf59bb0e679d8c9c41" dependencies = [ "anyhow", "byteorder", @@ -1554,8 +1559,8 @@ dependencies = [ [[package]] name = "fil_builtin_actors_bundle" -version = "10.0.0-alpha.1" -source = "git+https://github.com/filecoin-project/builtin-actors?rev=c5cbd5b#c5cbd5bc25b26958b83d43ecabed782132e43773" +version = "10.0.0" +source = "git+https://github.com/filecoin-project/builtin-actors?rev=89dc63d#89dc63dfc9473d7db42525bf59bb0e679d8c9c41" dependencies = [ "cid", "clap 3.2.23", @@ -1563,6 +1568,7 @@ dependencies = [ "fil_actor_bundler", "fil_actor_cron", "fil_actor_datacap", + "fil_actor_eam", "fil_actor_ethaccount", "fil_actor_evm", "fil_actor_init", @@ -1664,15 +1670,6 @@ dependencies = [ "storage-proofs-core", ] -[[package]] -name = "fixed-hash" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cfcf0ed7fe52a17a03854ec54a9f76d6d84508d1c0e66bc1793301c73fc8493c" -dependencies = [ - "static_assertions", -] - [[package]] name = "flume" version = "0.10.14" @@ -2415,15 +2412,6 @@ dependencies = [ "unicode-normalization", ] -[[package]] -name = "impl-serde" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4551f042f3438e64dbd6226b20527fc84a6e1fe65688b58746a2f53623f25f5c" -dependencies = [ - "serde", -] - [[package]] name = "indexmap" version = "1.9.2" @@ -2584,6 +2572,19 @@ name = "kythera-lib" version = "0.1.0" dependencies = [ "cid", + "fil_actor_account", + "fil_actor_cron", + "fil_actor_datacap", + "fil_actor_init", + "fil_actor_market", + "fil_actor_miner", + "fil_actor_multisig", + "fil_actor_paych", + "fil_actor_power", + "fil_actor_reward", + "fil_actor_system", + "fil_actor_verifreg", + "fil_actors_runtime", "fil_builtin_actors_bundle", "futures", "fvm_ipld_blockstore 0.1.1 (git+https://github.com/filecoin-project/ref-fvm.git)", @@ -2881,16 +2882,6 @@ dependencies = [ "synstructure", ] -[[package]] -name = "near-blake2" -version = "0.9.1" -source = "git+https://github.com/filecoin-project/near-blake2.git#47a58e5061ba6d6c1132f535188b7fde2f67bcb2" -dependencies = [ - "crypto-mac", - "digest 0.9.0", - "opaque-debug", -] - [[package]] name = "neptune" version = "8.0.0" @@ -3781,25 +3772,6 @@ version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" -[[package]] -name = "strum" -version = "0.24.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "063e6045c0e62079840579a7e47a355ae92f60eb74daaf156fb1e84ba164e63f" - -[[package]] -name = "strum_macros" -version = "0.24.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e385be0d24f186b4ce2f9982191e7101bb737312ad61c1f2f984f34bcf85d59" -dependencies = [ - "heck", - "proc-macro2", - "quote", - "rustversion", - "syn 1.0.109", -] - [[package]] name = "substrate-bn" version = "0.6.0" diff --git a/lib/Cargo.toml b/lib/Cargo.toml index 9cb1cc9..ecbea70 100644 --- a/lib/Cargo.toml +++ b/lib/Cargo.toml @@ -6,7 +6,21 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -actors-v10 = { package = "fil_builtin_actors_bundle", git = "https://github.com/filecoin-project/builtin-actors", rev = "c5cbd5b" } +actors-v10 = { package = "fil_builtin_actors_bundle", git = "https://github.com/filecoin-project/builtin-actors", rev = "89dc63d" } +fil_actor_account = { git = "https://github.com/filecoin-project/builtin-actors", rev = "89dc63d", features = [] } +fil_actor_cron = { git = "https://github.com/filecoin-project/builtin-actors", rev = "89dc63d", features = [] } +fil_actor_datacap = { git = "https://github.com/filecoin-project/builtin-actors", rev = "89dc63d", features = [] } +fil_actor_init = { git = "https://github.com/filecoin-project/builtin-actors", rev = "89dc63d", features = [] } +fil_actor_market = { git = "https://github.com/filecoin-project/builtin-actors", rev = "89dc63d", features = [] } +fil_actor_miner = { git = "https://github.com/filecoin-project/builtin-actors", rev = "89dc63d", features = [] } +fil_actor_multisig = { git = "https://github.com/filecoin-project/builtin-actors", rev = "89dc63d", features = [] } +fil_actor_paych = { git = "https://github.com/filecoin-project/builtin-actors", rev = "89dc63d", features = [] } +fil_actor_power = { git = "https://github.com/filecoin-project/builtin-actors", rev = "89dc63d", features = [] } +fil_actor_reward = { git = "https://github.com/filecoin-project/builtin-actors", rev = "89dc63d", features = [] } +fil_actor_system = { git = "https://github.com/filecoin-project/builtin-actors", rev = "89dc63d", features = [] } +fil_actor_verifreg = { git = "https://github.com/filecoin-project/builtin-actors", rev = "89dc63d", features = [] } +fil_actors_runtime = { git = "https://github.com/filecoin-project/builtin-actors", rev = "89dc63d", features = [] } + fvm_ipld_blockstore = { git = "https://github.com/filecoin-project/ref-fvm.git", version = "0.1.1" } fvm_ipld_car = { git = "https://github.com/filecoin-project/ref-fvm.git", version = "0.6.0" } fvm_ipld_encoding = { git = "https://github.com/filecoin-project/ref-fvm.git", version = "0.3.3" } From a8d80e4882e6e8c95d48c84c369432919fe92a85 Mon Sep 17 00:00:00 2001 From: Thomas Chataigner Date: Mon, 3 Apr 2023 15:24:01 +0200 Subject: [PATCH 02/38] feat(builtins): updated way to retrieve builtin code * Using code_by_id() method to retrieve builtins code CID from Manifest * Get builtins actor ID from builtin crate --- lib/src/lib.rs | 3 +-- lib/src/state_tree.rs | 35 +++++++++++++++-------------------- 2 files changed, 16 insertions(+), 22 deletions(-) diff --git a/lib/src/lib.rs b/lib/src/lib.rs index e598348..f081bcd 100644 --- a/lib/src/lib.rs +++ b/lib/src/lib.rs @@ -20,7 +20,6 @@ use fvm_shared::{ version::NetworkVersion, }; -use crate::error::WrapFVMError; use error::Error; use state_tree::{BuiltInActors, StateTree}; @@ -100,7 +99,7 @@ pub struct TestResult<'a> { impl<'a> TestResult<'a> { /// Get the [`Method`] tested. pub fn method(&self) -> &Method { - &self.method + self.method } /// Get the [`ApplyRet`] of the test. diff --git a/lib/src/state_tree.rs b/lib/src/state_tree.rs index 737ae00..b739334 100644 --- a/lib/src/state_tree.rs +++ b/lib/src/state_tree.rs @@ -18,7 +18,9 @@ use kythera_fvm::{ use libsecp256k1::{PublicKey, SecretKey}; use rand::SeedableRng; -const EAM_ACTOR_ID: ActorID = 10; +use fil_actors_runtime::{runtime::builtins::Type, INIT_ACTOR_ID, SYSTEM_ACTOR_ID}; +use fvm_shared::bigint::Zero; + const STATE_TREE_VERSION: StateTreeVersion = StateTreeVersion::V5; /// Built-in Actors that are deployed to the testing `StateTree`. @@ -108,34 +110,27 @@ impl StateTree { self.set_actor( "System Actor", sys_state, - *manifest.get_system_code(), - system_actor::SYSTEM_ACTOR_ID, - 1, - Default::default(), + *manifest + .code_by_id(Type::System as u32) + .expect("Should be able to get system Actor code from manifest"), + SYSTEM_ACTOR_ID, + 0, + TokenAmount::zero(), ) .expect("Should be able to set the system Actor"); self.set_actor( "Init Actor", init_state, - *manifest.get_init_code(), - init_actor::INIT_ACTOR_ID, - 1, - Default::default(), + *manifest + .code_by_id(Type::Init as u32) + .expect("Should be able to get init Actor code from manifest"), + INIT_ACTOR_ID, + 0, + TokenAmount::zero(), ) .expect("Should be able to set the Init Actor"); - self.set_actor( - "Eam Actor", - [(); 0], - *manifest.get_eam_code(), - // EAM Actor Id. - EAM_ACTOR_ID, - 1, - Default::default(), - ) - .expect("Should be able to set the Eam Actor"); - BuiltInActors { root: builtin_actors, manifest, From 3f92a49971680b07fc9eabaa1e83477ad8a96377 Mon Sep 17 00:00:00 2001 From: Thomas Chataigner Date: Mon, 3 Apr 2023 16:30:59 +0200 Subject: [PATCH 03/38] fix(builtins): bump helix lib & builtins lob --- Cargo.lock | 676 ++++++++---------- common/Cargo.toml | 2 +- fvm/Cargo.toml | 6 +- lib/Cargo.toml | 36 +- lib/src/state_tree.rs | 12 +- .../actors/basic_test_actor/Cargo.toml | 6 +- 6 files changed, 332 insertions(+), 406 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index daccb54..753338b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -57,6 +57,46 @@ dependencies = [ "memchr", ] +[[package]] +name = "anstream" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "342258dd14006105c2b75ab1bd7543a03bdf0cfc94383303ac212a04939dff6f" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-wincon", + "concolor-override", + "concolor-query", + "is-terminal", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23ea9e81bd02e310c216d080f6223c179012256e5151c41db88d12c88a1684d2" + +[[package]] +name = "anstyle-parse" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7d1bb534e9efed14f3e5f44e7dd1a4f709384023a4165199a4241e18dff0116" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-wincon" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3127af6145b149f3287bb9a0d10ad9c5692dba8c53ad48285e5bec4063834fa" +dependencies = [ + "anstyle", + "windows-sys 0.45.0", +] + [[package]] name = "anyhow" version = "1.0.70" @@ -138,7 +178,7 @@ dependencies = [ "log", "parking", "polling", - "rustix 0.37.3", + "rustix 0.37.6", "slab", "socket2", "waker-fn", @@ -181,19 +221,19 @@ dependencies = [ [[package]] name = "async-task" -version = "4.3.0" +version = "4.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a40729d2133846d9ed0ea60a8b9541bccddab49cd30f0715a1da672fe9a2524" +checksum = "ecc7ab41815b3c653ccd2978ec3255c81349336702dfdf62ee6f7069b12a3aae" [[package]] name = "async-trait" -version = "0.1.67" +version = "0.1.68" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86ea188f25f0255d8f92797797c97ebf5631fa88178beb1a46fdf5622c9a00e4" +checksum = "b9ccdd8f2a161be9bd5c023df56f1b2a0bd1d83872ae53b71a84a12c9bf6e842" dependencies = [ "proc-macro2", "quote", - "syn 2.0.5", + "syn 2.0.13", ] [[package]] @@ -250,9 +290,9 @@ checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" name = "basic_test_actor" version = "0.1.0" dependencies = [ - "fvm_ipld_encoding 0.3.3 (git+https://github.com/filecoin-project/ref-fvm.git)", - "fvm_sdk 3.0.0 (git+https://github.com/filecoin-project/ref-fvm.git)", - "fvm_shared 3.1.0", + "fvm_ipld_encoding", + "fvm_sdk", + "fvm_shared", "serde", "thiserror", ] @@ -300,12 +340,6 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" -[[package]] -name = "bitflags" -version = "2.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "487f1e0fcbe47deb8b0574e646def1c903389d95241dd1bbcc6ce4a715dfc0c1" - [[package]] name = "bitvec" version = "1.0.1" @@ -384,9 +418,9 @@ dependencies = [ [[package]] name = "block-padding" -version = "0.3.2" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a90ec2df9600c28a01c56c4784c9207a96d2451833aeceb8cc97e4c9548bb78" +checksum = "a8894febbff9f758034a5b8e12d87918f56dfc64a8e1fe757d65e29041538d93" dependencies = [ "generic-array", ] @@ -545,7 +579,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "71655c45cb9845d3270c9d6df84ebe72b4dad3c2ba3f7023ad47c144e4e473a5" dependencies = [ "atty", - "bitflags 1.3.2", + "bitflags", "clap_derive 3.2.18", "clap_lex 0.2.4", "indexmap", @@ -557,17 +591,26 @@ dependencies = [ [[package]] name = "clap" -version = "4.1.11" +version = "4.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42dfd32784433290c51d92c438bb72ea5063797fc3cc9a21a8c4346bebbb2098" +checksum = "046ae530c528f252094e4a77886ee1374437744b2bff1497aa898bbddbbb29b3" dependencies = [ - "bitflags 2.0.2", - "clap_derive 4.1.9", - "clap_lex 0.3.3", - "is-terminal", + "clap_builder", + "clap_derive 4.2.0", "once_cell", +] + +[[package]] +name = "clap_builder" +version = "4.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "223163f58c9a40c3b0a43e1c4b50a9ce09f007ea2cb1ec258a687945b4b7929f" +dependencies = [ + "anstream", + "anstyle", + "bitflags", + "clap_lex 0.4.1", "strsim", - "termcolor", ] [[package]] @@ -585,15 +628,14 @@ dependencies = [ [[package]] name = "clap_derive" -version = "4.1.9" +version = "4.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fddf67631444a3a3e3e5ac51c36a5e01335302de677bd78759eaa90ab1f46644" +checksum = "3f9644cd56d6b87dbe899ef8b053e331c0637664e9e21a33dfcdc36093f5c5c4" dependencies = [ "heck", - "proc-macro-error", "proc-macro2", "quote", - "syn 1.0.109", + "syn 2.0.13", ] [[package]] @@ -607,11 +649,23 @@ dependencies = [ [[package]] name = "clap_lex" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a2dd5a6fe8c6e3502f568a6353e5273bbb15193ad9a89e457b9970798efbea1" + +[[package]] +name = "concolor-override" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a855d4a1978dc52fb0536a04d384c2c0c1aa273597f08b77c8c4d3b2eec6037f" + +[[package]] +name = "concolor-query" version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "033f6b7a4acb1f358c742aaca805c939ee73b4c6209ae4318ec7aca81c42e646" +checksum = "88d11d52c3d7ca2e6d0040212be9e4dbbcd78b6447f535b6b561f449427944cf" dependencies = [ - "os_str_bytes", + "windows-sys 0.45.0", ] [[package]] @@ -675,9 +729,9 @@ dependencies = [ [[package]] name = "cpufeatures" -version = "0.2.5" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28d997bd5e24a5928dd43e46dc529867e207907fe0b239c3477d924f7f2ca320" +checksum = "280a9f2d8b3a38871a3c8a46fb80db65e5e5ed97da80c4d08bf27fb63e35e181" dependencies = [ "libc", ] @@ -1195,15 +1249,15 @@ dependencies = [ [[package]] name = "fil_actor_account" version = "10.0.0" -source = "git+https://github.com/filecoin-project/builtin-actors?rev=89dc63d#89dc63dfc9473d7db42525bf59bb0e679d8c9c41" +source = "git+https://github.com/filecoin-project/builtin-actors?rev=39571e2#39571e25eacd51326c9fc8e29d4b69943f15a3b1" dependencies = [ "anyhow", "fil_actors_runtime", "frc42_dispatch", "fvm_actor_utils", - "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_shared 3.0.0", + "fvm_ipld_blockstore", + "fvm_ipld_encoding", + "fvm_shared", "num-derive", "num-traits", "serde", @@ -1220,9 +1274,9 @@ dependencies = [ "cid", "clap 3.2.23", "futures", - "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_ipld_car 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_blockstore", + "fvm_ipld_car", + "fvm_ipld_encoding", "serde", "serde_ipld_dagcbor", "serde_json", @@ -1231,12 +1285,12 @@ dependencies = [ [[package]] name = "fil_actor_cron" version = "10.0.0" -source = "git+https://github.com/filecoin-project/builtin-actors?rev=89dc63d#89dc63dfc9473d7db42525bf59bb0e679d8c9c41" +source = "git+https://github.com/filecoin-project/builtin-actors?rev=39571e2#39571e25eacd51326c9fc8e29d4b69943f15a3b1" dependencies = [ "fil_actors_runtime", - "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_shared 3.0.0", + "fvm_ipld_blockstore", + "fvm_ipld_encoding", + "fvm_shared", "log", "num-derive", "num-traits", @@ -1246,17 +1300,17 @@ dependencies = [ [[package]] name = "fil_actor_datacap" version = "10.0.0" -source = "git+https://github.com/filecoin-project/builtin-actors?rev=89dc63d#89dc63dfc9473d7db42525bf59bb0e679d8c9c41" +source = "git+https://github.com/filecoin-project/builtin-actors?rev=39571e2#39571e25eacd51326c9fc8e29d4b69943f15a3b1" dependencies = [ "cid", "fil_actors_runtime", "frc42_dispatch", "frc46_token", "fvm_actor_utils", - "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_ipld_hamt 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_shared 3.0.0", + "fvm_ipld_blockstore", + "fvm_ipld_encoding", + "fvm_ipld_hamt", + "fvm_shared", "lazy_static", "log", "num-derive", @@ -1267,15 +1321,15 @@ dependencies = [ [[package]] name = "fil_actor_eam" version = "10.0.0" -source = "git+https://github.com/filecoin-project/builtin-actors?rev=89dc63d#89dc63dfc9473d7db42525bf59bb0e679d8c9c41" +source = "git+https://github.com/filecoin-project/builtin-actors?rev=39571e2#39571e25eacd51326c9fc8e29d4b69943f15a3b1" dependencies = [ "anyhow", "cid", "fil_actors_evm_shared", "fil_actors_runtime", - "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_shared 3.0.0", + "fvm_ipld_blockstore", + "fvm_ipld_encoding", + "fvm_shared", "hex-literal", "log", "multihash", @@ -1289,13 +1343,13 @@ dependencies = [ [[package]] name = "fil_actor_ethaccount" version = "10.0.0" -source = "git+https://github.com/filecoin-project/builtin-actors?rev=89dc63d#89dc63dfc9473d7db42525bf59bb0e679d8c9c41" +source = "git+https://github.com/filecoin-project/builtin-actors?rev=39571e2#39571e25eacd51326c9fc8e29d4b69943f15a3b1" dependencies = [ "fil_actors_runtime", "frc42_dispatch", "fvm_actor_utils", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_shared 3.0.0", + "fvm_ipld_encoding", + "fvm_shared", "hex-literal", "num-derive", "num-traits", @@ -1305,17 +1359,17 @@ dependencies = [ [[package]] name = "fil_actor_evm" version = "10.0.0" -source = "git+https://github.com/filecoin-project/builtin-actors?rev=89dc63d#89dc63dfc9473d7db42525bf59bb0e679d8c9c41" +source = "git+https://github.com/filecoin-project/builtin-actors?rev=39571e2#39571e25eacd51326c9fc8e29d4b69943f15a3b1" dependencies = [ "anyhow", "cid", "fil_actors_evm_shared", "fil_actors_runtime", "frc42_dispatch", - "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_blockstore", + "fvm_ipld_encoding", "fvm_ipld_kamt", - "fvm_shared 3.0.0", + "fvm_shared", "hex", "hex-literal", "log", @@ -1330,16 +1384,16 @@ dependencies = [ [[package]] name = "fil_actor_init" version = "10.0.0" -source = "git+https://github.com/filecoin-project/builtin-actors?rev=89dc63d#89dc63dfc9473d7db42525bf59bb0e679d8c9c41" +source = "git+https://github.com/filecoin-project/builtin-actors?rev=39571e2#39571e25eacd51326c9fc8e29d4b69943f15a3b1" dependencies = [ "anyhow", "cid", "fil_actors_runtime", "frc42_dispatch", - "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_ipld_hamt 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_shared 3.0.0", + "fvm_ipld_blockstore", + "fvm_ipld_encoding", + "fvm_ipld_hamt", + "fvm_shared", "log", "num-derive", "num-traits", @@ -1349,7 +1403,7 @@ dependencies = [ [[package]] name = "fil_actor_market" version = "10.0.0" -source = "git+https://github.com/filecoin-project/builtin-actors?rev=89dc63d#89dc63dfc9473d7db42525bf59bb0e679d8c9c41" +source = "git+https://github.com/filecoin-project/builtin-actors?rev=39571e2#39571e25eacd51326c9fc8e29d4b69943f15a3b1" dependencies = [ "anyhow", "cid", @@ -1357,10 +1411,10 @@ dependencies = [ "frc42_dispatch", "frc46_token", "fvm_ipld_bitfield", - "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_ipld_hamt 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_shared 3.0.0", + "fvm_ipld_blockstore", + "fvm_ipld_encoding", + "fvm_ipld_hamt", + "fvm_shared", "integer-encoding", "libipld-core 0.13.1", "log", @@ -1372,19 +1426,19 @@ dependencies = [ [[package]] name = "fil_actor_miner" version = "10.0.0" -source = "git+https://github.com/filecoin-project/builtin-actors?rev=89dc63d#89dc63dfc9473d7db42525bf59bb0e679d8c9c41" +source = "git+https://github.com/filecoin-project/builtin-actors?rev=39571e2#39571e25eacd51326c9fc8e29d4b69943f15a3b1" dependencies = [ "anyhow", "byteorder", "cid", "fil_actors_runtime", "frc42_dispatch", - "fvm_ipld_amt 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_amt", "fvm_ipld_bitfield", - "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_ipld_hamt 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_shared 3.0.0", + "fvm_ipld_blockstore", + "fvm_ipld_encoding", + "fvm_ipld_hamt", + "fvm_shared", "itertools 0.10.5", "lazy_static", "log", @@ -1397,17 +1451,17 @@ dependencies = [ [[package]] name = "fil_actor_multisig" version = "10.0.0" -source = "git+https://github.com/filecoin-project/builtin-actors?rev=89dc63d#89dc63dfc9473d7db42525bf59bb0e679d8c9c41" +source = "git+https://github.com/filecoin-project/builtin-actors?rev=39571e2#39571e25eacd51326c9fc8e29d4b69943f15a3b1" dependencies = [ "anyhow", "cid", "fil_actors_runtime", "frc42_dispatch", "fvm_actor_utils", - "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_ipld_hamt 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_shared 3.0.0", + "fvm_ipld_blockstore", + "fvm_ipld_encoding", + "fvm_ipld_hamt", + "fvm_shared", "indexmap", "integer-encoding", "num-derive", @@ -1418,15 +1472,15 @@ dependencies = [ [[package]] name = "fil_actor_paych" version = "10.0.0" -source = "git+https://github.com/filecoin-project/builtin-actors?rev=89dc63d#89dc63dfc9473d7db42525bf59bb0e679d8c9c41" +source = "git+https://github.com/filecoin-project/builtin-actors?rev=39571e2#39571e25eacd51326c9fc8e29d4b69943f15a3b1" dependencies = [ "anyhow", "cid", "fil_actors_runtime", "frc42_dispatch", - "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_shared 3.0.0", + "fvm_ipld_blockstore", + "fvm_ipld_encoding", + "fvm_shared", "num-derive", "num-traits", "serde", @@ -1435,21 +1489,21 @@ dependencies = [ [[package]] name = "fil_actor_placeholder" version = "10.0.0" -source = "git+https://github.com/filecoin-project/builtin-actors?rev=89dc63d#89dc63dfc9473d7db42525bf59bb0e679d8c9c41" +source = "git+https://github.com/filecoin-project/builtin-actors?rev=39571e2#39571e25eacd51326c9fc8e29d4b69943f15a3b1" [[package]] name = "fil_actor_power" version = "10.0.0" -source = "git+https://github.com/filecoin-project/builtin-actors?rev=89dc63d#89dc63dfc9473d7db42525bf59bb0e679d8c9c41" +source = "git+https://github.com/filecoin-project/builtin-actors?rev=39571e2#39571e25eacd51326c9fc8e29d4b69943f15a3b1" dependencies = [ "anyhow", "cid", "fil_actors_runtime", "frc42_dispatch", - "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_ipld_hamt 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_shared 3.0.0", + "fvm_ipld_blockstore", + "fvm_ipld_encoding", + "fvm_ipld_hamt", + "fvm_shared", "indexmap", "integer-encoding", "lazy_static", @@ -1462,12 +1516,12 @@ dependencies = [ [[package]] name = "fil_actor_reward" version = "10.0.0" -source = "git+https://github.com/filecoin-project/builtin-actors?rev=89dc63d#89dc63dfc9473d7db42525bf59bb0e679d8c9c41" +source = "git+https://github.com/filecoin-project/builtin-actors?rev=39571e2#39571e25eacd51326c9fc8e29d4b69943f15a3b1" dependencies = [ "fil_actors_runtime", - "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_shared 3.0.0", + "fvm_ipld_blockstore", + "fvm_ipld_encoding", + "fvm_shared", "lazy_static", "log", "num-derive", @@ -1478,14 +1532,14 @@ dependencies = [ [[package]] name = "fil_actor_system" version = "10.0.0" -source = "git+https://github.com/filecoin-project/builtin-actors?rev=89dc63d#89dc63dfc9473d7db42525bf59bb0e679d8c9c41" +source = "git+https://github.com/filecoin-project/builtin-actors?rev=39571e2#39571e25eacd51326c9fc8e29d4b69943f15a3b1" dependencies = [ "anyhow", "cid", "fil_actors_runtime", - "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_shared 3.0.0", + "fvm_ipld_blockstore", + "fvm_ipld_encoding", + "fvm_shared", "num-derive", "num-traits", "serde", @@ -1494,7 +1548,7 @@ dependencies = [ [[package]] name = "fil_actor_verifreg" version = "10.0.0" -source = "git+https://github.com/filecoin-project/builtin-actors?rev=89dc63d#89dc63dfc9473d7db42525bf59bb0e679d8c9c41" +source = "git+https://github.com/filecoin-project/builtin-actors?rev=39571e2#39571e25eacd51326c9fc8e29d4b69943f15a3b1" dependencies = [ "anyhow", "cid", @@ -1502,10 +1556,10 @@ dependencies = [ "frc42_dispatch", "frc46_token", "fvm_actor_utils", - "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_ipld_hamt 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_shared 3.0.0", + "fvm_ipld_blockstore", + "fvm_ipld_encoding", + "fvm_ipld_hamt", + "fvm_shared", "lazy_static", "log", "num-derive", @@ -1516,11 +1570,11 @@ dependencies = [ [[package]] name = "fil_actors_evm_shared" version = "10.0.0" -source = "git+https://github.com/filecoin-project/builtin-actors?rev=89dc63d#89dc63dfc9473d7db42525bf59bb0e679d8c9c41" +source = "git+https://github.com/filecoin-project/builtin-actors?rev=39571e2#39571e25eacd51326c9fc8e29d4b69943f15a3b1" dependencies = [ "fil_actors_runtime", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_shared 3.0.0", + "fvm_ipld_encoding", + "fvm_shared", "hex", "serde", "uint", @@ -1529,19 +1583,19 @@ dependencies = [ [[package]] name = "fil_actors_runtime" version = "10.0.0" -source = "git+https://github.com/filecoin-project/builtin-actors?rev=89dc63d#89dc63dfc9473d7db42525bf59bb0e679d8c9c41" +source = "git+https://github.com/filecoin-project/builtin-actors?rev=39571e2#39571e25eacd51326c9fc8e29d4b69943f15a3b1" dependencies = [ "anyhow", "byteorder", "castaway", "cid", - "fvm_ipld_amt 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_amt", "fvm_ipld_bitfield", - "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_ipld_hamt 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_sdk 3.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_shared 3.0.0", + "fvm_ipld_blockstore", + "fvm_ipld_encoding", + "fvm_ipld_hamt", + "fvm_sdk", + "fvm_shared", "itertools 0.10.5", "log", "multihash", @@ -1560,7 +1614,7 @@ dependencies = [ [[package]] name = "fil_builtin_actors_bundle" version = "10.0.0" -source = "git+https://github.com/filecoin-project/builtin-actors?rev=89dc63d#89dc63dfc9473d7db42525bf59bb0e679d8c9c41" +source = "git+https://github.com/filecoin-project/builtin-actors?rev=39571e2#39571e25eacd51326c9fc8e29d4b69943f15a3b1" dependencies = [ "cid", "clap 3.2.23", @@ -1676,7 +1730,7 @@ version = "0.10.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1657b4441c3403d9f7b3409e47575237dac27b1b5726df654a6ecbf92f0f7577" dependencies = [ - "spin 0.9.6", + "spin 0.9.8", ] [[package]] @@ -1720,34 +1774,34 @@ dependencies = [ [[package]] name = "frc42_dispatch" -version = "3.0.2" +version = "3.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7bc80f65be319b625b0a09e86ba0793e3da8e4ab9030a801f0cdd00bbcb8e24" +checksum = "a4dc594c941eba1d5a9474f595c6d0f9d752fa333b672755bbe7c23d30f64282" dependencies = [ "frc42_hasher", "frc42_macros", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_sdk 3.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_shared 3.0.0", + "fvm_ipld_encoding", + "fvm_sdk", + "fvm_shared", "thiserror", ] [[package]] name = "frc42_hasher" -version = "1.3.1" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab91345ff52851dfa6e3a253f08462e703a04c5c6458cecddbec9596519b9026" +checksum = "d6caf7fa3028536d11b1ff94a63bd1d60926ff7366b25b2a94d07bd23190f459" dependencies = [ - "fvm_sdk 3.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_shared 3.0.0", + "fvm_sdk", + "fvm_shared", "thiserror", ] [[package]] name = "frc42_macros" -version = "1.0.1" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9e5a8b295ad4267907612c931b60f25ab7a74e540de41668cee96ce6af0ed3b" +checksum = "c57201a8c3c26b41c4234a0f68b123ec2c33c958d31d09a3a780c345256e7928" dependencies = [ "blake2b_simd", "frc42_hasher", @@ -1758,20 +1812,20 @@ dependencies = [ [[package]] name = "frc46_token" -version = "4.0.2" +version = "5.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ef4c6ab802df24f9d29fe4f0c6b463b46a27954ea722d29a80ab3c93800c0a0" +checksum = "c0a7c3f316549c34350c5713ee6885fcaece30a83399c54681016dfc6faa671e" dependencies = [ "anyhow", "cid", "frc42_dispatch", "fvm_actor_utils", - "fvm_ipld_amt 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_ipld_hamt 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_sdk 3.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_shared 3.0.0", + "fvm_ipld_amt", + "fvm_ipld_blockstore", + "fvm_ipld_encoding", + "fvm_ipld_hamt", + "fvm_sdk", + "fvm_shared", "integer-encoding", "num-traits", "serde", @@ -1797,9 +1851,9 @@ checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" [[package]] name = "futures" -version = "0.3.27" +version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "531ac96c6ff5fd7c62263c5e3c67a603af4fcaee2e1a0ae5565ba3a11e69e549" +checksum = "23342abe12aba583913b2e62f22225ff9c950774065e4bfb61a19cd9770fec40" dependencies = [ "futures-channel", "futures-core", @@ -1812,9 +1866,9 @@ dependencies = [ [[package]] name = "futures-channel" -version = "0.3.27" +version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "164713a5a0dcc3e7b4b1ed7d3b433cabc18025386f9339346e8daf15963cf7ac" +checksum = "955518d47e09b25bbebc7a18df10b81f0c766eaf4c4f1cccef2fca5f2a4fb5f2" dependencies = [ "futures-core", "futures-sink", @@ -1822,15 +1876,15 @@ dependencies = [ [[package]] name = "futures-core" -version = "0.3.27" +version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86d7a0c1aa76363dac491de0ee99faf6941128376f1cf96f07db7603b7de69dd" +checksum = "4bca583b7e26f571124fe5b7561d49cb2868d79116cfa0eefce955557c6fee8c" [[package]] name = "futures-executor" -version = "0.3.27" +version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1997dd9df74cdac935c76252744c1ed5794fac083242ea4fe77ef3ed60ba0f83" +checksum = "ccecee823288125bd88b4d7f565c9e58e41858e47ab72e8ea2d64e93624386e0" dependencies = [ "futures-core", "futures-task", @@ -1839,9 +1893,9 @@ dependencies = [ [[package]] name = "futures-io" -version = "0.3.27" +version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89d422fa3cbe3b40dca574ab087abb5bc98258ea57eea3fd6f1fa7162c778b91" +checksum = "4fff74096e71ed47f8e023204cfd0aa1289cd54ae5430a9523be060cdb849964" [[package]] name = "futures-lite" @@ -1860,32 +1914,32 @@ dependencies = [ [[package]] name = "futures-macro" -version = "0.3.27" +version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3eb14ed937631bd8b8b8977f2c198443447a8355b6e3ca599f38c975e5a963b6" +checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72" dependencies = [ "proc-macro2", "quote", - "syn 1.0.109", + "syn 2.0.13", ] [[package]] name = "futures-sink" -version = "0.3.27" +version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec93083a4aecafb2a80a885c9de1f0ccae9dbd32c2bb54b0c3a65690e0b8d2f2" +checksum = "f43be4fe21a13b9781a69afa4985b0f6ee0e1afab2c6f454a8cf30e2b2237b6e" [[package]] name = "futures-task" -version = "0.3.27" +version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd65540d33b37b16542a0438c12e6aeead10d4ac5d05bd3f805b8f35ab592879" +checksum = "76d3d132be6c0e6aa1534069c705a74a5997a356c0dc2f86a47765e5617c5b65" [[package]] name = "futures-util" -version = "0.3.27" +version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ef6b17e481503ec85211fed8f39d1970f128935ca1f814cd32ac4a6842e84ab" +checksum = "26b01e40b772d54cf6c6d721c1d1abd0647a0106a12ecaa1c186273392a69533" dependencies = [ "futures-channel", "futures-core", @@ -1902,7 +1956,8 @@ dependencies = [ [[package]] name = "fvm" version = "3.1.0" -source = "git+https://github.com/filecoin-project/ref-fvm.git#37643fc02f0342256afecff5158c43693b5ee4f0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3760dd47434b4f53bc8944dfd800994fff61ece4ef7159975167c0adfa7363e4" dependencies = [ "anyhow", "blake2b_simd", @@ -1913,11 +1968,11 @@ dependencies = [ "derive_more", "filecoin-proofs-api", "fvm-wasm-instrument", - "fvm_ipld_amt 0.5.1 (git+https://github.com/filecoin-project/ref-fvm.git)", - "fvm_ipld_blockstore 0.1.1 (git+https://github.com/filecoin-project/ref-fvm.git)", - "fvm_ipld_encoding 0.3.3 (git+https://github.com/filecoin-project/ref-fvm.git)", - "fvm_ipld_hamt 0.6.1 (git+https://github.com/filecoin-project/ref-fvm.git)", - "fvm_shared 3.1.0", + "fvm_ipld_amt", + "fvm_ipld_blockstore", + "fvm_ipld_encoding", + "fvm_ipld_hamt", + "fvm_shared", "lazy_static", "log", "minstant", @@ -1953,17 +2008,17 @@ dependencies = [ [[package]] name = "fvm_actor_utils" -version = "4.0.2" +version = "5.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b37f347ddbb46adeba750a8bbc499d5b7f83610d977615b4bcd83b84081b8721" +checksum = "2ca7d35816608fb36ecc01448938d7827820051390459abb573fdad2aff626b1" dependencies = [ "anyhow", "cid", "frc42_dispatch", - "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_sdk 3.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_shared 3.0.0", + "fvm_ipld_blockstore", + "fvm_ipld_encoding", + "fvm_sdk", + "fvm_shared", "num-traits", "serde", "serde_tuple", @@ -1978,23 +2033,8 @@ checksum = "e84f16d6927ce342ef86bd20fcc2d5bd498ed33ae6d7a22fea7a1b453488ec88" dependencies = [ "anyhow", "cid", - "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", - "itertools 0.10.5", - "once_cell", - "serde", - "thiserror", -] - -[[package]] -name = "fvm_ipld_amt" -version = "0.5.1" -source = "git+https://github.com/filecoin-project/ref-fvm.git#37643fc02f0342256afecff5158c43693b5ee4f0" -dependencies = [ - "anyhow", - "cid", - "fvm_ipld_blockstore 0.1.1 (git+https://github.com/filecoin-project/ref-fvm.git)", - "fvm_ipld_encoding 0.3.3 (git+https://github.com/filecoin-project/ref-fvm.git)", + "fvm_ipld_blockstore", + "fvm_ipld_encoding", "itertools 0.10.5", "once_cell", "serde", @@ -2007,7 +2047,7 @@ version = "0.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d1950291f40d2d1047eb0a4568f7ef6d5b4973452dcef012dffb1957fe483ff7" dependencies = [ - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_encoding", "serde", "thiserror", "unsigned-varint", @@ -2024,16 +2064,6 @@ dependencies = [ "multihash", ] -[[package]] -name = "fvm_ipld_blockstore" -version = "0.1.1" -source = "git+https://github.com/filecoin-project/ref-fvm.git#37643fc02f0342256afecff5158c43693b5ee4f0" -dependencies = [ - "anyhow", - "cid", - "multihash", -] - [[package]] name = "fvm_ipld_car" version = "0.6.0" @@ -2042,22 +2072,8 @@ checksum = "c60423568393a284de6d7c342cd664690611f27d223eb78629fa568ddd4e7951" dependencies = [ "cid", "futures", - "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", - "integer-encoding", - "serde", - "thiserror", -] - -[[package]] -name = "fvm_ipld_car" -version = "0.6.0" -source = "git+https://github.com/filecoin-project/ref-fvm.git#37643fc02f0342256afecff5158c43693b5ee4f0" -dependencies = [ - "cid", - "futures", - "fvm_ipld_blockstore 0.1.1 (git+https://github.com/filecoin-project/ref-fvm.git)", - "fvm_ipld_encoding 0.3.3 (git+https://github.com/filecoin-project/ref-fvm.git)", + "fvm_ipld_blockstore", + "fvm_ipld_encoding", "integer-encoding", "serde", "thiserror", @@ -2071,23 +2087,7 @@ checksum = "f0816a2a6df4853de08a723d261110d56a121aa313bc570fe9d248f0a4bc5288" dependencies = [ "anyhow", "cid", - "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "multihash", - "serde", - "serde_ipld_dagcbor", - "serde_repr", - "serde_tuple", - "thiserror", -] - -[[package]] -name = "fvm_ipld_encoding" -version = "0.3.3" -source = "git+https://github.com/filecoin-project/ref-fvm.git#37643fc02f0342256afecff5158c43693b5ee4f0" -dependencies = [ - "anyhow", - "cid", - "fvm_ipld_blockstore 0.1.1 (git+https://github.com/filecoin-project/ref-fvm.git)", + "fvm_ipld_blockstore", "multihash", "serde", "serde_ipld_dagcbor", @@ -2106,27 +2106,8 @@ dependencies = [ "byteorder", "cid", "forest_hash_utils", - "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", - "libipld-core 0.14.0", - "multihash", - "once_cell", - "serde", - "sha2 0.10.6", - "thiserror", -] - -[[package]] -name = "fvm_ipld_hamt" -version = "0.6.1" -source = "git+https://github.com/filecoin-project/ref-fvm.git#37643fc02f0342256afecff5158c43693b5ee4f0" -dependencies = [ - "anyhow", - "byteorder", - "cid", - "forest_hash_utils", - "fvm_ipld_blockstore 0.1.1 (git+https://github.com/filecoin-project/ref-fvm.git)", - "fvm_ipld_encoding 0.3.3 (git+https://github.com/filecoin-project/ref-fvm.git)", + "fvm_ipld_blockstore", + "fvm_ipld_encoding", "libipld-core 0.14.0", "multihash", "once_cell", @@ -2145,8 +2126,8 @@ dependencies = [ "byteorder", "cid", "forest_hash_utils", - "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_blockstore", + "fvm_ipld_encoding", "multihash", "once_cell", "serde", @@ -2161,64 +2142,22 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2fef17308967cceb1d22f05003d60adb0d5b9ba53e34ace4ae04701eb7e6af02" dependencies = [ "cid", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_shared 3.0.0", - "lazy_static", - "log", - "num-traits", - "thiserror", -] - -[[package]] -name = "fvm_sdk" -version = "3.0.0" -source = "git+https://github.com/filecoin-project/ref-fvm.git#37643fc02f0342256afecff5158c43693b5ee4f0" -dependencies = [ - "cid", - "fvm_ipld_encoding 0.3.3 (git+https://github.com/filecoin-project/ref-fvm.git)", - "fvm_shared 3.1.0", + "fvm_ipld_encoding", + "fvm_shared", "lazy_static", "log", "num-traits", "thiserror", ] -[[package]] -name = "fvm_shared" -version = "3.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c99c06aa865e34198d9ca0da54e53e2fca14ae9ce5402f51b7c8e78175205861" -dependencies = [ - "anyhow", - "bitflags 1.3.2", - "blake2b_simd", - "byteorder", - "cid", - "data-encoding", - "data-encoding-macro", - "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static", - "log", - "multihash", - "num-bigint", - "num-derive", - "num-integer", - "num-traits", - "serde", - "serde_repr", - "serde_tuple", - "thiserror", - "unsigned-varint", -] - [[package]] name = "fvm_shared" version = "3.1.0" -source = "git+https://github.com/filecoin-project/ref-fvm.git#37643fc02f0342256afecff5158c43693b5ee4f0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "45742ae0f445a80121a97e9ee36fd0112f56e19daa5865fe458452ec6ff358f2" dependencies = [ "anyhow", - "bitflags 1.3.2", + "bitflags", "blake2b_simd", "bls-signatures", "byteorder", @@ -2226,8 +2165,8 @@ dependencies = [ "data-encoding", "data-encoding-macro", "filecoin-proofs-api", - "fvm_ipld_blockstore 0.1.1 (git+https://github.com/filecoin-project/ref-fvm.git)", - "fvm_ipld_encoding 0.3.3 (git+https://github.com/filecoin-project/ref-fvm.git)", + "fvm_ipld_blockstore", + "fvm_ipld_encoding", "lazy_static", "libsecp256k1", "log", @@ -2254,9 +2193,9 @@ dependencies = [ [[package]] name = "generic-array" -version = "0.14.6" +version = "0.14.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bff49e947297f3312447abdca79f45f4738097cc82b06e72054d2223f601f1b9" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" dependencies = [ "typenum", "version_check", @@ -2414,9 +2353,9 @@ dependencies = [ [[package]] name = "indexmap" -version = "1.9.2" +version = "1.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1885e79c1fc4b10f0e172c475f458b7f7b93061064d98c3293e98c5ba0c8b399" +checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" dependencies = [ "autocfg", "hashbrown", @@ -2471,13 +2410,13 @@ dependencies = [ [[package]] name = "is-terminal" -version = "0.4.5" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8687c819457e979cc940d09cb16e42a1bf70aa6b60a549de6d3a62a0ee90c69e" +checksum = "256017f749ab3117e93acb91063009e1f1bb56d03965b14c2c8df4eb02c524d8" dependencies = [ "hermit-abi 0.3.1", "io-lifetimes 1.0.9", - "rustix 0.36.11", + "rustix 0.37.6", "windows-sys 0.45.0", ] @@ -2537,7 +2476,7 @@ name = "kythera-cli" version = "0.1.0-alpha.2" dependencies = [ "anyhow", - "clap 4.1.11", + "clap 4.2.1", "kythera-lib", "log", "tempfile", @@ -2562,8 +2501,8 @@ dependencies = [ "anyhow", "cid", "fvm", - "fvm_ipld_encoding 0.3.3 (git+https://github.com/filecoin-project/ref-fvm.git)", - "fvm_shared 3.1.0", + "fvm_ipld_encoding", + "fvm_shared", "multihash", ] @@ -2587,10 +2526,10 @@ dependencies = [ "fil_actors_runtime", "fil_builtin_actors_bundle", "futures", - "fvm_ipld_blockstore 0.1.1 (git+https://github.com/filecoin-project/ref-fvm.git)", - "fvm_ipld_car 0.6.0 (git+https://github.com/filecoin-project/ref-fvm.git)", - "fvm_ipld_encoding 0.3.3 (git+https://github.com/filecoin-project/ref-fvm.git)", - "fvm_shared 3.1.0", + "fvm_ipld_blockstore", + "fvm_ipld_car", + "fvm_ipld_encoding", + "fvm_shared", "kythera-common", "kythera-fvm", "kythera_test_actors", @@ -2713,15 +2652,9 @@ checksum = "d4d2456c373231a208ad294c33dc5bff30051eafd954cd4caae83a712b12854d" [[package]] name = "linux-raw-sys" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f051f77a7c8e6957c0696eac88f26b0117e54f52d3fc682ab19397a8812846a4" - -[[package]] -name = "linux-raw-sys" -version = "0.3.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd550e73688e6d578f0ac2119e32b797a327631a42f9433e59d02e139c8df60d" +checksum = "d59d8c75012853d2e872fb56bc8a2e53718e2cafe1a4c823143141c6d90c322f" [[package]] name = "lock_api" @@ -2760,11 +2693,11 @@ checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" [[package]] name = "memfd" -version = "0.6.2" +version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b20a59d985586e4a5aef64564ac77299f8586d8be6cf9106a5a40207e8908efb" +checksum = "ffc89ccdc6e10d6907450f753537ebc5c5d3460d2e4e62ea74bd571db62c0f9e" dependencies = [ - "rustix 0.36.11", + "rustix 0.37.6", ] [[package]] @@ -3111,7 +3044,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7e1f879b2998099c2d69ab9605d145d5b661195627eccc680002c4918a7fb6fa" dependencies = [ "autocfg", - "bitflags 1.3.2", + "bitflags", "cfg-if", "concurrent-queue", "libc", @@ -3185,9 +3118,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.53" +version = "1.0.56" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba466839c78239c09faf015484e5cc04860f88242cff4d03eb038f04b4699b73" +checksum = "2b63bdb0cd06f1f4dedf69b254734f9b45af66e4a031e42a7480257d9898b435" dependencies = [ "unicode-ident", ] @@ -3279,11 +3212,11 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.2.16" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" +checksum = "567664f262709473930a4bf9e51bf2ebf3348f2e748ccc50dea20646858f8f29" dependencies = [ - "bitflags 1.3.2", + "bitflags", ] [[package]] @@ -3300,9 +3233,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.7.2" +version = "1.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cce168fea28d3e05f158bda4576cf0c844d5045bc2cc3620fa0292ed5bb5814c" +checksum = "8b1f693b24f6ac912f4893ef08244d70b6067480d2f1a46e950c9691e6749d1d" dependencies = [ "aho-corasick", "memchr", @@ -3342,9 +3275,9 @@ dependencies = [ [[package]] name = "rustc-demangle" -version = "0.1.21" +version = "0.1.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ef03e0a2b150c7a90d01faf6254c9c48a41e95fb2a8c2ac1c6f0d2b9aefc342" +checksum = "d4a36c42d1873f9a77c53bde094f9664d9891bc604a45b4798fd2c389ed12e5b" [[package]] name = "rustc-hex" @@ -3367,7 +3300,7 @@ version = "0.35.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "727a1a6d65f786ec22df8a81ca3121107f235970dc1705ed681d3e6e8b9cd5f9" dependencies = [ - "bitflags 1.3.2", + "bitflags", "errno 0.2.8", "io-lifetimes 0.7.5", "libc", @@ -3377,29 +3310,15 @@ dependencies = [ [[package]] name = "rustix" -version = "0.36.11" +version = "0.37.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db4165c9963ab29e422d6c26fbc1d37f15bace6b2810221f9d925023480fcf0e" +checksum = "d097081ed288dfe45699b72f5b5d648e5f15d64d900c7080273baa20c16a6849" dependencies = [ - "bitflags 1.3.2", - "errno 0.2.8", - "io-lifetimes 1.0.9", - "libc", - "linux-raw-sys 0.1.4", - "windows-sys 0.45.0", -] - -[[package]] -name = "rustix" -version = "0.37.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62b24138615de35e32031d041a09032ef3487a616d901ca4db224e7d557efae2" -dependencies = [ - "bitflags 1.3.2", + "bitflags", "errno 0.3.0", "io-lifetimes 1.0.9", "libc", - "linux-raw-sys 0.3.0", + "linux-raw-sys 0.3.1", "windows-sys 0.45.0", ] @@ -3438,9 +3357,9 @@ checksum = "bebd363326d05ec3e2f532ab7660680f3b02130d780c299bca73469d521bc0ed" [[package]] name = "serde" -version = "1.0.158" +version = "1.0.159" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "771d4d9c4163ee138805e12c710dd365e4f44be8be0503cb1bb9eb989425d9c9" +checksum = "3c04e8343c3daeec41f58990b9d77068df31209f2af111e059e9fe9646693065" dependencies = [ "serde_derive", ] @@ -3465,13 +3384,13 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.158" +version = "1.0.159" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e801c1712f48475582b7696ac71e0ca34ebb30e09338425384269d9717c62cad" +checksum = "4c614d17805b093df4b147b51339e7e44bf05ef59fba1e45d83500bcfb4d8585" dependencies = [ "proc-macro2", "quote", - "syn 2.0.5", + "syn 2.0.13", ] [[package]] @@ -3488,9 +3407,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.94" +version = "1.0.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c533a59c9d8a93a09c6ab31f0fd5e5f4dd1b8fc9434804029839884765d04ea" +checksum = "d721eca97ac802aa7777b701877c8004d950fc142651367300d21c1cc0194744" dependencies = [ "itoa", "ryu", @@ -3505,7 +3424,7 @@ checksum = "bcec881020c684085e55a25f7fd888954d56609ef363479dc5a1305eb0d40cab" dependencies = [ "proc-macro2", "quote", - "syn 2.0.5", + "syn 2.0.13", ] [[package]] @@ -3627,9 +3546,9 @@ checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" [[package]] name = "spin" -version = "0.9.6" +version = "0.9.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5d6e0250b93c8427a177b849d144a96d5acc57006149479403d7861ab721e34" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" dependencies = [ "lock_api", ] @@ -3804,9 +3723,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.5" +version = "2.0.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89c2d1c76a26822187a1fbb5964e3fff108bc208f02e820ab9dac1234f6b388a" +checksum = "4c9da457c5285ac1f936ebd076af6dac17a61cfe7826f2076b4d015cf47bc8ec" dependencies = [ "proc-macro2", "quote", @@ -3839,15 +3758,15 @@ checksum = "8ae9980cab1db3fceee2f6c6f643d5d8de2997c58ee8d25fb0cc8a9e9e7348e5" [[package]] name = "tempfile" -version = "3.4.0" +version = "3.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af18f7ae1acd354b992402e9ec5864359d693cd8a79dcbef59f76891701c1e95" +checksum = "b9fbec84f381d5795b08656e4912bec604d162bff9291d6189a78f4c8ab87998" dependencies = [ "cfg-if", "fastrand", "redox_syscall", - "rustix 0.36.11", - "windows-sys 0.42.0", + "rustix 0.37.6", + "windows-sys 0.45.0", ] [[package]] @@ -3882,7 +3801,7 @@ checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f" dependencies = [ "proc-macro2", "quote", - "syn 2.0.5", + "syn 2.0.13", ] [[package]] @@ -3997,6 +3916,12 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "utf8parse" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" + [[package]] name = "value-bag" version = "1.0.0-alpha.9" @@ -4534,21 +4459,20 @@ dependencies = [ [[package]] name = "zeroize" -version = "1.5.7" +version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c394b5bd0c6f669e7275d9c20aa90ae064cb22e75a1cad54e1b34088034b149f" +checksum = "2a0956f1ba7c7909bfb66c2e9e4124ab6f6482560f6628b5aaeba39207c9aad9" dependencies = [ "zeroize_derive", ] [[package]] name = "zeroize_derive" -version = "1.3.3" +version = "1.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44bf07cb3e50ea2003396695d58bf46bc9887a1f362260446fad6bc4e79bd36c" +checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", "quote", - "syn 1.0.109", - "synstructure", + "syn 2.0.13", ] diff --git a/common/Cargo.toml b/common/Cargo.toml index 8719a62..e6548c6 100644 --- a/common/Cargo.toml +++ b/common/Cargo.toml @@ -8,5 +8,5 @@ edition = "2021" [dependencies] anyhow = "1.0.70" blake2b_simd = { version = "1.0.0" } -frc42_dispatch = "3.0.0" +frc42_dispatch = "3.1.0" thiserror = "1.0.40" \ No newline at end of file diff --git a/fvm/Cargo.toml b/fvm/Cargo.toml index 31bd188..26b49ea 100644 --- a/fvm/Cargo.toml +++ b/fvm/Cargo.toml @@ -8,7 +8,7 @@ edition = "2021" [dependencies] anyhow = "1.0.70" cid = { version = "0.8.5", default-features = false } -fvm = { git = "https://github.com/filecoin-project/ref-fvm.git", version = "3.1.0", default-features = false, features = ["testing"] } -fvm_ipld_encoding = { git = "https://github.com/filecoin-project/ref-fvm.git", version = "0.3.3" } -fvm_shared = { git = "https://github.com/filecoin-project/ref-fvm.git", version = "3.1.0" } +fvm = { version = "3.1.0", default-features = false, features = ["testing"] } +fvm_ipld_encoding = { version = "0.3.3" } +fvm_shared = { version = "3.1.0" } multihash = { version = "0.16.1", default-features = false } diff --git a/lib/Cargo.toml b/lib/Cargo.toml index ecbea70..d0e7f48 100644 --- a/lib/Cargo.toml +++ b/lib/Cargo.toml @@ -6,25 +6,25 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -actors-v10 = { package = "fil_builtin_actors_bundle", git = "https://github.com/filecoin-project/builtin-actors", rev = "89dc63d" } -fil_actor_account = { git = "https://github.com/filecoin-project/builtin-actors", rev = "89dc63d", features = [] } -fil_actor_cron = { git = "https://github.com/filecoin-project/builtin-actors", rev = "89dc63d", features = [] } -fil_actor_datacap = { git = "https://github.com/filecoin-project/builtin-actors", rev = "89dc63d", features = [] } -fil_actor_init = { git = "https://github.com/filecoin-project/builtin-actors", rev = "89dc63d", features = [] } -fil_actor_market = { git = "https://github.com/filecoin-project/builtin-actors", rev = "89dc63d", features = [] } -fil_actor_miner = { git = "https://github.com/filecoin-project/builtin-actors", rev = "89dc63d", features = [] } -fil_actor_multisig = { git = "https://github.com/filecoin-project/builtin-actors", rev = "89dc63d", features = [] } -fil_actor_paych = { git = "https://github.com/filecoin-project/builtin-actors", rev = "89dc63d", features = [] } -fil_actor_power = { git = "https://github.com/filecoin-project/builtin-actors", rev = "89dc63d", features = [] } -fil_actor_reward = { git = "https://github.com/filecoin-project/builtin-actors", rev = "89dc63d", features = [] } -fil_actor_system = { git = "https://github.com/filecoin-project/builtin-actors", rev = "89dc63d", features = [] } -fil_actor_verifreg = { git = "https://github.com/filecoin-project/builtin-actors", rev = "89dc63d", features = [] } -fil_actors_runtime = { git = "https://github.com/filecoin-project/builtin-actors", rev = "89dc63d", features = [] } +actors-v10 = { package = "fil_builtin_actors_bundle", git = "https://github.com/filecoin-project/builtin-actors", rev = "39571e2" } +fil_actor_account = { git = "https://github.com/filecoin-project/builtin-actors", rev = "39571e2", features = [] } +fil_actor_cron = { git = "https://github.com/filecoin-project/builtin-actors", rev = "39571e2", features = [] } +fil_actor_datacap = { git = "https://github.com/filecoin-project/builtin-actors", rev = "39571e2", features = [] } +fil_actor_init = { git = "https://github.com/filecoin-project/builtin-actors", rev = "39571e2", features = [] } +fil_actor_market = { git = "https://github.com/filecoin-project/builtin-actors", rev = "39571e2", features = [] } +fil_actor_miner = { git = "https://github.com/filecoin-project/builtin-actors", rev = "39571e2", features = [] } +fil_actor_multisig = { git = "https://github.com/filecoin-project/builtin-actors", rev = "39571e2", features = [] } +fil_actor_paych = { git = "https://github.com/filecoin-project/builtin-actors", rev = "39571e2", features = [] } +fil_actor_power = { git = "https://github.com/filecoin-project/builtin-actors", rev = "39571e2", features = [] } +fil_actor_reward = { git = "https://github.com/filecoin-project/builtin-actors", rev = "39571e2", features = [] } +fil_actor_system = { git = "https://github.com/filecoin-project/builtin-actors", rev = "39571e2", features = [] } +fil_actor_verifreg = { git = "https://github.com/filecoin-project/builtin-actors", rev = "39571e2", features = [] } +fil_actors_runtime = { git = "https://github.com/filecoin-project/builtin-actors", rev = "39571e2", features = [] } -fvm_ipld_blockstore = { git = "https://github.com/filecoin-project/ref-fvm.git", version = "0.1.1" } -fvm_ipld_car = { git = "https://github.com/filecoin-project/ref-fvm.git", version = "0.6.0" } -fvm_ipld_encoding = { git = "https://github.com/filecoin-project/ref-fvm.git", version = "0.3.3" } -fvm_shared = { git = "https://github.com/filecoin-project/ref-fvm.git", version = "3.1.0", features = ["testing"] } +fvm_ipld_blockstore = { version = "0.1.1" } +fvm_ipld_car = { version = "0.6.0" } +fvm_ipld_encoding = { version = "0.3.3" } +fvm_shared = { version = "3.1.0", features = ["testing"] } kythera-fvm = { path = "../fvm" } kythera-common = { path = "../common" } diff --git a/lib/src/state_tree.rs b/lib/src/state_tree.rs index b739334..c81986f 100644 --- a/lib/src/state_tree.rs +++ b/lib/src/state_tree.rs @@ -101,15 +101,14 @@ impl StateTree { let manifest = Manifest::load(blockstore, &root, version) .expect("Should be able to load built-in Actor manifest"); - // deploy built-in Actors on the StateTree. let init_state = init_actor::State::new_test(&blockstore); - let sys_state = system_actor::State { - builtin_actors: root, - }; + // Set system actor. self.set_actor( "System Actor", - sys_state, + fil_actor_system::State { + builtin_actors: root, + }, *manifest .code_by_id(Type::System as u32) .expect("Should be able to get system Actor code from manifest"), @@ -119,6 +118,7 @@ impl StateTree { ) .expect("Should be able to set the system Actor"); + // Set init actor self.set_actor( "Init Actor", init_state, @@ -131,6 +131,8 @@ impl StateTree { ) .expect("Should be able to set the Init Actor"); + // Set reward actor + BuiltInActors { root: builtin_actors, manifest, diff --git a/test_actors/actors/basic_test_actor/Cargo.toml b/test_actors/actors/basic_test_actor/Cargo.toml index d5c9fec..6a0c83e 100644 --- a/test_actors/actors/basic_test_actor/Cargo.toml +++ b/test_actors/actors/basic_test_actor/Cargo.toml @@ -5,9 +5,9 @@ edition = "2021" publish=false [target.'cfg(target_arch = "wasm32")'.dependencies] -fvm_sdk = { git = "https://github.com/filecoin-project/ref-fvm.git", version = "3.0.0" } -fvm_shared = { git = "https://github.com/filecoin-project/ref-fvm.git", version = "3.1.0" } -fvm_ipld_encoding = { git = "https://github.com/filecoin-project/ref-fvm.git", version = "0.3.3" } +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" } From 1354bbf4598431454a438f30ad31c2d8f9e44293 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Oliveira?= Date: Mon, 3 Apr 2023 16:30:20 +0100 Subject: [PATCH 04/38] cli: rename read_actor and log the reason it failed to read. --- cli/src/search.rs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/cli/src/search.rs b/cli/src/search.rs index e00c605..9151a34 100644 --- a/cli/src/search.rs +++ b/cli/src/search.rs @@ -51,8 +51,8 @@ fn set_abi_extension>(path: P) -> anyhow::Result { .map_err(|_| anyhow!("Failed to convert abi path to string")) } -/// Create a WebAssembly actor from a binary and an Abi. -fn create_actor>(binary_path: P) -> anyhow::Result { +/// Read a WebAssembly actor from a binary and an Abi. +fn read_actor>(binary_path: P) -> anyhow::Result { let abi_path = set_abi_extension(&binary_path)?; let (file_name, bytecode) = read_file_data(binary_path)?; @@ -97,9 +97,12 @@ pub fn search_files>(path: P) -> anyhow::Result> { let mut tests = vec![]; for target_actor_path in target_actor_paths { // Get target actor. - let Ok(target_actor) = create_actor(&target_actor_path) else { - log::error!("Could not get target Actor for binary {target_actor_path}"); - continue; + let target_actor = match read_actor(&target_actor_path) { + Ok(target_actor) => target_actor, + Err(err) => { + log::error!("Could not get target Actor for binary {target_actor_path}: {err}"); + continue; + } }; let mut actor_tests = vec![]; @@ -123,7 +126,7 @@ pub fn search_files>(path: P) -> anyhow::Result> { } if test_path.is_file() { - let Ok(test) = create_actor(test_path) else { + let Ok(test) = read_actor(test_path) else { log::error!("Could not read test file {}", test_path.display()); return false; }; @@ -135,7 +138,7 @@ pub fn search_files>(path: P) -> anyhow::Result> { .filter_map(Result::ok) .filter_map(|tp| tp.into_path().into_os_string().into_string().ok()) .filter(|tp| tp.ends_with(".wasm")) - .filter_map(|tp| match create_actor(&tp) { + .filter_map(|tp| match read_actor(&tp) { Ok(actor_test) => Some(actor_test), Err(err) => { log::error!("Could not read test file {}: {err}", tp); From f3a3ed3f8d84002c2ca03647039a7e4a792f25bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Oliveira?= Date: Tue, 4 Apr 2023 12:26:05 +0100 Subject: [PATCH 05/38] common: separate constructor and set_up functions from the rest of the methods. --- cli/src/search.rs | 63 +++++++++++-------------- common/src/abi/mod.rs | 106 +++++++++++++++++++++++++++++++++++++++--- lib/src/lib.rs | 8 +++- 3 files changed, 134 insertions(+), 43 deletions(-) diff --git a/cli/src/search.rs b/cli/src/search.rs index 9151a34..b6fa6b1 100644 --- a/cli/src/search.rs +++ b/cli/src/search.rs @@ -209,16 +209,14 @@ mod tests { let dir = tempdir().unwrap(); let dir_path = dir.path(); let target_actor_abi = Abi { - methods: vec![ - Method::new_from_name("Constructor").unwrap(), - Method::new_from_name("Transfer").unwrap(), - ], + constructor: Method::new_from_name("Constructor").ok(), + set_up: None, + methods: vec![Method::new_from_name("Transfer").unwrap()], }; let test_actor_abi = Abi { - methods: vec![ - Method::new_from_name("Constructor").unwrap(), - Method::new_from_name("TestTransfer").unwrap(), - ], + constructor: Method::new_from_name("Constructor").ok(), + set_up: None, + methods: vec![Method::new_from_name("TestTransfer").unwrap()], }; // Create target & test actors files. @@ -242,22 +240,19 @@ mod tests { let dir = tempdir().unwrap(); let dir_path = dir.path(); let target_actor_abi = Abi { - methods: vec![ - Method::new_from_name("Constructor").unwrap(), - Method::new_from_name("Transfer").unwrap(), - ], + constructor: Method::new_from_name("Constructor").ok(), + set_up: None, + methods: vec![Method::new_from_name("Transfer").unwrap()], }; let test_1_actor_abi = Abi { - methods: vec![ - Method::new_from_name("Constructor").unwrap(), - Method::new_from_name("TestTransferOne").unwrap(), - ], + constructor: Method::new_from_name("Constructor").ok(), + set_up: None, + methods: vec![Method::new_from_name("TestTransferOne").unwrap()], }; let test_2_actor_abi = Abi { - methods: vec![ - Method::new_from_name("Constructor").unwrap(), - Method::new_from_name("TestTransferTwo").unwrap(), - ], + constructor: Method::new_from_name("Constructor").ok(), + set_up: None, + methods: vec![Method::new_from_name("TestTransferTwo").unwrap()], }; // Create target actor files. @@ -291,28 +286,24 @@ mod tests { let dir_path = dir.path(); let target_actor_abi = Abi { - methods: vec![ - Method::new_from_name("Constructor").unwrap(), - Method::new_from_name("Transfer").unwrap(), - ], + constructor: Method::new_from_name("Constructor").ok(), + set_up: None, + methods: vec![Method::new_from_name("Transfer").unwrap()], }; let test_1_actor_abi = Abi { - methods: vec![ - Method::new_from_name("Constructor").unwrap(), - Method::new_from_name("TestTransferOne").unwrap(), - ], + constructor: Method::new_from_name("Constructor").ok(), + set_up: None, + methods: vec![Method::new_from_name("TestTransferOne").unwrap()], }; let test_2_1_actor_abi = Abi { - methods: vec![ - Method::new_from_name("Constructor").unwrap(), - Method::new_from_name("TestTransferTwoOne").unwrap(), - ], + constructor: Method::new_from_name("Constructor").ok(), + set_up: None, + methods: vec![Method::new_from_name("TestTransferTwoOne").unwrap()], }; let test_2_2_actor_abi = Abi { - methods: vec![ - Method::new_from_name("Constructor").unwrap(), - Method::new_from_name("TestTransferTwoTwo").unwrap(), - ], + constructor: Method::new_from_name("Constructor").ok(), + set_up: None, + methods: vec![Method::new_from_name("TestTransferTwoTwo").unwrap()], }; // Create target actor files. diff --git a/common/src/abi/mod.rs b/common/src/abi/mod.rs index b38d1fc..66a3adc 100644 --- a/common/src/abi/mod.rs +++ b/common/src/abi/mod.rs @@ -3,7 +3,6 @@ use anyhow::Result; use frc42_dispatch::hash::MethodResolver; -use fvm_ipld_encoding::tuple::{Deserialize_tuple, Serialize_tuple}; use serde::de::SeqAccess; use crate::abi::blake2b::Blake2bHasher; @@ -40,21 +39,112 @@ pub fn pascal_case_split(s: &str) -> Vec<&str> { /// `Abi` is the structure we use internally to deal with Actor Binary Interface. It contains all /// exposed [`Method`] from a given Actor. -#[derive(Serialize_tuple, Deserialize_tuple, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)] +#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)] pub struct Abi { + pub constructor: Option, + pub set_up: Option, pub methods: Vec, } +impl Abi { + /// Get the `Constructor` method on the Abi if it exists. + pub fn constructor(&self) -> Option<&Method> { + self.constructor.as_ref() + } + + /// Get the `SetUp` method on the Abi if it exists. + pub fn set_up(&self) -> Option<&Method> { + self.set_up.as_ref() + } + + pub fn methods(&self) -> &[Method] { + &self.methods + } +} + +/// Custom implementation of [`Serialize`] so that we join `Constructor` and `SetUp` +/// into the rest of the methods. +impl serde::Serialize for Abi { + fn serialize(&self, serializer: S) -> std::result::Result + where + S: serde::Serializer, + { + let mut s = vec![]; + if let Some(constructor) = &self.constructor { + s.push(vec![constructor.name()]); + } + if let Some(constructor) = &self.set_up { + s.push(vec![constructor.name()]); + } + let methods = self.methods.iter().map(|m| vec![m.name()]); + s.extend(methods); + + serde::Serialize::serialize(&vec![s], serializer) + } +} + +/// Custom implementation of [`Deserialize`] so that we check for `Constructor` and `SetUp` +/// existence and assert there's only one of each. +impl<'de> serde::Deserialize<'de> for Abi { + fn deserialize(deserializer: D) -> std::result::Result + where + D: serde::Deserializer<'de>, + { + struct AbiVisitor; + + impl<'de> serde::de::Visitor<'de> for AbiVisitor { + type Value = Abi; + + fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result { + formatter.write_str("Abi") + } + + fn visit_seq(self, mut seq: A) -> std::result::Result + where + A: SeqAccess<'de>, + { + let mut constructor = None; + let mut set_up = None; + + let mut methods = vec![]; + let seq_methods = seq + .next_element::>()? + .ok_or_else(|| serde::de::Error::invalid_length(0, &self))?; + + // TODO: Can't we parse each method sequentially instead? and not have to + // iterate again all over here? + for method in seq_methods { + match (constructor.is_some(), set_up.is_some(), &method.r#type()) { + (false, _, MethodType::Constructor) => constructor = Some(method), + (_, false, MethodType::SetUp) => set_up = Some(method), + (true, _, MethodType::Constructor) | (_, true, MethodType::SetUp) => { + return Err(serde::de::Error::custom(format!( + "Abi can only have one Constructor and one SetUp function" + ))) + } + (_, _, _) => methods.push(method), + } + } + + Ok(Abi { + constructor, + set_up, + methods, + }) + } + } + deserializer.deserialize_seq(AbiVisitor) + } +} + /// Method number indicator for calling Actor methods. pub type MethodNum = u64; /// [`Method`] describes an exposed method from an actor entrypoint. -#[derive(Serialize_tuple, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)] +#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)] pub struct Method { - #[serde(skip_serializing)] number: MethodNum, name: String, - #[serde(skip_serializing)] r#type: MethodType, } @@ -109,7 +199,6 @@ impl Method { /// Implement custom deserialization method for [`Method`] as we expect the bytes to be deserialized to only contain /// the `name` and not the `number` property that is generated at deserialization time. -// TODO we could try to simplify our deserialization process in the future. impl<'de> serde::de::Deserialize<'de> for Method { fn deserialize(deserializer: D) -> Result where @@ -211,6 +300,8 @@ mod test { let test_transfer_fail_name = String::from("TestFailTransfer"); let abi = Abi { + constructor: None, + set_up: None, methods: vec![ Method { number: derive_method_num(&test_transfer_name).unwrap(), @@ -224,6 +315,7 @@ mod test { }, ], }; + let serialized_abi: Vec = vec![ 129, 130, 129, 108, 84, 101, 115, 116, 84, 114, 97, 110, 115, 102, 101, 114, 129, 112, 84, 101, 115, 116, 70, 97, 105, 108, 84, 114, 97, 110, 115, 102, 101, 114, @@ -245,6 +337,8 @@ mod test { let test_transfer_fail_name = String::from("testFailTransfer"); let abi = Abi { + constructor: None, + set_up: None, methods: vec![ Method { number: derive_method_num(&test_transfer_name).unwrap(), diff --git a/lib/src/lib.rs b/lib/src/lib.rs index cd68ce7..8007bb0 100644 --- a/lib/src/lib.rs +++ b/lib/src/lib.rs @@ -395,12 +395,18 @@ mod tests { // Set target actor let target_wasm_bin = wat::parse_str(TARGET_WAT).unwrap(); - let target_abi = Abi { methods: vec![] }; + let target_abi = Abi { + constructor: None, + set_up: None, + methods: vec![], + }; let target_actor = WasmActor::new(String::from("Target"), target_wasm_bin, target_abi); // Set test actor let test_wasm_bin: Vec = Vec::from(BASIC_TEST_ACTOR_BINARY); let test_abi = Abi { + constructor: None, + set_up: None, methods: vec![ Method::new_from_name("TestOne").unwrap(), Method::new_from_name("TestTwo").unwrap(), From 4901439070d61274c989c1e1a6c8c3fd8a06e336 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Oliveira?= Date: Tue, 4 Apr 2023 16:15:19 +0100 Subject: [PATCH 06/38] lib: execute Constructor and SetUp first --- lib/src/lib.rs | 59 +++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 51 insertions(+), 8 deletions(-) diff --git a/lib/src/lib.rs b/lib/src/lib.rs index 8007bb0..042f546 100644 --- a/lib/src/lib.rs +++ b/lib/src/lib.rs @@ -23,7 +23,7 @@ use fvm_shared::{ version::NetworkVersion, }; -use error::Error; +use error::{Error, WrapFVMError}; use state_tree::{BuiltInActors, StateTree}; mod error; @@ -189,8 +189,6 @@ impl Tester { test_actors: &'a [WasmActor], stream_results: Option)>>, ) -> Result>, Error> { - // TODO: Should we clone the `StateTree` before each test run, - // and make our `Tester` stateless? let target = self .target_actor .as_ref() @@ -222,9 +220,53 @@ impl Tester { } }; + log::info!("Testing Actor {}", target.name); + let root = self.state_tree.flush(); + let blockstore = self.state_tree.store().clone(); + let mut executor = Self::new_executor(blockstore, root, self.builtin_actors.root); + + // Run the constructor if it exists. + if let Some(constructor) = test_actor.abi().constructor() { + let message = Message { + from: self.account.1, + to: test_address, + gas_limit: 1000000000, + method_num: constructor.number(), + params: target_id.clone().into(), + ..Message::default() + }; + if let Err(err) = executor + .execute_message(message, ApplyKind::Explicit, 100) + .setting_err("Could not run Constructor") + { + return TestActorResults { + test_actor, + results: Err(err), + }; + } + } - log::info!("Testing Actor {}", target.name); + // Run SetUp if it exists. + if let Some(set_up) = test_actor.abi().set_up() { + let message = Message { + from: self.account.1, + to: test_address, + gas_limit: 1000000000, + method_num: set_up.number(), + params: target_id.clone().into(), + ..Message::default() + }; + if let Err(err) = executor + .execute_message(message, ApplyKind::Explicit, 100) + .setting_err("Could not run SetUp") + { + return TestActorResults { + test_actor, + results: Err(err), + }; + } + } // TODO concurrent testing // We'll be able to use thread to do concurrent testing once we set the Engine Pool with more than @@ -239,10 +281,11 @@ impl Tester { .methods .iter() .map(|method| { - let blockstore = self.state_tree.store().clone(); - - let mut executor = - Self::new_executor(blockstore, root, self.builtin_actors.root); + // let mut executor = Self::new_executor( + // blockstore.clone(), + // root, + // self.builtin_actors.root, + // ); let message = Message { from: self.account.1, From a75839f1869720028478ed7058390663c6bf83be Mon Sep 17 00:00:00 2001 From: Thomas Chataigner Date: Wed, 5 Apr 2023 08:26:18 +0200 Subject: [PATCH 07/38] feat(builtins): integrating builtins deployment --- lib/Cargo.toml | 26 +++++++++++++------------- lib/src/state_tree.rs | 34 ++++++++++++++++++++-------------- 2 files changed, 33 insertions(+), 27 deletions(-) diff --git a/lib/Cargo.toml b/lib/Cargo.toml index d0e7f48..f0089f9 100644 --- a/lib/Cargo.toml +++ b/lib/Cargo.toml @@ -7,19 +7,19 @@ edition = "2021" [dependencies] actors-v10 = { package = "fil_builtin_actors_bundle", git = "https://github.com/filecoin-project/builtin-actors", rev = "39571e2" } -fil_actor_account = { git = "https://github.com/filecoin-project/builtin-actors", rev = "39571e2", features = [] } -fil_actor_cron = { git = "https://github.com/filecoin-project/builtin-actors", rev = "39571e2", features = [] } -fil_actor_datacap = { git = "https://github.com/filecoin-project/builtin-actors", rev = "39571e2", features = [] } -fil_actor_init = { git = "https://github.com/filecoin-project/builtin-actors", rev = "39571e2", features = [] } -fil_actor_market = { git = "https://github.com/filecoin-project/builtin-actors", rev = "39571e2", features = [] } -fil_actor_miner = { git = "https://github.com/filecoin-project/builtin-actors", rev = "39571e2", features = [] } -fil_actor_multisig = { git = "https://github.com/filecoin-project/builtin-actors", rev = "39571e2", features = [] } -fil_actor_paych = { git = "https://github.com/filecoin-project/builtin-actors", rev = "39571e2", features = [] } -fil_actor_power = { git = "https://github.com/filecoin-project/builtin-actors", rev = "39571e2", features = [] } -fil_actor_reward = { git = "https://github.com/filecoin-project/builtin-actors", rev = "39571e2", features = [] } -fil_actor_system = { git = "https://github.com/filecoin-project/builtin-actors", rev = "39571e2", features = [] } -fil_actor_verifreg = { git = "https://github.com/filecoin-project/builtin-actors", rev = "39571e2", features = [] } -fil_actors_runtime = { git = "https://github.com/filecoin-project/builtin-actors", rev = "39571e2", features = [] } +fil_actor_account = { git = "https://github.com/filecoin-project/builtin-actors", rev = "39571e2" } +fil_actor_cron = { git = "https://github.com/filecoin-project/builtin-actors", rev = "39571e2" } +fil_actor_datacap = { git = "https://github.com/filecoin-project/builtin-actors", rev = "39571e2" } +fil_actor_init = { git = "https://github.com/filecoin-project/builtin-actors", rev = "39571e2" } +fil_actor_market = { git = "https://github.com/filecoin-project/builtin-actors", rev = "39571e2" } +fil_actor_miner = { git = "https://github.com/filecoin-project/builtin-actors", rev = "39571e2" } +fil_actor_multisig = { git = "https://github.com/filecoin-project/builtin-actors", rev = "39571e2" } +fil_actor_paych = { git = "https://github.com/filecoin-project/builtin-actors", rev = "39571e2" } +fil_actor_power = { git = "https://github.com/filecoin-project/builtin-actors", rev = "39571e2" } +fil_actor_reward = { git = "https://github.com/filecoin-project/builtin-actors", rev = "39571e2" } +fil_actor_system = { git = "https://github.com/filecoin-project/builtin-actors", rev = "39571e2" } +fil_actor_verifreg = { git = "https://github.com/filecoin-project/builtin-actors", rev = "39571e2" } +fil_actors_runtime = { git = "https://github.com/filecoin-project/builtin-actors", rev = "39571e2" } fvm_ipld_blockstore = { version = "0.1.1" } fvm_ipld_car = { version = "0.6.0" } diff --git a/lib/src/state_tree.rs b/lib/src/state_tree.rs index c81986f..d265f19 100644 --- a/lib/src/state_tree.rs +++ b/lib/src/state_tree.rs @@ -12,14 +12,15 @@ use fvm_ipld_blockstore::{Block, Blockstore, MemoryBlockstore}; use fvm_ipld_car::load_car_unchecked; use fvm_ipld_encoding::{serde::Serialize, CborStore}; use fvm_shared::{address::Address, econ::TokenAmount, state::StateTreeVersion, ActorID, IPLD_RAW}; -use kythera_fvm::{ - account_actor, init_actor, machine::Manifest, state_tree::ActorState, system_actor, Account, -}; +use kythera_fvm::{account_actor, init_actor, machine::Manifest, state_tree::ActorState, Account}; use libsecp256k1::{PublicKey, SecretKey}; use rand::SeedableRng; -use fil_actors_runtime::{runtime::builtins::Type, INIT_ACTOR_ID, SYSTEM_ACTOR_ID}; +use fil_actors_runtime::runtime::builtins::Type; +use fil_actors_runtime::{INIT_ACTOR_ID, SYSTEM_ACTOR_ID}; use fvm_shared::bigint::Zero; +use fvm_shared::sector::StoragePower; +use kythera_fvm::system_actor::State; const STATE_TREE_VERSION: StateTreeVersion = StateTreeVersion::V5; @@ -101,38 +102,43 @@ impl StateTree { let manifest = Manifest::load(blockstore, &root, version) .expect("Should be able to load built-in Actor manifest"); - let init_state = init_actor::State::new_test(&blockstore); + // Prepare actor states. + let sys_state = State { + builtin_actors: root, + }; + let init_state = fil_actor_init::State::new(&blockstore, "test".to_string()) + .expect("Should be able to initialize Init Actor state"); + //let init_state = init_actor::State::new_test(&blockstore); + let reward_state = fil_actor_reward::State::new(StoragePower::zero()); + + dbg!(&reward_state); // Set system actor. self.set_actor( "System Actor", - fil_actor_system::State { - builtin_actors: root, - }, + sys_state, *manifest .code_by_id(Type::System as u32) - .expect("Should be able to get system Actor code from manifest"), + .expect("Should be able to get System Actor code from manifest"), SYSTEM_ACTOR_ID, 0, TokenAmount::zero(), ) - .expect("Should be able to set the system Actor"); + .expect("Should be able to set the System Actor"); - // Set init actor + // Set init actor. self.set_actor( "Init Actor", init_state, *manifest .code_by_id(Type::Init as u32) - .expect("Should be able to get init Actor code from manifest"), + .expect("Should be able to get Init Actor code from manifest"), INIT_ACTOR_ID, 0, TokenAmount::zero(), ) .expect("Should be able to set the Init Actor"); - // Set reward actor - BuiltInActors { root: builtin_actors, manifest, From 4e191abb57ab2a2a2cc0d093de9cd6f2d4e1bc41 Mon Sep 17 00:00:00 2001 From: Thomas Chataigner Date: Wed, 5 Apr 2023 10:56:12 +0200 Subject: [PATCH 08/38] feat(builtins): chainsafe builtins dep * Removed dependencies to builtin actors to rely on Chainsafe repo instead as per https://github.com/filecoin-project/builtin-actors/issues/194#issuecomment-1316799088 --- lib/Cargo.toml | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/lib/Cargo.toml b/lib/Cargo.toml index f0089f9..9083628 100644 --- a/lib/Cargo.toml +++ b/lib/Cargo.toml @@ -7,19 +7,20 @@ edition = "2021" [dependencies] actors-v10 = { package = "fil_builtin_actors_bundle", git = "https://github.com/filecoin-project/builtin-actors", rev = "39571e2" } -fil_actor_account = { git = "https://github.com/filecoin-project/builtin-actors", rev = "39571e2" } -fil_actor_cron = { git = "https://github.com/filecoin-project/builtin-actors", rev = "39571e2" } -fil_actor_datacap = { git = "https://github.com/filecoin-project/builtin-actors", rev = "39571e2" } -fil_actor_init = { git = "https://github.com/filecoin-project/builtin-actors", rev = "39571e2" } -fil_actor_market = { git = "https://github.com/filecoin-project/builtin-actors", rev = "39571e2" } -fil_actor_miner = { git = "https://github.com/filecoin-project/builtin-actors", rev = "39571e2" } -fil_actor_multisig = { git = "https://github.com/filecoin-project/builtin-actors", rev = "39571e2" } -fil_actor_paych = { git = "https://github.com/filecoin-project/builtin-actors", rev = "39571e2" } -fil_actor_power = { git = "https://github.com/filecoin-project/builtin-actors", rev = "39571e2" } -fil_actor_reward = { git = "https://github.com/filecoin-project/builtin-actors", rev = "39571e2" } -fil_actor_system = { git = "https://github.com/filecoin-project/builtin-actors", rev = "39571e2" } -fil_actor_verifreg = { git = "https://github.com/filecoin-project/builtin-actors", rev = "39571e2" } -fil_actors_runtime = { git = "https://github.com/filecoin-project/builtin-actors", rev = "39571e2" } +fil_actor_account_v10 = "1.0.0" +fil_actor_cron_v10 = "1.0.0" +fil_actor_datacap_v10 = { git = "https://github.com/ChainSafe/fil-actor-states", branch = "main" } +fil_actor_init_v10 = "1.0.0" +fil_actor_market_v10 = "1.0.0" +fil_actor_miner_v10 = "1.0.0" +fil_actor_multisig_v10 = "1.0.0" +fil_actor_paych_v10 = "1.0.0" +fil_actor_power_v10 = "1.0.0" +fil_actor_reward_v10 = "1.0.0" +fil_actor_system_v10 = { git = "https://github.com/ChainSafe/fil-actor-states", branch = "main" } +fil_actor_verifreg_v10 = { git = "https://github.com/ChainSafe/fil-actor-states", branch = "main" } +fil_actor_ethaccount_v10 = { git = "https://github.com/ChainSafe/fil-actor-states", branch = "main" } +fil_actors_runtime_v10 = "1.0.0" fvm_ipld_blockstore = { version = "0.1.1" } fvm_ipld_car = { version = "0.6.0" } From fa10194f2f078dc2ee9f5f57e4a1a8c4255541fb Mon Sep 17 00:00:00 2001 From: Thomas Chataigner Date: Wed, 5 Apr 2023 10:56:27 +0200 Subject: [PATCH 09/38] feat(builtins): stable channel for rust toolchain --- rust-toolchain.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 4518cf1..f5c1d70 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,4 +1,4 @@ [toolchain] -channel = "nightly-2022-10-03" +channel = "stable" components = ["clippy", "llvm-tools-preview", "rustfmt"] targets = ["wasm32-unknown-unknown"] From ce8334d3bf4d9bf2236c01e47f2169393c8e5850 Mon Sep 17 00:00:00 2001 From: Thomas Chataigner Date: Wed, 5 Apr 2023 12:12:58 +0200 Subject: [PATCH 10/38] feat(builtins): setup all builtins * Setup all necessary builtins in our local development environment --- Cargo.lock | 605 +++++++++++++++++++++++++++++++++++------- lib/src/lib.rs | 3 +- lib/src/state_tree.rs | 222 ++++++++++++++-- 3 files changed, 708 insertions(+), 122 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 753338b..952c222 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -290,9 +290,9 @@ checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" name = "basic_test_actor" version = "0.1.0" dependencies = [ - "fvm_ipld_encoding", - "fvm_sdk", - "fvm_shared", + "fvm_ipld_encoding 0.3.3", + "fvm_sdk 3.0.0", + "fvm_shared 3.1.0", "serde", "thiserror", ] @@ -1254,10 +1254,24 @@ dependencies = [ "anyhow", "fil_actors_runtime", "frc42_dispatch", - "fvm_actor_utils", + "fvm_actor_utils 5.0.0", "fvm_ipld_blockstore", - "fvm_ipld_encoding", - "fvm_shared", + "fvm_ipld_encoding 0.3.3", + "fvm_shared 3.1.0", + "num-derive", + "num-traits", + "serde", +] + +[[package]] +name = "fil_actor_account_v10" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719246afbe4fef6c3a4cf1eacbc40d915aca7d8259b0fe0bda34d9e9e92d0f7d" +dependencies = [ + "frc42_dispatch", + "fvm_ipld_encoding 0.3.3", + "fvm_shared 3.1.0", "num-derive", "num-traits", "serde", @@ -1276,7 +1290,7 @@ dependencies = [ "futures", "fvm_ipld_blockstore", "fvm_ipld_car", - "fvm_ipld_encoding", + "fvm_ipld_encoding 0.3.3", "serde", "serde_ipld_dagcbor", "serde_json", @@ -1289,14 +1303,27 @@ source = "git+https://github.com/filecoin-project/builtin-actors?rev=39571e2#395 dependencies = [ "fil_actors_runtime", "fvm_ipld_blockstore", - "fvm_ipld_encoding", - "fvm_shared", + "fvm_ipld_encoding 0.3.3", + "fvm_shared 3.1.0", "log", "num-derive", "num-traits", "serde", ] +[[package]] +name = "fil_actor_cron_v10" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9dc95d44e5b1b9fe02196c75c7443426f255af398a1f96da888482bf33b2fef4" +dependencies = [ + "fvm_ipld_encoding 0.3.3", + "fvm_shared 3.1.0", + "num-derive", + "num-traits", + "serde", +] + [[package]] name = "fil_actor_datacap" version = "10.0.0" @@ -1305,12 +1332,12 @@ dependencies = [ "cid", "fil_actors_runtime", "frc42_dispatch", - "frc46_token", - "fvm_actor_utils", + "frc46_token 5.0.0", + "fvm_actor_utils 5.0.0", "fvm_ipld_blockstore", - "fvm_ipld_encoding", - "fvm_ipld_hamt", - "fvm_shared", + "fvm_ipld_encoding 0.3.3", + "fvm_ipld_hamt 0.6.1", + "fvm_shared 3.1.0", "lazy_static", "log", "num-derive", @@ -1318,6 +1345,22 @@ dependencies = [ "serde", ] +[[package]] +name = "fil_actor_datacap_v10" +version = "1.0.0" +source = "git+https://github.com/ChainSafe/fil-actor-states?branch=main#1700628fece5ac91cf32b7d61e65a2b9d73d219e" +dependencies = [ + "fil_actors_runtime_v10 1.0.0 (git+https://github.com/ChainSafe/fil-actor-states?branch=main)", + "frc42_dispatch", + "frc46_token 3.1.0", + "fvm_ipld_blockstore", + "fvm_ipld_encoding 0.3.3", + "fvm_shared 3.1.0", + "num-derive", + "num-traits", + "serde", +] + [[package]] name = "fil_actor_eam" version = "10.0.0" @@ -1328,8 +1371,8 @@ dependencies = [ "fil_actors_evm_shared", "fil_actors_runtime", "fvm_ipld_blockstore", - "fvm_ipld_encoding", - "fvm_shared", + "fvm_ipld_encoding 0.3.3", + "fvm_shared 3.1.0", "hex-literal", "log", "multihash", @@ -1347,15 +1390,26 @@ source = "git+https://github.com/filecoin-project/builtin-actors?rev=39571e2#395 dependencies = [ "fil_actors_runtime", "frc42_dispatch", - "fvm_actor_utils", - "fvm_ipld_encoding", - "fvm_shared", + "fvm_actor_utils 5.0.0", + "fvm_ipld_encoding 0.3.3", + "fvm_shared 3.1.0", "hex-literal", "num-derive", "num-traits", "serde", ] +[[package]] +name = "fil_actor_ethaccount_v10" +version = "1.0.0" +source = "git+https://github.com/ChainSafe/fil-actor-states?branch=main#1700628fece5ac91cf32b7d61e65a2b9d73d219e" +dependencies = [ + "fvm_shared 3.1.0", + "num-derive", + "num-traits", + "serde", +] + [[package]] name = "fil_actor_evm" version = "10.0.0" @@ -1367,9 +1421,9 @@ dependencies = [ "fil_actors_runtime", "frc42_dispatch", "fvm_ipld_blockstore", - "fvm_ipld_encoding", + "fvm_ipld_encoding 0.3.3", "fvm_ipld_kamt", - "fvm_shared", + "fvm_shared 3.1.0", "hex", "hex-literal", "log", @@ -1391,15 +1445,32 @@ dependencies = [ "fil_actors_runtime", "frc42_dispatch", "fvm_ipld_blockstore", - "fvm_ipld_encoding", - "fvm_ipld_hamt", - "fvm_shared", + "fvm_ipld_encoding 0.3.3", + "fvm_ipld_hamt 0.6.1", + "fvm_shared 3.1.0", "log", "num-derive", "num-traits", "serde", ] +[[package]] +name = "fil_actor_init_v10" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31cf353d310f37ff152b49ef6eb3a1a734e0e193ed7c44f50c8eae7034d054c1" +dependencies = [ + "cid", + "fil_actors_runtime_v10 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "frc42_dispatch", + "fvm_ipld_blockstore", + "fvm_ipld_encoding 0.3.3", + "fvm_shared 3.1.0", + "num-derive", + "num-traits", + "serde", +] + [[package]] name = "fil_actor_market" version = "10.0.0" @@ -1409,12 +1480,12 @@ dependencies = [ "cid", "fil_actors_runtime", "frc42_dispatch", - "frc46_token", + "frc46_token 5.0.0", "fvm_ipld_bitfield", "fvm_ipld_blockstore", - "fvm_ipld_encoding", - "fvm_ipld_hamt", - "fvm_shared", + "fvm_ipld_encoding 0.3.3", + "fvm_ipld_hamt 0.6.1", + "fvm_shared 3.1.0", "integer-encoding", "libipld-core 0.13.1", "log", @@ -1423,6 +1494,25 @@ dependencies = [ "serde", ] +[[package]] +name = "fil_actor_market_v10" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e023cdd8b8e0d39bdbbe3629dc761f2295bba792c7e57c8bf0ff356d88e4ab60" +dependencies = [ + "cid", + "fil_actors_runtime_v10 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "frc42_dispatch", + "fvm_ipld_blockstore", + "fvm_ipld_encoding 0.3.3", + "fvm_ipld_hamt 0.6.1", + "fvm_shared 3.1.0", + "libipld-core 0.14.0", + "num-derive", + "num-traits", + "serde", +] + [[package]] name = "fil_actor_miner" version = "10.0.0" @@ -1433,12 +1523,12 @@ dependencies = [ "cid", "fil_actors_runtime", "frc42_dispatch", - "fvm_ipld_amt", + "fvm_ipld_amt 0.5.1", "fvm_ipld_bitfield", "fvm_ipld_blockstore", - "fvm_ipld_encoding", - "fvm_ipld_hamt", - "fvm_shared", + "fvm_ipld_encoding 0.3.3", + "fvm_ipld_hamt 0.6.1", + "fvm_shared 3.1.0", "itertools 0.10.5", "lazy_static", "log", @@ -1448,6 +1538,30 @@ dependencies = [ "serde", ] +[[package]] +name = "fil_actor_miner_v10" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "888cfc1da1e748656ed9dfe8cf19e0e434d1d4050e2caa64f12a4d3ec4c9a58f" +dependencies = [ + "anyhow", + "cid", + "fil_actors_runtime_v10 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "frc42_dispatch", + "fvm_ipld_amt 0.5.1", + "fvm_ipld_bitfield", + "fvm_ipld_blockstore", + "fvm_ipld_encoding 0.3.3", + "fvm_ipld_hamt 0.6.1", + "fvm_shared 3.1.0", + "itertools 0.10.5", + "lazy_static", + "multihash", + "num-derive", + "num-traits", + "serde", +] + [[package]] name = "fil_actor_multisig" version = "10.0.0" @@ -1457,11 +1571,31 @@ dependencies = [ "cid", "fil_actors_runtime", "frc42_dispatch", - "fvm_actor_utils", + "fvm_actor_utils 5.0.0", "fvm_ipld_blockstore", - "fvm_ipld_encoding", - "fvm_ipld_hamt", - "fvm_shared", + "fvm_ipld_encoding 0.3.3", + "fvm_ipld_hamt 0.6.1", + "fvm_shared 3.1.0", + "indexmap", + "integer-encoding", + "num-derive", + "num-traits", + "serde", +] + +[[package]] +name = "fil_actor_multisig_v10" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5033cb154bc1fa54f5849d8d56553ba3bb777a6cb65ed360aed64bb064deade" +dependencies = [ + "cid", + "fil_actors_runtime_v10 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "frc42_dispatch", + "fvm_ipld_blockstore", + "fvm_ipld_encoding 0.3.3", + "fvm_ipld_hamt 0.6.1", + "fvm_shared 3.1.0", "indexmap", "integer-encoding", "num-derive", @@ -1479,8 +1613,23 @@ dependencies = [ "fil_actors_runtime", "frc42_dispatch", "fvm_ipld_blockstore", - "fvm_ipld_encoding", - "fvm_shared", + "fvm_ipld_encoding 0.3.3", + "fvm_shared 3.1.0", + "num-derive", + "num-traits", + "serde", +] + +[[package]] +name = "fil_actor_paych_v10" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b63acc144f0bb4df7006992e7e2e977fdc8171ae012697aadf5500e3b33c665" +dependencies = [ + "cid", + "frc42_dispatch", + "fvm_ipld_encoding 0.3.3", + "fvm_shared 3.1.0", "num-derive", "num-traits", "serde", @@ -1501,9 +1650,9 @@ dependencies = [ "fil_actors_runtime", "frc42_dispatch", "fvm_ipld_blockstore", - "fvm_ipld_encoding", - "fvm_ipld_hamt", - "fvm_shared", + "fvm_ipld_encoding 0.3.3", + "fvm_ipld_hamt 0.6.1", + "fvm_shared 3.1.0", "indexmap", "integer-encoding", "lazy_static", @@ -1513,6 +1662,27 @@ dependencies = [ "serde", ] +[[package]] +name = "fil_actor_power_v10" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5956a2e9ce0e16d046dab721d77cd8877de8571dd2c14394bf57f62b835bdba1" +dependencies = [ + "anyhow", + "cid", + "fil_actors_runtime_v10 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "frc42_dispatch", + "fvm_ipld_blockstore", + "fvm_ipld_encoding 0.3.3", + "fvm_ipld_hamt 0.6.1", + "fvm_shared 3.1.0", + "integer-encoding", + "lazy_static", + "num-derive", + "num-traits", + "serde", +] + [[package]] name = "fil_actor_reward" version = "10.0.0" @@ -1520,8 +1690,8 @@ source = "git+https://github.com/filecoin-project/builtin-actors?rev=39571e2#395 dependencies = [ "fil_actors_runtime", "fvm_ipld_blockstore", - "fvm_ipld_encoding", - "fvm_shared", + "fvm_ipld_encoding 0.3.3", + "fvm_shared 3.1.0", "lazy_static", "log", "num-derive", @@ -1529,6 +1699,20 @@ dependencies = [ "serde", ] +[[package]] +name = "fil_actor_reward_v10" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1db1f0dc4b3fe017179ff3e645aeaf8cf0ec2457bc67a89e7505802b87946ae" +dependencies = [ + "fvm_ipld_encoding 0.3.3", + "fvm_shared 3.1.0", + "lazy_static", + "num-derive", + "num-traits", + "serde", +] + [[package]] name = "fil_actor_system" version = "10.0.0" @@ -1538,8 +1722,21 @@ dependencies = [ "cid", "fil_actors_runtime", "fvm_ipld_blockstore", - "fvm_ipld_encoding", - "fvm_shared", + "fvm_ipld_encoding 0.3.3", + "fvm_shared 3.1.0", + "num-derive", + "num-traits", + "serde", +] + +[[package]] +name = "fil_actor_system_v10" +version = "1.0.0" +source = "git+https://github.com/ChainSafe/fil-actor-states?branch=main#1700628fece5ac91cf32b7d61e65a2b9d73d219e" +dependencies = [ + "cid", + "fvm_ipld_encoding 0.3.3", + "fvm_shared 2.3.0", "num-derive", "num-traits", "serde", @@ -1554,12 +1751,12 @@ dependencies = [ "cid", "fil_actors_runtime", "frc42_dispatch", - "frc46_token", - "fvm_actor_utils", + "frc46_token 5.0.0", + "fvm_actor_utils 5.0.0", "fvm_ipld_blockstore", - "fvm_ipld_encoding", - "fvm_ipld_hamt", - "fvm_shared", + "fvm_ipld_encoding 0.3.3", + "fvm_ipld_hamt 0.6.1", + "fvm_shared 3.1.0", "lazy_static", "log", "num-derive", @@ -1567,14 +1764,30 @@ dependencies = [ "serde", ] +[[package]] +name = "fil_actor_verifreg_v10" +version = "1.0.0" +source = "git+https://github.com/ChainSafe/fil-actor-states?branch=main#1700628fece5ac91cf32b7d61e65a2b9d73d219e" +dependencies = [ + "cid", + "fil_actors_runtime_v10 1.0.0 (git+https://github.com/ChainSafe/fil-actor-states?branch=main)", + "frc42_dispatch", + "fvm_ipld_blockstore", + "fvm_ipld_encoding 0.3.3", + "fvm_shared 3.1.0", + "num-derive", + "num-traits", + "serde", +] + [[package]] name = "fil_actors_evm_shared" version = "10.0.0" source = "git+https://github.com/filecoin-project/builtin-actors?rev=39571e2#39571e25eacd51326c9fc8e29d4b69943f15a3b1" dependencies = [ "fil_actors_runtime", - "fvm_ipld_encoding", - "fvm_shared", + "fvm_ipld_encoding 0.3.3", + "fvm_shared 3.1.0", "hex", "serde", "uint", @@ -1589,13 +1802,13 @@ dependencies = [ "byteorder", "castaway", "cid", - "fvm_ipld_amt", + "fvm_ipld_amt 0.5.1", "fvm_ipld_bitfield", "fvm_ipld_blockstore", - "fvm_ipld_encoding", - "fvm_ipld_hamt", - "fvm_sdk", - "fvm_shared", + "fvm_ipld_encoding 0.3.3", + "fvm_ipld_hamt 0.6.1", + "fvm_sdk 3.0.0", + "fvm_shared 3.1.0", "itertools 0.10.5", "log", "multihash", @@ -1611,6 +1824,55 @@ dependencies = [ "unsigned-varint", ] +[[package]] +name = "fil_actors_runtime_v10" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf58b5d04fe320d9fe29c6cb5911b4115aad9e72ee9afefa88442d1b21189989" +dependencies = [ + "anyhow", + "cid", + "fvm_ipld_amt 0.5.1", + "fvm_ipld_blockstore", + "fvm_ipld_encoding 0.3.3", + "fvm_ipld_hamt 0.6.1", + "fvm_shared 3.1.0", + "multihash", + "num-bigint", + "num-derive", + "num-traits", + "paste", + "serde", + "serde_repr", + "sha2 0.10.6", + "thiserror", + "unsigned-varint", +] + +[[package]] +name = "fil_actors_runtime_v10" +version = "1.0.0" +source = "git+https://github.com/ChainSafe/fil-actor-states?branch=main#1700628fece5ac91cf32b7d61e65a2b9d73d219e" +dependencies = [ + "anyhow", + "cid", + "fvm_ipld_amt 0.5.1", + "fvm_ipld_blockstore", + "fvm_ipld_encoding 0.3.3", + "fvm_ipld_hamt 0.6.1", + "fvm_shared 3.1.0", + "multihash", + "num-bigint", + "num-derive", + "num-traits", + "paste", + "serde", + "serde_repr", + "sha2 0.10.6", + "thiserror", + "unsigned-varint", +] + [[package]] name = "fil_builtin_actors_bundle" version = "10.0.0" @@ -1780,9 +2042,9 @@ checksum = "a4dc594c941eba1d5a9474f595c6d0f9d752fa333b672755bbe7c23d30f64282" dependencies = [ "frc42_hasher", "frc42_macros", - "fvm_ipld_encoding", - "fvm_sdk", - "fvm_shared", + "fvm_ipld_encoding 0.3.3", + "fvm_sdk 3.0.0", + "fvm_shared 3.1.0", "thiserror", ] @@ -1792,8 +2054,8 @@ version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d6caf7fa3028536d11b1ff94a63bd1d60926ff7366b25b2a94d07bd23190f459" dependencies = [ - "fvm_sdk", - "fvm_shared", + "fvm_sdk 3.0.0", + "fvm_shared 3.1.0", "thiserror", ] @@ -1810,6 +2072,29 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "frc46_token" +version = "3.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "112bdb7d37e58715087146b19465f59374e8cffd81561a8d20dbdb1eb2c75fbe" +dependencies = [ + "anyhow", + "cid", + "frc42_dispatch", + "fvm_actor_utils 3.0.0", + "fvm_ipld_amt 0.4.2", + "fvm_ipld_blockstore", + "fvm_ipld_encoding 0.2.3", + "fvm_ipld_hamt 0.5.1", + "fvm_sdk 2.2.0", + "fvm_shared 2.3.0", + "integer-encoding", + "num-traits", + "serde", + "serde_tuple", + "thiserror", +] + [[package]] name = "frc46_token" version = "5.0.0" @@ -1819,13 +2104,13 @@ dependencies = [ "anyhow", "cid", "frc42_dispatch", - "fvm_actor_utils", - "fvm_ipld_amt", + "fvm_actor_utils 5.0.0", + "fvm_ipld_amt 0.5.1", "fvm_ipld_blockstore", - "fvm_ipld_encoding", - "fvm_ipld_hamt", - "fvm_sdk", - "fvm_shared", + "fvm_ipld_encoding 0.3.3", + "fvm_ipld_hamt 0.6.1", + "fvm_sdk 3.0.0", + "fvm_shared 3.1.0", "integer-encoding", "num-traits", "serde", @@ -1968,11 +2253,11 @@ dependencies = [ "derive_more", "filecoin-proofs-api", "fvm-wasm-instrument", - "fvm_ipld_amt", + "fvm_ipld_amt 0.5.1", "fvm_ipld_blockstore", - "fvm_ipld_encoding", - "fvm_ipld_hamt", - "fvm_shared", + "fvm_ipld_encoding 0.3.3", + "fvm_ipld_hamt 0.6.1", + "fvm_shared 3.1.0", "lazy_static", "log", "minstant", @@ -2006,6 +2291,25 @@ dependencies = [ "wasmprinter", ] +[[package]] +name = "fvm_actor_utils" +version = "3.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a11cab1852eb6f381cc11ebcfa6b2c84d3df5b5603ab6c79d6b02761718da77" +dependencies = [ + "anyhow", + "cid", + "frc42_dispatch", + "fvm_ipld_blockstore", + "fvm_ipld_encoding 0.2.3", + "fvm_sdk 2.2.0", + "fvm_shared 2.3.0", + "num-traits", + "serde", + "serde_tuple", + "thiserror", +] + [[package]] name = "fvm_actor_utils" version = "5.0.0" @@ -2016,15 +2320,32 @@ dependencies = [ "cid", "frc42_dispatch", "fvm_ipld_blockstore", - "fvm_ipld_encoding", - "fvm_sdk", - "fvm_shared", + "fvm_ipld_encoding 0.3.3", + "fvm_sdk 3.0.0", + "fvm_shared 3.1.0", "num-traits", "serde", "serde_tuple", "thiserror", ] +[[package]] +name = "fvm_ipld_amt" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48d09e5aa7de45452676d18fcb70b750acd65faae7a4fe18fe784b4c85f869fb" +dependencies = [ + "ahash", + "anyhow", + "cid", + "fvm_ipld_blockstore", + "fvm_ipld_encoding 0.2.3", + "itertools 0.10.5", + "once_cell", + "serde", + "thiserror", +] + [[package]] name = "fvm_ipld_amt" version = "0.5.1" @@ -2034,7 +2355,7 @@ dependencies = [ "anyhow", "cid", "fvm_ipld_blockstore", - "fvm_ipld_encoding", + "fvm_ipld_encoding 0.3.3", "itertools 0.10.5", "once_cell", "serde", @@ -2047,7 +2368,7 @@ version = "0.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d1950291f40d2d1047eb0a4568f7ef6d5b4973452dcef012dffb1957fe483ff7" dependencies = [ - "fvm_ipld_encoding", + "fvm_ipld_encoding 0.3.3", "serde", "thiserror", "unsigned-varint", @@ -2073,12 +2394,30 @@ dependencies = [ "cid", "futures", "fvm_ipld_blockstore", - "fvm_ipld_encoding", + "fvm_ipld_encoding 0.3.3", "integer-encoding", "serde", "thiserror", ] +[[package]] +name = "fvm_ipld_encoding" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa1ff5ba581625ab38cf2829fbd04ac232c6277466fdbe0270b42dcb976902d5" +dependencies = [ + "anyhow", + "cid", + "cs_serde_bytes", + "fvm_ipld_blockstore", + "multihash", + "serde", + "serde_ipld_dagcbor", + "serde_repr", + "serde_tuple", + "thiserror", +] + [[package]] name = "fvm_ipld_encoding" version = "0.3.3" @@ -2096,6 +2435,27 @@ dependencies = [ "thiserror", ] +[[package]] +name = "fvm_ipld_hamt" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "65b5c939897aa1bfd63e7cb9c458ba10689371af3278ff20d66c6f8ca152c6c0" +dependencies = [ + "anyhow", + "byteorder", + "cid", + "cs_serde_bytes", + "forest_hash_utils", + "fvm_ipld_blockstore", + "fvm_ipld_encoding 0.2.3", + "libipld-core 0.13.1", + "multihash", + "once_cell", + "serde", + "sha2 0.10.6", + "thiserror", +] + [[package]] name = "fvm_ipld_hamt" version = "0.6.1" @@ -2107,7 +2467,7 @@ dependencies = [ "cid", "forest_hash_utils", "fvm_ipld_blockstore", - "fvm_ipld_encoding", + "fvm_ipld_encoding 0.3.3", "libipld-core 0.14.0", "multihash", "once_cell", @@ -2127,7 +2487,7 @@ dependencies = [ "cid", "forest_hash_utils", "fvm_ipld_blockstore", - "fvm_ipld_encoding", + "fvm_ipld_encoding 0.3.3", "multihash", "once_cell", "serde", @@ -2135,6 +2495,21 @@ dependencies = [ "thiserror", ] +[[package]] +name = "fvm_sdk" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb46d7b26e1609de1a3b7470cbd190d78f2d01fdf1b317f741bdd3ac8f59825e" +dependencies = [ + "cid", + "fvm_ipld_encoding 0.2.3", + "fvm_shared 2.3.0", + "lazy_static", + "log", + "num-traits", + "thiserror", +] + [[package]] name = "fvm_sdk" version = "3.0.0" @@ -2142,14 +2517,43 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2fef17308967cceb1d22f05003d60adb0d5b9ba53e34ace4ae04701eb7e6af02" dependencies = [ "cid", - "fvm_ipld_encoding", - "fvm_shared", + "fvm_ipld_encoding 0.3.3", + "fvm_shared 3.1.0", "lazy_static", "log", "num-traits", "thiserror", ] +[[package]] +name = "fvm_shared" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "518880fbf3facd8ba26298e27d0aa7c43459d14a2511d22d2a3f39abf3b73f6a" +dependencies = [ + "anyhow", + "blake2b_simd", + "byteorder", + "cid", + "cs_serde_bytes", + "data-encoding", + "data-encoding-macro", + "fvm_ipld_blockstore", + "fvm_ipld_encoding 0.2.3", + "lazy_static", + "log", + "multihash", + "num-bigint", + "num-derive", + "num-integer", + "num-traits", + "serde", + "serde_repr", + "serde_tuple", + "thiserror", + "unsigned-varint", +] + [[package]] name = "fvm_shared" version = "3.1.0" @@ -2166,7 +2570,7 @@ dependencies = [ "data-encoding-macro", "filecoin-proofs-api", "fvm_ipld_blockstore", - "fvm_ipld_encoding", + "fvm_ipld_encoding 0.3.3", "lazy_static", "libsecp256k1", "log", @@ -2501,8 +2905,8 @@ dependencies = [ "anyhow", "cid", "fvm", - "fvm_ipld_encoding", - "fvm_shared", + "fvm_ipld_encoding 0.3.3", + "fvm_shared 3.1.0", "multihash", ] @@ -2511,25 +2915,26 @@ name = "kythera-lib" version = "0.1.0" dependencies = [ "cid", - "fil_actor_account", - "fil_actor_cron", - "fil_actor_datacap", - "fil_actor_init", - "fil_actor_market", - "fil_actor_miner", - "fil_actor_multisig", - "fil_actor_paych", - "fil_actor_power", - "fil_actor_reward", - "fil_actor_system", - "fil_actor_verifreg", - "fil_actors_runtime", + "fil_actor_account_v10", + "fil_actor_cron_v10", + "fil_actor_datacap_v10", + "fil_actor_ethaccount_v10", + "fil_actor_init_v10", + "fil_actor_market_v10", + "fil_actor_miner_v10", + "fil_actor_multisig_v10", + "fil_actor_paych_v10", + "fil_actor_power_v10", + "fil_actor_reward_v10", + "fil_actor_system_v10", + "fil_actor_verifreg_v10", + "fil_actors_runtime_v10 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "fil_builtin_actors_bundle", "futures", "fvm_ipld_blockstore", "fvm_ipld_car", - "fvm_ipld_encoding", - "fvm_shared", + "fvm_ipld_encoding 0.3.3", + "fvm_shared 3.1.0", "kythera-common", "kythera-fvm", "kythera_test_actors", diff --git a/lib/src/lib.rs b/lib/src/lib.rs index f081bcd..c8e7460 100644 --- a/lib/src/lib.rs +++ b/lib/src/lib.rs @@ -375,7 +375,8 @@ mod tests { .has(&*builtins_actors.manifest.get_eam_code()) .unwrap()); - assert_eq!(tester.account.0, 100); + // Expect actor Id to be 102 as we deployed verified registry signer & multisig previously + assert_eq!(tester.account.0, 102); assert!(tester.target_actor.is_none()); } diff --git a/lib/src/state_tree.rs b/lib/src/state_tree.rs index d265f19..2ea5ad1 100644 --- a/lib/src/state_tree.rs +++ b/lib/src/state_tree.rs @@ -11,16 +11,22 @@ use futures::executor::block_on; use fvm_ipld_blockstore::{Block, Blockstore, MemoryBlockstore}; use fvm_ipld_car::load_car_unchecked; use fvm_ipld_encoding::{serde::Serialize, CborStore}; -use fvm_shared::{address::Address, econ::TokenAmount, state::StateTreeVersion, ActorID, IPLD_RAW}; -use kythera_fvm::{account_actor, init_actor, machine::Manifest, state_tree::ActorState, Account}; +use fvm_shared::{ + address::Address, econ::TokenAmount, state::StateTreeVersion, ActorID, HAMT_BIT_WIDTH, IPLD_RAW, +}; +use kythera_fvm::{account_actor, machine::Manifest, state_tree::ActorState, Account}; use libsecp256k1::{PublicKey, SecretKey}; use rand::SeedableRng; -use fil_actors_runtime::runtime::builtins::Type; -use fil_actors_runtime::{INIT_ACTOR_ID, SYSTEM_ACTOR_ID}; +use fil_actors_runtime_v10::runtime::builtins::Type; +use fil_actors_runtime_v10::{ + make_empty_map, BURNT_FUNDS_ACTOR_ADDR, BURNT_FUNDS_ACTOR_ID, CRON_ACTOR_ID, + DATACAP_TOKEN_ACTOR_ID, INIT_ACTOR_ID, REWARD_ACTOR_ID, STORAGE_MARKET_ACTOR_ADDR, + STORAGE_MARKET_ACTOR_ID, STORAGE_POWER_ACTOR_ADDR, STORAGE_POWER_ACTOR_ID, SYSTEM_ACTOR_ID, + VERIFIED_REGISTRY_ACTOR_ADDR, VERIFIED_REGISTRY_ACTOR_ID, +}; use fvm_shared::bigint::Zero; use fvm_shared::sector::StoragePower; -use kythera_fvm::system_actor::State; const STATE_TREE_VERSION: StateTreeVersion = StateTreeVersion::V5; @@ -88,32 +94,26 @@ impl StateTree { /// Load the built-in actors into the `Blockstore`. /// And activate them on the `StateTree`. pub fn load_builtin_actors(&mut self) -> BuiltInActors { - let blockstore = self.inner.store(); // Load the built-in Actors - let builtin_actors = - block_on(async { load_car_unchecked(blockstore, actors_v10::BUNDLE_CAR).await }) - .expect("Should be able to import built-in Actors")[0]; + let builtin_actors = block_on(async { + load_car_unchecked(self.inner.store(), actors_v10::BUNDLE_CAR).await + }) + .expect("Should be able to import built-in Actors")[0]; - let (version, root) = blockstore + let (version, root) = self + .inner + .store() .get_cbor::<(u32, Cid)>(&builtin_actors) .expect("Should be able to decode the built-in Actor CBOR") .expect("There should be manifest information for built-in Actor Cid"); - let manifest = Manifest::load(blockstore, &root, version) + let manifest = Manifest::load(self.inner.store(), &root, version) .expect("Should be able to load built-in Actor manifest"); - // Prepare actor states. - let sys_state = State { + // Set system actor. + let sys_state = fil_actor_system_v10::State { builtin_actors: root, }; - let init_state = fil_actor_init::State::new(&blockstore, "test".to_string()) - .expect("Should be able to initialize Init Actor state"); - //let init_state = init_actor::State::new_test(&blockstore); - let reward_state = fil_actor_reward::State::new(StoragePower::zero()); - - dbg!(&reward_state); - - // Set system actor. self.set_actor( "System Actor", sys_state, @@ -127,6 +127,8 @@ impl StateTree { .expect("Should be able to set the System Actor"); // Set init actor. + let init_state = fil_actor_init_v10::State::new(self.inner.store(), "test".to_string()) + .expect("Should be able to initialize Init Actor state"); self.set_actor( "Init Actor", init_state, @@ -139,6 +141,184 @@ impl StateTree { ) .expect("Should be able to set the Init Actor"); + // Set reward actor. + let reward_state = fil_actor_reward_v10::State::new(StoragePower::zero()); + self.set_actor( + "Reward Actor", + reward_state, + *manifest + .code_by_id(Type::Reward as u32) + .expect("Should be able to get Reward Actor code from manifest"), + REWARD_ACTOR_ID, + 0, + TokenAmount::from_whole(1_100_000_000), + ) + .expect("Should be able to set the Reward Actor"); + + // Set cron actor. + let cron_state = fil_actor_cron_v10::State { + entries: vec![ + fil_actor_cron_v10::Entry { + receiver: STORAGE_POWER_ACTOR_ADDR, + method_num: fil_actor_power_v10::Method::OnEpochTickEnd as u64, + }, + fil_actor_cron_v10::Entry { + receiver: STORAGE_MARKET_ACTOR_ADDR, + method_num: fil_actor_market_v10::Method::CronTick as u64, + }, + ], + }; + self.set_actor( + "Cron Actor", + cron_state, + *manifest + .code_by_id(Type::Cron as u32) + .expect("Should be able to get Cron Actor code from manifest"), + CRON_ACTOR_ID, + 0, + TokenAmount::zero(), + ) + .expect("Should be able to set the Cron Actor"); + + // Set power actor. + let power_state = fil_actor_power_v10::State::new(self.inner.store()) + .expect("Should be able to initialize Power Actor state"); + self.set_actor( + "Storage Power Actor", + power_state, + *manifest + .code_by_id(Type::Power as u32) + .expect("Should be able to get Storage Power Actor code from manifest"), + STORAGE_POWER_ACTOR_ID, + 0, + TokenAmount::zero(), + ) + .expect("Should be able to set the Storage Power Actor"); + + // Set market actor. + let market_state = fil_actor_market_v10::State::new(self.inner.store()) + .expect("Should be able to initialize Market Actor state"); + self.set_actor( + "Storage Market Actor", + market_state, + *manifest + .code_by_id(Type::Market as u32) + .expect("Should be able to get Storage Market Actor code from manifest"), + STORAGE_MARKET_ACTOR_ID, + 0, + TokenAmount::zero(), + ) + .expect("Should be able to set the Storage Market Actor"); + + // Deploy multisig and a signer to act as verified registry root. + // Initialize signer address. + let verified_reg_signer_address = + Address::new_bls(&[200; fvm_shared::address::BLS_PUB_LEN]) + .expect("Should be able to generate verified registry multisig signer address"); + let verified_reg_signer_id = self + .inner + .register_new_address(&verified_reg_signer_address) + .expect("Should be able to register verified registry multisig signer address"); + // Initialize signer state. + let verified_reg_signer_state = fil_actor_account_v10::State { + address: verified_reg_signer_address, + }; + dbg!(verified_reg_signer_id); + // Set signer actor. + self.set_actor( + "Verified Registry Signer", + verified_reg_signer_state, + *manifest + .code_by_id(Type::Account as u32) + .expect("Should be able to get Account Actor code from manifest"), + verified_reg_signer_id, + 0, + TokenAmount::zero(), + ) + .expect("Should be able to set the Verified Registry Signer"); + + // Initialize verified registry root address. + let empty_root = make_empty_map::<_, ()>(self.inner.store(), HAMT_BIT_WIDTH) + .flush() + .expect("Should be able to generate an empty root CID"); + let verified_reg_root_address = Address::new_actor(b"VerifiedRegistryRoot"); + let verified_reg_root_id = self + .inner + .register_new_address(&verified_reg_root_address) + .expect("Should be able to register verified registry multisig root address"); + // Initialize verified registry root state. + let verified_reg_root_state = fil_actor_multisig_v10::State { + signers: vec![Address::new_id(verified_reg_signer_id)], + num_approvals_threshold: 1, + next_tx_id: Default::default(), + initial_balance: Default::default(), + start_epoch: 0, + unlock_duration: 0, + pending_txs: empty_root, + }; + // Set verified registry root. + self.set_actor( + "Verified Registry Root", + verified_reg_root_state, + *manifest + .code_by_id(Type::Multisig as u32) + .expect("Should be able to get Multisig Actor code from manifest"), + verified_reg_root_id, + 0, + TokenAmount::zero(), + ) + .expect("Should be able to set the Verified Registry Root"); + + // Set verified registry itself. + let verified_reg_state = fil_actor_verifreg_v10::State::new( + self.inner.store(), + Address::new_id(verified_reg_root_id), + ) + .expect("Should be able to initialize Verified Registry Actor state"); + self.set_actor( + "Verified Registry Actor", + verified_reg_state, + *manifest + .code_by_id(Type::VerifiedRegistry as u32) + .expect("Should be able to get Verified Registry Actor code from manifest"), + VERIFIED_REGISTRY_ACTOR_ID, + 0, + TokenAmount::zero(), + ) + .expect("Should be able to set the Verified Registry Actor"); + + // Set datacap actor. + let datacap_state = + fil_actor_datacap_v10::State::new(self.inner.store(), VERIFIED_REGISTRY_ACTOR_ADDR) + .expect("Should be able to initialize Datacap Actor state"); + self.set_actor( + "Datacap Actor", + datacap_state, + *manifest + .code_by_id(Type::DataCap as u32) + .expect("Should be able to get Datacap Actor code from manifest"), + DATACAP_TOKEN_ACTOR_ID, + 0, + TokenAmount::zero(), + ) + .expect("Should be able to set the Datacap Actor"); + + // Set burnt funds actor. + let burnt_state = fil_actor_account_v10::State { + address: BURNT_FUNDS_ACTOR_ADDR, + }; + self.set_actor( + "Burnt Funds Actor", + burnt_state, + *manifest + .code_by_id(Type::DataCap as u32) + .expect("Should be able to get Burnt Funds Actor code from manifest"), + BURNT_FUNDS_ACTOR_ID, + 0, + TokenAmount::zero(), + ) + .expect("Should be able to set the Burnt Funds Actor"); + BuiltInActors { root: builtin_actors, manifest, From e46769ccdae1812e8758f763e61f5e625082fac5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Oliveira?= Date: Wed, 5 Apr 2023 12:22:13 +0100 Subject: [PATCH 11/38] lib: address Thomas review --- common/src/abi/mod.rs | 6 +++--- fvm/src/lib.rs | 4 +--- lib/src/lib.rs | 23 +++++++++++++++++------ 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/common/src/abi/mod.rs b/common/src/abi/mod.rs index 66a3adc..3f97fc0 100644 --- a/common/src/abi/mod.rs +++ b/common/src/abi/mod.rs @@ -118,9 +118,9 @@ impl<'de> serde::Deserialize<'de> for Abi { (false, _, MethodType::Constructor) => constructor = Some(method), (_, false, MethodType::SetUp) => set_up = Some(method), (true, _, MethodType::Constructor) | (_, true, MethodType::SetUp) => { - return Err(serde::de::Error::custom(format!( - "Abi can only have one Constructor and one SetUp function" - ))) + return Err(serde::de::Error::custom( + "Abi can only have one Constructor and one SetUp function", + )) } (_, _, _) => methods.push(method), } diff --git a/fvm/src/lib.rs b/fvm/src/lib.rs index 4fec99f..c72de45 100644 --- a/fvm/src/lib.rs +++ b/fvm/src/lib.rs @@ -22,9 +22,7 @@ pub mod executor { } pub mod machine { - pub use fvm::machine::DefaultMachine as KytheraMachine; - pub use fvm::machine::Manifest; - pub use fvm::machine::NetworkConfig; + pub use fvm::machine::{DefaultMachine as KytheraMachine, Machine, Manifest, NetworkConfig}; } pub mod state_tree { diff --git a/lib/src/lib.rs b/lib/src/lib.rs index 042f546..7204ed6 100644 --- a/lib/src/lib.rs +++ b/lib/src/lib.rs @@ -13,7 +13,7 @@ use kythera_fvm::{ engine::EnginePool, executor::{ApplyKind, ApplyRet, Executor, KytheraExecutor}, externs::FakeExterns, - machine::{KytheraMachine, NetworkConfig}, + machine::{KytheraMachine, Machine, NetworkConfig}, Account, }; @@ -255,6 +255,7 @@ impl Tester { gas_limit: 1000000000, method_num: set_up.number(), params: target_id.clone().into(), + sequence: 1, ..Message::default() }; if let Err(err) = executor @@ -268,6 +269,16 @@ impl Tester { } } + let root = executor + .flush() + .expect("Should be able to flush the executor"); + + let blockstore = executor + .into_machine() + .expect("Machine should exist at this point") + .into_store() + .into_inner(); + // TODO concurrent testing // We'll be able to use thread to do concurrent testing once we set the Engine Pool with more than // one possible concurrent engine. @@ -281,11 +292,11 @@ impl Tester { .methods .iter() .map(|method| { - // let mut executor = Self::new_executor( - // blockstore.clone(), - // root, - // self.builtin_actors.root, - // ); + let mut executor = Self::new_executor( + blockstore.clone(), + root, + self.builtin_actors.root, + ); let message = Message { from: self.account.1, From 5f0f338be95dc699e0a11a8a15af13c66e8a5b03 Mon Sep 17 00:00:00 2001 From: Thomas Chataigner Date: Wed, 5 Apr 2023 13:23:53 +0200 Subject: [PATCH 12/38] feat(builtins): builtins tests * Adding actor to test builtins deployment in Kythera --- Cargo.lock | 12 +++++ lib/tests/lib.rs | 6 +++ .../actors/basic_test_actor/Cargo.toml | 1 + .../actors/basic_test_actor/src/actor.rs | 23 +++++---- .../actors/builtins_test_actor/Cargo.toml | 15 ++++++ .../actors/builtins_test_actor/README.md | 3 ++ .../actors/builtins_test_actor/src/actor.rs | 51 +++++++++++++++++++ .../actors/builtins_test_actor/src/lib.rs | 5 ++ test_actors/build.rs | 2 +- test_actors/src/wasm_bin/mod.rs | 1 + 10 files changed, 108 insertions(+), 11 deletions(-) create mode 100644 lib/tests/lib.rs create mode 100644 test_actors/actors/builtins_test_actor/Cargo.toml create mode 100644 test_actors/actors/builtins_test_actor/README.md create mode 100644 test_actors/actors/builtins_test_actor/src/actor.rs create mode 100644 test_actors/actors/builtins_test_actor/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index 952c222..0a09eab 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -290,6 +290,7 @@ checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" name = "basic_test_actor" version = "0.1.0" dependencies = [ + "frc42_dispatch", "fvm_ipld_encoding 0.3.3", "fvm_sdk 3.0.0", "fvm_shared 3.1.0", @@ -485,6 +486,17 @@ dependencies = [ "subtle", ] +[[package]] +name = "builtin_test_actor" +version = "0.1.0" +dependencies = [ + "fvm_ipld_encoding 0.3.3", + "fvm_sdk 3.0.0", + "fvm_shared 3.1.0", + "serde", + "thiserror", +] + [[package]] name = "bumpalo" version = "3.12.0" diff --git a/lib/tests/lib.rs b/lib/tests/lib.rs new file mode 100644 index 0000000..a435f55 --- /dev/null +++ b/lib/tests/lib.rs @@ -0,0 +1,6 @@ +use kythera_lib::Tester; + +#[test] +fn test_builtins_setup() { + let tester = Tester::new(); +} diff --git a/test_actors/actors/basic_test_actor/Cargo.toml b/test_actors/actors/basic_test_actor/Cargo.toml index 6a0c83e..9b8f15e 100644 --- a/test_actors/actors/basic_test_actor/Cargo.toml +++ b/test_actors/actors/basic_test_actor/Cargo.toml @@ -5,6 +5,7 @@ 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" } diff --git a/test_actors/actors/basic_test_actor/src/actor.rs b/test_actors/actors/basic_test_actor/src/actor.rs index 984daf2..d8f069f 100644 --- a/test_actors/actors/basic_test_actor/src/actor.rs +++ b/test_actors/actors/basic_test_actor/src/actor.rs @@ -1,6 +1,7 @@ // 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; @@ -24,20 +25,22 @@ where Ok(sdk::ipld::put_block(DAG_CBOR, bytes.as_slice())?) } -// TODO use helix frc42_dispatch when their dependencies are up to date. #[no_mangle] fn invoke(_input: u32) -> u32 { let method_num = sdk::message::method_number(); - match method_num { - 3948827889 => return_ipld(TestOne()).unwrap(), - 891686990 => return_ipld(TestTwo()).unwrap(), - _ => { - sdk::vm::abort( - ExitCode::USR_UNHANDLED_MESSAGE.value(), - Some("Unknown method number"), - ); + match_method!( + method_num, + { + "TestOne" => return_ipld(TestOne()).unwrap(), + "TestTwo" => return_ipld(TestTwo()).unwrap(), + _ => { + sdk::vm::abort( + ExitCode::USR_UNHANDLED_MESSAGE.value(), + Some("Unknown method number"), + ); + } } - } + ) } #[allow(non_snake_case)] diff --git a/test_actors/actors/builtins_test_actor/Cargo.toml b/test_actors/actors/builtins_test_actor/Cargo.toml new file mode 100644 index 0000000..19cfe8f --- /dev/null +++ b/test_actors/actors/builtins_test_actor/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "builtin_test_actor" +version = "0.1.0" +edition = "2021" +publish=false + +[target.'cfg(target_arch = "wasm32")'.dependencies] +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"] \ No newline at end of file diff --git a/test_actors/actors/builtins_test_actor/README.md b/test_actors/actors/builtins_test_actor/README.md new file mode 100644 index 0000000..6ad4aa7 --- /dev/null +++ b/test_actors/actors/builtins_test_actor/README.md @@ -0,0 +1,3 @@ +## Builtin Test Actor + +This is an actor to test that Kythera properly gives access to builtin actors. \ No newline at end of file diff --git a/test_actors/actors/builtins_test_actor/src/actor.rs b/test_actors/actors/builtins_test_actor/src/actor.rs new file mode 100644 index 0000000..984daf2 --- /dev/null +++ b/test_actors/actors/builtins_test_actor/src/actor.rs @@ -0,0 +1,51 @@ +// Copyright 2023 Polyphene. +// SPDX-License-Identifier: Apache-2.0, MIT + +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(value: &T) -> std::result::Result +where + T: ser::Serialize + ?Sized, +{ + let bytes = fvm_ipld_encoding::to_vec(value)?; + Ok(sdk::ipld::put_block(DAG_CBOR, bytes.as_slice())?) +} + +// TODO use helix frc42_dispatch when their dependencies are up to date. +#[no_mangle] +fn invoke(_input: u32) -> u32 { + let method_num = sdk::message::method_number(); + match method_num { + 3948827889 => return_ipld(TestOne()).unwrap(), + 891686990 => return_ipld(TestTwo()).unwrap(), + _ => { + sdk::vm::abort( + ExitCode::USR_UNHANDLED_MESSAGE.value(), + Some("Unknown method number"), + ); + } + } +} + +#[allow(non_snake_case)] +fn TestOne() -> &'static str { + "TestOne" +} + +#[allow(non_snake_case)] +fn TestTwo() -> &'static str { + "TestTwo" +} diff --git a/test_actors/actors/builtins_test_actor/src/lib.rs b/test_actors/actors/builtins_test_actor/src/lib.rs new file mode 100644 index 0000000..6662b42 --- /dev/null +++ b/test_actors/actors/builtins_test_actor/src/lib.rs @@ -0,0 +1,5 @@ +// Copyright 2023 Polyphene. +// SPDX-License-Identifier: Apache-2.0, MIT + +#[cfg(target_arch = "wasm32")] +mod actor; diff --git a/test_actors/build.rs b/test_actors/build.rs index 8467d6d..330526c 100644 --- a/test_actors/build.rs +++ b/test_actors/build.rs @@ -6,7 +6,7 @@ use std::path::Path; use std::process::{Command, Stdio}; use std::thread; -const ACTORS: &[&str] = &["basic_test_actor"]; +const ACTORS: &[&str] = &["basic_test_actor", "builtin_test_actor"]; fn main() -> Result<(), Box> { // Cargo executable location. diff --git a/test_actors/src/wasm_bin/mod.rs b/test_actors/src/wasm_bin/mod.rs index a5b0aff..3b946e5 100644 --- a/test_actors/src/wasm_bin/mod.rs +++ b/test_actors/src/wasm_bin/mod.rs @@ -15,3 +15,4 @@ macro_rules! wasm_bin { // Integration test actors. pub const BASIC_TEST_ACTOR_BINARY: &[u8] = include_bytes!(wasm_bin!("basic_test_actor")); +pub const BUILTIN_TEST_ACTOR_BINARY: &[u8] = include_bytes!(wasm_bin!("builtin_test_actor")); From b12287631d2af956a5582a64d3b60c0aae9a6d50 Mon Sep 17 00:00:00 2001 From: Thomas Chataigner Date: Wed, 5 Apr 2023 14:33:10 +0200 Subject: [PATCH 13/38] feat(lib): testing flow * Adding actor to test constructor and setup being called in test flow --- Cargo.lock | 26 ++++++ lib/src/lib.rs | 81 +++++++++++++++++-- .../actors/constructor_test_actor/Cargo.toml | 17 ++++ .../actors/constructor_test_actor/README.md | 3 + .../constructor_test_actor/src/actor.rs | 73 +++++++++++++++++ .../actors/constructor_test_actor/src/lib.rs | 5 ++ .../actors/setup_test_actor/Cargo.toml | 17 ++++ test_actors/actors/setup_test_actor/README.md | 3 + .../actors/setup_test_actor/src/actor.rs | 73 +++++++++++++++++ .../actors/setup_test_actor/src/lib.rs | 5 ++ test_actors/build.rs | 6 +- test_actors/src/wasm_bin/mod.rs | 3 + 12 files changed, 305 insertions(+), 7 deletions(-) create mode 100644 test_actors/actors/constructor_test_actor/Cargo.toml create mode 100644 test_actors/actors/constructor_test_actor/README.md create mode 100644 test_actors/actors/constructor_test_actor/src/actor.rs create mode 100644 test_actors/actors/constructor_test_actor/src/lib.rs create mode 100644 test_actors/actors/setup_test_actor/Cargo.toml create mode 100644 test_actors/actors/setup_test_actor/README.md create mode 100644 test_actors/actors/setup_test_actor/src/actor.rs create mode 100644 test_actors/actors/setup_test_actor/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index 7b1cacd..4c5f3ac 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -709,6 +709,19 @@ version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "13418e745008f7349ec7e449155f419a61b92b58a99cc3616942b926825ec76b" +[[package]] +name = "constructor_test_actor" +version = "0.1.0" +dependencies = [ + "cid", + "fvm_ipld_blockstore 0.1.1 (git+https://github.com/filecoin-project/ref-fvm.git)", + "fvm_ipld_encoding 0.3.3 (git+https://github.com/filecoin-project/ref-fvm.git)", + "fvm_sdk 3.0.0 (git+https://github.com/filecoin-project/ref-fvm.git)", + "fvm_shared 3.1.0", + "serde", + "serde_tuple", +] + [[package]] name = "convert_case" version = "0.4.0" @@ -3478,6 +3491,19 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "setup_test_actor" +version = "0.1.0" +dependencies = [ + "cid", + "fvm_ipld_blockstore 0.1.1 (git+https://github.com/filecoin-project/ref-fvm.git)", + "fvm_ipld_encoding 0.3.3 (git+https://github.com/filecoin-project/ref-fvm.git)", + "fvm_sdk 3.0.0 (git+https://github.com/filecoin-project/ref-fvm.git)", + "fvm_shared 3.1.0", + "serde", + "serde_tuple", +] + [[package]] name = "sha2" version = "0.9.9" diff --git a/lib/src/lib.rs b/lib/src/lib.rs index 7204ed6..f95b22d 100644 --- a/lib/src/lib.rs +++ b/lib/src/lib.rs @@ -236,14 +236,26 @@ impl Tester { params: target_id.clone().into(), ..Message::default() }; - if let Err(err) = executor + + match executor .execute_message(message, ApplyKind::Explicit, 100) .setting_err("Could not run Constructor") { - return TestActorResults { - test_actor, - results: Err(err), - }; + Ok(apply_ret) => { + if apply_ret.msg_receipt.exit_code != ExitCode::OK { + // TODO we should properly handle constructor not running by returning + // directly. We need to pass the apply ret there but constructor is not a + // test. This will have to be figured out how. Anyway apply ret of constructor + // should be returned. + panic!("Constructor should run") + } + } + Err(err) => { + return TestActorResults { + test_actor, + results: Err(err), + } + } } } @@ -304,6 +316,9 @@ impl Tester { gas_limit: 1000000000, method_num: method.number(), params: target_id.clone().into(), + // TODO sequence hard coded here for constructor test to work. This should be dynamic + // based on previous messages (1 if either constructor or setup is called, 2 if both have been called) + sequence: 1, ..Message::default() }; @@ -355,7 +370,7 @@ impl Default for Tester { #[cfg(test)] mod tests { use fvm_shared::error::ExitCode; - use kythera_test_actors::wasm_bin::BASIC_TEST_ACTOR_BINARY; + use kythera_test_actors::wasm_bin::{BASIC_TEST_ACTOR_BINARY, CONSTRUCTOR_TEST_ACTOR_BINARY}; use super::*; use kythera_common::abi::{Abi, Method}; @@ -508,4 +523,58 @@ mod tests { } } } + + #[test] + fn test_constructor_called() { + // Instantiate tester + let mut tester = Tester::new(); + + // Set target actor + let target_wasm_bin = wat::parse_str(TARGET_WAT).unwrap(); + let target_abi = Abi { + constructor: None, + set_up: None, + methods: vec![], + }; + let target_actor = WasmActor::new(String::from("Target"), target_wasm_bin, target_abi); + + // Set test actor + let test_wasm_bin: Vec = Vec::from(CONSTRUCTOR_TEST_ACTOR_BINARY); + let test_abi = Abi { + constructor: Some(Method::new_from_name("Constructor").unwrap()), + set_up: None, + methods: vec![Method::new_from_name("TestConstructor").unwrap()], + }; + let test_actor = WasmActor::new(String::from("Constructor Test"), test_wasm_bin, test_abi); + + match tester.deploy_target_actor(target_actor) { + Err(_) => { + panic!("Could not set target Actor when testing if Constructor is properly called") + } + _ => {} + } + + match tester.test(&[test_actor.clone()], None) { + Err(_) => { + panic!("Could not run test when testing Tester") + } + Ok(test_res) => { + assert_eq!(test_res.len(), 1usize); + assert_eq!(test_res[0].results.as_ref().unwrap().len(), 1usize); + assert_eq!(test_res[0].test_actor, &test_actor); + dbg!(&test_res[0].results); + test_res[0] + .results + .as_ref() + .unwrap() + .iter() + .for_each(|result| match (result.method().r#type(), result.ret()) { + (MethodType::Test, TestResultType::Passed(apply_ret)) => { + assert_eq!(apply_ret.msg_receipt.exit_code, ExitCode::OK); + } + _ => panic!("test against basic test actor should pass"), + }) + } + } + } } diff --git a/test_actors/actors/constructor_test_actor/Cargo.toml b/test_actors/actors/constructor_test_actor/Cargo.toml new file mode 100644 index 0000000..769f475 --- /dev/null +++ b/test_actors/actors/constructor_test_actor/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "constructor_test_actor" +version = "0.1.0" +edition = "2021" +publish=false + +[target.'cfg(target_arch = "wasm32")'.dependencies] +cid = { version = "0.8.5", default-features = false } +fvm_ipld_blockstore = { git = "https://github.com/filecoin-project/ref-fvm.git", version = "0.1.1" } +fvm_sdk = { git = "https://github.com/filecoin-project/ref-fvm.git", version = "3.0.0" } +fvm_shared = { git = "https://github.com/filecoin-project/ref-fvm.git", version = "3.1.0" } +fvm_ipld_encoding = { git = "https://github.com/filecoin-project/ref-fvm.git", version = "0.3.3" } +serde = { version = "1.0.136", features = ["derive"] } +serde_tuple = { version = "0.5.0" } + +[lib] +crate-type = ["cdylib"] \ No newline at end of file diff --git a/test_actors/actors/constructor_test_actor/README.md b/test_actors/actors/constructor_test_actor/README.md new file mode 100644 index 0000000..ce160b4 --- /dev/null +++ b/test_actors/actors/constructor_test_actor/README.md @@ -0,0 +1,3 @@ +## Constructor Test Actor + +This is an actor to test that constructor are being properly called in Kythera testing framework. \ No newline at end of file diff --git a/test_actors/actors/constructor_test_actor/src/actor.rs b/test_actors/actors/constructor_test_actor/src/actor.rs new file mode 100644 index 0000000..92993b0 --- /dev/null +++ b/test_actors/actors/constructor_test_actor/src/actor.rs @@ -0,0 +1,73 @@ +// Copyright 2023 Polyphene. +// SPDX-License-Identifier: Apache-2.0, MIT + +use cid::{multihash::Code, Cid}; +use fvm_ipld_blockstore::Block; +use fvm_ipld_encoding::tuple::{Deserialize_tuple, Serialize_tuple}; +use fvm_ipld_encoding::DAG_CBOR; +use fvm_sdk as sdk; +use fvm_sdk::NO_DATA_BLOCK_ID; +use fvm_shared::error::ExitCode; + +#[derive(Serialize_tuple, Deserialize_tuple)] +struct TestConstructorActorState { + value: u32, +} + +impl TestConstructorActorState { + pub fn load(cid: &Cid) -> Self { + let data = sdk::ipld::get(cid).unwrap(); + fvm_ipld_encoding::from_slice::(&data).unwrap() + } + + pub fn save(&self) -> Cid { + let serialized = fvm_ipld_encoding::to_vec(self).unwrap(); + let block = Block { + codec: DAG_CBOR, + data: serialized, + }; + sdk::ipld::put( + Code::Blake2b256.into(), + 32, + block.codec, + block.data.as_ref(), + ) + .unwrap() + } +} + +// TODO use helix frc42_dispatch when their dependencies are up to date. +#[no_mangle] +fn invoke(_input: u32) -> u32 { + let method_num = sdk::message::method_number(); + match method_num { + 1 => Constructor(), + 862222151 => TestConstructor(), + _ => { + sdk::vm::abort( + ExitCode::USR_UNHANDLED_MESSAGE.value(), + Some("Unknown method number"), + ); + } + } + + NO_DATA_BLOCK_ID +} + +#[allow(non_snake_case)] +fn Constructor() { + let state = TestConstructorActorState { value: 1 }; + let cid = state.save(); + fvm_sdk::sself::set_root(&cid).unwrap(); +} + +#[allow(non_snake_case)] +fn TestConstructor() { + let state = TestConstructorActorState::load(&sdk::sself::root().unwrap()); + if state.value != 1u32 { + sdk::vm::abort( + ExitCode::USR_ASSERTION_FAILED.value(), + Some("Constructor was not called"), + ) + } +} diff --git a/test_actors/actors/constructor_test_actor/src/lib.rs b/test_actors/actors/constructor_test_actor/src/lib.rs new file mode 100644 index 0000000..6662b42 --- /dev/null +++ b/test_actors/actors/constructor_test_actor/src/lib.rs @@ -0,0 +1,5 @@ +// Copyright 2023 Polyphene. +// SPDX-License-Identifier: Apache-2.0, MIT + +#[cfg(target_arch = "wasm32")] +mod actor; diff --git a/test_actors/actors/setup_test_actor/Cargo.toml b/test_actors/actors/setup_test_actor/Cargo.toml new file mode 100644 index 0000000..db81fa4 --- /dev/null +++ b/test_actors/actors/setup_test_actor/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "setup_test_actor" +version = "0.1.0" +edition = "2021" +publish=false + +[target.'cfg(target_arch = "wasm32")'.dependencies] +cid = { version = "0.8.5", default-features = false } +fvm_ipld_blockstore = { git = "https://github.com/filecoin-project/ref-fvm.git", version = "0.1.1" } +fvm_sdk = { git = "https://github.com/filecoin-project/ref-fvm.git", version = "3.0.0" } +fvm_shared = { git = "https://github.com/filecoin-project/ref-fvm.git", version = "3.1.0" } +fvm_ipld_encoding = { git = "https://github.com/filecoin-project/ref-fvm.git", version = "0.3.3" } +serde = { version = "1.0.136", features = ["derive"] } +serde_tuple = { version = "0.5.0" } + +[lib] +crate-type = ["cdylib"] \ No newline at end of file diff --git a/test_actors/actors/setup_test_actor/README.md b/test_actors/actors/setup_test_actor/README.md new file mode 100644 index 0000000..ce5b738 --- /dev/null +++ b/test_actors/actors/setup_test_actor/README.md @@ -0,0 +1,3 @@ +## Setup Test Actor + +This is an actor to test that setup are being properly called in Kythera testing framework. \ No newline at end of file diff --git a/test_actors/actors/setup_test_actor/src/actor.rs b/test_actors/actors/setup_test_actor/src/actor.rs new file mode 100644 index 0000000..57784fe --- /dev/null +++ b/test_actors/actors/setup_test_actor/src/actor.rs @@ -0,0 +1,73 @@ +// Copyright 2023 Polyphene. +// SPDX-License-Identifier: Apache-2.0, MIT + +use cid::{multihash::Code, Cid}; +use fvm_ipld_blockstore::Block; +use fvm_ipld_encoding::tuple::{Deserialize_tuple, Serialize_tuple}; +use fvm_ipld_encoding::DAG_CBOR; +use fvm_sdk as sdk; +use fvm_sdk::NO_DATA_BLOCK_ID; +use fvm_shared::error::ExitCode; + +#[derive(Serialize_tuple, Deserialize_tuple)] +struct TestSetupActorState { + value: u32, +} + +impl TestSetupActorState { + pub fn load(cid: &Cid) -> Self { + let data = sdk::ipld::get(cid).unwrap(); + fvm_ipld_encoding::from_slice::(&data).unwrap() + } + + pub fn save(&self) -> Cid { + let serialized = fvm_ipld_encoding::to_vec(self).unwrap(); + let block = Block { + codec: DAG_CBOR, + data: serialized, + }; + sdk::ipld::put( + Code::Blake2b256.into(), + 32, + block.codec, + block.data.as_ref(), + ) + .unwrap() + } +} + +// TODO use helix frc42_dispatch when their dependencies are up to date. +#[no_mangle] +fn invoke(_input: u32) -> u32 { + let method_num = sdk::message::method_number(); + match method_num { + 3556852554 => Setup(), + 787295010 => TestSetup(), + _ => { + sdk::vm::abort( + ExitCode::USR_UNHANDLED_MESSAGE.value(), + Some("Unknown method number"), + ); + } + } + + NO_DATA_BLOCK_ID +} + +#[allow(non_snake_case)] +fn Setup() { + let state = TestSetupActorState { value: 1 }; + let cid = state.save(); + fvm_sdk::sself::set_root(&cid).unwrap(); +} + +#[allow(non_snake_case)] +fn TestSetup() { + let state = TestSetupActorState::load(&sdk::sself::root().unwrap()); + if state.value != 1u32 { + sdk::vm::abort( + ExitCode::USR_ASSERTION_FAILED.value(), + Some("Setup was not called"), + ) + } +} diff --git a/test_actors/actors/setup_test_actor/src/lib.rs b/test_actors/actors/setup_test_actor/src/lib.rs new file mode 100644 index 0000000..6662b42 --- /dev/null +++ b/test_actors/actors/setup_test_actor/src/lib.rs @@ -0,0 +1,5 @@ +// Copyright 2023 Polyphene. +// SPDX-License-Identifier: Apache-2.0, MIT + +#[cfg(target_arch = "wasm32")] +mod actor; diff --git a/test_actors/build.rs b/test_actors/build.rs index 8467d6d..dd12abc 100644 --- a/test_actors/build.rs +++ b/test_actors/build.rs @@ -6,7 +6,11 @@ use std::path::Path; use std::process::{Command, Stdio}; use std::thread; -const ACTORS: &[&str] = &["basic_test_actor"]; +const ACTORS: &[&str] = &[ + "basic_test_actor", + "constructor_test_actor", + "setup_test_actor", +]; fn main() -> Result<(), Box> { // Cargo executable location. diff --git a/test_actors/src/wasm_bin/mod.rs b/test_actors/src/wasm_bin/mod.rs index a5b0aff..891dcbc 100644 --- a/test_actors/src/wasm_bin/mod.rs +++ b/test_actors/src/wasm_bin/mod.rs @@ -15,3 +15,6 @@ macro_rules! wasm_bin { // Integration test actors. pub const BASIC_TEST_ACTOR_BINARY: &[u8] = include_bytes!(wasm_bin!("basic_test_actor")); +pub const CONSTRUCTOR_TEST_ACTOR_BINARY: &[u8] = + include_bytes!(wasm_bin!("constructor_test_actor")); +pub const SETUP_TEST_ACTOR_BINARY: &[u8] = include_bytes!(wasm_bin!("setup_test_actor")); From ee346229194eb7817ad2e236798de44c75ec994c Mon Sep 17 00:00:00 2001 From: Thomas Chataigner Date: Wed, 5 Apr 2023 16:26:59 +0200 Subject: [PATCH 14/38] feat(builtins): testing builtins deployment * Updating the builtin test actor to test that all builtins code are deployed at their address * Fix clippy --- Cargo.lock | 3 +- cli/src/search.rs | 1 - lib/src/state_tree.rs | 4 +- lib/tests/lib.rs | 66 +++++++- .../actors/builtins_test_actor/Cargo.toml | 3 +- .../actors/builtins_test_actor/src/actor.rs | 149 ++++++++++++++---- test_actors/build.rs | 2 +- 7 files changed, 184 insertions(+), 44 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0a09eab..ea6c410 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -490,11 +490,12 @@ dependencies = [ name = "builtin_test_actor" version = "0.1.0" dependencies = [ + "fil_actors_runtime_v10 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "frc42_dispatch", "fvm_ipld_encoding 0.3.3", "fvm_sdk 3.0.0", "fvm_shared 3.1.0", "serde", - "thiserror", ] [[package]] diff --git a/cli/src/search.rs b/cli/src/search.rs index f3dea68..a89bdd3 100644 --- a/cli/src/search.rs +++ b/cli/src/search.rs @@ -50,7 +50,6 @@ pub fn search_files>(path: P) -> anyhow::Result> { let (target_actor_paths, mut test_artifacts_paths): (Vec, Vec) = fs::read_dir(path) .context("Could not read the input path")? - .into_iter() .filter_map(Result::ok) // Path::ends_with is different from String::ends_with, // Path::ends_with operates on the child, in this case diff --git a/lib/src/state_tree.rs b/lib/src/state_tree.rs index 2ea5ad1..22945ab 100644 --- a/lib/src/state_tree.rs +++ b/lib/src/state_tree.rs @@ -223,7 +223,7 @@ impl StateTree { let verified_reg_signer_state = fil_actor_account_v10::State { address: verified_reg_signer_address, }; - dbg!(verified_reg_signer_id); + // Set signer actor. self.set_actor( "Verified Registry Signer", @@ -311,7 +311,7 @@ impl StateTree { "Burnt Funds Actor", burnt_state, *manifest - .code_by_id(Type::DataCap as u32) + .code_by_id(Type::Account as u32) .expect("Should be able to get Burnt Funds Actor code from manifest"), BURNT_FUNDS_ACTOR_ID, 0, diff --git a/lib/tests/lib.rs b/lib/tests/lib.rs index a435f55..2f63eff 100644 --- a/lib/tests/lib.rs +++ b/lib/tests/lib.rs @@ -1,6 +1,66 @@ -use kythera_lib::Tester; +use fvm_shared::error::ExitCode; +use kythera_common::abi::{Abi, Method, MethodType}; +use kythera_lib::{TestResultType, Tester, WasmActor}; +use kythera_test_actors::wasm_bin::BUILTIN_TEST_ACTOR_BINARY; + +const TARGET_WAT: &str = r#" + ;; Mock invoke function + (module + (func (export "invoke") (param $x i32) (result i32) + (i32.const 1) + ) + ) + "#; #[test] -fn test_builtins_setup() { - let tester = Tester::new(); +fn test_builtin_deployed() { + // Instantiate tester + let mut tester = Tester::new(); + + // Set target actor + let target_wasm_bin = wat::parse_str(TARGET_WAT).unwrap(); + let target_abi = Abi { methods: vec![] }; + let target_actor = WasmActor::new(String::from("Target"), target_wasm_bin, target_abi); + + // Set test actor + let test_wasm_bin: Vec = Vec::from(BUILTIN_TEST_ACTOR_BINARY); + let test_abi = Abi { + methods: vec![Method::new_from_name("TestBuiltinsDeployed").unwrap()], + }; + let test_actor = WasmActor::new( + String::from("Builtins Deployed Test"), + test_wasm_bin, + test_abi, + ); + + match tester.deploy_target_actor(target_actor) { + Err(_) => { + panic!("Could not set target Actor when testing if builtins are properly deployed") + } + _ => {} + } + + // Run test + match tester.test(&[test_actor.clone()], None) { + Err(_) => { + panic!("Could not run test when testing Tester") + } + Ok(test_res) => { + assert_eq!(test_res.len(), 1usize); + assert_eq!(test_res[0].results.as_ref().unwrap().len(), 1usize); + assert_eq!(test_res[0].test_actor, &test_actor); + + test_res[0] + .results + .as_ref() + .unwrap() + .iter() + .for_each(|result| match (result.method().r#type(), result.ret()) { + (MethodType::Test, TestResultType::Passed(apply_ret)) => { + assert_eq!(apply_ret.msg_receipt.exit_code, ExitCode::OK); + } + _ => panic!("test against basic test actor should pass"), + }) + } + } } diff --git a/test_actors/actors/builtins_test_actor/Cargo.toml b/test_actors/actors/builtins_test_actor/Cargo.toml index 19cfe8f..a4a77c8 100644 --- a/test_actors/actors/builtins_test_actor/Cargo.toml +++ b/test_actors/actors/builtins_test_actor/Cargo.toml @@ -5,11 +5,12 @@ edition = "2021" publish=false [target.'cfg(target_arch = "wasm32")'.dependencies] +fil_actors_runtime_v10 = "1.0.0" +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"] \ No newline at end of file diff --git a/test_actors/actors/builtins_test_actor/src/actor.rs b/test_actors/actors/builtins_test_actor/src/actor.rs index 984daf2..819a94f 100644 --- a/test_actors/actors/builtins_test_actor/src/actor.rs +++ b/test_actors/actors/builtins_test_actor/src/actor.rs @@ -1,51 +1,130 @@ // Copyright 2023 Polyphene. // SPDX-License-Identifier: Apache-2.0, MIT -use fvm_ipld_encoding::DAG_CBOR; +use fil_actors_runtime_v10::runtime::builtins::Type; +use fil_actors_runtime_v10::{ + BURNT_FUNDS_ACTOR_ADDR, CRON_ACTOR_ADDR, DATACAP_TOKEN_ACTOR_ADDR, DATACAP_TOKEN_ACTOR_ID, + INIT_ACTOR_ADDR, REWARD_ACTOR_ADDR, STORAGE_MARKET_ACTOR_ADDR, STORAGE_POWER_ACTOR_ADDR, + SYSTEM_ACTOR_ADDR, VERIFIED_REGISTRY_ACTOR_ADDR, +}; +use frc42_dispatch::match_method; use fvm_sdk as sdk; +use fvm_sdk::actor::{get_actor_code_cid, get_builtin_actor_type}; +use fvm_sdk::NO_DATA_BLOCK_ID; 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(value: &T) -> std::result::Result -where - T: ser::Serialize + ?Sized, -{ - let bytes = fvm_ipld_encoding::to_vec(value)?; - Ok(sdk::ipld::put_block(DAG_CBOR, bytes.as_slice())?) -} // TODO use helix frc42_dispatch when their dependencies are up to date. #[no_mangle] fn invoke(_input: u32) -> u32 { + std::panic::set_hook(Box::new(|info| { + sdk::vm::abort( + ExitCode::USR_ASSERTION_FAILED.value(), + Some(&format!("{info}")), + ) + })); + let method_num = sdk::message::method_number(); - match method_num { - 3948827889 => return_ipld(TestOne()).unwrap(), - 891686990 => return_ipld(TestTwo()).unwrap(), - _ => { - sdk::vm::abort( - ExitCode::USR_UNHANDLED_MESSAGE.value(), - Some("Unknown method number"), - ); + match_method!( + method_num, + { + "TestBuiltinsDeployed" => { + TestBuiltinsDeployed(); + + NO_DATA_BLOCK_ID + }, + _ => { + sdk::vm::abort( + ExitCode::USR_UNHANDLED_MESSAGE.value(), + Some("Unknown method number"), + ); + } } - } + ) } +// Checks that all relevant builtins are deployed at a correct actor Id in Kythera #[allow(non_snake_case)] -fn TestOne() -> &'static str { - "TestOne" -} +fn TestBuiltinsDeployed() { + // Test system actor deployment. + let code_cid = get_actor_code_cid(&SYSTEM_ACTOR_ADDR) + .unwrap_or_else(|| panic!("Should get an code CID at address: {}", &SYSTEM_ACTOR_ADDR)); + let actor_type = get_builtin_actor_type(&code_cid) + .unwrap_or_else(|| panic!("Should get a builtin actor type for CID: {}", &code_cid)); + assert_eq!(actor_type, Type::System as i32); -#[allow(non_snake_case)] -fn TestTwo() -> &'static str { - "TestTwo" + // Test init actor deployment. + let code_cid = get_actor_code_cid(&INIT_ACTOR_ADDR) + .unwrap_or_else(|| panic!("Should get an code CID at address: {}", &INIT_ACTOR_ADDR)); + let actor_type = get_builtin_actor_type(&code_cid) + .unwrap_or_else(|| panic!("Should get a builtin actor type for CID: {}", &code_cid)); + assert_eq!(actor_type, Type::Init as i32); + + // Test reward actor deployment. + let code_cid = get_actor_code_cid(&REWARD_ACTOR_ADDR) + .unwrap_or_else(|| panic!("Should get an code CID at address: {}", &REWARD_ACTOR_ADDR)); + let actor_type = get_builtin_actor_type(&code_cid) + .unwrap_or_else(|| panic!("Should get a builtin actor type for CID: {}", &code_cid)); + assert_eq!(actor_type, Type::Reward as i32); + + // Test cron actor deployment. + let code_cid = get_actor_code_cid(&CRON_ACTOR_ADDR) + .unwrap_or_else(|| panic!("Should get an code CID at address: {}", &CRON_ACTOR_ADDR)); + let actor_type = get_builtin_actor_type(&code_cid) + .unwrap_or_else(|| panic!("Should get a builtin actor type for CID: {}", &code_cid)); + assert_eq!(actor_type, Type::Cron as i32); + + // Test power actor deployment. + let code_cid = get_actor_code_cid(&STORAGE_POWER_ACTOR_ADDR).unwrap_or_else(|| { + panic!( + "Should get an code CID at address: {}", + &STORAGE_POWER_ACTOR_ADDR + ) + }); + let actor_type = get_builtin_actor_type(&code_cid) + .unwrap_or_else(|| panic!("Should get a builtin actor type for CID: {}", &code_cid)); + assert_eq!(actor_type, Type::Power as i32); + + // Test market actor deployment. + let code_cid = get_actor_code_cid(&STORAGE_MARKET_ACTOR_ADDR).unwrap_or_else(|| { + panic!( + "Should get an code CID at address: {}", + &STORAGE_MARKET_ACTOR_ADDR + ) + }); + let actor_type = get_builtin_actor_type(&code_cid) + .unwrap_or_else(|| panic!("Should get a builtin actor type for CID: {}", &code_cid)); + assert_eq!(actor_type, Type::Market as i32); + + // Test verified registry actor deployment. + let code_cid = get_actor_code_cid(&VERIFIED_REGISTRY_ACTOR_ADDR).unwrap_or_else(|| { + panic!( + "Should get an code CID at address: {}", + &VERIFIED_REGISTRY_ACTOR_ADDR + ) + }); + let actor_type = get_builtin_actor_type(&code_cid) + .unwrap_or_else(|| panic!("Should get a builtin actor type for CID: {}", &code_cid)); + assert_eq!(actor_type, Type::VerifiedRegistry as i32); + + // Test datacap actor deployment. + let code_cid = get_actor_code_cid(&DATACAP_TOKEN_ACTOR_ADDR).unwrap_or_else(|| { + panic!( + "Should get an code CID at address: {}", + &DATACAP_TOKEN_ACTOR_ID + ) + }); + let actor_type = get_builtin_actor_type(&code_cid) + .unwrap_or_else(|| panic!("Should get a builtin actor type for CID: {}", &code_cid)); + assert_eq!(actor_type, Type::DataCap as i32); + + // Test burnt funds actor deployment. + let code_cid = get_actor_code_cid(&BURNT_FUNDS_ACTOR_ADDR).unwrap_or_else(|| { + panic!( + "Should get an code CID at address: {}", + &BURNT_FUNDS_ACTOR_ADDR + ) + }); + let actor_type = get_builtin_actor_type(&code_cid) + .unwrap_or_else(|| panic!("Should get a builtin actor type for CID: {}", &code_cid)); + assert_eq!(actor_type, Type::Account as i32); } diff --git a/test_actors/build.rs b/test_actors/build.rs index 330526c..588500a 100644 --- a/test_actors/build.rs +++ b/test_actors/build.rs @@ -28,7 +28,7 @@ fn main() -> Result<(), Box> { } // Cargo build command for all actors at once. - let mut cmd = Command::new(&cargo); + let mut cmd = Command::new(cargo); cmd.arg("build") .args(ACTORS.iter().map(|pkg| "-p=".to_owned() + pkg)) .arg("--target=wasm32-unknown-unknown") From c0683e88692af53891a643f54ae560967cde4dcb Mon Sep 17 00:00:00 2001 From: Thomas Chataigner Date: Wed, 5 Apr 2023 16:30:59 +0200 Subject: [PATCH 15/38] fix(builtins): changing Chainsafe dep to be based on crates.io --- Cargo.lock | 54 ++++++++++++++++---------------------------------- lib/Cargo.toml | 8 ++++---- 2 files changed, 21 insertions(+), 41 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ea6c410..51f98c5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -490,7 +490,7 @@ dependencies = [ name = "builtin_test_actor" version = "0.1.0" dependencies = [ - "fil_actors_runtime_v10 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "fil_actors_runtime_v10", "frc42_dispatch", "fvm_ipld_encoding 0.3.3", "fvm_sdk 3.0.0", @@ -1361,9 +1361,10 @@ dependencies = [ [[package]] name = "fil_actor_datacap_v10" version = "1.0.0" -source = "git+https://github.com/ChainSafe/fil-actor-states?branch=main#1700628fece5ac91cf32b7d61e65a2b9d73d219e" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce1f4d418fe7b1f5fadc0614b62fb31e842f25ccd4e53184a604d19a645b60ad" dependencies = [ - "fil_actors_runtime_v10 1.0.0 (git+https://github.com/ChainSafe/fil-actor-states?branch=main)", + "fil_actors_runtime_v10", "frc42_dispatch", "frc46_token 3.1.0", "fvm_ipld_blockstore", @@ -1415,7 +1416,8 @@ dependencies = [ [[package]] name = "fil_actor_ethaccount_v10" version = "1.0.0" -source = "git+https://github.com/ChainSafe/fil-actor-states?branch=main#1700628fece5ac91cf32b7d61e65a2b9d73d219e" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43680472c5351870e2705d9f992e415d8b9ca81cd84fb31e4f99153271a1e606" dependencies = [ "fvm_shared 3.1.0", "num-derive", @@ -1474,7 +1476,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "31cf353d310f37ff152b49ef6eb3a1a734e0e193ed7c44f50c8eae7034d054c1" dependencies = [ "cid", - "fil_actors_runtime_v10 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "fil_actors_runtime_v10", "frc42_dispatch", "fvm_ipld_blockstore", "fvm_ipld_encoding 0.3.3", @@ -1514,7 +1516,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e023cdd8b8e0d39bdbbe3629dc761f2295bba792c7e57c8bf0ff356d88e4ab60" dependencies = [ "cid", - "fil_actors_runtime_v10 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "fil_actors_runtime_v10", "frc42_dispatch", "fvm_ipld_blockstore", "fvm_ipld_encoding 0.3.3", @@ -1559,7 +1561,7 @@ checksum = "888cfc1da1e748656ed9dfe8cf19e0e434d1d4050e2caa64f12a4d3ec4c9a58f" dependencies = [ "anyhow", "cid", - "fil_actors_runtime_v10 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "fil_actors_runtime_v10", "frc42_dispatch", "fvm_ipld_amt 0.5.1", "fvm_ipld_bitfield", @@ -1603,7 +1605,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5033cb154bc1fa54f5849d8d56553ba3bb777a6cb65ed360aed64bb064deade" dependencies = [ "cid", - "fil_actors_runtime_v10 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "fil_actors_runtime_v10", "frc42_dispatch", "fvm_ipld_blockstore", "fvm_ipld_encoding 0.3.3", @@ -1683,7 +1685,7 @@ checksum = "5956a2e9ce0e16d046dab721d77cd8877de8571dd2c14394bf57f62b835bdba1" dependencies = [ "anyhow", "cid", - "fil_actors_runtime_v10 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "fil_actors_runtime_v10", "frc42_dispatch", "fvm_ipld_blockstore", "fvm_ipld_encoding 0.3.3", @@ -1745,7 +1747,8 @@ dependencies = [ [[package]] name = "fil_actor_system_v10" version = "1.0.0" -source = "git+https://github.com/ChainSafe/fil-actor-states?branch=main#1700628fece5ac91cf32b7d61e65a2b9d73d219e" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38c10a8bb4b1b1d3c321dc52332d30fa967e61689fe715f639de10d3a0c9e65d" dependencies = [ "cid", "fvm_ipld_encoding 0.3.3", @@ -1780,10 +1783,11 @@ dependencies = [ [[package]] name = "fil_actor_verifreg_v10" version = "1.0.0" -source = "git+https://github.com/ChainSafe/fil-actor-states?branch=main#1700628fece5ac91cf32b7d61e65a2b9d73d219e" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74ea02fc52c01628bdcf1bb9aaa86b1b27e442d067bdaa96a874cfe307741ffd" dependencies = [ "cid", - "fil_actors_runtime_v10 1.0.0 (git+https://github.com/ChainSafe/fil-actor-states?branch=main)", + "fil_actors_runtime_v10", "frc42_dispatch", "fvm_ipld_blockstore", "fvm_ipld_encoding 0.3.3", @@ -1862,30 +1866,6 @@ dependencies = [ "unsigned-varint", ] -[[package]] -name = "fil_actors_runtime_v10" -version = "1.0.0" -source = "git+https://github.com/ChainSafe/fil-actor-states?branch=main#1700628fece5ac91cf32b7d61e65a2b9d73d219e" -dependencies = [ - "anyhow", - "cid", - "fvm_ipld_amt 0.5.1", - "fvm_ipld_blockstore", - "fvm_ipld_encoding 0.3.3", - "fvm_ipld_hamt 0.6.1", - "fvm_shared 3.1.0", - "multihash", - "num-bigint", - "num-derive", - "num-traits", - "paste", - "serde", - "serde_repr", - "sha2 0.10.6", - "thiserror", - "unsigned-varint", -] - [[package]] name = "fil_builtin_actors_bundle" version = "10.0.0" @@ -2941,7 +2921,7 @@ dependencies = [ "fil_actor_reward_v10", "fil_actor_system_v10", "fil_actor_verifreg_v10", - "fil_actors_runtime_v10 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "fil_actors_runtime_v10", "fil_builtin_actors_bundle", "futures", "fvm_ipld_blockstore", diff --git a/lib/Cargo.toml b/lib/Cargo.toml index 9083628..22228ac 100644 --- a/lib/Cargo.toml +++ b/lib/Cargo.toml @@ -9,7 +9,7 @@ edition = "2021" actors-v10 = { package = "fil_builtin_actors_bundle", git = "https://github.com/filecoin-project/builtin-actors", rev = "39571e2" } fil_actor_account_v10 = "1.0.0" fil_actor_cron_v10 = "1.0.0" -fil_actor_datacap_v10 = { git = "https://github.com/ChainSafe/fil-actor-states", branch = "main" } +fil_actor_datacap_v10 = "1.0.0" fil_actor_init_v10 = "1.0.0" fil_actor_market_v10 = "1.0.0" fil_actor_miner_v10 = "1.0.0" @@ -17,9 +17,9 @@ fil_actor_multisig_v10 = "1.0.0" fil_actor_paych_v10 = "1.0.0" fil_actor_power_v10 = "1.0.0" fil_actor_reward_v10 = "1.0.0" -fil_actor_system_v10 = { git = "https://github.com/ChainSafe/fil-actor-states", branch = "main" } -fil_actor_verifreg_v10 = { git = "https://github.com/ChainSafe/fil-actor-states", branch = "main" } -fil_actor_ethaccount_v10 = { git = "https://github.com/ChainSafe/fil-actor-states", branch = "main" } +fil_actor_system_v10 = "1.0.0" +fil_actor_verifreg_v10 = "1.0.0" +fil_actor_ethaccount_v10 = "1.0.0" fil_actors_runtime_v10 = "1.0.0" fvm_ipld_blockstore = { version = "0.1.1" } From b8930744d05a3a86f35a080b1dbed588af9992e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Oliveira?= Date: Thu, 6 Apr 2023 20:02:53 +0100 Subject: [PATCH 16/38] lib: extract executor into it's own mod - introduce constructor_setup_test_actor crate to test Setup and Constructor functions --- Cargo.lock | 13 + common/src/abi/mod.rs | 19 +- fvm/Cargo.toml | 1 + fvm/src/lib.rs | 2 +- lib/Cargo.toml | 3 +- lib/src/error.rs | 6 + lib/src/executor.rs | 108 +++++++ lib/src/lib.rs | 288 +++++++++++------- .../constructor_setup_test_actor/Cargo.toml | 17 ++ .../constructor_setup_test_actor/README.md | 3 + .../constructor_setup_test_actor/src/actor.rs | 84 +++++ .../constructor_setup_test_actor/src/lib.rs | 5 + test_actors/build.rs | 1 + test_actors/src/wasm_bin/mod.rs | 4 +- 14 files changed, 428 insertions(+), 126 deletions(-) create mode 100644 lib/src/executor.rs create mode 100644 test_actors/actors/constructor_setup_test_actor/Cargo.toml create mode 100644 test_actors/actors/constructor_setup_test_actor/README.md create mode 100644 test_actors/actors/constructor_setup_test_actor/src/actor.rs create mode 100644 test_actors/actors/constructor_setup_test_actor/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index 4c5f3ac..22c2b84 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -709,6 +709,19 @@ version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "13418e745008f7349ec7e449155f419a61b92b58a99cc3616942b926825ec76b" +[[package]] +name = "constructor_setup_test_actor" +version = "0.1.0" +dependencies = [ + "cid", + "fvm_ipld_blockstore 0.1.1 (git+https://github.com/filecoin-project/ref-fvm.git)", + "fvm_ipld_encoding 0.3.3 (git+https://github.com/filecoin-project/ref-fvm.git)", + "fvm_sdk 3.0.0 (git+https://github.com/filecoin-project/ref-fvm.git)", + "fvm_shared 3.1.0", + "serde", + "serde_tuple", +] + [[package]] name = "constructor_test_actor" version = "0.1.0" diff --git a/common/src/abi/mod.rs b/common/src/abi/mod.rs index 3f97fc0..ee44854 100644 --- a/common/src/abi/mod.rs +++ b/common/src/abi/mod.rs @@ -52,7 +52,7 @@ impl Abi { self.constructor.as_ref() } - /// Get the `SetUp` method on the Abi if it exists. + /// Get the `Setup` method on the Abi if it exists. pub fn set_up(&self) -> Option<&Method> { self.set_up.as_ref() } @@ -62,7 +62,7 @@ impl Abi { } } -/// Custom implementation of [`Serialize`] so that we join `Constructor` and `SetUp` +/// Custom implementation of [`Serialize`] so that we join `Constructor` and `Setup` /// into the rest of the methods. impl serde::Serialize for Abi { fn serialize(&self, serializer: S) -> std::result::Result @@ -83,7 +83,7 @@ impl serde::Serialize for Abi { } } -/// Custom implementation of [`Deserialize`] so that we check for `Constructor` and `SetUp` +/// Custom implementation of [`Deserialize`] so that we check for `Constructor` and `Setup` /// existence and assert there's only one of each. impl<'de> serde::Deserialize<'de> for Abi { fn deserialize(deserializer: D) -> std::result::Result @@ -116,8 +116,8 @@ impl<'de> serde::Deserialize<'de> for Abi { for method in seq_methods { match (constructor.is_some(), set_up.is_some(), &method.r#type()) { (false, _, MethodType::Constructor) => constructor = Some(method), - (_, false, MethodType::SetUp) => set_up = Some(method), - (true, _, MethodType::Constructor) | (_, true, MethodType::SetUp) => { + (_, false, MethodType::Setup) => set_up = Some(method), + (true, _, MethodType::Constructor) | (_, true, MethodType::Setup) => { return Err(serde::de::Error::custom( "Abi can only have one Constructor and one SetUp function", )) @@ -153,7 +153,7 @@ pub struct Method { pub enum MethodType { Constructor, Entrypoint, - SetUp, + Setup, Test, TestFail, } @@ -183,7 +183,7 @@ impl Method { let split = pascal_case_split(&name); let r#type = match &split[..] { ["Constructor", ..] => MethodType::Constructor, - ["Set", "Up", ..] => MethodType::SetUp, + ["Setup", ..] => MethodType::Setup, ["Test", "Fail", ..] => MethodType::TestFail, ["Test", ..] => MethodType::Test, _ => MethodType::Entrypoint, @@ -366,7 +366,6 @@ mod test { match crate::from_slice::(&serialized_abi) { Ok(_) => panic!("Deserialization should fail"), Err(err) => { - dbg!(&err); assert!(err .to_string() .contains("Couldn't deserialize method: testFailTransfer")); @@ -389,8 +388,8 @@ mod test { MethodType::Constructor ); assert_eq!( - Method::new_from_name("SetUp").unwrap().r#type, - MethodType::SetUp + Method::new_from_name("Setup").unwrap().r#type, + MethodType::Setup ); assert!(Method::new_from_name("testOne").is_err()); diff --git a/fvm/Cargo.toml b/fvm/Cargo.toml index 31bd188..7276137 100644 --- a/fvm/Cargo.toml +++ b/fvm/Cargo.toml @@ -8,6 +8,7 @@ edition = "2021" [dependencies] anyhow = "1.0.70" cid = { version = "0.8.5", default-features = false } +# TODO since this is a library, we need to depend on actual published versions. fvm = { git = "https://github.com/filecoin-project/ref-fvm.git", version = "3.1.0", default-features = false, features = ["testing"] } fvm_ipld_encoding = { git = "https://github.com/filecoin-project/ref-fvm.git", version = "0.3.3" } fvm_shared = { git = "https://github.com/filecoin-project/ref-fvm.git", version = "3.1.0" } diff --git a/fvm/src/lib.rs b/fvm/src/lib.rs index c72de45..fe8fef7 100644 --- a/fvm/src/lib.rs +++ b/fvm/src/lib.rs @@ -16,7 +16,7 @@ pub mod executor { use fvm::DefaultKernel; pub use fvm::executor::Executor; - pub use fvm::executor::{ApplyKind, ApplyRet}; + pub use fvm::executor::{ApplyFailure, ApplyKind, ApplyRet}; pub type KytheraExecutor = DefaultExecutor>>>; } diff --git a/lib/Cargo.toml b/lib/Cargo.toml index 9cb1cc9..9e3d754 100644 --- a/lib/Cargo.toml +++ b/lib/Cargo.toml @@ -6,6 +6,7 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +# TODO since this is a library, we need to depend on actual published versions. actors-v10 = { package = "fil_builtin_actors_bundle", git = "https://github.com/filecoin-project/builtin-actors", rev = "c5cbd5b" } fvm_ipld_blockstore = { git = "https://github.com/filecoin-project/ref-fvm.git", version = "0.1.1" } fvm_ipld_car = { git = "https://github.com/filecoin-project/ref-fvm.git", version = "0.6.0" } @@ -25,4 +26,4 @@ thiserror = "1.0.39" [dev-dependencies] wat = "1.0.51" -kythera_test_actors = { path = "../test_actors" } \ No newline at end of file +kythera_test_actors = { path = "../test_actors" } diff --git a/lib/src/error.rs b/lib/src/error.rs index 859593c..47758bf 100644 --- a/lib/src/error.rs +++ b/lib/src/error.rs @@ -2,8 +2,14 @@ // SPDX-License-Identifier: Apache-2.0, MIT /// Kythera lib errors. +use kythera_fvm::executor::ApplyFailure; + #[derive(Debug, thiserror::Error)] pub enum Error { + #[error("Constructor exit code was not ok")] + ConstructorError(Option), + #[error("SetUp exit code was not ok")] + SetUpError(Option), #[error("Main Actor not loaded")] MissingActor, #[error("Could not set Actor: {name} on the BlockStore")] diff --git a/lib/src/executor.rs b/lib/src/executor.rs new file mode 100644 index 0000000..97dbb13 --- /dev/null +++ b/lib/src/executor.rs @@ -0,0 +1,108 @@ +// Copyright 2023 Polyphene. +// SPDX-License-Identifier: Apache-2.0, MIT + +use cid::Cid; +use fvm_ipld_blockstore::MemoryBlockstore; +use fvm_ipld_encoding::RawBytes; +use fvm_shared::address::Address; +use fvm_shared::econ::TokenAmount; +use fvm_shared::message::Message; +use fvm_shared::version::NetworkVersion; +use fvm_shared::MethodNum; +use kythera_fvm::engine::EnginePool; +use kythera_fvm::executor::{ApplyRet, Executor as _}; +use kythera_fvm::machine::NetworkConfig; +use kythera_fvm::{ + executor::{ApplyKind, KytheraExecutor}, + externs::FakeExterns, + machine::{KytheraMachine, Machine}, +}; + +use crate::error::{Error, WrapFVMError}; + +const NETWORK_VERSION: NetworkVersion = NetworkVersion::V18; +const DEFAULT_BASE_FEE: u64 = 100; + +/// Wrapper around `fvm` Executor with sane defaults. +pub struct Executor { + inner: KytheraExecutor, + account_address: Address, + test_address: Address, + target_actor_id: RawBytes, +} + +impl Executor { + /// Create a new `Executor`. + pub fn new( + blockstore: MemoryBlockstore, + state_root: Cid, + builtin_actors: Cid, + account_address: Address, + test_address: Address, + target_actor_id: RawBytes, + ) -> Executor { + let mut nc = NetworkConfig::new(NETWORK_VERSION); + nc.override_actors(builtin_actors); + nc.enable_actor_debugging(); + + let mut mc = nc.for_epoch(0, 0, state_root); + mc.set_base_fee(TokenAmount::from_atto(DEFAULT_BASE_FEE)) + .enable_tracing(); + + let code_cids = vec![]; + + let engine = EnginePool::new_default((&mc.network.clone()).into()) + .expect("Should be able to start EnginePool"); + engine + .acquire() + .preload(&blockstore, &code_cids) + .expect("Should be able to preload Executor"); + + let machine = KytheraMachine::new(&mc, blockstore, FakeExterns::new()) + .expect("Should be able to start KytheraMachine"); + + Self { + inner: KytheraExecutor::new(engine, machine).expect("Should be able to start Executor"), + account_address, + test_address, + target_actor_id, + } + } + + /// Execute the provided method. + pub fn execute_method( + &mut self, + method_num: MethodNum, + sequence: u64, + ) -> Result { + let message = Message { + from: self.account_address, + to: self.test_address, + gas_limit: 1000000000, + method_num, + params: self.target_actor_id.clone().into(), + sequence, + ..Message::default() + }; + + self.inner + .execute_message(message, ApplyKind::Explicit, 100) + .tester_err("Could not execute message") + } + + /// Convert the executor back into a [`Blockstore`]. + pub fn into_store(mut self) -> (Cid, MemoryBlockstore) { + let root = self + .inner + .flush() + .expect("Should be able to flush Executor"); + + let blockstore = self + .inner + .into_machine() + .expect("Machine should exist at this point") + .into_store() + .into_inner(); + (root, blockstore) + } +} diff --git a/lib/src/lib.rs b/lib/src/lib.rs index f95b22d..d85a730 100644 --- a/lib/src/lib.rs +++ b/lib/src/lib.rs @@ -1,37 +1,24 @@ -use std::sync::mpsc::Sender; - // Copyright 2023 Polyphene. // SPDX-License-Identifier: Apache-2.0, MIT -use cid::Cid; +use executor::Executor; pub use kythera_common::{ abi::{pascal_case_split, Abi, Method, MethodType}, from_slice, to_vec, }; -use kythera_fvm::{ - engine::EnginePool, - executor::{ApplyKind, ApplyRet, Executor, KytheraExecutor}, - externs::FakeExterns, - machine::{KytheraMachine, Machine, NetworkConfig}, - Account, -}; +use kythera_fvm::{executor::ApplyRet, Account}; +use std::sync::mpsc::Sender; -use fvm_ipld_blockstore::Blockstore; -use fvm_shared::{ - address::Address, bigint::Zero, econ::TokenAmount, error::ExitCode, message::Message, - version::NetworkVersion, -}; +use fvm_shared::{address::Address, bigint::Zero, econ::TokenAmount, error::ExitCode}; -use error::{Error, WrapFVMError}; +use error::Error; use state_tree::{BuiltInActors, StateTree}; mod error; +mod executor; mod state_tree; -const NETWORK_VERSION: NetworkVersion = NetworkVersion::V18; -const DEFAULT_BASE_FEE: u64 = 100; - /// Main interface to test `Actor`s with Kythera. pub struct Tester { // Builtin actors root Cid used in the Machine @@ -42,6 +29,8 @@ pub struct Tester { account: Account, // The Target Actor to be tested. target_actor: Option, + // The Method message sequence number. + sequence: u64, } /// WebAssembly Actor. @@ -136,38 +125,10 @@ impl Tester { state_tree, account, target_actor: None, + sequence: 0, } } - /// Create a new `Executor` to test the provided test Actor. - fn new_executor( - blockstore: B, - state_root: Cid, - builtin_actors: Cid, - ) -> KytheraExecutor { - let mut nc = NetworkConfig::new(NETWORK_VERSION); - nc.override_actors(builtin_actors); - nc.enable_actor_debugging(); - - let mut mc = nc.for_epoch(0, 0, state_root); - mc.set_base_fee(TokenAmount::from_atto(DEFAULT_BASE_FEE)) - .enable_tracing(); - - let code_cids = vec![]; - - let engine = EnginePool::new_default((&mc.network.clone()).into()) - .expect("Should be able to start EnginePool"); - engine - .acquire() - .preload(&blockstore, &code_cids) - .expect("Should be able to preload Executor"); - - let machine = KytheraMachine::new(&mc, blockstore, FakeExterns::new()) - .expect("Should be able to start KytheraMachine"); - - KytheraExecutor::new(engine, machine).expect("Should be able to start Executor") - } - /// Deploy the target Actor file into the `StateTree`. pub fn deploy_target_actor(&mut self, actor: WasmActor) -> Result<(), Error> { let address = self @@ -181,6 +142,13 @@ impl Tester { Ok(()) } + // Get and increment the next Actor sequence. + pub fn next_sequence(&mut self) -> u64 { + let sequence = self.sequence; + self.sequence = sequence + 1; + sequence + } + /// Test an Actor on a `MemoryBlockstore`. /// TODO: Instead of accepting `stream_results` as a channel that we then yield each result, /// Should we make `test` return an iterator that yields each result by default? @@ -224,30 +192,24 @@ impl Tester { let root = self.state_tree.flush(); let blockstore = self.state_tree.store().clone(); - let mut executor = Self::new_executor(blockstore, root, self.builtin_actors.root); + let mut executor = Executor::new( + blockstore, + root, + self.builtin_actors.root, + self.account.1, + test_address, + target_id.clone().into(), + ); // Run the constructor if it exists. if let Some(constructor) = test_actor.abi().constructor() { - let message = Message { - from: self.account.1, - to: test_address, - gas_limit: 1000000000, - method_num: constructor.number(), - params: target_id.clone().into(), - ..Message::default() - }; - - match executor - .execute_message(message, ApplyKind::Explicit, 100) - .setting_err("Could not run Constructor") - { + match executor.execute_method(constructor.number(), self.next_sequence()) { Ok(apply_ret) => { if apply_ret.msg_receipt.exit_code != ExitCode::OK { - // TODO we should properly handle constructor not running by returning - // directly. We need to pass the apply ret there but constructor is not a - // test. This will have to be figured out how. Anyway apply ret of constructor - // should be returned. - panic!("Constructor should run") + return TestActorResults { + test_actor, + results: Err(Error::ConstructorError(apply_ret.failure_info)), + }; } } Err(err) => { @@ -259,37 +221,30 @@ impl Tester { } } - // Run SetUp if it exists. + // Run Setup if it exists. if let Some(set_up) = test_actor.abi().set_up() { - let message = Message { - from: self.account.1, - to: test_address, - gas_limit: 1000000000, - method_num: set_up.number(), - params: target_id.clone().into(), - sequence: 1, - ..Message::default() - }; - if let Err(err) = executor - .execute_message(message, ApplyKind::Explicit, 100) - .setting_err("Could not run SetUp") - { - return TestActorResults { - test_actor, - results: Err(err), - }; + match executor.execute_method(set_up.number(), self.next_sequence()) { + Ok(apply_ret) => { + if apply_ret.msg_receipt.exit_code != ExitCode::OK { + return TestActorResults { + test_actor, + results: Err(Error::SetUpError(apply_ret.failure_info)), + }; + } + } + Err(err) => { + return TestActorResults { + test_actor, + results: Err(err), + } + } } } - let root = executor - .flush() - .expect("Should be able to flush the executor"); + let (root, blockstore) = executor.into_store(); - let blockstore = executor - .into_machine() - .expect("Machine should exist at this point") - .into_store() - .into_inner(); + // Increment the sequence for the methods tests. + let sequence = self.next_sequence(); // TODO concurrent testing // We'll be able to use thread to do concurrent testing once we set the Engine Pool with more than @@ -304,32 +259,24 @@ impl Tester { .methods .iter() .map(|method| { - let mut executor = Self::new_executor( + // TODO is it possible to impl `Clone` for `DefaultExecutor` + // and submit PR upstream to implement with it? + let mut executor = Executor::new( blockstore.clone(), root, self.builtin_actors.root, + self.account.1, + test_address, + target_id.clone().into(), ); - let message = Message { - from: self.account.1, - to: test_address, - gas_limit: 1000000000, - method_num: method.number(), - params: target_id.clone().into(), - // TODO sequence hard coded here for constructor test to work. This should be dynamic - // based on previous messages (1 if either constructor or setup is called, 2 if both have been called) - sequence: 1, - ..Message::default() - }; - log::info!( "Testing test {}.{}() for Actor {}", test_actor.name, method.name(), target.name ); - let message = - executor.execute_message(message, ApplyKind::Explicit, 100); + let message = executor.execute_method(method.number(), sequence); let ret = match message { Ok(apply_ret) => { @@ -369,8 +316,12 @@ impl Default for Tester { #[cfg(test)] mod tests { + use fvm_ipld_blockstore::Blockstore; use fvm_shared::error::ExitCode; - use kythera_test_actors::wasm_bin::{BASIC_TEST_ACTOR_BINARY, CONSTRUCTOR_TEST_ACTOR_BINARY}; + use kythera_test_actors::wasm_bin::{ + BASIC_TEST_ACTOR_BINARY, CONSTRUCTOR_SETUP_TEST_ACTOR_BINARY, + CONSTRUCTOR_TEST_ACTOR_BINARY, SETUP_TEST_ACTOR_BINARY, + }; use super::*; use kythera_common::abi::{Abi, Method}; @@ -559,10 +510,9 @@ mod tests { panic!("Could not run test when testing Tester") } Ok(test_res) => { - assert_eq!(test_res.len(), 1usize); - assert_eq!(test_res[0].results.as_ref().unwrap().len(), 1usize); + assert_eq!(test_res.len(), 1); + assert_eq!(test_res[0].results.as_ref().unwrap().len(), 1); assert_eq!(test_res[0].test_actor, &test_actor); - dbg!(&test_res[0].results); test_res[0] .results .as_ref() @@ -572,7 +522,119 @@ mod tests { (MethodType::Test, TestResultType::Passed(apply_ret)) => { assert_eq!(apply_ret.msg_receipt.exit_code, ExitCode::OK); } - _ => panic!("test against basic test actor should pass"), + apply_ret => { + panic!("test against basic test actor should pass: {apply_ret:?}") + } + }) + } + } + } + + #[test] + fn test_set_up_called() { + // Instantiate tester + let mut tester = Tester::new(); + + // Set target actor + let target_wasm_bin = wat::parse_str(TARGET_WAT).unwrap(); + let target_abi = Abi { + constructor: None, + set_up: None, + methods: vec![], + }; + let target_actor = WasmActor::new(String::from("Target"), target_wasm_bin, target_abi); + + // Set test actor + let test_wasm_bin: Vec = Vec::from(SETUP_TEST_ACTOR_BINARY); + let test_abi = Abi { + constructor: None, + set_up: Some(Method::new_from_name("Setup").unwrap()), + methods: vec![Method::new_from_name("TestSetup").unwrap()], + }; + let test_actor = WasmActor::new(String::from("Setup Test"), test_wasm_bin, test_abi); + + match tester.deploy_target_actor(target_actor) { + Err(_) => { + panic!("Could not set target Actor when testing if SetUp is properly called") + } + _ => {} + } + + match tester.test(&[test_actor.clone()], None) { + Err(_) => { + panic!("Could not run test when testing Tester") + } + Ok(test_res) => { + assert_eq!(test_res.len(), 1); + assert_eq!(test_res[0].results.as_ref().unwrap().len(), 1); + assert_eq!(test_res[0].test_actor, &test_actor); + test_res[0] + .results + .as_ref() + .unwrap() + .iter() + .for_each(|result| match (result.method().r#type(), result.ret()) { + (MethodType::Test, TestResultType::Passed(apply_ret)) => { + assert_eq!(apply_ret.msg_receipt.exit_code, ExitCode::OK); + } + apply_ret => { + panic!("test against basic test actor should pass: {apply_ret:?}") + } + }) + } + } + } + + #[test] + fn test_constructor_and_set_up_called() { + // Instantiate tester + let mut tester = Tester::new(); + + // Set target actor + let target_wasm_bin = wat::parse_str(TARGET_WAT).unwrap(); + let target_abi = Abi { + constructor: None, + set_up: None, + methods: vec![], + }; + let target_actor = WasmActor::new(String::from("Target"), target_wasm_bin, target_abi); + + // Set test actor + let test_wasm_bin: Vec = Vec::from(CONSTRUCTOR_SETUP_TEST_ACTOR_BINARY); + let test_abi = Abi { + constructor: Some(Method::new_from_name("Constructor").unwrap()), + set_up: Some(Method::new_from_name("Setup").unwrap()), + methods: vec![Method::new_from_name("TestConstructorSetup").unwrap()], + }; + let test_actor = WasmActor::new(String::from("Constructor Test"), test_wasm_bin, test_abi); + + match tester.deploy_target_actor(target_actor) { + Err(_) => { + panic!("Could not set target Actor when testing if Constructor is properly called") + } + _ => {} + } + + match tester.test(&[test_actor.clone()], None) { + Err(_) => { + panic!("Could not run test when testing Tester") + } + Ok(test_res) => { + assert_eq!(test_res.len(), 1); + assert_eq!(test_res[0].results.as_ref().unwrap().len(), 1); + assert_eq!(test_res[0].test_actor, &test_actor); + test_res[0] + .results + .as_ref() + .unwrap() + .iter() + .for_each(|result| match (result.method().r#type(), result.ret()) { + (MethodType::Test, TestResultType::Passed(apply_ret)) => { + assert_eq!(apply_ret.msg_receipt.exit_code, ExitCode::OK); + } + apply_ret => { + panic!("test against basic test actor should pass: {apply_ret:?}") + } }) } } diff --git a/test_actors/actors/constructor_setup_test_actor/Cargo.toml b/test_actors/actors/constructor_setup_test_actor/Cargo.toml new file mode 100644 index 0000000..cd6e90e --- /dev/null +++ b/test_actors/actors/constructor_setup_test_actor/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "constructor_setup_test_actor" +version = "0.1.0" +edition = "2021" +publish=false + +[target.'cfg(target_arch = "wasm32")'.dependencies] +cid = { version = "0.8.5", default-features = false } +fvm_ipld_blockstore = { git = "https://github.com/filecoin-project/ref-fvm.git", version = "0.1.1" } +fvm_sdk = { git = "https://github.com/filecoin-project/ref-fvm.git", version = "3.0.0" } +fvm_shared = { git = "https://github.com/filecoin-project/ref-fvm.git", version = "3.1.0" } +fvm_ipld_encoding = { git = "https://github.com/filecoin-project/ref-fvm.git", version = "0.3.3" } +serde = { version = "1.0.136", features = ["derive"] } +serde_tuple = { version = "0.5.0" } + +[lib] +crate-type = ["cdylib"] diff --git a/test_actors/actors/constructor_setup_test_actor/README.md b/test_actors/actors/constructor_setup_test_actor/README.md new file mode 100644 index 0000000..621e68c --- /dev/null +++ b/test_actors/actors/constructor_setup_test_actor/README.md @@ -0,0 +1,3 @@ +## Constructor Setup Test Actor + +This is an actor to test that constructor and setup are being properly called in Kythera testing framework. diff --git a/test_actors/actors/constructor_setup_test_actor/src/actor.rs b/test_actors/actors/constructor_setup_test_actor/src/actor.rs new file mode 100644 index 0000000..9936fc4 --- /dev/null +++ b/test_actors/actors/constructor_setup_test_actor/src/actor.rs @@ -0,0 +1,84 @@ +// Copyright 2023 Polyphene. +// SPDX-License-Identifier: Apache-2.0, MIT + +use cid::{multihash::Code, Cid}; +use fvm_ipld_blockstore::Block; +use fvm_ipld_encoding::tuple::{Deserialize_tuple, Serialize_tuple}; +use fvm_ipld_encoding::DAG_CBOR; +use fvm_sdk as sdk; +use fvm_sdk::NO_DATA_BLOCK_ID; +use fvm_shared::error::ExitCode; + +#[derive(Serialize_tuple, Deserialize_tuple)] +struct TestConstructorSetupActorState { + value: u32, +} + +impl TestConstructorSetupActorState { + pub fn load(cid: &Cid) -> Self { + let data = sdk::ipld::get(cid).unwrap(); + fvm_ipld_encoding::from_slice::(&data).unwrap() + } + + pub fn save(&self) -> Cid { + let serialized = fvm_ipld_encoding::to_vec(self).unwrap(); + let block = Block { + codec: DAG_CBOR, + data: serialized, + }; + sdk::ipld::put( + Code::Blake2b256.into(), + 32, + block.codec, + block.data.as_ref(), + ) + .unwrap() + } +} + +// TODO use helix frc42_dispatch when their dependencies are up to date. +#[no_mangle] +fn invoke(_input: u32) -> u32 { + let method_num = sdk::message::method_number(); + match method_num { + 1 => Constructor(), + 3556852554 => Setup(), + 3654954405 => TestConstructorSetup(), + method => { + sdk::vm::abort( + ExitCode::USR_UNHANDLED_MESSAGE.value(), + Some(&format!("Unknown method number: {method}")), + ); + } + } + + NO_DATA_BLOCK_ID +} + +#[allow(non_snake_case)] +fn Constructor() { + let state = TestConstructorSetupActorState { value: 1 }; + let cid = state.save(); + fvm_sdk::sself::set_root(&cid).unwrap(); +} + +#[allow(non_snake_case)] +fn Setup() { + let state = TestConstructorSetupActorState::load(&sdk::sself::root().unwrap()); + let value = state.value + 1; + let state = TestConstructorSetupActorState { value }; + let cid = state.save(); + fvm_sdk::sself::set_root(&cid).unwrap(); +} + +#[allow(non_snake_case)] +fn TestConstructorSetup() { + let state = TestConstructorSetupActorState::load(&sdk::sself::root().unwrap()); + let value = state.value; + if state.value != 2u32 { + sdk::vm::abort( + ExitCode::USR_ASSERTION_FAILED.value(), + Some(&format!("value is different was not called {value}")), + ) + } +} diff --git a/test_actors/actors/constructor_setup_test_actor/src/lib.rs b/test_actors/actors/constructor_setup_test_actor/src/lib.rs new file mode 100644 index 0000000..6662b42 --- /dev/null +++ b/test_actors/actors/constructor_setup_test_actor/src/lib.rs @@ -0,0 +1,5 @@ +// Copyright 2023 Polyphene. +// SPDX-License-Identifier: Apache-2.0, MIT + +#[cfg(target_arch = "wasm32")] +mod actor; diff --git a/test_actors/build.rs b/test_actors/build.rs index dd12abc..ee6a770 100644 --- a/test_actors/build.rs +++ b/test_actors/build.rs @@ -10,6 +10,7 @@ const ACTORS: &[&str] = &[ "basic_test_actor", "constructor_test_actor", "setup_test_actor", + "constructor_setup_test_actor", ]; fn main() -> Result<(), Box> { diff --git a/test_actors/src/wasm_bin/mod.rs b/test_actors/src/wasm_bin/mod.rs index 891dcbc..c05af44 100644 --- a/test_actors/src/wasm_bin/mod.rs +++ b/test_actors/src/wasm_bin/mod.rs @@ -1,6 +1,6 @@ // Copyright 2023 Polyphene. // SPDX-License-Identifier: Apache-2.0, MIT -// constants for wasm build artifacts +// Constants for wasm build artifacts. macro_rules! wasm_bin { ($x: expr) => { @@ -18,3 +18,5 @@ pub const BASIC_TEST_ACTOR_BINARY: &[u8] = include_bytes!(wasm_bin!("basic_test_ pub const CONSTRUCTOR_TEST_ACTOR_BINARY: &[u8] = include_bytes!(wasm_bin!("constructor_test_actor")); pub const SETUP_TEST_ACTOR_BINARY: &[u8] = include_bytes!(wasm_bin!("setup_test_actor")); +pub const CONSTRUCTOR_SETUP_TEST_ACTOR_BINARY: &[u8] = + include_bytes!(wasm_bin!("constructor_setup_test_actor")); From ab0ebd8e038bc3957492183b3a0db6c9fafbc216 Mon Sep 17 00:00:00 2001 From: tchataigner Date: Fri, 7 Apr 2023 08:31:45 +0200 Subject: [PATCH 17/38] Update test_actors/actors/builtins_test_actor/src/actor.rs Co-authored-by: PhilippeMts <1371613+PhilippeMts@users.noreply.github.com> --- test_actors/actors/builtins_test_actor/src/actor.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/test_actors/actors/builtins_test_actor/src/actor.rs b/test_actors/actors/builtins_test_actor/src/actor.rs index 819a94f..4bc9251 100644 --- a/test_actors/actors/builtins_test_actor/src/actor.rs +++ b/test_actors/actors/builtins_test_actor/src/actor.rs @@ -13,7 +13,6 @@ use fvm_sdk::actor::{get_actor_code_cid, get_builtin_actor_type}; use fvm_sdk::NO_DATA_BLOCK_ID; use fvm_shared::error::ExitCode; -// TODO use helix frc42_dispatch when their dependencies are up to date. #[no_mangle] fn invoke(_input: u32) -> u32 { std::panic::set_hook(Box::new(|info| { From 84177e242fb0457ddd7cb82e2727b3814f64ebba Mon Sep 17 00:00:00 2001 From: tchataigner Date: Fri, 7 Apr 2023 08:32:08 +0200 Subject: [PATCH 18/38] Update lib/tests/lib.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: João Oliveira --- lib/tests/lib.rs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/lib/tests/lib.rs b/lib/tests/lib.rs index 2f63eff..03c1f4a 100644 --- a/lib/tests/lib.rs +++ b/lib/tests/lib.rs @@ -33,12 +33,7 @@ fn test_builtin_deployed() { test_abi, ); - match tester.deploy_target_actor(target_actor) { - Err(_) => { - panic!("Could not set target Actor when testing if builtins are properly deployed") - } - _ => {} - } + tester.deploy_target_actor(target_actor).expect("Could not set target Actor when testing if builtins are properly deployed"); // Run test match tester.test(&[test_actor.clone()], None) { From 089d096e73e288cf8648236c16e2566a4c07f023 Mon Sep 17 00:00:00 2001 From: Thomas Chataigner Date: Fri, 7 Apr 2023 08:51:34 +0200 Subject: [PATCH 19/38] fix(builtins): refactor test code --- common/Cargo.toml | 2 +- lib/src/lib.rs | 74 -------------------------------------------- lib/tests/lib.rs | 78 +++++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 73 insertions(+), 81 deletions(-) diff --git a/common/Cargo.toml b/common/Cargo.toml index 16c65df..f957a8e 100644 --- a/common/Cargo.toml +++ b/common/Cargo.toml @@ -9,7 +9,7 @@ edition = "2021" anyhow = "1.0.70" blake2b_simd = { version = "1.0.0" } frc42_dispatch = "3.1.0" -fvm_ipld_encoding = { git = "https://github.com/filecoin-project/ref-fvm.git", version = "0.3.3" } +fvm_ipld_encoding = { version = "0.3.3" } serde = { version = "1.0.136", features = ["derive"] } serde_tuple = { version = "0.5.0" } thiserror = "1.0.40" \ No newline at end of file diff --git a/lib/src/lib.rs b/lib/src/lib.rs index 8b7db4a..85989d2 100644 --- a/lib/src/lib.rs +++ b/lib/src/lib.rs @@ -300,20 +300,7 @@ impl Default for Tester { #[cfg(test)] mod tests { - use fvm_shared::error::ExitCode; - use kythera_test_actors::wasm_bin::BASIC_TEST_ACTOR_BINARY; - use super::*; - use kythera_common::abi::{Abi, Method}; - - const TARGET_WAT: &str = r#" - ;; Mock invoke function - (module - (func (export "invoke") (param $x i32) (result i32) - (i32.const 1) - ) - ) - "#; #[test] fn test_tester_instantiation() { @@ -388,65 +375,4 @@ mod tests { assert!(tester.target_actor.is_none()); } - - #[test] - fn test_tester_test() { - // Instantiate tester - let mut tester = Tester::new(); - - // Set target actor - let target_wasm_bin = wat::parse_str(TARGET_WAT).unwrap(); - let target_abi = Abi { methods: vec![] }; - let target_actor = WasmActor::new(String::from("Target"), target_wasm_bin, target_abi); - - // Set test actor - let test_wasm_bin: Vec = Vec::from(BASIC_TEST_ACTOR_BINARY); - let test_abi = Abi { - methods: vec![ - Method::new_from_name("TestOne").unwrap(), - Method::new_from_name("TestTwo").unwrap(), - ], - }; - let test_actor = WasmActor::new(String::from("Basic"), test_wasm_bin, test_abi); - - match tester.deploy_target_actor(target_actor) { - Err(_) => { - panic!("Could not set target Actor when testing Tester") - } - _ => {} - } - - match tester.test(&[test_actor.clone()], None) { - Err(_) => { - panic!("Could not run test when testing Tester") - } - Ok(test_res) => { - assert_eq!(test_res.len(), 1usize); - assert_eq!(test_res[0].results.as_ref().unwrap().len(), 2usize); - assert_eq!(test_res[0].test_actor, &test_actor); - - test_res[0] - .results - .as_ref() - .unwrap() - .iter() - .enumerate() - .for_each( - |(i, result)| match (result.method().r#type(), result.ret()) { - (MethodType::Test, TestResultType::Passed(apply_ret)) => { - assert_eq!(apply_ret.msg_receipt.exit_code, ExitCode::OK); - let ret_value: String = - apply_ret.msg_receipt.return_data.deserialize().unwrap(); - if i == 0usize { - assert_eq!(ret_value, String::from("TestOne")) - } else { - assert_eq!(ret_value, String::from("TestTwo")) - } - } - _ => panic!("test against basic test actor should pass"), - }, - ) - } - } - } } diff --git a/lib/tests/lib.rs b/lib/tests/lib.rs index 03c1f4a..001218e 100644 --- a/lib/tests/lib.rs +++ b/lib/tests/lib.rs @@ -1,7 +1,7 @@ use fvm_shared::error::ExitCode; use kythera_common::abi::{Abi, Method, MethodType}; use kythera_lib::{TestResultType, Tester, WasmActor}; -use kythera_test_actors::wasm_bin::BUILTIN_TEST_ACTOR_BINARY; +use kythera_test_actors::wasm_bin::{BASIC_TEST_ACTOR_BINARY, BUILTIN_TEST_ACTOR_BINARY}; const TARGET_WAT: &str = r#" ;; Mock invoke function @@ -12,15 +12,83 @@ const TARGET_WAT: &str = r#" ) "#; +fn set_target_actor(test: &mut Tester, name: String, binary: Vec, abi: Abi) { + let target_actor = WasmActor::new(name, binary, abi); + + tester + .deploy_target_actor(target_actor) + .expect("Could not set target Actor when testing if builtins are properly deployed"); +} + +#[test] +fn test_tester_test() { + // Instantiate tester + let mut tester = Tester::new(); + + // Set target actor + set_target_actor( + &mut tester, + String::from("Target"), + wat::parse_str(TARGET_WAT).unwrap(), + Abi { methods: vec![] }, + ); + + // Set test actor + let test_wasm_bin: Vec = Vec::from(BASIC_TEST_ACTOR_BINARY); + let test_abi = Abi { + methods: vec![ + Method::new_from_name("TestOne").unwrap(), + Method::new_from_name("TestTwo").unwrap(), + ], + }; + let test_actor = WasmActor::new(String::from("Basic"), test_wasm_bin, test_abi); + + match tester.test(&[test_actor.clone()], None) { + Err(_) => { + panic!("Could not run test when testing Tester") + } + Ok(test_res) => { + assert_eq!(test_res.len(), 1usize); + assert_eq!(test_res[0].results.as_ref().unwrap().len(), 2usize); + assert_eq!(test_res[0].test_actor, &test_actor); + + test_res[0] + .results + .as_ref() + .unwrap() + .iter() + .enumerate() + .for_each( + |(i, result)| match (result.method().r#type(), result.ret()) { + (MethodType::Test, TestResultType::Passed(apply_ret)) => { + assert_eq!(apply_ret.msg_receipt.exit_code, ExitCode::OK); + let ret_value: String = + apply_ret.msg_receipt.return_data.deserialize().unwrap(); + if i == 0usize { + assert_eq!(ret_value, String::from("TestOne")) + } else { + assert_eq!(ret_value, String::from("TestTwo")) + } + } + _ => panic!("test against basic test actor should pass"), + }, + ) + } + } +} + #[test] fn test_builtin_deployed() { // Instantiate tester let mut tester = Tester::new(); // Set target actor - let target_wasm_bin = wat::parse_str(TARGET_WAT).unwrap(); - let target_abi = Abi { methods: vec![] }; - let target_actor = WasmActor::new(String::from("Target"), target_wasm_bin, target_abi); + set_target_actor( + &mut tester, + String::from("Target"), + wat::parse_str(TARGET_WAT).unwrap(), + Abi { methods: vec![] }, + ); // Set test actor let test_wasm_bin: Vec = Vec::from(BUILTIN_TEST_ACTOR_BINARY); @@ -33,8 +101,6 @@ fn test_builtin_deployed() { test_abi, ); - tester.deploy_target_actor(target_actor).expect("Could not set target Actor when testing if builtins are properly deployed"); - // Run test match tester.test(&[test_actor.clone()], None) { Err(_) => { From 409e736525ac0db3a92e1445836a68e4c3aeb9fd Mon Sep 17 00:00:00 2001 From: Thomas Chataigner Date: Fri, 7 Apr 2023 08:53:21 +0200 Subject: [PATCH 20/38] fix(builtins): fixed typo in variable --- Cargo.lock | 200 +++++++++++++++++++++-------------------------- lib/tests/lib.rs | 2 +- 2 files changed, 88 insertions(+), 114 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d95425f..288b4ab 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -291,7 +291,7 @@ name = "basic_test_actor" version = "0.1.0" dependencies = [ "frc42_dispatch", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_encoding 0.3.3", "fvm_sdk 3.0.0", "fvm_shared 3.1.0", "serde", @@ -492,7 +492,7 @@ version = "0.1.0" dependencies = [ "fil_actors_runtime_v10", "frc42_dispatch", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_encoding 0.3.3", "fvm_sdk 3.0.0", "fvm_shared 3.1.0", "serde", @@ -1268,8 +1268,8 @@ dependencies = [ "fil_actors_runtime", "frc42_dispatch", "fvm_actor_utils 5.0.0", - "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_blockstore", + "fvm_ipld_encoding 0.3.3", "fvm_shared 3.1.0", "num-derive", "num-traits", @@ -1283,7 +1283,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719246afbe4fef6c3a4cf1eacbc40d915aca7d8259b0fe0bda34d9e9e92d0f7d" dependencies = [ "frc42_dispatch", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_encoding 0.3.3", "fvm_shared 3.1.0", "num-derive", "num-traits", @@ -1301,9 +1301,9 @@ dependencies = [ "cid", "clap 3.2.23", "futures", - "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_blockstore", "fvm_ipld_car", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_encoding 0.3.3", "serde", "serde_ipld_dagcbor", "serde_json", @@ -1315,8 +1315,8 @@ version = "10.0.0" source = "git+https://github.com/filecoin-project/builtin-actors?rev=39571e2#39571e25eacd51326c9fc8e29d4b69943f15a3b1" dependencies = [ "fil_actors_runtime", - "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_blockstore", + "fvm_ipld_encoding 0.3.3", "fvm_shared 3.1.0", "log", "num-derive", @@ -1330,7 +1330,7 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9dc95d44e5b1b9fe02196c75c7443426f255af398a1f96da888482bf33b2fef4" dependencies = [ - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_encoding 0.3.3", "fvm_shared 3.1.0", "num-derive", "num-traits", @@ -1347,8 +1347,8 @@ dependencies = [ "frc42_dispatch", "frc46_token 5.0.0", "fvm_actor_utils 5.0.0", - "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_blockstore", + "fvm_ipld_encoding 0.3.3", "fvm_ipld_hamt 0.6.1", "fvm_shared 3.1.0", "lazy_static", @@ -1367,8 +1367,8 @@ dependencies = [ "fil_actors_runtime_v10", "frc42_dispatch", "frc46_token 3.1.0", - "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_blockstore", + "fvm_ipld_encoding 0.3.3", "fvm_shared 3.1.0", "num-derive", "num-traits", @@ -1384,8 +1384,8 @@ dependencies = [ "cid", "fil_actors_evm_shared", "fil_actors_runtime", - "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_blockstore", + "fvm_ipld_encoding 0.3.3", "fvm_shared 3.1.0", "hex-literal", "log", @@ -1405,7 +1405,7 @@ dependencies = [ "fil_actors_runtime", "frc42_dispatch", "fvm_actor_utils 5.0.0", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_encoding 0.3.3", "fvm_shared 3.1.0", "hex-literal", "num-derive", @@ -1435,8 +1435,8 @@ dependencies = [ "fil_actors_evm_shared", "fil_actors_runtime", "frc42_dispatch", - "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_blockstore", + "fvm_ipld_encoding 0.3.3", "fvm_ipld_kamt", "fvm_shared 3.1.0", "hex", @@ -1459,8 +1459,8 @@ dependencies = [ "cid", "fil_actors_runtime", "frc42_dispatch", - "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_blockstore", + "fvm_ipld_encoding 0.3.3", "fvm_ipld_hamt 0.6.1", "fvm_shared 3.1.0", "log", @@ -1478,8 +1478,8 @@ dependencies = [ "cid", "fil_actors_runtime_v10", "frc42_dispatch", - "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_blockstore", + "fvm_ipld_encoding 0.3.3", "fvm_shared 3.1.0", "num-derive", "num-traits", @@ -1497,8 +1497,8 @@ dependencies = [ "frc42_dispatch", "frc46_token 5.0.0", "fvm_ipld_bitfield", - "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_blockstore", + "fvm_ipld_encoding 0.3.3", "fvm_ipld_hamt 0.6.1", "fvm_shared 3.1.0", "integer-encoding", @@ -1518,8 +1518,8 @@ dependencies = [ "cid", "fil_actors_runtime_v10", "frc42_dispatch", - "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_blockstore", + "fvm_ipld_encoding 0.3.3", "fvm_ipld_hamt 0.6.1", "fvm_shared 3.1.0", "libipld-core 0.14.0", @@ -1540,8 +1540,8 @@ dependencies = [ "frc42_dispatch", "fvm_ipld_amt 0.5.1", "fvm_ipld_bitfield", - "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_blockstore", + "fvm_ipld_encoding 0.3.3", "fvm_ipld_hamt 0.6.1", "fvm_shared 3.1.0", "itertools 0.10.5", @@ -1565,8 +1565,8 @@ dependencies = [ "frc42_dispatch", "fvm_ipld_amt 0.5.1", "fvm_ipld_bitfield", - "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_blockstore", + "fvm_ipld_encoding 0.3.3", "fvm_ipld_hamt 0.6.1", "fvm_shared 3.1.0", "itertools 0.10.5", @@ -1587,8 +1587,8 @@ dependencies = [ "fil_actors_runtime", "frc42_dispatch", "fvm_actor_utils 5.0.0", - "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_blockstore", + "fvm_ipld_encoding 0.3.3", "fvm_ipld_hamt 0.6.1", "fvm_shared 3.1.0", "indexmap", @@ -1607,8 +1607,8 @@ dependencies = [ "cid", "fil_actors_runtime_v10", "frc42_dispatch", - "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_blockstore", + "fvm_ipld_encoding 0.3.3", "fvm_ipld_hamt 0.6.1", "fvm_shared 3.1.0", "indexmap", @@ -1627,8 +1627,8 @@ dependencies = [ "cid", "fil_actors_runtime", "frc42_dispatch", - "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_blockstore", + "fvm_ipld_encoding 0.3.3", "fvm_shared 3.1.0", "num-derive", "num-traits", @@ -1643,7 +1643,7 @@ checksum = "0b63acc144f0bb4df7006992e7e2e977fdc8171ae012697aadf5500e3b33c665" dependencies = [ "cid", "frc42_dispatch", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_encoding 0.3.3", "fvm_shared 3.1.0", "num-derive", "num-traits", @@ -1664,8 +1664,8 @@ dependencies = [ "cid", "fil_actors_runtime", "frc42_dispatch", - "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_blockstore", + "fvm_ipld_encoding 0.3.3", "fvm_ipld_hamt 0.6.1", "fvm_shared 3.1.0", "indexmap", @@ -1687,8 +1687,8 @@ dependencies = [ "cid", "fil_actors_runtime_v10", "frc42_dispatch", - "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_blockstore", + "fvm_ipld_encoding 0.3.3", "fvm_ipld_hamt 0.6.1", "fvm_shared 3.1.0", "integer-encoding", @@ -1704,8 +1704,8 @@ version = "10.0.0" source = "git+https://github.com/filecoin-project/builtin-actors?rev=39571e2#39571e25eacd51326c9fc8e29d4b69943f15a3b1" dependencies = [ "fil_actors_runtime", - "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_blockstore", + "fvm_ipld_encoding 0.3.3", "fvm_shared 3.1.0", "lazy_static", "log", @@ -1720,7 +1720,7 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f1db1f0dc4b3fe017179ff3e645aeaf8cf0ec2457bc67a89e7505802b87946ae" dependencies = [ - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_encoding 0.3.3", "fvm_shared 3.1.0", "lazy_static", "num-derive", @@ -1736,8 +1736,8 @@ dependencies = [ "anyhow", "cid", "fil_actors_runtime", - "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_blockstore", + "fvm_ipld_encoding 0.3.3", "fvm_shared 3.1.0", "num-derive", "num-traits", @@ -1751,7 +1751,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "38c10a8bb4b1b1d3c321dc52332d30fa967e61689fe715f639de10d3a0c9e65d" dependencies = [ "cid", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_encoding 0.3.3", "fvm_shared 2.3.0", "num-derive", "num-traits", @@ -1769,8 +1769,8 @@ dependencies = [ "frc42_dispatch", "frc46_token 5.0.0", "fvm_actor_utils 5.0.0", - "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_blockstore", + "fvm_ipld_encoding 0.3.3", "fvm_ipld_hamt 0.6.1", "fvm_shared 3.1.0", "lazy_static", @@ -1789,8 +1789,8 @@ dependencies = [ "cid", "fil_actors_runtime_v10", "frc42_dispatch", - "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_blockstore", + "fvm_ipld_encoding 0.3.3", "fvm_shared 3.1.0", "num-derive", "num-traits", @@ -1803,7 +1803,7 @@ version = "10.0.0" source = "git+https://github.com/filecoin-project/builtin-actors?rev=39571e2#39571e25eacd51326c9fc8e29d4b69943f15a3b1" dependencies = [ "fil_actors_runtime", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_encoding 0.3.3", "fvm_shared 3.1.0", "hex", "serde", @@ -1821,8 +1821,8 @@ dependencies = [ "cid", "fvm_ipld_amt 0.5.1", "fvm_ipld_bitfield", - "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_blockstore", + "fvm_ipld_encoding 0.3.3", "fvm_ipld_hamt 0.6.1", "fvm_sdk 3.0.0", "fvm_shared 3.1.0", @@ -1850,8 +1850,8 @@ dependencies = [ "anyhow", "cid", "fvm_ipld_amt 0.5.1", - "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_blockstore", + "fvm_ipld_encoding 0.3.3", "fvm_ipld_hamt 0.6.1", "fvm_shared 3.1.0", "multihash", @@ -2035,7 +2035,7 @@ checksum = "a4dc594c941eba1d5a9474f595c6d0f9d752fa333b672755bbe7c23d30f64282" dependencies = [ "frc42_hasher", "frc42_macros", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_encoding 0.3.3", "fvm_sdk 3.0.0", "fvm_shared 3.1.0", "thiserror", @@ -2076,7 +2076,7 @@ dependencies = [ "frc42_dispatch", "fvm_actor_utils 3.0.0", "fvm_ipld_amt 0.4.2", - "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_blockstore", "fvm_ipld_encoding 0.2.3", "fvm_ipld_hamt 0.5.1", "fvm_sdk 2.2.0", @@ -2099,8 +2099,8 @@ dependencies = [ "frc42_dispatch", "fvm_actor_utils 5.0.0", "fvm_ipld_amt 0.5.1", - "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_blockstore", + "fvm_ipld_encoding 0.3.3", "fvm_ipld_hamt 0.6.1", "fvm_sdk 3.0.0", "fvm_shared 3.1.0", @@ -2247,8 +2247,8 @@ dependencies = [ "filecoin-proofs-api", "fvm-wasm-instrument", "fvm_ipld_amt 0.5.1", - "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_blockstore", + "fvm_ipld_encoding 0.3.3", "fvm_ipld_hamt 0.6.1", "fvm_shared 3.1.0", "lazy_static", @@ -2293,7 +2293,7 @@ dependencies = [ "anyhow", "cid", "frc42_dispatch", - "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_blockstore", "fvm_ipld_encoding 0.2.3", "fvm_sdk 2.2.0", "fvm_shared 2.3.0", @@ -2312,8 +2312,8 @@ dependencies = [ "anyhow", "cid", "frc42_dispatch", - "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_blockstore", + "fvm_ipld_encoding 0.3.3", "fvm_sdk 3.0.0", "fvm_shared 3.1.0", "num-traits", @@ -2331,7 +2331,7 @@ dependencies = [ "ahash", "anyhow", "cid", - "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_blockstore", "fvm_ipld_encoding 0.2.3", "itertools 0.10.5", "once_cell", @@ -2347,8 +2347,8 @@ checksum = "e84f16d6927ce342ef86bd20fcc2d5bd498ed33ae6d7a22fea7a1b453488ec88" dependencies = [ "anyhow", "cid", - "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_blockstore", + "fvm_ipld_encoding 0.3.3", "itertools 0.10.5", "once_cell", "serde", @@ -2361,7 +2361,7 @@ version = "0.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d1950291f40d2d1047eb0a4568f7ef6d5b4973452dcef012dffb1957fe483ff7" dependencies = [ - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_encoding 0.3.3", "serde", "thiserror", "unsigned-varint", @@ -2378,16 +2378,6 @@ dependencies = [ "multihash", ] -[[package]] -name = "fvm_ipld_blockstore" -version = "0.1.1" -source = "git+https://github.com/filecoin-project/ref-fvm.git#458262d8b305cf212d9c51408beb5d616c499e93" -dependencies = [ - "anyhow", - "cid", - "multihash", -] - [[package]] name = "fvm_ipld_car" version = "0.6.0" @@ -2396,8 +2386,8 @@ checksum = "c60423568393a284de6d7c342cd664690611f27d223eb78629fa568ddd4e7951" dependencies = [ "cid", "futures", - "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_blockstore", + "fvm_ipld_encoding 0.3.3", "integer-encoding", "serde", "thiserror", @@ -2412,7 +2402,7 @@ dependencies = [ "anyhow", "cid", "cs_serde_bytes", - "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_blockstore", "multihash", "serde", "serde_ipld_dagcbor", @@ -2429,23 +2419,7 @@ checksum = "f0816a2a6df4853de08a723d261110d56a121aa313bc570fe9d248f0a4bc5288" dependencies = [ "anyhow", "cid", - "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "multihash", - "serde", - "serde_ipld_dagcbor", - "serde_repr", - "serde_tuple", - "thiserror", -] - -[[package]] -name = "fvm_ipld_encoding" -version = "0.3.3" -source = "git+https://github.com/filecoin-project/ref-fvm.git#458262d8b305cf212d9c51408beb5d616c499e93" -dependencies = [ - "anyhow", - "cid", - "fvm_ipld_blockstore 0.1.1 (git+https://github.com/filecoin-project/ref-fvm.git)", + "fvm_ipld_blockstore", "multihash", "serde", "serde_ipld_dagcbor", @@ -2465,7 +2439,7 @@ dependencies = [ "cid", "cs_serde_bytes", "forest_hash_utils", - "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_blockstore", "fvm_ipld_encoding 0.2.3", "libipld-core 0.13.1", "multihash", @@ -2485,8 +2459,8 @@ dependencies = [ "byteorder", "cid", "forest_hash_utils", - "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_blockstore", + "fvm_ipld_encoding 0.3.3", "libipld-core 0.14.0", "multihash", "once_cell", @@ -2505,8 +2479,8 @@ dependencies = [ "byteorder", "cid", "forest_hash_utils", - "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_blockstore", + "fvm_ipld_encoding 0.3.3", "multihash", "once_cell", "serde", @@ -2536,7 +2510,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2fef17308967cceb1d22f05003d60adb0d5b9ba53e34ace4ae04701eb7e6af02" dependencies = [ "cid", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_encoding 0.3.3", "fvm_shared 3.1.0", "lazy_static", "log", @@ -2557,7 +2531,7 @@ dependencies = [ "cs_serde_bytes", "data-encoding", "data-encoding-macro", - "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_blockstore", "fvm_ipld_encoding 0.2.3", "lazy_static", "log", @@ -2588,8 +2562,8 @@ dependencies = [ "data-encoding", "data-encoding-macro", "filecoin-proofs-api", - "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_blockstore", + "fvm_ipld_encoding 0.3.3", "lazy_static", "libsecp256k1", "log", @@ -2915,7 +2889,7 @@ dependencies = [ "anyhow", "blake2b_simd", "frc42_dispatch", - "fvm_ipld_encoding 0.3.3 (git+https://github.com/filecoin-project/ref-fvm.git)", + "fvm_ipld_encoding 0.3.3", "serde", "serde_tuple", "thiserror", @@ -2928,7 +2902,7 @@ dependencies = [ "anyhow", "cid", "fvm", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_encoding 0.3.3", "fvm_shared 3.1.0", "multihash", ] @@ -2954,9 +2928,9 @@ dependencies = [ "fil_actors_runtime_v10", "fil_builtin_actors_bundle", "futures", - "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_blockstore", "fvm_ipld_car", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_encoding 0.3.3", "fvm_shared 3.1.0", "kythera-common", "kythera-fvm", diff --git a/lib/tests/lib.rs b/lib/tests/lib.rs index 001218e..c65042e 100644 --- a/lib/tests/lib.rs +++ b/lib/tests/lib.rs @@ -12,7 +12,7 @@ const TARGET_WAT: &str = r#" ) "#; -fn set_target_actor(test: &mut Tester, name: String, binary: Vec, abi: Abi) { +fn set_target_actor(tester: &mut Tester, name: String, binary: Vec, abi: Abi) { let target_actor = WasmActor::new(name, binary, abi); tester From 039b80b16b51a4815e4047f29346991970600e10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Oliveira?= Date: Fri, 7 Apr 2023 12:40:55 +0100 Subject: [PATCH 21/38] lib: address Thomas review --- Cargo.lock | 14 +--- fvm/Cargo.toml | 2 +- {lib => fvm}/src/executor.rs | 35 ++++---- fvm/src/lib.rs | 13 +-- lib/Cargo.toml | 1 - lib/src/error.rs | 13 ++- lib/src/lib.rs | 80 ++++--------------- .../actors/setup_test_actor/Cargo.toml | 17 ---- test_actors/actors/setup_test_actor/README.md | 3 - .../actors/setup_test_actor/src/actor.rs | 73 ----------------- .../actors/setup_test_actor/src/lib.rs | 5 -- test_actors/build.rs | 1 - test_actors/src/wasm_bin/mod.rs | 1 - 13 files changed, 46 insertions(+), 212 deletions(-) rename {lib => fvm}/src/executor.rs (80%) delete mode 100644 test_actors/actors/setup_test_actor/Cargo.toml delete mode 100644 test_actors/actors/setup_test_actor/README.md delete mode 100644 test_actors/actors/setup_test_actor/src/actor.rs delete mode 100644 test_actors/actors/setup_test_actor/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index 22c2b84..e87b4ce 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2560,6 +2560,7 @@ dependencies = [ "anyhow", "cid", "fvm", + "fvm_ipld_blockstore 0.1.1 (git+https://github.com/filecoin-project/ref-fvm.git)", "fvm_ipld_encoding 0.3.3 (git+https://github.com/filecoin-project/ref-fvm.git)", "fvm_shared 3.1.0", "multihash", @@ -3504,19 +3505,6 @@ dependencies = [ "syn 1.0.109", ] -[[package]] -name = "setup_test_actor" -version = "0.1.0" -dependencies = [ - "cid", - "fvm_ipld_blockstore 0.1.1 (git+https://github.com/filecoin-project/ref-fvm.git)", - "fvm_ipld_encoding 0.3.3 (git+https://github.com/filecoin-project/ref-fvm.git)", - "fvm_sdk 3.0.0 (git+https://github.com/filecoin-project/ref-fvm.git)", - "fvm_shared 3.1.0", - "serde", - "serde_tuple", -] - [[package]] name = "sha2" version = "0.9.9" diff --git a/fvm/Cargo.toml b/fvm/Cargo.toml index 7276137..1a1e53c 100644 --- a/fvm/Cargo.toml +++ b/fvm/Cargo.toml @@ -8,8 +8,8 @@ edition = "2021" [dependencies] anyhow = "1.0.70" cid = { version = "0.8.5", default-features = false } -# TODO since this is a library, we need to depend on actual published versions. fvm = { git = "https://github.com/filecoin-project/ref-fvm.git", version = "3.1.0", default-features = false, features = ["testing"] } +fvm_ipld_blockstore = { git = "https://github.com/filecoin-project/ref-fvm.git", version = "0.1.1" } fvm_ipld_encoding = { git = "https://github.com/filecoin-project/ref-fvm.git", version = "0.3.3" } fvm_shared = { git = "https://github.com/filecoin-project/ref-fvm.git", version = "3.1.0" } multihash = { version = "0.16.1", default-features = false } diff --git a/lib/src/executor.rs b/fvm/src/executor.rs similarity index 80% rename from lib/src/executor.rs rename to fvm/src/executor.rs index 97dbb13..bb87423 100644 --- a/lib/src/executor.rs +++ b/fvm/src/executor.rs @@ -1,7 +1,17 @@ // Copyright 2023 Polyphene. // SPDX-License-Identifier: Apache-2.0, MIT +use crate::externs::FakeExterns; +use crate::machine::KytheraMachine; use cid::Cid; +use fvm::call_manager::DefaultCallManager; +use fvm::engine::EnginePool; +use fvm::executor::DefaultExecutor; +use fvm::DefaultKernel; + +pub use fvm::executor::Executor as _; +pub use fvm::executor::{ApplyFailure, ApplyKind, ApplyRet}; +use fvm::machine::{Machine, NetworkConfig}; use fvm_ipld_blockstore::MemoryBlockstore; use fvm_ipld_encoding::RawBytes; use fvm_shared::address::Address; @@ -9,29 +19,21 @@ use fvm_shared::econ::TokenAmount; use fvm_shared::message::Message; use fvm_shared::version::NetworkVersion; use fvm_shared::MethodNum; -use kythera_fvm::engine::EnginePool; -use kythera_fvm::executor::{ApplyRet, Executor as _}; -use kythera_fvm::machine::NetworkConfig; -use kythera_fvm::{ - executor::{ApplyKind, KytheraExecutor}, - externs::FakeExterns, - machine::{KytheraMachine, Machine}, -}; - -use crate::error::{Error, WrapFVMError}; const NETWORK_VERSION: NetworkVersion = NetworkVersion::V18; const DEFAULT_BASE_FEE: u64 = 100; /// Wrapper around `fvm` Executor with sane defaults. -pub struct Executor { - inner: KytheraExecutor, +pub struct KytheraExecutor { + inner: DefaultExecutor< + DefaultKernel>>, + >, account_address: Address, test_address: Address, target_actor_id: RawBytes, } -impl Executor { +impl KytheraExecutor { /// Create a new `Executor`. pub fn new( blockstore: MemoryBlockstore, @@ -40,7 +42,7 @@ impl Executor { account_address: Address, test_address: Address, target_actor_id: RawBytes, - ) -> Executor { + ) -> Self { let mut nc = NetworkConfig::new(NETWORK_VERSION); nc.override_actors(builtin_actors); nc.enable_actor_debugging(); @@ -62,7 +64,7 @@ impl Executor { .expect("Should be able to start KytheraMachine"); Self { - inner: KytheraExecutor::new(engine, machine).expect("Should be able to start Executor"), + inner: DefaultExecutor::new(engine, machine).expect("Should be able to start Executor"), account_address, test_address, target_actor_id, @@ -74,7 +76,7 @@ impl Executor { &mut self, method_num: MethodNum, sequence: u64, - ) -> Result { + ) -> Result { let message = Message { from: self.account_address, to: self.test_address, @@ -87,7 +89,6 @@ impl Executor { self.inner .execute_message(message, ApplyKind::Explicit, 100) - .tester_err("Could not execute message") } /// Convert the executor back into a [`Blockstore`]. diff --git a/fvm/src/lib.rs b/fvm/src/lib.rs index fe8fef7..eb3ffee 100644 --- a/fvm/src/lib.rs +++ b/fvm/src/lib.rs @@ -9,18 +9,7 @@ pub mod engine { pub use fvm::engine::EnginePool; } -pub mod executor { - use crate::machine::KytheraMachine; - use fvm::call_manager::DefaultCallManager; - use fvm::executor::DefaultExecutor; - use fvm::DefaultKernel; - - pub use fvm::executor::Executor; - pub use fvm::executor::{ApplyFailure, ApplyKind, ApplyRet}; - pub type KytheraExecutor = - DefaultExecutor>>>; -} - +pub mod executor; pub mod machine { pub use fvm::machine::{DefaultMachine as KytheraMachine, Machine, Manifest, NetworkConfig}; } diff --git a/lib/Cargo.toml b/lib/Cargo.toml index 9e3d754..647d170 100644 --- a/lib/Cargo.toml +++ b/lib/Cargo.toml @@ -6,7 +6,6 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -# TODO since this is a library, we need to depend on actual published versions. actors-v10 = { package = "fil_builtin_actors_bundle", git = "https://github.com/filecoin-project/builtin-actors", rev = "c5cbd5b" } fvm_ipld_blockstore = { git = "https://github.com/filecoin-project/ref-fvm.git", version = "0.1.1" } fvm_ipld_car = { git = "https://github.com/filecoin-project/ref-fvm.git", version = "0.6.0" } diff --git a/lib/src/error.rs b/lib/src/error.rs index 47758bf..548f7f3 100644 --- a/lib/src/error.rs +++ b/lib/src/error.rs @@ -2,14 +2,19 @@ // SPDX-License-Identifier: Apache-2.0, MIT /// Kythera lib errors. -use kythera_fvm::executor::ApplyFailure; #[derive(Debug, thiserror::Error)] pub enum Error { #[error("Constructor exit code was not ok")] - ConstructorError(Option), - #[error("SetUp exit code was not ok")] - SetUpError(Option), + ConstructorError { + #[source] + source: Option>, + }, + #[error("Setup exit code was not ok")] + SetupError { + #[source] + source: Option>, + }, #[error("Main Actor not loaded")] MissingActor, #[error("Could not set Actor: {name} on the BlockStore")] diff --git a/lib/src/lib.rs b/lib/src/lib.rs index d85a730..7e4e5db 100644 --- a/lib/src/lib.rs +++ b/lib/src/lib.rs @@ -1,13 +1,15 @@ // Copyright 2023 Polyphene. // SPDX-License-Identifier: Apache-2.0, MIT -use executor::Executor; pub use kythera_common::{ abi::{pascal_case_split, Abi, Method, MethodType}, from_slice, to_vec, }; -use kythera_fvm::{executor::ApplyRet, Account}; +use kythera_fvm::{ + executor::{ApplyRet, KytheraExecutor}, + Account, +}; use std::sync::mpsc::Sender; use fvm_shared::{address::Address, bigint::Zero, econ::TokenAmount, error::ExitCode}; @@ -16,7 +18,6 @@ use error::Error; use state_tree::{BuiltInActors, StateTree}; mod error; -mod executor; mod state_tree; /// Main interface to test `Actor`s with Kythera. @@ -192,7 +193,7 @@ impl Tester { let root = self.state_tree.flush(); let blockstore = self.state_tree.store().clone(); - let mut executor = Executor::new( + let mut executor = KytheraExecutor::new( blockstore, root, self.builtin_actors.root, @@ -206,16 +207,19 @@ impl Tester { match executor.execute_method(constructor.number(), self.next_sequence()) { Ok(apply_ret) => { if apply_ret.msg_receipt.exit_code != ExitCode::OK { + let source = apply_ret.failure_info.map(|f| f.to_string().into()); return TestActorResults { test_actor, - results: Err(Error::ConstructorError(apply_ret.failure_info)), + results: Err(Error::ConstructorError { source }), }; } } Err(err) => { return TestActorResults { test_actor, - results: Err(err), + results: Err(Error::ConstructorError { + source: Some(err.into()), + }), } } } @@ -226,16 +230,19 @@ impl Tester { match executor.execute_method(set_up.number(), self.next_sequence()) { Ok(apply_ret) => { if apply_ret.msg_receipt.exit_code != ExitCode::OK { + let source = apply_ret.failure_info.map(|f| f.to_string().into()); return TestActorResults { test_actor, - results: Err(Error::SetUpError(apply_ret.failure_info)), + results: Err(Error::SetupError { source }), }; } } Err(err) => { return TestActorResults { test_actor, - results: Err(err), + results: Err(Error::SetupError { + source: Some(err.into()), + }), } } } @@ -261,7 +268,7 @@ impl Tester { .map(|method| { // TODO is it possible to impl `Clone` for `DefaultExecutor` // and submit PR upstream to implement with it? - let mut executor = Executor::new( + let mut executor = KytheraExecutor::new( blockstore.clone(), root, self.builtin_actors.root, @@ -530,61 +537,6 @@ mod tests { } } - #[test] - fn test_set_up_called() { - // Instantiate tester - let mut tester = Tester::new(); - - // Set target actor - let target_wasm_bin = wat::parse_str(TARGET_WAT).unwrap(); - let target_abi = Abi { - constructor: None, - set_up: None, - methods: vec![], - }; - let target_actor = WasmActor::new(String::from("Target"), target_wasm_bin, target_abi); - - // Set test actor - let test_wasm_bin: Vec = Vec::from(SETUP_TEST_ACTOR_BINARY); - let test_abi = Abi { - constructor: None, - set_up: Some(Method::new_from_name("Setup").unwrap()), - methods: vec![Method::new_from_name("TestSetup").unwrap()], - }; - let test_actor = WasmActor::new(String::from("Setup Test"), test_wasm_bin, test_abi); - - match tester.deploy_target_actor(target_actor) { - Err(_) => { - panic!("Could not set target Actor when testing if SetUp is properly called") - } - _ => {} - } - - match tester.test(&[test_actor.clone()], None) { - Err(_) => { - panic!("Could not run test when testing Tester") - } - Ok(test_res) => { - assert_eq!(test_res.len(), 1); - assert_eq!(test_res[0].results.as_ref().unwrap().len(), 1); - assert_eq!(test_res[0].test_actor, &test_actor); - test_res[0] - .results - .as_ref() - .unwrap() - .iter() - .for_each(|result| match (result.method().r#type(), result.ret()) { - (MethodType::Test, TestResultType::Passed(apply_ret)) => { - assert_eq!(apply_ret.msg_receipt.exit_code, ExitCode::OK); - } - apply_ret => { - panic!("test against basic test actor should pass: {apply_ret:?}") - } - }) - } - } - } - #[test] fn test_constructor_and_set_up_called() { // Instantiate tester diff --git a/test_actors/actors/setup_test_actor/Cargo.toml b/test_actors/actors/setup_test_actor/Cargo.toml deleted file mode 100644 index db81fa4..0000000 --- a/test_actors/actors/setup_test_actor/Cargo.toml +++ /dev/null @@ -1,17 +0,0 @@ -[package] -name = "setup_test_actor" -version = "0.1.0" -edition = "2021" -publish=false - -[target.'cfg(target_arch = "wasm32")'.dependencies] -cid = { version = "0.8.5", default-features = false } -fvm_ipld_blockstore = { git = "https://github.com/filecoin-project/ref-fvm.git", version = "0.1.1" } -fvm_sdk = { git = "https://github.com/filecoin-project/ref-fvm.git", version = "3.0.0" } -fvm_shared = { git = "https://github.com/filecoin-project/ref-fvm.git", version = "3.1.0" } -fvm_ipld_encoding = { git = "https://github.com/filecoin-project/ref-fvm.git", version = "0.3.3" } -serde = { version = "1.0.136", features = ["derive"] } -serde_tuple = { version = "0.5.0" } - -[lib] -crate-type = ["cdylib"] \ No newline at end of file diff --git a/test_actors/actors/setup_test_actor/README.md b/test_actors/actors/setup_test_actor/README.md deleted file mode 100644 index ce5b738..0000000 --- a/test_actors/actors/setup_test_actor/README.md +++ /dev/null @@ -1,3 +0,0 @@ -## Setup Test Actor - -This is an actor to test that setup are being properly called in Kythera testing framework. \ No newline at end of file diff --git a/test_actors/actors/setup_test_actor/src/actor.rs b/test_actors/actors/setup_test_actor/src/actor.rs deleted file mode 100644 index 57784fe..0000000 --- a/test_actors/actors/setup_test_actor/src/actor.rs +++ /dev/null @@ -1,73 +0,0 @@ -// Copyright 2023 Polyphene. -// SPDX-License-Identifier: Apache-2.0, MIT - -use cid::{multihash::Code, Cid}; -use fvm_ipld_blockstore::Block; -use fvm_ipld_encoding::tuple::{Deserialize_tuple, Serialize_tuple}; -use fvm_ipld_encoding::DAG_CBOR; -use fvm_sdk as sdk; -use fvm_sdk::NO_DATA_BLOCK_ID; -use fvm_shared::error::ExitCode; - -#[derive(Serialize_tuple, Deserialize_tuple)] -struct TestSetupActorState { - value: u32, -} - -impl TestSetupActorState { - pub fn load(cid: &Cid) -> Self { - let data = sdk::ipld::get(cid).unwrap(); - fvm_ipld_encoding::from_slice::(&data).unwrap() - } - - pub fn save(&self) -> Cid { - let serialized = fvm_ipld_encoding::to_vec(self).unwrap(); - let block = Block { - codec: DAG_CBOR, - data: serialized, - }; - sdk::ipld::put( - Code::Blake2b256.into(), - 32, - block.codec, - block.data.as_ref(), - ) - .unwrap() - } -} - -// TODO use helix frc42_dispatch when their dependencies are up to date. -#[no_mangle] -fn invoke(_input: u32) -> u32 { - let method_num = sdk::message::method_number(); - match method_num { - 3556852554 => Setup(), - 787295010 => TestSetup(), - _ => { - sdk::vm::abort( - ExitCode::USR_UNHANDLED_MESSAGE.value(), - Some("Unknown method number"), - ); - } - } - - NO_DATA_BLOCK_ID -} - -#[allow(non_snake_case)] -fn Setup() { - let state = TestSetupActorState { value: 1 }; - let cid = state.save(); - fvm_sdk::sself::set_root(&cid).unwrap(); -} - -#[allow(non_snake_case)] -fn TestSetup() { - let state = TestSetupActorState::load(&sdk::sself::root().unwrap()); - if state.value != 1u32 { - sdk::vm::abort( - ExitCode::USR_ASSERTION_FAILED.value(), - Some("Setup was not called"), - ) - } -} diff --git a/test_actors/actors/setup_test_actor/src/lib.rs b/test_actors/actors/setup_test_actor/src/lib.rs deleted file mode 100644 index 6662b42..0000000 --- a/test_actors/actors/setup_test_actor/src/lib.rs +++ /dev/null @@ -1,5 +0,0 @@ -// Copyright 2023 Polyphene. -// SPDX-License-Identifier: Apache-2.0, MIT - -#[cfg(target_arch = "wasm32")] -mod actor; diff --git a/test_actors/build.rs b/test_actors/build.rs index ee6a770..d1900b9 100644 --- a/test_actors/build.rs +++ b/test_actors/build.rs @@ -9,7 +9,6 @@ use std::thread; const ACTORS: &[&str] = &[ "basic_test_actor", "constructor_test_actor", - "setup_test_actor", "constructor_setup_test_actor", ]; diff --git a/test_actors/src/wasm_bin/mod.rs b/test_actors/src/wasm_bin/mod.rs index c05af44..65e73a5 100644 --- a/test_actors/src/wasm_bin/mod.rs +++ b/test_actors/src/wasm_bin/mod.rs @@ -17,6 +17,5 @@ macro_rules! wasm_bin { pub const BASIC_TEST_ACTOR_BINARY: &[u8] = include_bytes!(wasm_bin!("basic_test_actor")); pub const CONSTRUCTOR_TEST_ACTOR_BINARY: &[u8] = include_bytes!(wasm_bin!("constructor_test_actor")); -pub const SETUP_TEST_ACTOR_BINARY: &[u8] = include_bytes!(wasm_bin!("setup_test_actor")); pub const CONSTRUCTOR_SETUP_TEST_ACTOR_BINARY: &[u8] = include_bytes!(wasm_bin!("constructor_setup_test_actor")); From 97a2639e7e546b9ecae5a499a8b9e7cb8c65a544 Mon Sep 17 00:00:00 2001 From: Thomas Chataigner Date: Fri, 7 Apr 2023 15:48:49 +0200 Subject: [PATCH 22/38] feat(cheatcodes): started cheatcodes testing ground --- Cargo.lock | 12 ++ .../actors/cheatcodes_test_actor/Cargo.toml | 16 +++ .../actors/cheatcodes_test_actor/README.md | 13 ++ .../actors/cheatcodes_test_actor/src/actor.rs | 129 ++++++++++++++++++ .../actors/cheatcodes_test_actor/src/lib.rs | 5 + test_actors/build.rs | 6 +- test_actors/src/wasm_bin/mod.rs | 1 + 7 files changed, 181 insertions(+), 1 deletion(-) create mode 100644 test_actors/actors/cheatcodes_test_actor/Cargo.toml create mode 100644 test_actors/actors/cheatcodes_test_actor/README.md create mode 100644 test_actors/actors/cheatcodes_test_actor/src/actor.rs create mode 100644 test_actors/actors/cheatcodes_test_actor/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index 288b4ab..2f8ddc7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -561,6 +561,18 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "cheatcodes_test_actor" +version = "0.1.0" +dependencies = [ + "fil_actors_runtime_v10", + "frc42_dispatch", + "fvm_ipld_encoding 0.3.3", + "fvm_sdk 3.0.0", + "fvm_shared 3.1.0", + "serde", +] + [[package]] name = "cid" version = "0.8.6" diff --git a/test_actors/actors/cheatcodes_test_actor/Cargo.toml b/test_actors/actors/cheatcodes_test_actor/Cargo.toml new file mode 100644 index 0000000..dc78ccb --- /dev/null +++ b/test_actors/actors/cheatcodes_test_actor/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "cheatcodes_test_actor" +version = "0.1.0" +edition = "2021" +publish=false + +[target.'cfg(target_arch = "wasm32")'.dependencies] +fil_actors_runtime_v10 = "1.0.0" +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"] } + +[lib] +crate-type = ["cdylib"] \ No newline at end of file diff --git a/test_actors/actors/cheatcodes_test_actor/README.md b/test_actors/actors/cheatcodes_test_actor/README.md new file mode 100644 index 0000000..e148049 --- /dev/null +++ b/test_actors/actors/cheatcodes_test_actor/README.md @@ -0,0 +1,13 @@ +## Cheatcodes Test Actor + +This is an actor to test Kythera cheatcodes implementation. + +### Cheatcodes + +The following cheatcodes are tested 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 call**'s `NetworkContext::caller` to be the input address +- `Trick`: Sets the **next call**'s `NetworkContext::origin` to be the input address \ No newline at end of file diff --git a/test_actors/actors/cheatcodes_test_actor/src/actor.rs b/test_actors/actors/cheatcodes_test_actor/src/actor.rs new file mode 100644 index 0000000..4bc9251 --- /dev/null +++ b/test_actors/actors/cheatcodes_test_actor/src/actor.rs @@ -0,0 +1,129 @@ +// Copyright 2023 Polyphene. +// SPDX-License-Identifier: Apache-2.0, MIT + +use fil_actors_runtime_v10::runtime::builtins::Type; +use fil_actors_runtime_v10::{ + BURNT_FUNDS_ACTOR_ADDR, CRON_ACTOR_ADDR, DATACAP_TOKEN_ACTOR_ADDR, DATACAP_TOKEN_ACTOR_ID, + INIT_ACTOR_ADDR, REWARD_ACTOR_ADDR, STORAGE_MARKET_ACTOR_ADDR, STORAGE_POWER_ACTOR_ADDR, + SYSTEM_ACTOR_ADDR, VERIFIED_REGISTRY_ACTOR_ADDR, +}; +use frc42_dispatch::match_method; +use fvm_sdk as sdk; +use fvm_sdk::actor::{get_actor_code_cid, get_builtin_actor_type}; +use fvm_sdk::NO_DATA_BLOCK_ID; +use fvm_shared::error::ExitCode; + +#[no_mangle] +fn invoke(_input: u32) -> u32 { + std::panic::set_hook(Box::new(|info| { + sdk::vm::abort( + ExitCode::USR_ASSERTION_FAILED.value(), + Some(&format!("{info}")), + ) + })); + + let method_num = sdk::message::method_number(); + match_method!( + method_num, + { + "TestBuiltinsDeployed" => { + TestBuiltinsDeployed(); + + NO_DATA_BLOCK_ID + }, + _ => { + sdk::vm::abort( + ExitCode::USR_UNHANDLED_MESSAGE.value(), + Some("Unknown method number"), + ); + } + } + ) +} + +// Checks that all relevant builtins are deployed at a correct actor Id in Kythera +#[allow(non_snake_case)] +fn TestBuiltinsDeployed() { + // Test system actor deployment. + let code_cid = get_actor_code_cid(&SYSTEM_ACTOR_ADDR) + .unwrap_or_else(|| panic!("Should get an code CID at address: {}", &SYSTEM_ACTOR_ADDR)); + let actor_type = get_builtin_actor_type(&code_cid) + .unwrap_or_else(|| panic!("Should get a builtin actor type for CID: {}", &code_cid)); + assert_eq!(actor_type, Type::System as i32); + + // Test init actor deployment. + let code_cid = get_actor_code_cid(&INIT_ACTOR_ADDR) + .unwrap_or_else(|| panic!("Should get an code CID at address: {}", &INIT_ACTOR_ADDR)); + let actor_type = get_builtin_actor_type(&code_cid) + .unwrap_or_else(|| panic!("Should get a builtin actor type for CID: {}", &code_cid)); + assert_eq!(actor_type, Type::Init as i32); + + // Test reward actor deployment. + let code_cid = get_actor_code_cid(&REWARD_ACTOR_ADDR) + .unwrap_or_else(|| panic!("Should get an code CID at address: {}", &REWARD_ACTOR_ADDR)); + let actor_type = get_builtin_actor_type(&code_cid) + .unwrap_or_else(|| panic!("Should get a builtin actor type for CID: {}", &code_cid)); + assert_eq!(actor_type, Type::Reward as i32); + + // Test cron actor deployment. + let code_cid = get_actor_code_cid(&CRON_ACTOR_ADDR) + .unwrap_or_else(|| panic!("Should get an code CID at address: {}", &CRON_ACTOR_ADDR)); + let actor_type = get_builtin_actor_type(&code_cid) + .unwrap_or_else(|| panic!("Should get a builtin actor type for CID: {}", &code_cid)); + assert_eq!(actor_type, Type::Cron as i32); + + // Test power actor deployment. + let code_cid = get_actor_code_cid(&STORAGE_POWER_ACTOR_ADDR).unwrap_or_else(|| { + panic!( + "Should get an code CID at address: {}", + &STORAGE_POWER_ACTOR_ADDR + ) + }); + let actor_type = get_builtin_actor_type(&code_cid) + .unwrap_or_else(|| panic!("Should get a builtin actor type for CID: {}", &code_cid)); + assert_eq!(actor_type, Type::Power as i32); + + // Test market actor deployment. + let code_cid = get_actor_code_cid(&STORAGE_MARKET_ACTOR_ADDR).unwrap_or_else(|| { + panic!( + "Should get an code CID at address: {}", + &STORAGE_MARKET_ACTOR_ADDR + ) + }); + let actor_type = get_builtin_actor_type(&code_cid) + .unwrap_or_else(|| panic!("Should get a builtin actor type for CID: {}", &code_cid)); + assert_eq!(actor_type, Type::Market as i32); + + // Test verified registry actor deployment. + let code_cid = get_actor_code_cid(&VERIFIED_REGISTRY_ACTOR_ADDR).unwrap_or_else(|| { + panic!( + "Should get an code CID at address: {}", + &VERIFIED_REGISTRY_ACTOR_ADDR + ) + }); + let actor_type = get_builtin_actor_type(&code_cid) + .unwrap_or_else(|| panic!("Should get a builtin actor type for CID: {}", &code_cid)); + assert_eq!(actor_type, Type::VerifiedRegistry as i32); + + // Test datacap actor deployment. + let code_cid = get_actor_code_cid(&DATACAP_TOKEN_ACTOR_ADDR).unwrap_or_else(|| { + panic!( + "Should get an code CID at address: {}", + &DATACAP_TOKEN_ACTOR_ID + ) + }); + let actor_type = get_builtin_actor_type(&code_cid) + .unwrap_or_else(|| panic!("Should get a builtin actor type for CID: {}", &code_cid)); + assert_eq!(actor_type, Type::DataCap as i32); + + // Test burnt funds actor deployment. + let code_cid = get_actor_code_cid(&BURNT_FUNDS_ACTOR_ADDR).unwrap_or_else(|| { + panic!( + "Should get an code CID at address: {}", + &BURNT_FUNDS_ACTOR_ADDR + ) + }); + let actor_type = get_builtin_actor_type(&code_cid) + .unwrap_or_else(|| panic!("Should get a builtin actor type for CID: {}", &code_cid)); + assert_eq!(actor_type, Type::Account as i32); +} diff --git a/test_actors/actors/cheatcodes_test_actor/src/lib.rs b/test_actors/actors/cheatcodes_test_actor/src/lib.rs new file mode 100644 index 0000000..6662b42 --- /dev/null +++ b/test_actors/actors/cheatcodes_test_actor/src/lib.rs @@ -0,0 +1,5 @@ +// Copyright 2023 Polyphene. +// SPDX-License-Identifier: Apache-2.0, MIT + +#[cfg(target_arch = "wasm32")] +mod actor; diff --git a/test_actors/build.rs b/test_actors/build.rs index 588500a..efd0ad3 100644 --- a/test_actors/build.rs +++ b/test_actors/build.rs @@ -6,7 +6,11 @@ use std::path::Path; use std::process::{Command, Stdio}; use std::thread; -const ACTORS: &[&str] = &["basic_test_actor", "builtin_test_actor"]; +const ACTORS: &[&str] = &[ + "basic_test_actor", + "builtin_test_actor", + "cheatcodes_test_actor", +]; fn main() -> Result<(), Box> { // Cargo executable location. diff --git a/test_actors/src/wasm_bin/mod.rs b/test_actors/src/wasm_bin/mod.rs index 3b946e5..6817ed0 100644 --- a/test_actors/src/wasm_bin/mod.rs +++ b/test_actors/src/wasm_bin/mod.rs @@ -16,3 +16,4 @@ macro_rules! wasm_bin { // Integration test actors. pub const BASIC_TEST_ACTOR_BINARY: &[u8] = include_bytes!(wasm_bin!("basic_test_actor")); pub const BUILTIN_TEST_ACTOR_BINARY: &[u8] = include_bytes!(wasm_bin!("builtin_test_actor")); +pub const CHEATCODES_TEST_ACTOR_BINARY: &[u8] = include_bytes!(wasm_bin!("cheatcodes_test_actor")); From 8f9063c3433a09b77e7d996a13a6634e7b7fb359 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Oliveira?= Date: Mon, 10 Apr 2023 11:48:33 +0100 Subject: [PATCH 23/38] lib: address Thomas review --- Cargo.lock | 262 +++++++----------- lib/tests/lib.rs | 80 +----- .../constructor_setup_test_actor/Cargo.toml | 9 +- .../constructor_setup_test_actor/src/actor.rs | 36 ++- .../actors/constructor_test_actor/Cargo.toml | 17 -- .../actors/constructor_test_actor/README.md | 3 - .../constructor_test_actor/src/actor.rs | 73 ----- .../actors/constructor_test_actor/src/lib.rs | 5 - test_actors/build.rs | 1 - test_actors/src/wasm_bin/mod.rs | 2 - 10 files changed, 132 insertions(+), 356 deletions(-) delete mode 100644 test_actors/actors/constructor_test_actor/Cargo.toml delete mode 100644 test_actors/actors/constructor_test_actor/README.md delete mode 100644 test_actors/actors/constructor_test_actor/src/actor.rs delete mode 100644 test_actors/actors/constructor_test_actor/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index 186d1fa..d346a1b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -291,7 +291,7 @@ name = "basic_test_actor" version = "0.1.0" dependencies = [ "frc42_dispatch", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_encoding 0.3.3", "fvm_sdk 3.0.0", "fvm_shared 3.1.0", "serde", @@ -492,7 +492,7 @@ version = "0.1.0" dependencies = [ "fil_actors_runtime_v10", "frc42_dispatch", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_encoding 0.3.3", "fvm_sdk 3.0.0", "fvm_shared 3.1.0", "serde", @@ -721,23 +721,11 @@ name = "constructor_setup_test_actor" version = "0.1.0" dependencies = [ "cid", - "fvm_ipld_blockstore 0.1.1 (git+https://github.com/filecoin-project/ref-fvm.git)", - "fvm_ipld_encoding 0.3.3 (git+https://github.com/filecoin-project/ref-fvm.git)", - "fvm_sdk 3.2.0", - "fvm_shared 3.2.0", - "serde", - "serde_tuple", -] - -[[package]] -name = "constructor_test_actor" -version = "0.1.0" -dependencies = [ - "cid", - "fvm_ipld_blockstore 0.1.1 (git+https://github.com/filecoin-project/ref-fvm.git)", - "fvm_ipld_encoding 0.3.3 (git+https://github.com/filecoin-project/ref-fvm.git)", - "fvm_sdk 3.2.0", - "fvm_shared 3.2.0", + "frc42_dispatch", + "fvm_ipld_blockstore", + "fvm_ipld_encoding 0.3.3", + "fvm_sdk 3.0.0", + "fvm_shared 3.1.0", "serde", "serde_tuple", ] @@ -1294,8 +1282,8 @@ dependencies = [ "fil_actors_runtime", "frc42_dispatch", "fvm_actor_utils 5.0.0", - "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_blockstore", + "fvm_ipld_encoding 0.3.3", "fvm_shared 3.1.0", "num-derive", "num-traits", @@ -1309,7 +1297,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719246afbe4fef6c3a4cf1eacbc40d915aca7d8259b0fe0bda34d9e9e92d0f7d" dependencies = [ "frc42_dispatch", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_encoding 0.3.3", "fvm_shared 3.1.0", "num-derive", "num-traits", @@ -1327,9 +1315,9 @@ dependencies = [ "cid", "clap 3.2.23", "futures", - "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_blockstore", "fvm_ipld_car", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_encoding 0.3.3", "serde", "serde_ipld_dagcbor", "serde_json", @@ -1341,8 +1329,8 @@ version = "10.0.0" source = "git+https://github.com/filecoin-project/builtin-actors?rev=39571e2#39571e25eacd51326c9fc8e29d4b69943f15a3b1" dependencies = [ "fil_actors_runtime", - "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_blockstore", + "fvm_ipld_encoding 0.3.3", "fvm_shared 3.1.0", "log", "num-derive", @@ -1356,7 +1344,7 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9dc95d44e5b1b9fe02196c75c7443426f255af398a1f96da888482bf33b2fef4" dependencies = [ - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_encoding 0.3.3", "fvm_shared 3.1.0", "num-derive", "num-traits", @@ -1373,8 +1361,8 @@ dependencies = [ "frc42_dispatch", "frc46_token 5.0.0", "fvm_actor_utils 5.0.0", - "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_blockstore", + "fvm_ipld_encoding 0.3.3", "fvm_ipld_hamt 0.6.1", "fvm_shared 3.1.0", "lazy_static", @@ -1393,8 +1381,8 @@ dependencies = [ "fil_actors_runtime_v10", "frc42_dispatch", "frc46_token 3.1.0", - "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_blockstore", + "fvm_ipld_encoding 0.3.3", "fvm_shared 3.1.0", "num-derive", "num-traits", @@ -1410,8 +1398,8 @@ dependencies = [ "cid", "fil_actors_evm_shared", "fil_actors_runtime", - "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_blockstore", + "fvm_ipld_encoding 0.3.3", "fvm_shared 3.1.0", "hex-literal", "log", @@ -1431,7 +1419,7 @@ dependencies = [ "fil_actors_runtime", "frc42_dispatch", "fvm_actor_utils 5.0.0", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_encoding 0.3.3", "fvm_shared 3.1.0", "hex-literal", "num-derive", @@ -1461,8 +1449,8 @@ dependencies = [ "fil_actors_evm_shared", "fil_actors_runtime", "frc42_dispatch", - "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_blockstore", + "fvm_ipld_encoding 0.3.3", "fvm_ipld_kamt", "fvm_shared 3.1.0", "hex", @@ -1485,8 +1473,8 @@ dependencies = [ "cid", "fil_actors_runtime", "frc42_dispatch", - "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_blockstore", + "fvm_ipld_encoding 0.3.3", "fvm_ipld_hamt 0.6.1", "fvm_shared 3.1.0", "log", @@ -1504,8 +1492,8 @@ dependencies = [ "cid", "fil_actors_runtime_v10", "frc42_dispatch", - "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_blockstore", + "fvm_ipld_encoding 0.3.3", "fvm_shared 3.1.0", "num-derive", "num-traits", @@ -1523,8 +1511,8 @@ dependencies = [ "frc42_dispatch", "frc46_token 5.0.0", "fvm_ipld_bitfield", - "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_blockstore", + "fvm_ipld_encoding 0.3.3", "fvm_ipld_hamt 0.6.1", "fvm_shared 3.1.0", "integer-encoding", @@ -1544,8 +1532,8 @@ dependencies = [ "cid", "fil_actors_runtime_v10", "frc42_dispatch", - "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_blockstore", + "fvm_ipld_encoding 0.3.3", "fvm_ipld_hamt 0.6.1", "fvm_shared 3.1.0", "libipld-core 0.14.0", @@ -1566,8 +1554,8 @@ dependencies = [ "frc42_dispatch", "fvm_ipld_amt 0.5.1", "fvm_ipld_bitfield", - "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_blockstore", + "fvm_ipld_encoding 0.3.3", "fvm_ipld_hamt 0.6.1", "fvm_shared 3.1.0", "itertools 0.10.5", @@ -1591,8 +1579,8 @@ dependencies = [ "frc42_dispatch", "fvm_ipld_amt 0.5.1", "fvm_ipld_bitfield", - "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_blockstore", + "fvm_ipld_encoding 0.3.3", "fvm_ipld_hamt 0.6.1", "fvm_shared 3.1.0", "itertools 0.10.5", @@ -1613,8 +1601,8 @@ dependencies = [ "fil_actors_runtime", "frc42_dispatch", "fvm_actor_utils 5.0.0", - "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_blockstore", + "fvm_ipld_encoding 0.3.3", "fvm_ipld_hamt 0.6.1", "fvm_shared 3.1.0", "indexmap", @@ -1633,8 +1621,8 @@ dependencies = [ "cid", "fil_actors_runtime_v10", "frc42_dispatch", - "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_blockstore", + "fvm_ipld_encoding 0.3.3", "fvm_ipld_hamt 0.6.1", "fvm_shared 3.1.0", "indexmap", @@ -1653,8 +1641,8 @@ dependencies = [ "cid", "fil_actors_runtime", "frc42_dispatch", - "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_blockstore", + "fvm_ipld_encoding 0.3.3", "fvm_shared 3.1.0", "num-derive", "num-traits", @@ -1669,7 +1657,7 @@ checksum = "0b63acc144f0bb4df7006992e7e2e977fdc8171ae012697aadf5500e3b33c665" dependencies = [ "cid", "frc42_dispatch", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_encoding 0.3.3", "fvm_shared 3.1.0", "num-derive", "num-traits", @@ -1690,8 +1678,8 @@ dependencies = [ "cid", "fil_actors_runtime", "frc42_dispatch", - "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_blockstore", + "fvm_ipld_encoding 0.3.3", "fvm_ipld_hamt 0.6.1", "fvm_shared 3.1.0", "indexmap", @@ -1713,8 +1701,8 @@ dependencies = [ "cid", "fil_actors_runtime_v10", "frc42_dispatch", - "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_blockstore", + "fvm_ipld_encoding 0.3.3", "fvm_ipld_hamt 0.6.1", "fvm_shared 3.1.0", "integer-encoding", @@ -1730,8 +1718,8 @@ version = "10.0.0" source = "git+https://github.com/filecoin-project/builtin-actors?rev=39571e2#39571e25eacd51326c9fc8e29d4b69943f15a3b1" dependencies = [ "fil_actors_runtime", - "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_blockstore", + "fvm_ipld_encoding 0.3.3", "fvm_shared 3.1.0", "lazy_static", "log", @@ -1746,7 +1734,7 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f1db1f0dc4b3fe017179ff3e645aeaf8cf0ec2457bc67a89e7505802b87946ae" dependencies = [ - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_encoding 0.3.3", "fvm_shared 3.1.0", "lazy_static", "num-derive", @@ -1762,8 +1750,8 @@ dependencies = [ "anyhow", "cid", "fil_actors_runtime", - "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_blockstore", + "fvm_ipld_encoding 0.3.3", "fvm_shared 3.1.0", "num-derive", "num-traits", @@ -1777,7 +1765,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "38c10a8bb4b1b1d3c321dc52332d30fa967e61689fe715f639de10d3a0c9e65d" dependencies = [ "cid", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_encoding 0.3.3", "fvm_shared 2.3.0", "num-derive", "num-traits", @@ -1795,8 +1783,8 @@ dependencies = [ "frc42_dispatch", "frc46_token 5.0.0", "fvm_actor_utils 5.0.0", - "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_blockstore", + "fvm_ipld_encoding 0.3.3", "fvm_ipld_hamt 0.6.1", "fvm_shared 3.1.0", "lazy_static", @@ -1815,8 +1803,8 @@ dependencies = [ "cid", "fil_actors_runtime_v10", "frc42_dispatch", - "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_blockstore", + "fvm_ipld_encoding 0.3.3", "fvm_shared 3.1.0", "num-derive", "num-traits", @@ -1829,7 +1817,7 @@ version = "10.0.0" source = "git+https://github.com/filecoin-project/builtin-actors?rev=39571e2#39571e25eacd51326c9fc8e29d4b69943f15a3b1" dependencies = [ "fil_actors_runtime", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_encoding 0.3.3", "fvm_shared 3.1.0", "hex", "serde", @@ -1847,8 +1835,8 @@ dependencies = [ "cid", "fvm_ipld_amt 0.5.1", "fvm_ipld_bitfield", - "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_blockstore", + "fvm_ipld_encoding 0.3.3", "fvm_ipld_hamt 0.6.1", "fvm_sdk 3.0.0", "fvm_shared 3.1.0", @@ -1876,8 +1864,8 @@ dependencies = [ "anyhow", "cid", "fvm_ipld_amt 0.5.1", - "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_blockstore", + "fvm_ipld_encoding 0.3.3", "fvm_ipld_hamt 0.6.1", "fvm_shared 3.1.0", "multihash", @@ -2061,7 +2049,7 @@ checksum = "a4dc594c941eba1d5a9474f595c6d0f9d752fa333b672755bbe7c23d30f64282" dependencies = [ "frc42_hasher", "frc42_macros", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_encoding 0.3.3", "fvm_sdk 3.0.0", "fvm_shared 3.1.0", "thiserror", @@ -2102,7 +2090,7 @@ dependencies = [ "frc42_dispatch", "fvm_actor_utils 3.0.0", "fvm_ipld_amt 0.4.2", - "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_blockstore", "fvm_ipld_encoding 0.2.3", "fvm_ipld_hamt 0.5.1", "fvm_sdk 2.2.0", @@ -2125,8 +2113,8 @@ dependencies = [ "frc42_dispatch", "fvm_actor_utils 5.0.0", "fvm_ipld_amt 0.5.1", - "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_blockstore", + "fvm_ipld_encoding 0.3.3", "fvm_ipld_hamt 0.6.1", "fvm_sdk 3.0.0", "fvm_shared 3.1.0", @@ -2273,8 +2261,8 @@ dependencies = [ "filecoin-proofs-api", "fvm-wasm-instrument", "fvm_ipld_amt 0.5.1", - "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_blockstore", + "fvm_ipld_encoding 0.3.3", "fvm_ipld_hamt 0.6.1", "fvm_shared 3.1.0", "lazy_static", @@ -2319,7 +2307,7 @@ dependencies = [ "anyhow", "cid", "frc42_dispatch", - "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_blockstore", "fvm_ipld_encoding 0.2.3", "fvm_sdk 2.2.0", "fvm_shared 2.3.0", @@ -2338,8 +2326,8 @@ dependencies = [ "anyhow", "cid", "frc42_dispatch", - "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_blockstore", + "fvm_ipld_encoding 0.3.3", "fvm_sdk 3.0.0", "fvm_shared 3.1.0", "num-traits", @@ -2357,7 +2345,7 @@ dependencies = [ "ahash", "anyhow", "cid", - "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_blockstore", "fvm_ipld_encoding 0.2.3", "itertools 0.10.5", "once_cell", @@ -2373,8 +2361,8 @@ checksum = "e84f16d6927ce342ef86bd20fcc2d5bd498ed33ae6d7a22fea7a1b453488ec88" dependencies = [ "anyhow", "cid", - "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_blockstore", + "fvm_ipld_encoding 0.3.3", "itertools 0.10.5", "once_cell", "serde", @@ -2387,7 +2375,7 @@ version = "0.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d1950291f40d2d1047eb0a4568f7ef6d5b4973452dcef012dffb1957fe483ff7" dependencies = [ - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_encoding 0.3.3", "serde", "thiserror", "unsigned-varint", @@ -2404,16 +2392,6 @@ dependencies = [ "multihash", ] -[[package]] -name = "fvm_ipld_blockstore" -version = "0.1.1" -source = "git+https://github.com/filecoin-project/ref-fvm.git#eec5e4aff2893f7a53e9a88e18973532b6712a42" -dependencies = [ - "anyhow", - "cid", - "multihash", -] - [[package]] name = "fvm_ipld_car" version = "0.6.0" @@ -2422,8 +2400,8 @@ checksum = "c60423568393a284de6d7c342cd664690611f27d223eb78629fa568ddd4e7951" dependencies = [ "cid", "futures", - "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_blockstore", + "fvm_ipld_encoding 0.3.3", "integer-encoding", "serde", "thiserror", @@ -2438,7 +2416,7 @@ dependencies = [ "anyhow", "cid", "cs_serde_bytes", - "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_blockstore", "multihash", "serde", "serde_ipld_dagcbor", @@ -2455,23 +2433,7 @@ checksum = "f0816a2a6df4853de08a723d261110d56a121aa313bc570fe9d248f0a4bc5288" dependencies = [ "anyhow", "cid", - "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "multihash", - "serde", - "serde_ipld_dagcbor", - "serde_repr", - "serde_tuple", - "thiserror", -] - -[[package]] -name = "fvm_ipld_encoding" -version = "0.3.3" -source = "git+https://github.com/filecoin-project/ref-fvm.git#eec5e4aff2893f7a53e9a88e18973532b6712a42" -dependencies = [ - "anyhow", - "cid", - "fvm_ipld_blockstore 0.1.1 (git+https://github.com/filecoin-project/ref-fvm.git)", + "fvm_ipld_blockstore", "multihash", "serde", "serde_ipld_dagcbor", @@ -2491,7 +2453,7 @@ dependencies = [ "cid", "cs_serde_bytes", "forest_hash_utils", - "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_blockstore", "fvm_ipld_encoding 0.2.3", "libipld-core 0.13.1", "multihash", @@ -2511,8 +2473,8 @@ dependencies = [ "byteorder", "cid", "forest_hash_utils", - "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_blockstore", + "fvm_ipld_encoding 0.3.3", "libipld-core 0.14.0", "multihash", "once_cell", @@ -2531,8 +2493,8 @@ dependencies = [ "byteorder", "cid", "forest_hash_utils", - "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_blockstore", + "fvm_ipld_encoding 0.3.3", "multihash", "once_cell", "serde", @@ -2562,7 +2524,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2fef17308967cceb1d22f05003d60adb0d5b9ba53e34ace4ae04701eb7e6af02" dependencies = [ "cid", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_encoding 0.3.3", "fvm_shared 3.1.0", "lazy_static", "log", @@ -2570,20 +2532,6 @@ dependencies = [ "thiserror", ] -[[package]] -name = "fvm_sdk" -version = "3.2.0" -source = "git+https://github.com/filecoin-project/ref-fvm.git#eec5e4aff2893f7a53e9a88e18973532b6712a42" -dependencies = [ - "cid", - "fvm_ipld_encoding 0.3.3 (git+https://github.com/filecoin-project/ref-fvm.git)", - "fvm_shared 3.2.0", - "lazy_static", - "log", - "num-traits", - "thiserror", -] - [[package]] name = "fvm_shared" version = "2.3.0" @@ -2597,7 +2545,7 @@ dependencies = [ "cs_serde_bytes", "data-encoding", "data-encoding-macro", - "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_blockstore", "fvm_ipld_encoding 0.2.3", "lazy_static", "log", @@ -2628,8 +2576,8 @@ dependencies = [ "data-encoding", "data-encoding-macro", "filecoin-proofs-api", - "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_blockstore", + "fvm_ipld_encoding 0.3.3", "lazy_static", "libsecp256k1", "log", @@ -2645,30 +2593,6 @@ dependencies = [ "unsigned-varint", ] -[[package]] -name = "fvm_shared" -version = "3.2.0" -source = "git+https://github.com/filecoin-project/ref-fvm.git#eec5e4aff2893f7a53e9a88e18973532b6712a42" -dependencies = [ - "anyhow", - "bitflags", - "blake2b_simd", - "cid", - "data-encoding", - "data-encoding-macro", - "fvm_ipld_encoding 0.3.3 (git+https://github.com/filecoin-project/ref-fvm.git)", - "lazy_static", - "multihash", - "num-bigint", - "num-derive", - "num-integer", - "num-traits", - "serde", - "serde_tuple", - "thiserror", - "unsigned-varint", -] - [[package]] name = "fxhash" version = "0.2.1" @@ -2979,7 +2903,7 @@ dependencies = [ "anyhow", "blake2b_simd", "frc42_dispatch", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_encoding 0.3.3", "serde", "serde_tuple", "thiserror", @@ -2992,8 +2916,8 @@ dependencies = [ "anyhow", "cid", "fvm", - "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_blockstore", + "fvm_ipld_encoding 0.3.3", "fvm_shared 3.1.0", "multihash", ] @@ -3019,9 +2943,9 @@ dependencies = [ "fil_actors_runtime_v10", "fil_builtin_actors_bundle", "futures", - "fvm_ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_blockstore", "fvm_ipld_car", - "fvm_ipld_encoding 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fvm_ipld_encoding 0.3.3", "fvm_shared 3.1.0", "kythera-common", "kythera-fvm", diff --git a/lib/tests/lib.rs b/lib/tests/lib.rs index 041cf04..18b1ebb 100644 --- a/lib/tests/lib.rs +++ b/lib/tests/lib.rs @@ -3,7 +3,6 @@ use kythera_common::abi::{Abi, Method, MethodType}; use kythera_lib::{TestResultType, Tester, WasmActor}; use kythera_test_actors::wasm_bin::{ BASIC_TEST_ACTOR_BINARY, BUILTIN_TEST_ACTOR_BINARY, CONSTRUCTOR_SETUP_TEST_ACTOR_BINARY, - CONSTRUCTOR_TEST_ACTOR_BINARY, }; const TARGET_WAT: &str = r#" ;; Mock invoke function @@ -139,60 +138,6 @@ fn test_builtin_deployed() { } } } -#[test] -fn test_constructor_called() { - // Instantiate tester - let mut tester = Tester::new(); - - // Set target actor - let target_wasm_bin = wat::parse_str(TARGET_WAT).unwrap(); - let target_abi = Abi { - constructor: None, - set_up: None, - methods: vec![], - }; - let target_actor = WasmActor::new(String::from("Target"), target_wasm_bin, target_abi); - - // Set test actor - let test_wasm_bin: Vec = Vec::from(CONSTRUCTOR_TEST_ACTOR_BINARY); - let test_abi = Abi { - constructor: Some(Method::new_from_name("Constructor").unwrap()), - set_up: None, - methods: vec![Method::new_from_name("TestConstructor").unwrap()], - }; - let test_actor = WasmActor::new(String::from("Constructor Test"), test_wasm_bin, test_abi); - - match tester.deploy_target_actor(target_actor) { - Err(_) => { - panic!("Could not set target Actor when testing if Constructor is properly called") - } - _ => {} - } - - match tester.test(&[test_actor.clone()], None) { - Err(_) => { - panic!("Could not run test when testing Tester") - } - Ok(test_res) => { - assert_eq!(test_res.len(), 1); - assert_eq!(test_res[0].results.as_ref().unwrap().len(), 1); - assert_eq!(test_res[0].test_actor, &test_actor); - test_res[0] - .results - .as_ref() - .unwrap() - .iter() - .for_each(|result| match (result.method().r#type(), result.ret()) { - (MethodType::Test, TestResultType::Passed(apply_ret)) => { - assert_eq!(apply_ret.msg_receipt.exit_code, ExitCode::OK); - } - apply_ret => { - panic!("test against basic test actor should pass: {apply_ret:?}") - } - }) - } - } -} #[test] fn test_constructor_and_set_up_called() { @@ -200,13 +145,17 @@ fn test_constructor_and_set_up_called() { let mut tester = Tester::new(); // Set target actor - let target_wasm_bin = wat::parse_str(TARGET_WAT).unwrap(); - let target_abi = Abi { - constructor: None, - set_up: None, - methods: vec![], - }; - let target_actor = WasmActor::new(String::from("Target"), target_wasm_bin, target_abi); + + set_target_actor( + &mut tester, + String::from("Target"), + wat::parse_str(TARGET_WAT).unwrap(), + Abi { + constructor: None, + set_up: None, + methods: vec![], + }, + ); // Set test actor let test_wasm_bin: Vec = Vec::from(CONSTRUCTOR_SETUP_TEST_ACTOR_BINARY); @@ -217,13 +166,6 @@ fn test_constructor_and_set_up_called() { }; let test_actor = WasmActor::new(String::from("Constructor Test"), test_wasm_bin, test_abi); - match tester.deploy_target_actor(target_actor) { - Err(_) => { - panic!("Could not set target Actor when testing if Constructor is properly called") - } - _ => {} - } - match tester.test(&[test_actor.clone()], None) { Err(_) => { panic!("Could not run test when testing Tester") diff --git a/test_actors/actors/constructor_setup_test_actor/Cargo.toml b/test_actors/actors/constructor_setup_test_actor/Cargo.toml index cd6e90e..9bfaf52 100644 --- a/test_actors/actors/constructor_setup_test_actor/Cargo.toml +++ b/test_actors/actors/constructor_setup_test_actor/Cargo.toml @@ -6,10 +6,11 @@ publish=false [target.'cfg(target_arch = "wasm32")'.dependencies] cid = { version = "0.8.5", default-features = false } -fvm_ipld_blockstore = { git = "https://github.com/filecoin-project/ref-fvm.git", version = "0.1.1" } -fvm_sdk = { git = "https://github.com/filecoin-project/ref-fvm.git", version = "3.0.0" } -fvm_shared = { git = "https://github.com/filecoin-project/ref-fvm.git", version = "3.1.0" } -fvm_ipld_encoding = { git = "https://github.com/filecoin-project/ref-fvm.git", version = "0.3.3" } +frc42_dispatch = "3.1.0" +fvm_ipld_blockstore = "0.1.1" +fvm_sdk = "3.0.0" +fvm_shared = { version = "3.1.0", features = ["testing"] } +fvm_ipld_encoding = { version = "0.3.3" } serde = { version = "1.0.136", features = ["derive"] } serde_tuple = { version = "0.5.0" } diff --git a/test_actors/actors/constructor_setup_test_actor/src/actor.rs b/test_actors/actors/constructor_setup_test_actor/src/actor.rs index 9936fc4..599725a 100644 --- a/test_actors/actors/constructor_setup_test_actor/src/actor.rs +++ b/test_actors/actors/constructor_setup_test_actor/src/actor.rs @@ -2,6 +2,7 @@ // SPDX-License-Identifier: Apache-2.0, MIT use cid::{multihash::Code, Cid}; +use frc42_dispatch::match_method; use fvm_ipld_blockstore::Block; use fvm_ipld_encoding::tuple::{Deserialize_tuple, Serialize_tuple}; use fvm_ipld_encoding::DAG_CBOR; @@ -36,23 +37,32 @@ impl TestConstructorSetupActorState { } } -// TODO use helix frc42_dispatch when their dependencies are up to date. #[no_mangle] fn invoke(_input: u32) -> u32 { let method_num = sdk::message::method_number(); - match method_num { - 1 => Constructor(), - 3556852554 => Setup(), - 3654954405 => TestConstructorSetup(), - method => { - sdk::vm::abort( - ExitCode::USR_UNHANDLED_MESSAGE.value(), - Some(&format!("Unknown method number: {method}")), - ); + match_method!( + method_num, + { + "Constructor" => { + Constructor(); + NO_DATA_BLOCK_ID + } + "Setup" => { + Setup(); + NO_DATA_BLOCK_ID + } + "TestConstructorSetup" => { + TestConstructorSetup(); + NO_DATA_BLOCK_ID + }, + _ => { + sdk::vm::abort( + ExitCode::USR_UNHANDLED_MESSAGE.value(), + Some("Unknown method number"), + ); + } } - } - - NO_DATA_BLOCK_ID + ) } #[allow(non_snake_case)] diff --git a/test_actors/actors/constructor_test_actor/Cargo.toml b/test_actors/actors/constructor_test_actor/Cargo.toml deleted file mode 100644 index 769f475..0000000 --- a/test_actors/actors/constructor_test_actor/Cargo.toml +++ /dev/null @@ -1,17 +0,0 @@ -[package] -name = "constructor_test_actor" -version = "0.1.0" -edition = "2021" -publish=false - -[target.'cfg(target_arch = "wasm32")'.dependencies] -cid = { version = "0.8.5", default-features = false } -fvm_ipld_blockstore = { git = "https://github.com/filecoin-project/ref-fvm.git", version = "0.1.1" } -fvm_sdk = { git = "https://github.com/filecoin-project/ref-fvm.git", version = "3.0.0" } -fvm_shared = { git = "https://github.com/filecoin-project/ref-fvm.git", version = "3.1.0" } -fvm_ipld_encoding = { git = "https://github.com/filecoin-project/ref-fvm.git", version = "0.3.3" } -serde = { version = "1.0.136", features = ["derive"] } -serde_tuple = { version = "0.5.0" } - -[lib] -crate-type = ["cdylib"] \ No newline at end of file diff --git a/test_actors/actors/constructor_test_actor/README.md b/test_actors/actors/constructor_test_actor/README.md deleted file mode 100644 index ce160b4..0000000 --- a/test_actors/actors/constructor_test_actor/README.md +++ /dev/null @@ -1,3 +0,0 @@ -## Constructor Test Actor - -This is an actor to test that constructor are being properly called in Kythera testing framework. \ No newline at end of file diff --git a/test_actors/actors/constructor_test_actor/src/actor.rs b/test_actors/actors/constructor_test_actor/src/actor.rs deleted file mode 100644 index 92993b0..0000000 --- a/test_actors/actors/constructor_test_actor/src/actor.rs +++ /dev/null @@ -1,73 +0,0 @@ -// Copyright 2023 Polyphene. -// SPDX-License-Identifier: Apache-2.0, MIT - -use cid::{multihash::Code, Cid}; -use fvm_ipld_blockstore::Block; -use fvm_ipld_encoding::tuple::{Deserialize_tuple, Serialize_tuple}; -use fvm_ipld_encoding::DAG_CBOR; -use fvm_sdk as sdk; -use fvm_sdk::NO_DATA_BLOCK_ID; -use fvm_shared::error::ExitCode; - -#[derive(Serialize_tuple, Deserialize_tuple)] -struct TestConstructorActorState { - value: u32, -} - -impl TestConstructorActorState { - pub fn load(cid: &Cid) -> Self { - let data = sdk::ipld::get(cid).unwrap(); - fvm_ipld_encoding::from_slice::(&data).unwrap() - } - - pub fn save(&self) -> Cid { - let serialized = fvm_ipld_encoding::to_vec(self).unwrap(); - let block = Block { - codec: DAG_CBOR, - data: serialized, - }; - sdk::ipld::put( - Code::Blake2b256.into(), - 32, - block.codec, - block.data.as_ref(), - ) - .unwrap() - } -} - -// TODO use helix frc42_dispatch when their dependencies are up to date. -#[no_mangle] -fn invoke(_input: u32) -> u32 { - let method_num = sdk::message::method_number(); - match method_num { - 1 => Constructor(), - 862222151 => TestConstructor(), - _ => { - sdk::vm::abort( - ExitCode::USR_UNHANDLED_MESSAGE.value(), - Some("Unknown method number"), - ); - } - } - - NO_DATA_BLOCK_ID -} - -#[allow(non_snake_case)] -fn Constructor() { - let state = TestConstructorActorState { value: 1 }; - let cid = state.save(); - fvm_sdk::sself::set_root(&cid).unwrap(); -} - -#[allow(non_snake_case)] -fn TestConstructor() { - let state = TestConstructorActorState::load(&sdk::sself::root().unwrap()); - if state.value != 1u32 { - sdk::vm::abort( - ExitCode::USR_ASSERTION_FAILED.value(), - Some("Constructor was not called"), - ) - } -} diff --git a/test_actors/actors/constructor_test_actor/src/lib.rs b/test_actors/actors/constructor_test_actor/src/lib.rs deleted file mode 100644 index 6662b42..0000000 --- a/test_actors/actors/constructor_test_actor/src/lib.rs +++ /dev/null @@ -1,5 +0,0 @@ -// Copyright 2023 Polyphene. -// SPDX-License-Identifier: Apache-2.0, MIT - -#[cfg(target_arch = "wasm32")] -mod actor; diff --git a/test_actors/build.rs b/test_actors/build.rs index ad2b0f8..674e016 100644 --- a/test_actors/build.rs +++ b/test_actors/build.rs @@ -9,7 +9,6 @@ use std::thread; const ACTORS: &[&str] = &[ "basic_test_actor", "builtin_test_actor", - "constructor_test_actor", "constructor_setup_test_actor", ]; diff --git a/test_actors/src/wasm_bin/mod.rs b/test_actors/src/wasm_bin/mod.rs index 49966a7..16a489f 100644 --- a/test_actors/src/wasm_bin/mod.rs +++ b/test_actors/src/wasm_bin/mod.rs @@ -15,8 +15,6 @@ macro_rules! wasm_bin { // Integration test actors. pub const BASIC_TEST_ACTOR_BINARY: &[u8] = include_bytes!(wasm_bin!("basic_test_actor")); -pub const CONSTRUCTOR_TEST_ACTOR_BINARY: &[u8] = - include_bytes!(wasm_bin!("constructor_test_actor")); pub const CONSTRUCTOR_SETUP_TEST_ACTOR_BINARY: &[u8] = include_bytes!(wasm_bin!("constructor_setup_test_actor")); pub const BUILTIN_TEST_ACTOR_BINARY: &[u8] = include_bytes!(wasm_bin!("builtin_test_actor")); From 4511d809decb3a401d71f9e09df191a67a077868 Mon Sep 17 00:00:00 2001 From: Thomas Chataigner Date: Tue, 11 Apr 2023 11:52:13 +0200 Subject: [PATCH 24/38] fix(cheatcodes): sanitize actor compilation at runtime * Needed to have a Cheatcodes actor incorporated in our library so re-used the kythera_test_actors crate logic to generate it. kythera_test_actors have been renamed to kythera_actors. * Created a testing feature for kythera_actors to only build test_actors when we need them (mostly during tests of our kythera_lib). --- Cargo.lock | 30 ++-- Cargo.toml | 5 +- {test_actors => actors}/Cargo.toml | 6 +- .../actors/cheatcodes_actor}/Cargo.toml | 2 +- .../actors/cheatcodes_actor}/README.md | 0 .../actors/cheatcodes_actor}/src/actor.rs | 0 .../actors/cheatcodes_actor}/src/lib.rs | 0 {test_actors => actors}/build.rs | 33 +++-- {test_actors => actors}/src/README.md | 2 +- {test_actors => actors}/src/lib.rs | 0 actors/src/wasm_bin/mod.rs | 27 ++++ .../test_actors/basic_test_actor}/Cargo.toml | 4 +- actors/test_actors/basic_test_actor/README.md | 7 + .../test_actors/basic_test_actor/src/actor.rs | 54 ++++++++ .../test_actors/basic_test_actor}/src/lib.rs | 0 .../builtins_test_actor/Cargo.toml | 2 +- .../builtins_test_actor/README.md | 0 .../builtins_test_actor/src/actor.rs | 0 .../builtins_test_actor}/src/lib.rs | 0 .../cheatcodes_test_actor/Cargo.toml | 24 ++++ .../cheatcodes_test_actor/README.md | 0 .../cheatcodes_test_actor/src/actor.rs | 68 +++++++++ .../cheatcodes_test_actor}/src/lib.rs | 0 .../constructor_setup_test_actor/Cargo.toml | 2 +- .../constructor_setup_test_actor/README.md | 0 .../constructor_setup_test_actor/src/actor.rs | 0 .../constructor_setup_test_actor/src/lib.rs | 5 + cli/src/search.rs | 10 +- lib/Cargo.toml | 6 +- lib/src/lib.rs | 6 +- lib/src/state_tree.rs | 2 +- lib/tests/lib.rs | 61 ++++++++- .../actors/cheatcodes_test_actor/src/actor.rs | 129 ------------------ test_actors/src/wasm_bin/mod.rs | 21 --- 34 files changed, 315 insertions(+), 191 deletions(-) rename {test_actors => actors}/Cargo.toml (73%) rename {test_actors/actors/basic_test_actor => actors/actors/cheatcodes_actor}/Cargo.toml (93%) rename {test_actors/actors/basic_test_actor => actors/actors/cheatcodes_actor}/README.md (100%) rename {test_actors/actors/basic_test_actor => actors/actors/cheatcodes_actor}/src/actor.rs (100%) rename {test_actors/actors/basic_test_actor => actors/actors/cheatcodes_actor}/src/lib.rs (100%) rename {test_actors => actors}/build.rs (77%) rename {test_actors => actors}/src/README.md (69%) rename {test_actors => actors}/src/lib.rs (100%) create mode 100644 actors/src/wasm_bin/mod.rs rename {test_actors/actors/cheatcodes_test_actor => actors/test_actors/basic_test_actor}/Cargo.toml (83%) create mode 100644 actors/test_actors/basic_test_actor/README.md create mode 100644 actors/test_actors/basic_test_actor/src/actor.rs rename {test_actors/actors/builtins_test_actor => actors/test_actors/basic_test_actor}/src/lib.rs (100%) rename {test_actors/actors => actors/test_actors}/builtins_test_actor/Cargo.toml (92%) rename {test_actors/actors => actors/test_actors}/builtins_test_actor/README.md (100%) rename {test_actors/actors => actors/test_actors}/builtins_test_actor/src/actor.rs (100%) rename {test_actors/actors/cheatcodes_test_actor => actors/test_actors/builtins_test_actor}/src/lib.rs (100%) create mode 100644 actors/test_actors/cheatcodes_test_actor/Cargo.toml rename {test_actors/actors => actors/test_actors}/cheatcodes_test_actor/README.md (100%) create mode 100644 actors/test_actors/cheatcodes_test_actor/src/actor.rs rename {test_actors/actors/constructor_setup_test_actor => actors/test_actors/cheatcodes_test_actor}/src/lib.rs (100%) rename {test_actors/actors => actors/test_actors}/constructor_setup_test_actor/Cargo.toml (92%) rename {test_actors/actors => actors/test_actors}/constructor_setup_test_actor/README.md (100%) rename {test_actors/actors => actors/test_actors}/constructor_setup_test_actor/src/actor.rs (100%) create mode 100644 actors/test_actors/constructor_setup_test_actor/src/lib.rs delete mode 100644 test_actors/actors/cheatcodes_test_actor/src/actor.rs delete mode 100644 test_actors/src/wasm_bin/mod.rs diff --git a/Cargo.lock b/Cargo.lock index 1b40c97..0d34da2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -287,7 +287,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" [[package]] -name = "basic_test_actor" +name = "basic-test-actor" version = "0.1.0" dependencies = [ "frc42_dispatch", @@ -488,7 +488,7 @@ dependencies = [ ] [[package]] -name = "builtin_test_actor" +name = "builtins-test-actor" version = "0.1.0" dependencies = [ "fil_actors_runtime_v10", @@ -563,7 +563,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] -name = "cheatcodes_test_actor" +name = "cheatcodes-actor" +version = "0.1.0" +dependencies = [ + "frc42_dispatch", + "fvm_ipld_encoding 0.3.3", + "fvm_sdk 3.0.0", + "fvm_shared 3.1.0", + "serde", + "thiserror", +] + +[[package]] +name = "cheatcodes-test-actor" version = "0.1.0" dependencies = [ "fil_actors_runtime_v10", @@ -730,7 +742,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "13418e745008f7349ec7e449155f419a61b92b58a99cc3616942b926825ec76b" [[package]] -name = "constructor_setup_test_actor" +name = "constructor-setup-test-actor" version = "0.1.0" dependencies = [ "cid", @@ -2895,6 +2907,10 @@ dependencies = [ "log", ] +[[package]] +name = "kythera-actors" +version = "0.1.0" + [[package]] name = "kythera-cli" version = "0.1.0-alpha.2" @@ -2960,9 +2976,9 @@ dependencies = [ "fvm_ipld_car", "fvm_ipld_encoding 0.3.3", "fvm_shared 3.1.0", + "kythera-actors", "kythera-common", "kythera-fvm", - "kythera_test_actors", "libsecp256k1", "log", "rand", @@ -2971,10 +2987,6 @@ dependencies = [ "wat", ] -[[package]] -name = "kythera_test_actors" -version = "0.1.0" - [[package]] name = "lazy_static" version = "1.4.0" diff --git a/Cargo.toml b/Cargo.toml index 16fe620..92d8a5d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,8 +5,9 @@ members = [ "lib", "fvm", "common", - "test_actors", - "test_actors/actors/*", + "actors", + "actors/test_actors/*", + "actors/actors/*", ] diff --git a/test_actors/Cargo.toml b/actors/Cargo.toml similarity index 73% rename from test_actors/Cargo.toml rename to actors/Cargo.toml index 7205173..1c6a978 100644 --- a/test_actors/Cargo.toml +++ b/actors/Cargo.toml @@ -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=[] diff --git a/test_actors/actors/basic_test_actor/Cargo.toml b/actors/actors/cheatcodes_actor/Cargo.toml similarity index 93% rename from test_actors/actors/basic_test_actor/Cargo.toml rename to actors/actors/cheatcodes_actor/Cargo.toml index 9b8f15e..e0aa5b1 100644 --- a/test_actors/actors/basic_test_actor/Cargo.toml +++ b/actors/actors/cheatcodes_actor/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "basic_test_actor" +name = "cheatcodes-actor" version = "0.1.0" edition = "2021" publish=false diff --git a/test_actors/actors/basic_test_actor/README.md b/actors/actors/cheatcodes_actor/README.md similarity index 100% rename from test_actors/actors/basic_test_actor/README.md rename to actors/actors/cheatcodes_actor/README.md diff --git a/test_actors/actors/basic_test_actor/src/actor.rs b/actors/actors/cheatcodes_actor/src/actor.rs similarity index 100% rename from test_actors/actors/basic_test_actor/src/actor.rs rename to actors/actors/cheatcodes_actor/src/actor.rs diff --git a/test_actors/actors/basic_test_actor/src/lib.rs b/actors/actors/cheatcodes_actor/src/lib.rs similarity index 100% rename from test_actors/actors/basic_test_actor/src/lib.rs rename to actors/actors/cheatcodes_actor/src/lib.rs diff --git a/test_actors/build.rs b/actors/build.rs similarity index 77% rename from test_actors/build.rs rename to actors/build.rs index 2fc000e..1fe43fe 100644 --- a/test_actors/build.rs +++ b/actors/build.rs @@ -6,13 +6,18 @@ use std::path::Path; use std::process::{Command, Stdio}; use std::thread; -const ACTORS: &[&str] = &[ - "basic_test_actor", - "builtin_test_actor", - "cheatcodes_test_actor", - "constructor_setup_test_actor", +const ACTORS: &[&str] = &[]; + +#[cfg(feature = "testing")] +const TEST_ACTORS: &[&str] = &[ + "cheatcodes-actor", + "builtins-test-actor", + "cheatcodes-test-actor", + "constructor-setup-test-actor", ]; +const FILES_TO_WATCH: &[&str] = &["Cargo.toml", "src", "actors"]; + fn main() -> Result<(), Box> { // Cargo executable location. let cargo = std::env::var_os("CARGO").expect("no CARGO env var"); @@ -28,14 +33,26 @@ fn main() -> Result<(), Box> { Path::new(&std::env::var_os("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR unset")) .join("Cargo.toml"); - for file in ["Cargo.toml", "src", "actors"] { + let mut files_to_watch = FILES_TO_WATCH.to_vec(); + + if cfg!(feature = "testing") { + files_to_watch = [files_to_watch, vec!["test_actors"]].concat(); + } + + for file in files_to_watch { println!("cargo:rerun-if-changed={}", file); } - // Cargo build command for all actors at once. + let mut actors = ACTORS.to_vec(); + + if cfg!(feature = "testing") { + actors = [ACTORS, TEST_ACTORS].concat(); + } + + // Cargo build command for all test_actors at once. let mut cmd = Command::new(cargo); cmd.arg("build") - .args(ACTORS.iter().map(|pkg| "-p=".to_owned() + pkg)) + .args(actors.iter().map(|pkg| "-p=".to_owned() + pkg)) .arg("--target=wasm32-unknown-unknown") .arg("--profile=wasm") .arg("--locked") diff --git a/test_actors/src/README.md b/actors/src/README.md similarity index 69% rename from test_actors/src/README.md rename to actors/src/README.md index a9916a3..3fb5e27 100644 --- a/test_actors/src/README.md +++ b/actors/src/README.md @@ -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. \ No newline at end of file diff --git a/test_actors/src/lib.rs b/actors/src/lib.rs similarity index 100% rename from test_actors/src/lib.rs rename to actors/src/lib.rs diff --git a/actors/src/wasm_bin/mod.rs b/actors/src/wasm_bin/mod.rs new file mode 100644 index 0000000..86879ff --- /dev/null +++ b/actors/src/wasm_bin/mod.rs @@ -0,0 +1,27 @@ +// 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 test test_actors. + pub const BASIC_TEST_ACTOR_BINARY: &[u8] = include_bytes!(wasm_bin!("cheatcodes_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")); +} diff --git a/test_actors/actors/cheatcodes_test_actor/Cargo.toml b/actors/test_actors/basic_test_actor/Cargo.toml similarity index 83% rename from test_actors/actors/cheatcodes_test_actor/Cargo.toml rename to actors/test_actors/basic_test_actor/Cargo.toml index dc78ccb..35421eb 100644 --- a/test_actors/actors/cheatcodes_test_actor/Cargo.toml +++ b/actors/test_actors/basic_test_actor/Cargo.toml @@ -1,16 +1,16 @@ [package] -name = "cheatcodes_test_actor" +name = "basic-test-actor" version = "0.1.0" edition = "2021" publish=false [target.'cfg(target_arch = "wasm32")'.dependencies] -fil_actors_runtime_v10 = "1.0.0" 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"] \ No newline at end of file diff --git a/actors/test_actors/basic_test_actor/README.md b/actors/test_actors/basic_test_actor/README.md new file mode 100644 index 0000000..59d1bab --- /dev/null +++ b/actors/test_actors/basic_test_actor/README.md @@ -0,0 +1,7 @@ +## Basic Test Actor + +This is a basic actor to test our Kythera testing framework. It has two main entry points: `TestOne()` and `TestTwo()`. + +Their entry point values, respectively `3948827889` and `891686990` have been calculated through the FRC 0042 and Helix +`frc42_dispatch` crate. We wanted to use the `frc42_dispatch::match_method!` macro to generate proper method number value at compilation +time but we faced dependencies issue that prevented us from doing so for now. \ No newline at end of file diff --git a/actors/test_actors/basic_test_actor/src/actor.rs b/actors/test_actors/basic_test_actor/src/actor.rs new file mode 100644 index 0000000..d8f069f --- /dev/null +++ b/actors/test_actors/basic_test_actor/src/actor.rs @@ -0,0 +1,54 @@ +// 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(value: &T) -> std::result::Result +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 = sdk::message::method_number(); + match_method!( + method_num, + { + "TestOne" => return_ipld(TestOne()).unwrap(), + "TestTwo" => return_ipld(TestTwo()).unwrap(), + _ => { + sdk::vm::abort( + ExitCode::USR_UNHANDLED_MESSAGE.value(), + Some("Unknown method number"), + ); + } + } + ) +} + +#[allow(non_snake_case)] +fn TestOne() -> &'static str { + "TestOne" +} + +#[allow(non_snake_case)] +fn TestTwo() -> &'static str { + "TestTwo" +} diff --git a/test_actors/actors/builtins_test_actor/src/lib.rs b/actors/test_actors/basic_test_actor/src/lib.rs similarity index 100% rename from test_actors/actors/builtins_test_actor/src/lib.rs rename to actors/test_actors/basic_test_actor/src/lib.rs diff --git a/test_actors/actors/builtins_test_actor/Cargo.toml b/actors/test_actors/builtins_test_actor/Cargo.toml similarity index 92% rename from test_actors/actors/builtins_test_actor/Cargo.toml rename to actors/test_actors/builtins_test_actor/Cargo.toml index a4a77c8..d069be6 100644 --- a/test_actors/actors/builtins_test_actor/Cargo.toml +++ b/actors/test_actors/builtins_test_actor/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "builtin_test_actor" +name = "builtins-test-actor" version = "0.1.0" edition = "2021" publish=false diff --git a/test_actors/actors/builtins_test_actor/README.md b/actors/test_actors/builtins_test_actor/README.md similarity index 100% rename from test_actors/actors/builtins_test_actor/README.md rename to actors/test_actors/builtins_test_actor/README.md diff --git a/test_actors/actors/builtins_test_actor/src/actor.rs b/actors/test_actors/builtins_test_actor/src/actor.rs similarity index 100% rename from test_actors/actors/builtins_test_actor/src/actor.rs rename to actors/test_actors/builtins_test_actor/src/actor.rs diff --git a/test_actors/actors/cheatcodes_test_actor/src/lib.rs b/actors/test_actors/builtins_test_actor/src/lib.rs similarity index 100% rename from test_actors/actors/cheatcodes_test_actor/src/lib.rs rename to actors/test_actors/builtins_test_actor/src/lib.rs diff --git a/actors/test_actors/cheatcodes_test_actor/Cargo.toml b/actors/test_actors/cheatcodes_test_actor/Cargo.toml new file mode 100644 index 0000000..a4da921 --- /dev/null +++ b/actors/test_actors/cheatcodes_test_actor/Cargo.toml @@ -0,0 +1,24 @@ +[package] +name = "cheatcodes-test-actor" +version = "0.1.0" +edition = "2021" +publish=false + +[dependencies] +fil_actors_runtime_v10 = "1.0.0" +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"] } + +[target.'cfg(target_arch = "wasm32")'.dependencies] +fil_actors_runtime_v10 = "1.0.0" +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"] } + +[lib] +crate-type = ["cdylib"] \ No newline at end of file diff --git a/test_actors/actors/cheatcodes_test_actor/README.md b/actors/test_actors/cheatcodes_test_actor/README.md similarity index 100% rename from test_actors/actors/cheatcodes_test_actor/README.md rename to actors/test_actors/cheatcodes_test_actor/README.md diff --git a/actors/test_actors/cheatcodes_test_actor/src/actor.rs b/actors/test_actors/cheatcodes_test_actor/src/actor.rs new file mode 100644 index 0000000..52ed06b --- /dev/null +++ b/actors/test_actors/cheatcodes_test_actor/src/actor.rs @@ -0,0 +1,68 @@ +// Copyright 2023 Polyphene. +// SPDX-License-Identifier: Apache-2.0, MIT + +use frc42_dispatch::match_method; +use fvm_ipld_encoding::ipld_block::IpldBlock; +use fvm_ipld_encoding::DAG_CBOR; +use fvm_sdk as sdk; +use fvm_sdk::NO_DATA_BLOCK_ID; +use fvm_shared::address::Address; +use fvm_shared::bigint::Zero; +use fvm_shared::econ::TokenAmount; +use fvm_shared::error::ExitCode; +use fvm_shared::sys::SendFlags; + +#[no_mangle] +fn invoke(_input: u32) -> u32 { + std::panic::set_hook(Box::new(|info| { + sdk::vm::abort( + ExitCode::USR_ASSERTION_FAILED.value(), + Some(&format!("{info}")), + ) + })); + + let method_num = sdk::message::method_number(); + match_method!( + method_num, + { + "TestWarp" => { + TestWarp(); + + NO_DATA_BLOCK_ID + }, + _ => { + sdk::vm::abort( + ExitCode::USR_UNHANDLED_MESSAGE.value(), + Some("Unknown method number"), + ); + } + } + ) +} + +// Checks that all relevant builtins are deployed at a correct actor Id in Kythera +#[allow(non_snake_case)] +fn TestWarp() { + let timestamp = fvm_sdk::network::tipset_timestamp(); + + assert_eq!(timestamp, 0u64); + + let new_timestamp = 10000u64; + let bytes = fvm_ipld_encoding::to_vec(&new_timestamp).unwrap(); + + let res = fvm_sdk::send::send( + &Address::new_id(98), + 112632689, + Some(IpldBlock::serialize(DAG_CBOR, bytes.as_slice()).unwrap()), + TokenAmount::zero(), + None, + SendFlags::empty(), + ) + .unwrap(); + + assert_eq!(res.exit_code, ExitCode::OK); + + let timestamp = fvm_sdk::network::tipset_timestamp(); + + assert_eq!(timestamp, new_timestamp); +} diff --git a/test_actors/actors/constructor_setup_test_actor/src/lib.rs b/actors/test_actors/cheatcodes_test_actor/src/lib.rs similarity index 100% rename from test_actors/actors/constructor_setup_test_actor/src/lib.rs rename to actors/test_actors/cheatcodes_test_actor/src/lib.rs diff --git a/test_actors/actors/constructor_setup_test_actor/Cargo.toml b/actors/test_actors/constructor_setup_test_actor/Cargo.toml similarity index 92% rename from test_actors/actors/constructor_setup_test_actor/Cargo.toml rename to actors/test_actors/constructor_setup_test_actor/Cargo.toml index 9bfaf52..e0468a2 100644 --- a/test_actors/actors/constructor_setup_test_actor/Cargo.toml +++ b/actors/test_actors/constructor_setup_test_actor/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "constructor_setup_test_actor" +name = "constructor-setup-test-actor" version = "0.1.0" edition = "2021" publish=false diff --git a/test_actors/actors/constructor_setup_test_actor/README.md b/actors/test_actors/constructor_setup_test_actor/README.md similarity index 100% rename from test_actors/actors/constructor_setup_test_actor/README.md rename to actors/test_actors/constructor_setup_test_actor/README.md diff --git a/test_actors/actors/constructor_setup_test_actor/src/actor.rs b/actors/test_actors/constructor_setup_test_actor/src/actor.rs similarity index 100% rename from test_actors/actors/constructor_setup_test_actor/src/actor.rs rename to actors/test_actors/constructor_setup_test_actor/src/actor.rs diff --git a/actors/test_actors/constructor_setup_test_actor/src/lib.rs b/actors/test_actors/constructor_setup_test_actor/src/lib.rs new file mode 100644 index 0000000..6662b42 --- /dev/null +++ b/actors/test_actors/constructor_setup_test_actor/src/lib.rs @@ -0,0 +1,5 @@ +// Copyright 2023 Polyphene. +// SPDX-License-Identifier: Apache-2.0, MIT + +#[cfg(target_arch = "wasm32")] +mod actor; diff --git a/cli/src/search.rs b/cli/src/search.rs index eff4662..1a59178 100644 --- a/cli/src/search.rs +++ b/cli/src/search.rs @@ -63,11 +63,11 @@ fn read_actor>(binary_path: P) -> anyhow::Result { /// Gather the target Actor file and its test files. /// The rules for reading Actor files and it's matching tests are: -/// - All .wasm files that are at the root of the kythera input dir are actors. -/// - All .t.wasm files that are at the root of the kythera wasm dir are test actors. -/// - All .wasm files that are in .t dirs are test actors. +/// - All .wasm files that are at the root of the kythera input dir are test_actors. +/// - All .t.wasm files that are at the root of the kythera wasm dir are test test_actors. +/// - All .wasm files that are in .t dirs are test test_actors. pub fn search_files>(path: P) -> anyhow::Result> { - // Search the root dir and find all the .wasm files there which may be target actors + // Search the root dir and find all the .wasm files there which may be target test_actors // or its matching test dirs and files. // Split into two lists, the first being the target Actors and the second // their matching test files and dirs. @@ -218,7 +218,7 @@ mod tests { methods: vec![Method::new_from_name("TestTransfer").unwrap()], }; - // Create target & test actors files. + // Create target & test test_actors files. create_actors_in_dir( dir_path, vec![("token", &target_actor_abi), ("token.t", &test_actor_abi)], diff --git a/lib/Cargo.toml b/lib/Cargo.toml index 44fdad4..aee489f 100644 --- a/lib/Cargo.toml +++ b/lib/Cargo.toml @@ -27,6 +27,7 @@ fvm_ipld_car = { version = "0.6.0" } fvm_ipld_encoding = { version = "0.3.3" } fvm_shared = { version = "3.1.0", features = ["testing"] } +kythera-actors = { path = "../actors" } kythera-fvm = { path = "../fvm" } kythera-common = { path = "../common" } @@ -38,6 +39,9 @@ rand = "0.8.5" rand_chacha = "0.3.1" thiserror = "1.0.39" +[dev-dependencies.kythera-actors] +path = "../actors" +features = ["testing"] + [dev-dependencies] wat = "1.0.51" -kythera_test_actors = { path = "../test_actors" } diff --git a/lib/src/lib.rs b/lib/src/lib.rs index f053e09..27f5e50 100644 --- a/lib/src/lib.rs +++ b/lib/src/lib.rs @@ -22,7 +22,7 @@ mod state_tree; /// Main interface to test `Actor`s with Kythera. pub struct Tester { - // Builtin actors root Cid used in the Machine + // Builtin test_actors root Cid used in the Machine builtin_actors: BuiltInActors, // State tree constructed before instantiating the Machine state_tree: StateTree, @@ -163,7 +163,7 @@ impl Tester { Err(_) => panic!("Actor Id should be valid"), }; - // Iterate over all test actors + // Iterate over all test test_actors Ok(test_actors .iter() .map(|test_actor| { @@ -329,7 +329,7 @@ mod tests { // Instantiate tester let tester = Tester::new(); - // Testing that we got proper CIDs for our revision for builtin actors and that they are + // Testing that we got proper CIDs for our revision for builtin test_actors and that they are // set in the state tree assert_eq!(tester.builtin_actors.root, builtins_actors.root); assert!(tester diff --git a/lib/src/state_tree.rs b/lib/src/state_tree.rs index 22945ab..c5b10ae 100644 --- a/lib/src/state_tree.rs +++ b/lib/src/state_tree.rs @@ -91,7 +91,7 @@ impl StateTree { Ok(()) } - /// Load the built-in actors into the `Blockstore`. + /// Load the built-in test_actors into the `Blockstore`. /// And activate them on the `StateTree`. pub fn load_builtin_actors(&mut self) -> BuiltInActors { // Load the built-in Actors diff --git a/lib/tests/lib.rs b/lib/tests/lib.rs index 3435109..0786e51 100644 --- a/lib/tests/lib.rs +++ b/lib/tests/lib.rs @@ -1,9 +1,10 @@ use fvm_shared::error::ExitCode; +use kythera_actors::wasm_bin::test_actors::{ + BASIC_TEST_ACTOR_BINARY, BUILTINS_TEST_ACTOR_BINARY, CHEATCODES_TEST_ACTOR_BINARY, + CONSTRUCTOR_SETUP_TEST_ACTOR_BINARY, +}; use kythera_common::abi::{Abi, Method, MethodType}; use kythera_lib::{TestResultType, Tester, WasmActor}; -use kythera_test_actors::wasm_bin::{ - BASIC_TEST_ACTOR_BINARY, BUILTIN_TEST_ACTOR_BINARY, CONSTRUCTOR_SETUP_TEST_ACTOR_BINARY, -}; const TARGET_WAT: &str = r#" ;; Mock invoke function @@ -103,7 +104,7 @@ fn test_builtin_deployed() { ); // Set test actor - let test_wasm_bin: Vec = Vec::from(BUILTIN_TEST_ACTOR_BINARY); + let test_wasm_bin: Vec = Vec::from(BUILTINS_TEST_ACTOR_BINARY); let test_abi = Abi { constructor: None, set_up: None, @@ -146,7 +147,6 @@ fn test_constructor_and_set_up_called() { let mut tester = Tester::new(); // Set target actor - set_target_actor( &mut tester, String::from("Target"), @@ -191,3 +191,54 @@ fn test_constructor_and_set_up_called() { } } } + +#[test] +fn test_cheatcodes() { + // Instantiate tester + let mut tester = Tester::new(); + + // Set target actor + set_target_actor( + &mut tester, + String::from("Target"), + wat::parse_str(TARGET_WAT).unwrap(), + Abi { + constructor: None, + set_up: None, + methods: vec![], + }, + ); + + // Set test actor + let test_wasm_bin: Vec = Vec::from(CHEATCODES_TEST_ACTOR_BINARY); + let test_abi = Abi { + constructor: None, + set_up: None, + methods: vec![Method::new_from_name("TestWarp").unwrap()], + }; + let test_actor = WasmActor::new(String::from("Cheatcodes Tests"), test_wasm_bin, test_abi); + + match tester.test(&[test_actor.clone()], None) { + Err(_) => { + panic!("Could not run test when testing Tester") + } + Ok(test_res) => { + assert_eq!(test_res.len(), 1); + assert_eq!(test_res[0].results.as_ref().unwrap().len(), 1); + assert_eq!(test_res[0].test_actor, &test_actor); + test_res[0] + .results + .as_ref() + .unwrap() + .iter() + .for_each(|result| match (result.method().r#type(), result.ret()) { + (MethodType::Test, TestResultType::Passed(apply_ret)) => { + assert_eq!(apply_ret.msg_receipt.exit_code, ExitCode::OK); + } + apply_ret => { + panic!("test against basic test actor should pass: {apply_ret:?}") + } + }) + } + } +} diff --git a/test_actors/actors/cheatcodes_test_actor/src/actor.rs b/test_actors/actors/cheatcodes_test_actor/src/actor.rs deleted file mode 100644 index 4bc9251..0000000 --- a/test_actors/actors/cheatcodes_test_actor/src/actor.rs +++ /dev/null @@ -1,129 +0,0 @@ -// Copyright 2023 Polyphene. -// SPDX-License-Identifier: Apache-2.0, MIT - -use fil_actors_runtime_v10::runtime::builtins::Type; -use fil_actors_runtime_v10::{ - BURNT_FUNDS_ACTOR_ADDR, CRON_ACTOR_ADDR, DATACAP_TOKEN_ACTOR_ADDR, DATACAP_TOKEN_ACTOR_ID, - INIT_ACTOR_ADDR, REWARD_ACTOR_ADDR, STORAGE_MARKET_ACTOR_ADDR, STORAGE_POWER_ACTOR_ADDR, - SYSTEM_ACTOR_ADDR, VERIFIED_REGISTRY_ACTOR_ADDR, -}; -use frc42_dispatch::match_method; -use fvm_sdk as sdk; -use fvm_sdk::actor::{get_actor_code_cid, get_builtin_actor_type}; -use fvm_sdk::NO_DATA_BLOCK_ID; -use fvm_shared::error::ExitCode; - -#[no_mangle] -fn invoke(_input: u32) -> u32 { - std::panic::set_hook(Box::new(|info| { - sdk::vm::abort( - ExitCode::USR_ASSERTION_FAILED.value(), - Some(&format!("{info}")), - ) - })); - - let method_num = sdk::message::method_number(); - match_method!( - method_num, - { - "TestBuiltinsDeployed" => { - TestBuiltinsDeployed(); - - NO_DATA_BLOCK_ID - }, - _ => { - sdk::vm::abort( - ExitCode::USR_UNHANDLED_MESSAGE.value(), - Some("Unknown method number"), - ); - } - } - ) -} - -// Checks that all relevant builtins are deployed at a correct actor Id in Kythera -#[allow(non_snake_case)] -fn TestBuiltinsDeployed() { - // Test system actor deployment. - let code_cid = get_actor_code_cid(&SYSTEM_ACTOR_ADDR) - .unwrap_or_else(|| panic!("Should get an code CID at address: {}", &SYSTEM_ACTOR_ADDR)); - let actor_type = get_builtin_actor_type(&code_cid) - .unwrap_or_else(|| panic!("Should get a builtin actor type for CID: {}", &code_cid)); - assert_eq!(actor_type, Type::System as i32); - - // Test init actor deployment. - let code_cid = get_actor_code_cid(&INIT_ACTOR_ADDR) - .unwrap_or_else(|| panic!("Should get an code CID at address: {}", &INIT_ACTOR_ADDR)); - let actor_type = get_builtin_actor_type(&code_cid) - .unwrap_or_else(|| panic!("Should get a builtin actor type for CID: {}", &code_cid)); - assert_eq!(actor_type, Type::Init as i32); - - // Test reward actor deployment. - let code_cid = get_actor_code_cid(&REWARD_ACTOR_ADDR) - .unwrap_or_else(|| panic!("Should get an code CID at address: {}", &REWARD_ACTOR_ADDR)); - let actor_type = get_builtin_actor_type(&code_cid) - .unwrap_or_else(|| panic!("Should get a builtin actor type for CID: {}", &code_cid)); - assert_eq!(actor_type, Type::Reward as i32); - - // Test cron actor deployment. - let code_cid = get_actor_code_cid(&CRON_ACTOR_ADDR) - .unwrap_or_else(|| panic!("Should get an code CID at address: {}", &CRON_ACTOR_ADDR)); - let actor_type = get_builtin_actor_type(&code_cid) - .unwrap_or_else(|| panic!("Should get a builtin actor type for CID: {}", &code_cid)); - assert_eq!(actor_type, Type::Cron as i32); - - // Test power actor deployment. - let code_cid = get_actor_code_cid(&STORAGE_POWER_ACTOR_ADDR).unwrap_or_else(|| { - panic!( - "Should get an code CID at address: {}", - &STORAGE_POWER_ACTOR_ADDR - ) - }); - let actor_type = get_builtin_actor_type(&code_cid) - .unwrap_or_else(|| panic!("Should get a builtin actor type for CID: {}", &code_cid)); - assert_eq!(actor_type, Type::Power as i32); - - // Test market actor deployment. - let code_cid = get_actor_code_cid(&STORAGE_MARKET_ACTOR_ADDR).unwrap_or_else(|| { - panic!( - "Should get an code CID at address: {}", - &STORAGE_MARKET_ACTOR_ADDR - ) - }); - let actor_type = get_builtin_actor_type(&code_cid) - .unwrap_or_else(|| panic!("Should get a builtin actor type for CID: {}", &code_cid)); - assert_eq!(actor_type, Type::Market as i32); - - // Test verified registry actor deployment. - let code_cid = get_actor_code_cid(&VERIFIED_REGISTRY_ACTOR_ADDR).unwrap_or_else(|| { - panic!( - "Should get an code CID at address: {}", - &VERIFIED_REGISTRY_ACTOR_ADDR - ) - }); - let actor_type = get_builtin_actor_type(&code_cid) - .unwrap_or_else(|| panic!("Should get a builtin actor type for CID: {}", &code_cid)); - assert_eq!(actor_type, Type::VerifiedRegistry as i32); - - // Test datacap actor deployment. - let code_cid = get_actor_code_cid(&DATACAP_TOKEN_ACTOR_ADDR).unwrap_or_else(|| { - panic!( - "Should get an code CID at address: {}", - &DATACAP_TOKEN_ACTOR_ID - ) - }); - let actor_type = get_builtin_actor_type(&code_cid) - .unwrap_or_else(|| panic!("Should get a builtin actor type for CID: {}", &code_cid)); - assert_eq!(actor_type, Type::DataCap as i32); - - // Test burnt funds actor deployment. - let code_cid = get_actor_code_cid(&BURNT_FUNDS_ACTOR_ADDR).unwrap_or_else(|| { - panic!( - "Should get an code CID at address: {}", - &BURNT_FUNDS_ACTOR_ADDR - ) - }); - let actor_type = get_builtin_actor_type(&code_cid) - .unwrap_or_else(|| panic!("Should get a builtin actor type for CID: {}", &code_cid)); - assert_eq!(actor_type, Type::Account as i32); -} diff --git a/test_actors/src/wasm_bin/mod.rs b/test_actors/src/wasm_bin/mod.rs deleted file mode 100644 index 4aeb270..0000000 --- a/test_actors/src/wasm_bin/mod.rs +++ /dev/null @@ -1,21 +0,0 @@ -// 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" - ) - }; -} - -// Integration test actors. -pub const BASIC_TEST_ACTOR_BINARY: &[u8] = include_bytes!(wasm_bin!("basic_test_actor")); -pub const BUILTIN_TEST_ACTOR_BINARY: &[u8] = include_bytes!(wasm_bin!("builtin_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")); From 1a70fad6ddaed19c1108501fb4f558450ef1f246 Mon Sep 17 00:00:00 2001 From: Thomas Chataigner Date: Thu, 13 Apr 2023 12:11:10 +0200 Subject: [PATCH 25/38] feat(cheatcodes): WIP trying to implement a persistent context for our cheatcodes --- Cargo.lock | 2 + actors/actors/cheatcodes_actor/Cargo.toml | 8 + actors/actors/cheatcodes_actor/src/actor.rs | 59 ++-- actors/build.rs | 5 +- actors/src/wasm_bin/mod.rs | 2 +- .../cheatcodes_test_actor/src/actor.rs | 18 +- common/src/abi/mod.rs | 10 + fvm/Cargo.toml | 3 + fvm/src/call_manager.rs | 169 +++++++++ fvm/src/context.rs | 38 ++ fvm/src/executor.rs | 7 +- fvm/src/kernel.rs | 330 ++++++++++++++++++ fvm/src/lib.rs | 4 + fvm/src/utils.rs | 7 + lib/src/lib.rs | 1 + lib/src/state_tree.rs | 53 ++- lib/tests/lib.rs | 1 + 17 files changed, 656 insertions(+), 61 deletions(-) create mode 100644 fvm/src/call_manager.rs create mode 100644 fvm/src/context.rs create mode 100644 fvm/src/kernel.rs create mode 100644 fvm/src/utils.rs diff --git a/Cargo.lock b/Cargo.lock index a17711b..b6bd09a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3059,6 +3059,8 @@ dependencies = [ "fvm_ipld_blockstore", "fvm_ipld_encoding 0.3.3", "fvm_shared 3.1.0", + "kythera-common", + "lazy_static", "multihash", ] diff --git a/actors/actors/cheatcodes_actor/Cargo.toml b/actors/actors/cheatcodes_actor/Cargo.toml index e0aa5b1..d5c02e9 100644 --- a/actors/actors/cheatcodes_actor/Cargo.toml +++ b/actors/actors/cheatcodes_actor/Cargo.toml @@ -4,6 +4,14 @@ version = "0.1.0" edition = "2021" publish=false +[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" } + [target.'cfg(target_arch = "wasm32")'.dependencies] frc42_dispatch = "3.1.0" fvm_sdk = { version = "3.0.0" } diff --git a/actors/actors/cheatcodes_actor/src/actor.rs b/actors/actors/cheatcodes_actor/src/actor.rs index d8f069f..0d6c194 100644 --- a/actors/actors/cheatcodes_actor/src/actor.rs +++ b/actors/actors/cheatcodes_actor/src/actor.rs @@ -2,39 +2,39 @@ // 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_ipld_encoding::{de::DeserializeOwned, RawBytes}; +use fvm_sdk::NO_DATA_BLOCK_ID; 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(value: &T) -> std::result::Result -where - T: ser::Serialize + ?Sized, -{ - let bytes = fvm_ipld_encoding::to_vec(value)?; - Ok(sdk::ipld::put_block(DAG_CBOR, bytes.as_slice())?) +/// Deserialize message parameters into given struct. +pub fn deserialize_params(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 = sdk::message::method_number(); +fn invoke(input: u32) -> u32 { + let method_num = fvm_sdk::message::method_number(); match_method!( method_num, { - "TestOne" => return_ipld(TestOne()).unwrap(), - "TestTwo" => return_ipld(TestTwo()).unwrap(), + "Warp" => { + // Ensure that the message params can be deserialized. + let new_timestamp: u64 = deserialize_params(input); + + Warp(new_timestamp); + + NO_DATA_BLOCK_ID + }, _ => { - sdk::vm::abort( + fvm_sdk::vm::abort( ExitCode::USR_UNHANDLED_MESSAGE.value(), Some("Unknown method number"), ); @@ -43,12 +43,7 @@ fn invoke(_input: u32) -> u32 { ) } +/// Warp the machine context to a given timestamp. Aside the handling of the message in the Kernel, +/// there is currently nNo additional logic is currently needed in the execution. #[allow(non_snake_case)] -fn TestOne() -> &'static str { - "TestOne" -} - -#[allow(non_snake_case)] -fn TestTwo() -> &'static str { - "TestTwo" -} +fn Warp(_new_timestamp: u64) {} diff --git a/actors/build.rs b/actors/build.rs index 082a5af..d134e7f 100644 --- a/actors/build.rs +++ b/actors/build.rs @@ -6,17 +6,18 @@ use std::path::Path; use std::process::{Command, Stdio}; use std::thread; -const ACTORS: &[&str] = &[]; +const ACTORS: &[&str] = &["cheatcodes-actor"]; #[cfg(feature = "testing")] const TEST_ACTORS: &[&str] = &[ - "cheatcodes-actor", + "basic-test-actor", "builtins-test-actor", "cheatcodes-test-actor", "constructor-setup-test-actor", ]; const FILES_TO_WATCH: &[&str] = &["Cargo.toml", "src", "actors"]; + fn main() -> Result<(), Box> { // Cargo executable location. let cargo = std::env::var_os("CARGO").expect("no CARGO env var"); diff --git a/actors/src/wasm_bin/mod.rs b/actors/src/wasm_bin/mod.rs index 86879ff..0308778 100644 --- a/actors/src/wasm_bin/mod.rs +++ b/actors/src/wasm_bin/mod.rs @@ -18,7 +18,7 @@ pub const CHEATCODES_ACTOR_BINARY: &[u8] = include_bytes!(wasm_bin!("cheatcodes_ #[cfg(feature = "testing")] pub mod test_actors { // Integration test test_actors. - pub const BASIC_TEST_ACTOR_BINARY: &[u8] = include_bytes!(wasm_bin!("cheatcodes_actor")); + pub const BASIC_TEST_ACTOR_BINARY: &[u8] = include_bytes!(wasm_bin!("basic_test_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")); diff --git a/actors/test_actors/cheatcodes_test_actor/src/actor.rs b/actors/test_actors/cheatcodes_test_actor/src/actor.rs index 52ed06b..a97ae6a 100644 --- a/actors/test_actors/cheatcodes_test_actor/src/actor.rs +++ b/actors/test_actors/cheatcodes_test_actor/src/actor.rs @@ -14,13 +14,6 @@ use fvm_shared::sys::SendFlags; #[no_mangle] fn invoke(_input: u32) -> u32 { - std::panic::set_hook(Box::new(|info| { - sdk::vm::abort( - ExitCode::USR_ASSERTION_FAILED.value(), - Some(&format!("{info}")), - ) - })); - let method_num = sdk::message::method_number(); match_method!( method_num, @@ -28,7 +21,7 @@ fn invoke(_input: u32) -> u32 { "TestWarp" => { TestWarp(); - NO_DATA_BLOCK_ID + return NO_DATA_BLOCK_ID; }, _ => { sdk::vm::abort( @@ -40,7 +33,7 @@ fn invoke(_input: u32) -> u32 { ) } -// Checks that all relevant builtins are deployed at a correct actor Id in Kythera +// Checks that all relevant builtins are deployed at a correct actor Id in Kythera. #[allow(non_snake_case)] fn TestWarp() { let timestamp = fvm_sdk::network::tipset_timestamp(); @@ -48,12 +41,11 @@ fn TestWarp() { assert_eq!(timestamp, 0u64); let new_timestamp = 10000u64; - let bytes = fvm_ipld_encoding::to_vec(&new_timestamp).unwrap(); let res = fvm_sdk::send::send( &Address::new_id(98), 112632689, - Some(IpldBlock::serialize(DAG_CBOR, bytes.as_slice()).unwrap()), + Some(IpldBlock::serialize(DAG_CBOR, &new_timestamp).unwrap()), TokenAmount::zero(), None, SendFlags::empty(), @@ -62,7 +54,7 @@ fn TestWarp() { assert_eq!(res.exit_code, ExitCode::OK); - let timestamp = fvm_sdk::network::tipset_timestamp(); + let nc_timestamp = unsafe { fvm_sdk::sys::network::context().unwrap().timestamp }; - assert_eq!(timestamp, new_timestamp); + assert_eq!(new_timestamp, nc_timestamp); } diff --git a/common/src/abi/mod.rs b/common/src/abi/mod.rs index ee44854..f302180 100644 --- a/common/src/abi/mod.rs +++ b/common/src/abi/mod.rs @@ -137,6 +137,16 @@ impl<'de> serde::Deserialize<'de> for Abi { } } +impl Default for Abi { + fn default() -> Self { + Self { + constructor: None, + set_up: None, + methods: vec![], + } + } +} + /// Method number indicator for calling Actor methods. pub type MethodNum = u64; diff --git a/fvm/Cargo.toml b/fvm/Cargo.toml index ebe3d9b..e8e73cf 100644 --- a/fvm/Cargo.toml +++ b/fvm/Cargo.toml @@ -12,4 +12,7 @@ fvm = { version = "3.1.0", default-features = false, features = ["testing"] } fvm_ipld_blockstore = "0.1.1" fvm_ipld_encoding = { version = "0.3.3" } fvm_shared = { version = "3.1.0" } +lazy_static = "1.4.0" multihash = { version = "0.16.1", default-features = false } + +kythera-common = { path = "../common" } diff --git a/fvm/src/call_manager.rs b/fvm/src/call_manager.rs new file mode 100644 index 0000000..a6c5fee --- /dev/null +++ b/fvm/src/call_manager.rs @@ -0,0 +1,169 @@ +use crate::context::OverrideContext; +use crate::externs::FakeExterns; +use crate::machine::KytheraMachine; +use anyhow::anyhow; +use cid::Cid; +use fvm::call_manager::{CallManager, DefaultCallManager, FinishRet, InvocationResult}; +use fvm::engine::Engine; +use fvm::gas::{Gas, GasTracker}; +use fvm::kernel::{Block, ExecutionError}; +use fvm::machine::Machine; +use fvm::state_tree::ActorState; +use fvm::{DefaultKernel, Kernel}; +use fvm_ipld_blockstore::MemoryBlockstore; +use fvm_ipld_encoding::from_slice; +use fvm_shared::address::Address; +use fvm_shared::econ::TokenAmount; +use fvm_shared::event::StampedEvent; +use fvm_shared::{ActorID, MethodNum}; + +pub struct KytheraCallManager { + inner: DefaultCallManager>, + override_context: OverrideContext, +} + +impl CallManager for KytheraCallManager { + type Machine = KytheraMachine; + + fn new( + machine: Self::Machine, + engine: Engine, + gas_limit: u64, + origin: ActorID, + origin_address: Address, + receiver: Option, + receiver_address: Address, + nonce: u64, + gas_premium: TokenAmount, + ) -> Self { + Self { + inner: DefaultCallManager::new( + machine, + engine, + gas_limit, + origin, + origin_address, + receiver, + receiver_address, + nonce, + gas_premium, + ), + override_context: OverrideContext::default(), + } + } + + fn send>( + &mut self, + from: ActorID, + to: Address, + method: MethodNum, + params: Option, + value: &TokenAmount, + gas_limit: Option, + read_only: bool, + ) -> fvm::kernel::Result { + if &to == &Address::new_id(98) { + if method == *crate::utils::WARP_NUM { + if !params.is_none() { + let new_timestamp: u64 = from_slice(params.clone().unwrap().data()).unwrap(); + dbg!(new_timestamp); + } + } + } + // TODO Having call manager require the Kernel to refer to the same structure prevent us from doing this + self.inner.send::>>>( + from, to, method, params, value, gas_limit, read_only, + ) + } + + fn with_transaction( + &mut self, + _f: impl FnOnce(&mut Self) -> fvm::kernel::Result, + ) -> fvm::kernel::Result { + // TODO having the callback function refering to this structure prevent us from passing it to the inner call manager + Err(ExecutionError::Fatal(anyhow!("aa"))) + } + + fn finish(self) -> (fvm::kernel::Result, Self::Machine) { + self.inner.finish() + } + + fn machine(&self) -> &Self::Machine { + self.inner.machine() + } + + fn machine_mut(&mut self) -> &mut Self::Machine { + self.inner.machine_mut() + } + + fn engine(&self) -> &Engine { + self.inner.engine() + } + + fn gas_tracker(&self) -> &GasTracker { + self.inner.gas_tracker() + } + + fn gas_premium(&self) -> &TokenAmount { + self.inner.gas_premium() + } + + fn origin(&self) -> ActorID { + self.inner.origin() + } + + fn next_actor_address(&self) -> Address { + self.inner.next_actor_address() + } + + fn create_actor( + &mut self, + code_id: Cid, + actor_id: ActorID, + delegated_address: Option
, + ) -> fvm::kernel::Result<()> { + self.inner + .create_actor(code_id, actor_id, delegated_address) + } + + fn resolve_address(&self, address: &Address) -> fvm::kernel::Result> { + self.inner.resolve_address(address) + } + + fn set_actor(&mut self, id: ActorID, state: ActorState) -> fvm::kernel::Result<()> { + self.inner.set_actor(id, state) + } + + fn get_actor(&self, id: ActorID) -> fvm::kernel::Result> { + self.inner.get_actor(id) + } + + fn delete_actor(&mut self, id: ActorID) -> fvm::kernel::Result<()> { + self.inner.delete_actor(id) + } + + fn transfer( + &mut self, + from: ActorID, + to: ActorID, + value: &TokenAmount, + ) -> fvm::kernel::Result<()> { + self.inner.transfer(from, to, value) + } + + fn nonce(&self) -> u64 { + self.inner.nonce() + } + + fn invocation_count(&self) -> u64 { + self.inner.invocation_count() + } + + fn limiter_mut(&mut self) -> &mut ::Limiter { + self.inner.limiter_mut() + } + + fn append_event(&mut self, evt: StampedEvent) { + self.inner.append_event(evt) + } +} diff --git a/fvm/src/context.rs b/fvm/src/context.rs new file mode 100644 index 0000000..be7f518 --- /dev/null +++ b/fvm/src/context.rs @@ -0,0 +1,38 @@ +use fvm::machine::{MachineContext, NetworkConfig}; +use fvm_shared::chainid::ChainID; +use fvm_shared::clock::ChainEpoch; +use fvm_shared::econ::TokenAmount; + +pub trait Override { + fn override_with_context(&self, context: &S) -> Self; +} + +#[derive(Default, Debug, Clone)] +pub struct OverrideContext { + /// The Chain ID of the network. + pub chain_id: Option, + + /// The current epoch. + pub epoch: Option, + + /// The UNIX timestamp (in seconds) of the current tipset. + pub timestamp: Option, + + /// The base fee that's in effect when the Machine runs. + pub base_fee: Option, +} + +impl Override for MachineContext { + fn override_with_context(&self, context: &OverrideContext) -> MachineContext { + MachineContext { + network: NetworkConfig { + chain_id: context.chain_id.unwrap_or(self.network.chain_id), + ..self.network.clone() + }, + epoch: context.epoch.unwrap_or(self.epoch), + timestamp: context.timestamp.unwrap_or(self.timestamp), + base_fee: context.base_fee.clone().unwrap_or(self.base_fee.clone()), + ..self.clone() + } + } +} diff --git a/fvm/src/executor.rs b/fvm/src/executor.rs index bb87423..0041802 100644 --- a/fvm/src/executor.rs +++ b/fvm/src/executor.rs @@ -4,11 +4,10 @@ use crate::externs::FakeExterns; use crate::machine::KytheraMachine; use cid::Cid; -use fvm::call_manager::DefaultCallManager; use fvm::engine::EnginePool; use fvm::executor::DefaultExecutor; -use fvm::DefaultKernel; +use crate::kernel::KytheraKernel; pub use fvm::executor::Executor as _; pub use fvm::executor::{ApplyFailure, ApplyKind, ApplyRet}; use fvm::machine::{Machine, NetworkConfig}; @@ -25,9 +24,7 @@ const DEFAULT_BASE_FEE: u64 = 100; /// Wrapper around `fvm` Executor with sane defaults. pub struct KytheraExecutor { - inner: DefaultExecutor< - DefaultKernel>>, - >, + inner: DefaultExecutor, account_address: Address, test_address: Address, target_actor_id: RawBytes, diff --git a/fvm/src/kernel.rs b/fvm/src/kernel.rs new file mode 100644 index 0000000..23f4d51 --- /dev/null +++ b/fvm/src/kernel.rs @@ -0,0 +1,330 @@ +use crate::call_manager::KytheraCallManager; +use crate::externs::FakeExterns; +use crate::machine::KytheraMachine; +use cid::Cid; +use fvm::call_manager::CallManager; +use fvm::gas::{Gas, GasTimer, PriceList}; +use fvm::kernel::{ + ActorOps, BlockId, BlockRegistry, BlockStat, CircSupplyOps, CryptoOps, DebugOps, EventOps, + GasOps, IpldBlockOps, LimiterOps, MessageOps, NetworkOps, RandomnessOps, SelfOps, SendOps, + SendResult, +}; +use fvm::machine::Machine; +use fvm::{DefaultKernel, Kernel}; +use fvm_ipld_blockstore::MemoryBlockstore; +use fvm_shared::address::Address; +use fvm_shared::clock::ChainEpoch; +use fvm_shared::consensus::ConsensusFault; +use fvm_shared::crypto::signature::{ + SignatureType, SECP_PUB_LEN, SECP_SIG_LEN, SECP_SIG_MESSAGE_HASH_SIZE, +}; +use fvm_shared::econ::TokenAmount; +use fvm_shared::piece::PieceInfo; +use fvm_shared::randomness::RANDOMNESS_LENGTH; +use fvm_shared::sector::{ + AggregateSealVerifyProofAndInfos, RegisteredSealProof, ReplicaUpdateInfo, SealVerifyInfo, + WindowPoStVerifyInfo, +}; +use fvm_shared::sys::out::network::NetworkContext; +use fvm_shared::sys::out::vm::MessageContext; +use fvm_shared::sys::SendFlags; +use fvm_shared::{ActorID, MethodNum}; + +pub struct KytheraKernel { + inner: DefaultKernel, +} + +impl Kernel for KytheraKernel { + type CallManager = KytheraCallManager; + + fn into_inner(self) -> (Self::CallManager, BlockRegistry) + where + Self: Sized, + { + self.inner.into_inner() + } + + fn new( + mgr: Self::CallManager, + blocks: BlockRegistry, + caller: ActorID, + actor_id: ActorID, + method: MethodNum, + value_received: TokenAmount, + read_only: bool, + ) -> Self + where + Self: Sized, + { + Self { + inner: DefaultKernel::new( + mgr, + blocks, + caller, + actor_id, + method, + value_received, + read_only, + ), + } + } + + fn machine(&self) -> &::Machine { + self.inner.machine() + } +} + +impl ActorOps for KytheraKernel { + fn resolve_address(&self, address: &Address) -> fvm::kernel::Result { + self.inner.resolve_address(address) + } + + fn lookup_delegated_address(&self, actor_id: ActorID) -> fvm::kernel::Result> { + self.inner.lookup_delegated_address(actor_id) + } + + fn get_actor_code_cid(&self, id: ActorID) -> fvm::kernel::Result { + self.inner.get_actor_code_cid(id) + } + + fn next_actor_address(&self) -> fvm::kernel::Result
{ + self.inner.next_actor_address() + } + + fn create_actor( + &mut self, + code_cid: Cid, + actor_id: ActorID, + delegated_address: Option
, + ) -> fvm::kernel::Result<()> { + self.inner + .create_actor(code_cid, actor_id, delegated_address) + } + + fn get_builtin_actor_type(&self, code_cid: &Cid) -> fvm::kernel::Result { + self.inner.get_builtin_actor_type(code_cid) + } + + fn get_code_cid_for_type(&self, typ: u32) -> fvm::kernel::Result { + self.inner.get_code_cid_for_type(typ) + } + + fn balance_of(&self, actor_id: ActorID) -> fvm::kernel::Result { + self.inner.balance_of(actor_id) + } +} + +impl IpldBlockOps for KytheraKernel { + fn block_open(&mut self, cid: &Cid) -> fvm::kernel::Result<(BlockId, BlockStat)> { + self.inner.block_open(cid) + } + + fn block_create(&mut self, codec: u64, data: &[u8]) -> fvm::kernel::Result { + self.inner.block_create(codec, data) + } + + fn block_link( + &mut self, + id: BlockId, + hash_fun: u64, + hash_len: u32, + ) -> fvm::kernel::Result { + self.inner.block_link(id, hash_fun, hash_len) + } + + fn block_read(&self, id: BlockId, offset: u32, buf: &mut [u8]) -> fvm::kernel::Result { + self.inner.block_read(id, offset, buf) + } + + fn block_stat(&self, id: BlockId) -> fvm::kernel::Result { + self.inner.block_stat(id) + } +} + +impl CircSupplyOps for KytheraKernel { + fn total_fil_circ_supply(&self) -> fvm::kernel::Result { + self.inner.total_fil_circ_supply() + } +} + +impl CryptoOps for KytheraKernel { + fn verify_signature( + &self, + sig_type: SignatureType, + signature: &[u8], + signer: &Address, + plaintext: &[u8], + ) -> fvm::kernel::Result { + self.inner + .verify_signature(sig_type, signature, signer, plaintext) + } + + fn recover_secp_public_key( + &self, + hash: &[u8; SECP_SIG_MESSAGE_HASH_SIZE], + signature: &[u8; SECP_SIG_LEN], + ) -> fvm::kernel::Result<[u8; SECP_PUB_LEN]> { + self.inner.recover_secp_public_key(hash, signature) + } + + fn hash(&self, code: u64, data: &[u8]) -> fvm::kernel::Result { + self.inner.hash(code, data) + } + + fn compute_unsealed_sector_cid( + &self, + proof_type: RegisteredSealProof, + pieces: &[PieceInfo], + ) -> fvm::kernel::Result { + self.inner.compute_unsealed_sector_cid(proof_type, pieces) + } + + fn verify_seal(&self, vi: &SealVerifyInfo) -> fvm::kernel::Result { + self.inner.verify_seal(vi) + } + + fn verify_post(&self, verify_info: &WindowPoStVerifyInfo) -> fvm::kernel::Result { + self.inner.verify_post(verify_info) + } + + fn verify_consensus_fault( + &self, + h1: &[u8], + h2: &[u8], + extra: &[u8], + ) -> fvm::kernel::Result> { + self.inner.verify_consensus_fault(h1, h2, extra) + } + + fn batch_verify_seals(&self, vis: &[SealVerifyInfo]) -> fvm::kernel::Result> { + self.inner.batch_verify_seals(vis) + } + + fn verify_aggregate_seals( + &self, + aggregate: &AggregateSealVerifyProofAndInfos, + ) -> fvm::kernel::Result { + self.inner.verify_aggregate_seals(aggregate) + } + + fn verify_replica_update(&self, replica: &ReplicaUpdateInfo) -> fvm::kernel::Result { + self.inner.verify_replica_update(replica) + } +} + +impl DebugOps for KytheraKernel { + fn log(&self, msg: String) { + self.inner.log(msg) + } + + fn debug_enabled(&self) -> bool { + self.inner.debug_enabled() + } + + fn store_artifact(&self, name: &str, data: &[u8]) -> fvm::kernel::Result<()> { + self.inner.store_artifact(name, data) + } +} + +impl EventOps for KytheraKernel { + fn emit_event(&mut self, raw_evt: &[u8]) -> fvm::kernel::Result<()> { + self.inner.emit_event(raw_evt) + } +} + +impl GasOps for KytheraKernel { + fn gas_used(&self) -> Gas { + self.inner.gas_used() + } + + fn gas_available(&self) -> Gas { + self.inner.gas_available() + } + + fn charge_gas(&self, name: &str, compute: Gas) -> fvm::kernel::Result { + self.inner.charge_gas(name, compute) + } + + fn price_list(&self) -> &PriceList { + self.inner.price_list() + } +} + +impl MessageOps for KytheraKernel { + fn msg_context(&self) -> fvm::kernel::Result { + self.inner.msg_context() + } +} + +impl NetworkOps for KytheraKernel { + fn network_context(&self) -> fvm::kernel::Result { + self.inner.network_context() + } + + fn tipset_cid(&self, epoch: ChainEpoch) -> fvm::kernel::Result { + self.inner.tipset_cid(epoch) + } +} + +impl RandomnessOps for KytheraKernel { + fn get_randomness_from_tickets( + &self, + personalization: i64, + rand_epoch: ChainEpoch, + entropy: &[u8], + ) -> fvm::kernel::Result<[u8; RANDOMNESS_LENGTH]> { + self.inner + .get_randomness_from_tickets(personalization, rand_epoch, entropy) + } + + fn get_randomness_from_beacon( + &self, + personalization: i64, + rand_epoch: ChainEpoch, + entropy: &[u8], + ) -> fvm::kernel::Result<[u8; RANDOMNESS_LENGTH]> { + self.inner + .get_randomness_from_beacon(personalization, rand_epoch, entropy) + } +} + +impl SelfOps for KytheraKernel { + fn root(&self) -> fvm::kernel::Result { + self.inner.root() + } + + fn set_root(&mut self, root: Cid) -> fvm::kernel::Result<()> { + self.inner.set_root(root) + } + + fn current_balance(&self) -> fvm::kernel::Result { + self.inner.current_balance() + } + + fn self_destruct(&mut self, beneficiary: &Address) -> fvm::kernel::Result<()> { + self.inner.self_destruct(beneficiary) + } +} + +impl SendOps for KytheraKernel { + fn send( + &mut self, + recipient: &Address, + method: u64, + params: BlockId, + value: &TokenAmount, + gas_limit: Option, + flags: SendFlags, + ) -> fvm::kernel::Result { + self.inner + .send(recipient, method, params, value, gas_limit, flags) + } +} + +impl LimiterOps for KytheraKernel { + type Limiter = as Machine>::Limiter; + + fn limiter_mut(&mut self) -> &mut Self::Limiter { + self.inner.limiter_mut() + } +} diff --git a/fvm/src/lib.rs b/fvm/src/lib.rs index eb3ffee..ac061d7 100644 --- a/fvm/src/lib.rs +++ b/fvm/src/lib.rs @@ -21,4 +21,8 @@ pub mod state_tree { pub type Account = (ActorID, Address); +mod call_manager; +mod context; pub mod externs; +mod kernel; +pub(crate) mod utils; diff --git a/fvm/src/utils.rs b/fvm/src/utils.rs new file mode 100644 index 0000000..1d63df3 --- /dev/null +++ b/fvm/src/utils.rs @@ -0,0 +1,7 @@ +use kythera_common::abi::derive_method_num; + +pub(crate) const WARP_METHOD: &'static str = "Warp"; + +lazy_static::lazy_static! { + pub(crate) static ref WARP_NUM: u64 = derive_method_num(WARP_METHOD).unwrap(); +} diff --git a/lib/src/lib.rs b/lib/src/lib.rs index 71cfeaf..8fdfe3c 100644 --- a/lib/src/lib.rs +++ b/lib/src/lib.rs @@ -115,6 +115,7 @@ impl Tester { let mut state_tree = StateTree::new(); let builtin_actors = state_tree.load_builtin_actors(); + state_tree.load_kythera_actors(); let account = state_tree.create_account(*builtin_actors.manifest.get_account_code()); Self { diff --git a/lib/src/state_tree.rs b/lib/src/state_tree.rs index c5b10ae..a36103d 100644 --- a/lib/src/state_tree.rs +++ b/lib/src/state_tree.rs @@ -27,6 +27,8 @@ use fil_actors_runtime_v10::{ }; use fvm_shared::bigint::Zero; use fvm_shared::sector::StoragePower; +use kythera_actors::wasm_bin::CHEATCODES_ACTOR_BINARY; +use kythera_common::abi::Abi; const STATE_TREE_VERSION: StateTreeVersion = StateTreeVersion::V5; @@ -325,6 +327,23 @@ impl StateTree { } } + /// Load Kythera utilities' actors + pub fn load_kythera_actors(&mut self) { + // Deploy cheatcodes actor. + let cheatcodes_actor = WasmActor::new( + String::from("Cheatcodes"), + CHEATCODES_ACTOR_BINARY.to_vec(), + Abi::default(), + ); + + self.deploy_actor_from_bin_at_address( + &Address::new_id(98u64), + &cheatcodes_actor, + TokenAmount::zero(), + ) + .expect("Should be able to load cheatcodes actor"); + } + /// Creates new accounts in the testing context /// Inserts the account in the state tree, all with the provided balance, returning it and its public key address. pub fn create_account(&mut self, accounts_code_cid: Cid) -> Account { @@ -363,16 +382,12 @@ impl StateTree { (assigned_addr, pub_key_addr) } - /// Deploy a new Actor at a given address, provided with a given token balance - /// and returns the CodeCID of the installed actor - pub fn deploy_actor_from_bin( + fn deploy_actor_from_bin_at_address( &mut self, + address: &Address, actor: &WasmActor, balance: TokenAmount, - ) -> Result { - let actor_id = rand::random(); - let actor_address = Address::new_id(actor_id); - + ) -> Result<(), Error> { // Put the WASM code into the blockstore. log::debug!("Deploying Actor {} code", actor.name); let code_cid = self @@ -388,7 +403,29 @@ impl StateTree { .setting_err(&actor.name)?; // Set the Actor State on the `BlockStore`. - self.set_actor(&actor.name, [(); 0], code_cid, actor_id, 0, balance)?; + self.set_actor( + &actor.name, + [(); 0], + code_cid, + address + .id() + .expect("Should be able to get actor Id from address"), + 0, + balance, + ) + } + + /// Deploy a new Actor at a given address, provided with a given token balance + /// and returns the CodeCID of the installed actor + pub fn deploy_actor_from_bin( + &mut self, + actor: &WasmActor, + balance: TokenAmount, + ) -> Result { + let actor_id = rand::random(); + let actor_address = Address::new_id(actor_id); + + self.deploy_actor_from_bin_at_address(&actor_address, actor, balance)?; Ok(actor_address) } diff --git a/lib/tests/lib.rs b/lib/tests/lib.rs index 0786e51..4f3b9e8 100644 --- a/lib/tests/lib.rs +++ b/lib/tests/lib.rs @@ -225,6 +225,7 @@ fn test_cheatcodes() { Ok(test_res) => { assert_eq!(test_res.len(), 1); assert_eq!(test_res[0].results.as_ref().unwrap().len(), 1); + dbg!(&test_res[0].results); assert_eq!(test_res[0].test_actor, &test_actor); test_res[0] .results From af435a52f5dc6e7f1fd66f2c4b3dd18c718cbbc1 Mon Sep 17 00:00:00 2001 From: Thomas Chataigner Date: Tue, 18 Apr 2023 19:44:10 +0200 Subject: [PATCH 26/38] feat(cheatcodes): cheatcodes for Kythera --- Cargo.lock | 14 + actors/actors/cheatcodes_actor/Cargo.toml | 1 + actors/actors/cheatcodes_actor/README.md | 16 +- actors/actors/cheatcodes_actor/src/actor.rs | 69 +++- actors/build.rs | 1 + actors/src/wasm_bin/mod.rs | 1 + .../test_actors/basic_target_actor/Cargo.toml | 16 + .../test_actors/basic_target_actor/README.md | 6 + .../basic_target_actor/src/actor.rs | 52 +++ .../test_actors/basic_target_actor/src/lib.rs | 5 + .../cheatcodes_test_actor/Cargo.toml | 2 + .../cheatcodes_test_actor/src/actor.rs | 331 ++++++++++++++++-- common/src/abi/mod.rs | 12 +- fvm/src/call_manager.rs | 257 +++++++++++--- fvm/src/context.rs | 39 ++- fvm/src/executor.rs | 38 +- fvm/src/kernel.rs | 122 +++++-- fvm/src/lib.rs | 5 +- fvm/src/machine.rs | 77 ++++ fvm/src/utils.rs | 15 +- lib/src/lib.rs | 10 +- lib/src/state_tree.rs | 15 +- lib/tests/lib.rs | 111 ++++-- 23 files changed, 1033 insertions(+), 182 deletions(-) create mode 100644 actors/test_actors/basic_target_actor/Cargo.toml create mode 100644 actors/test_actors/basic_target_actor/README.md create mode 100644 actors/test_actors/basic_target_actor/src/actor.rs create mode 100644 actors/test_actors/basic_target_actor/src/lib.rs create mode 100644 fvm/src/machine.rs diff --git a/Cargo.lock b/Cargo.lock index b6bd09a..42782bf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -316,6 +316,18 @@ version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" +[[package]] +name = "basic-target-actor" +version = "0.1.0" +dependencies = [ + "frc42_dispatch", + "fvm_ipld_encoding 0.3.3", + "fvm_sdk 3.0.0", + "fvm_shared 3.1.0", + "serde", + "thiserror", +] + [[package]] name = "basic-test-actor" version = "0.1.0" @@ -613,6 +625,7 @@ dependencies = [ "fvm_sdk 3.0.0", "fvm_shared 3.1.0", "serde", + "serde_tuple", "thiserror", ] @@ -625,6 +638,7 @@ dependencies = [ "fvm_ipld_encoding 0.3.3", "fvm_sdk 3.0.0", "fvm_shared 3.1.0", + "paste", "serde", ] diff --git a/actors/actors/cheatcodes_actor/Cargo.toml b/actors/actors/cheatcodes_actor/Cargo.toml index d5c02e9..71ab1a0 100644 --- a/actors/actors/cheatcodes_actor/Cargo.toml +++ b/actors/actors/cheatcodes_actor/Cargo.toml @@ -18,6 +18,7 @@ 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"] } +serde_tuple = "0.5.0" thiserror = { version = "1.0.31" } [lib] diff --git a/actors/actors/cheatcodes_actor/README.md b/actors/actors/cheatcodes_actor/README.md index 59d1bab..607adc1 100644 --- a/actors/actors/cheatcodes_actor/README.md +++ b/actors/actors/cheatcodes_actor/README.md @@ -1,7 +1,13 @@ -## Basic Test Actor +## Cheatcodes Test Actor -This is a basic actor to test our Kythera testing framework. It has two main entry points: `TestOne()` and `TestTwo()`. +This is the actor embedded in our `kythera-fvm` to expose the cheatcodes interface. -Their entry point values, respectively `3948827889` and `891686990` have been calculated through the FRC 0042 and Helix -`frc42_dispatch` crate. We wanted to use the `frc42_dispatch::match_method!` macro to generate proper method number value at compilation -time but we faced dependencies issue that prevented us from doing so for now. \ No newline at end of file +### 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 \ No newline at end of file diff --git a/actors/actors/cheatcodes_actor/src/actor.rs b/actors/actors/cheatcodes_actor/src/actor.rs index 0d6c194..a8b5af6 100644 --- a/actors/actors/cheatcodes_actor/src/actor.rs +++ b/actors/actors/cheatcodes_actor/src/actor.rs @@ -4,6 +4,7 @@ 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. @@ -33,6 +34,51 @@ fn invoke(input: u32) -> u32 { 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(), @@ -43,7 +89,26 @@ fn invoke(input: u32) -> u32 { ) } -/// Warp the machine context to a given timestamp. Aside the handling of the message in the Kernel, -/// there is currently nNo additional logic is currently needed in the execution. +/// 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) {} diff --git a/actors/build.rs b/actors/build.rs index d134e7f..059086a 100644 --- a/actors/build.rs +++ b/actors/build.rs @@ -11,6 +11,7 @@ const ACTORS: &[&str] = &["cheatcodes-actor"]; #[cfg(feature = "testing")] const TEST_ACTORS: &[&str] = &[ "basic-test-actor", + "basic-target-actor", "builtins-test-actor", "cheatcodes-test-actor", "constructor-setup-test-actor", diff --git a/actors/src/wasm_bin/mod.rs b/actors/src/wasm_bin/mod.rs index 0308778..3ded121 100644 --- a/actors/src/wasm_bin/mod.rs +++ b/actors/src/wasm_bin/mod.rs @@ -19,6 +19,7 @@ pub const CHEATCODES_ACTOR_BINARY: &[u8] = include_bytes!(wasm_bin!("cheatcodes_ pub mod test_actors { // Integration test test_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")); diff --git a/actors/test_actors/basic_target_actor/Cargo.toml b/actors/test_actors/basic_target_actor/Cargo.toml new file mode 100644 index 0000000..e2e0f01 --- /dev/null +++ b/actors/test_actors/basic_target_actor/Cargo.toml @@ -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"] \ No newline at end of file diff --git a/actors/test_actors/basic_target_actor/README.md b/actors/test_actors/basic_target_actor/README.md new file mode 100644 index 0000000..3d1f31f --- /dev/null +++ b/actors/test_actors/basic_target_actor/README.md @@ -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` diff --git a/actors/test_actors/basic_target_actor/src/actor.rs b/actors/test_actors/basic_target_actor/src/actor.rs new file mode 100644 index 0000000..d4643dd --- /dev/null +++ b/actors/test_actors/basic_target_actor/src/actor.rs @@ -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(value: &T) -> std::result::Result +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"), + ); + } + } + ) +} diff --git a/actors/test_actors/basic_target_actor/src/lib.rs b/actors/test_actors/basic_target_actor/src/lib.rs new file mode 100644 index 0000000..6662b42 --- /dev/null +++ b/actors/test_actors/basic_target_actor/src/lib.rs @@ -0,0 +1,5 @@ +// Copyright 2023 Polyphene. +// SPDX-License-Identifier: Apache-2.0, MIT + +#[cfg(target_arch = "wasm32")] +mod actor; diff --git a/actors/test_actors/cheatcodes_test_actor/Cargo.toml b/actors/test_actors/cheatcodes_test_actor/Cargo.toml index a4da921..9f4cc08 100644 --- a/actors/test_actors/cheatcodes_test_actor/Cargo.toml +++ b/actors/test_actors/cheatcodes_test_actor/Cargo.toml @@ -10,6 +10,7 @@ frc42_dispatch = "3.1.0" fvm_sdk = { version = "3.0.0" } fvm_shared = { version = "3.1.0" } fvm_ipld_encoding = { version = "0.3.3" } +paste = "1.0.12" serde = { version = "1.0.136", features = ["derive"] } [target.'cfg(target_arch = "wasm32")'.dependencies] @@ -18,6 +19,7 @@ frc42_dispatch = "3.1.0" fvm_sdk = { version = "3.0.0" } fvm_shared = { version = "3.1.0" } fvm_ipld_encoding = { version = "0.3.3" } +paste = "1.0.12" serde = { version = "1.0.136", features = ["derive"] } [lib] diff --git a/actors/test_actors/cheatcodes_test_actor/src/actor.rs b/actors/test_actors/cheatcodes_test_actor/src/actor.rs index a97ae6a..eba69b3 100644 --- a/actors/test_actors/cheatcodes_test_actor/src/actor.rs +++ b/actors/test_actors/cheatcodes_test_actor/src/actor.rs @@ -1,9 +1,10 @@ // Copyright 2023 Polyphene. // SPDX-License-Identifier: Apache-2.0, MIT -use frc42_dispatch::match_method; +use frc42_dispatch::{match_method, method_hash}; use fvm_ipld_encoding::ipld_block::IpldBlock; use fvm_ipld_encoding::DAG_CBOR; +use fvm_ipld_encoding::{de::DeserializeOwned, RawBytes}; use fvm_sdk as sdk; use fvm_sdk::NO_DATA_BLOCK_ID; use fvm_shared::address::Address; @@ -11,31 +12,116 @@ use fvm_shared::bigint::Zero; use fvm_shared::econ::TokenAmount; use fvm_shared::error::ExitCode; use fvm_shared::sys::SendFlags; +use paste::paste; -#[no_mangle] -fn invoke(_input: u32) -> u32 { - let method_num = sdk::message::method_number(); - match_method!( - method_num, - { - "TestWarp" => { - TestWarp(); - - return NO_DATA_BLOCK_ID; - }, - _ => { - sdk::vm::abort( - ExitCode::USR_UNHANDLED_MESSAGE.value(), - Some("Unknown method number"), - ); +macro_rules! declare_match_method { + ( + $input:expr, $($name:literal => $func:path,)* + ) => { + let method_num = sdk::message::method_number(); + match_method! { + method_num, + { + $($name => { + $func($input); + NO_DATA_BLOCK_ID + }),* + _ => { + sdk::vm::abort( + ExitCode::USR_UNHANDLED_MESSAGE.value(), + Some("Unknown method number"), + ); + }, } } - ) + }; +} + +macro_rules! declare_tests_fail { + ($($method:literal),*) => { + $( + paste! { + #[allow(non_snake_case)] + fn [](_input: u32) { + let new_timestamp = String::from("timestamp"); + + fvm_sdk::send::send( + &Address::new_id(98), + method_hash!($method), + Some(IpldBlock::serialize(DAG_CBOR, &new_timestamp).unwrap()), + TokenAmount::zero(), + None, + SendFlags::empty(), + ) + .unwrap(); + } + #[allow(non_snake_case)] + fn [](_input: u32) { + fvm_sdk::send::send( + &Address::new_id(98), + method_hash!($method), + None, + TokenAmount::zero(), + None, + SendFlags::empty(), + ) + .unwrap(); + } + } + )* + }; +} + +/// Deserialize message parameters into given struct. +pub fn deserialize_params(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 { + std::panic::set_hook(Box::new(|info| { + sdk::vm::abort( + ExitCode::USR_ASSERTION_FAILED.value(), + Some(&format!("{info}")), + ) + })); + + declare_match_method! { + input, + "TestFailDeserializationWarp" => TestFailDeserializationWarp, + "TestFailNoParametersWarp" => TestFailNoParametersWarp, + "TestWarp" => TestWarp, + "TestFailDeserializationEpoch" => TestFailDeserializationEpoch, + "TestFailNoParametersEpoch" => TestFailNoParametersEpoch, + "TestEpoch" => TestEpoch, + "TestFailDeserializationFee" => TestFailDeserializationFee, + "TestFailNoParametersFee" => TestFailNoParametersFee, + "TestFee" => TestFee, + "TestFailDeserializationChainId" => TestFailDeserializationChainId, + "TestFailNoParametersChainId" => TestFailNoParametersChainId, + "TestChainId" => TestChainId, + "TestFailDeserializationPrank" => TestFailDeserializationPrank, + "TestFailNoParametersPrank" => TestFailNoParametersPrank, + "TestFailAddressTypePrank" => TestFailAddressTypePrank, + "TestPrank" => TestPrank, + "TestFailDeserializationTrick" => TestFailDeserializationTrick, + "TestFailNoParametersTrick" => TestFailNoParametersTrick, + "TestFailAddressTypeTrick" => TestFailAddressTypeTrick, + "TestTrick" => TestTrick, + } } -// Checks that all relevant builtins are deployed at a correct actor Id in Kythera. +// Checks Warp cheatcode happy path. #[allow(non_snake_case)] -fn TestWarp() { +fn TestWarp(_input: u32) { let timestamp = fvm_sdk::network::tipset_timestamp(); assert_eq!(timestamp, 0u64); @@ -44,7 +130,7 @@ fn TestWarp() { let res = fvm_sdk::send::send( &Address::new_id(98), - 112632689, + method_hash!("Warp"), Some(IpldBlock::serialize(DAG_CBOR, &new_timestamp).unwrap()), TokenAmount::zero(), None, @@ -58,3 +144,206 @@ fn TestWarp() { assert_eq!(new_timestamp, nc_timestamp); } + +// Checks Epoch cheatcode happy path. +#[allow(non_snake_case)] +fn TestEpoch(_input: u32) { + let epoch = fvm_sdk::network::curr_epoch(); + + assert_eq!(epoch, 0i64); + + let new_epoch = 10000i64; + + let res = fvm_sdk::send::send( + &Address::new_id(98), + method_hash!("Epoch"), + Some(IpldBlock::serialize(DAG_CBOR, &new_epoch).unwrap()), + TokenAmount::zero(), + None, + SendFlags::empty(), + ) + .unwrap(); + + assert_eq!(res.exit_code, ExitCode::OK); + + let nc_epoch = unsafe { fvm_sdk::sys::network::context().unwrap().epoch }; + + assert_eq!(new_epoch, nc_epoch); +} + +// Checks Fee cheatcode happy path. +#[allow(non_snake_case)] +fn TestFee(_input: u32) { + let base_fee_sys = + fvm_shared::sys::TokenAmount::try_from(fvm_sdk::network::base_fee()).unwrap(); + let lo = base_fee_sys.lo; + let hi = base_fee_sys.hi; + + assert_eq!(lo, 100u64); + assert_eq!(hi, 0u64); + + let new_base_fee = (200u64, 200u64); + + let res = fvm_sdk::send::send( + &Address::new_id(98), + method_hash!("Fee"), + Some(IpldBlock::serialize(DAG_CBOR, &new_base_fee).unwrap()), + TokenAmount::zero(), + None, + SendFlags::empty(), + ) + .unwrap(); + + assert_eq!(res.exit_code, ExitCode::OK); + + let nc_base_fee = unsafe { + let base_fee = fvm_sdk::sys::network::context().unwrap().base_fee; + (base_fee.lo, base_fee.hi) + }; + + assert_eq!(new_base_fee, nc_base_fee); +} + +// Checks ChainId cheatcode happy path. +#[allow(non_snake_case)] +fn TestChainId(_input: u32) { + let chain_id = fvm_sdk::network::chain_id(); + + assert_eq!(u64::from(chain_id), 1312u64); + + let new_chain_id = 1500u64; + + let res = fvm_sdk::send::send( + &Address::new_id(98), + method_hash!("ChainId"), + Some(IpldBlock::serialize(DAG_CBOR, &new_chain_id).unwrap()), + TokenAmount::zero(), + None, + SendFlags::empty(), + ) + .unwrap(); + + assert_eq!(res.exit_code, ExitCode::OK); + + let nc_chain_id = unsafe { fvm_sdk::sys::network::context().unwrap().chain_id }; + + assert_eq!(new_chain_id, nc_chain_id); +} + +// Checks Prank cheatcode happy path. +#[allow(non_snake_case)] +fn TestPrank(input: u32) { + let target_actor_id: u64 = deserialize_params(input); + + let new_caller = Address::new_id(1); + + let res = fvm_sdk::send::send( + &Address::new_id(98), + method_hash!("Prank"), + Some(IpldBlock::serialize(DAG_CBOR, &new_caller).unwrap()), + TokenAmount::zero(), + None, + SendFlags::empty(), + ) + .unwrap(); + + assert_eq!(res.exit_code, ExitCode::OK); + + let res = fvm_sdk::send::send( + &Address::new_id(target_actor_id), + method_hash!("Caller"), + None, + TokenAmount::zero(), + None, + SendFlags::empty(), + ) + .unwrap(); + + assert_eq!(res.exit_code, ExitCode::OK); + + let caller: u64 = RawBytes::new( + res.return_data + .expect("Should be able to get Caller from target actor") + .data, + ) + .deserialize() + .unwrap(); + + assert_eq!(new_caller.id().unwrap(), caller); +} + +// Checks Prank with a wrong address type. +#[allow(non_snake_case)] +fn TestFailAddressTypePrank(_input: u32) { + let new_caller = Address::new_actor(b"WrongType"); + + fvm_sdk::send::send( + &Address::new_id(98), + method_hash!("Prank"), + Some(IpldBlock::serialize(DAG_CBOR, &new_caller).unwrap()), + TokenAmount::zero(), + None, + SendFlags::empty(), + ) + .unwrap(); +} + +// Checks Trick cheatcode happy path. +#[allow(non_snake_case)] +fn TestTrick(input: u32) { + let target_actor_id: u64 = deserialize_params(input); + + let new_origin = Address::new_id(1); + + let res = fvm_sdk::send::send( + &Address::new_id(98), + method_hash!("Trick"), + Some(IpldBlock::serialize(DAG_CBOR, &new_origin).unwrap()), + TokenAmount::zero(), + None, + SendFlags::empty(), + ) + .unwrap(); + + assert_eq!(res.exit_code, ExitCode::OK); + + let res = fvm_sdk::send::send( + &Address::new_id(target_actor_id), + method_hash!("Origin"), + None, + TokenAmount::zero(), + None, + SendFlags::empty(), + ) + .unwrap(); + + assert_eq!(res.exit_code, ExitCode::OK); + + let origin: u64 = RawBytes::new( + res.return_data + .expect("Should be able to get Origin from target actor") + .data, + ) + .deserialize() + .unwrap(); + + assert_eq!(new_origin.id().unwrap(), origin); +} + +// Checks Trick with a wrong address type. +#[allow(non_snake_case)] +fn TestFailAddressTypeTrick(_input: u32) { + let new_origin = Address::new_actor(b"WrongType"); + + fvm_sdk::send::send( + &Address::new_id(98), + method_hash!("Trick"), + Some(IpldBlock::serialize(DAG_CBOR, &new_origin).unwrap()), + TokenAmount::zero(), + None, + SendFlags::empty(), + ) + .unwrap(); +} + +declare_tests_fail!("Warp", "Epoch", "Fee", "ChainId", "Prank", "Trick"); diff --git a/common/src/abi/mod.rs b/common/src/abi/mod.rs index f302180..80830c5 100644 --- a/common/src/abi/mod.rs +++ b/common/src/abi/mod.rs @@ -39,7 +39,7 @@ pub fn pascal_case_split(s: &str) -> Vec<&str> { /// `Abi` is the structure we use internally to deal with Actor Binary Interface. It contains all /// exposed [`Method`] from a given Actor. -#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)] +#[derive(Clone, Default, Debug, PartialEq, Eq, PartialOrd, Ord)] pub struct Abi { pub constructor: Option, pub set_up: Option, @@ -137,16 +137,6 @@ impl<'de> serde::Deserialize<'de> for Abi { } } -impl Default for Abi { - fn default() -> Self { - Self { - constructor: None, - set_up: None, - methods: vec![], - } - } -} - /// Method number indicator for calling Actor methods. pub type MethodNum = u64; diff --git a/fvm/src/call_manager.rs b/fvm/src/call_manager.rs index a6c5fee..66870fe 100644 --- a/fvm/src/call_manager.rs +++ b/fvm/src/call_manager.rs @@ -1,5 +1,4 @@ -use crate::context::OverrideContext; -use crate::externs::FakeExterns; +use crate::kernel::KytheraKernel; use crate::machine::KytheraMachine; use anyhow::anyhow; use cid::Cid; @@ -9,21 +8,161 @@ use fvm::gas::{Gas, GasTracker}; use fvm::kernel::{Block, ExecutionError}; use fvm::machine::Machine; use fvm::state_tree::ActorState; -use fvm::{DefaultKernel, Kernel}; -use fvm_ipld_blockstore::MemoryBlockstore; +use fvm::Kernel; use fvm_ipld_encoding::from_slice; use fvm_shared::address::Address; use fvm_shared::econ::TokenAmount; use fvm_shared::event::StampedEvent; use fvm_shared::{ActorID, MethodNum}; -pub struct KytheraCallManager { - inner: DefaultCallManager>, - override_context: OverrideContext, +#[repr(transparent)] +pub struct KytheraCallManager>(pub C); + +impl KytheraCallManager +where + M: Machine, + C: CallManager>, +{ + fn handle_cheatcode( + &mut self, + method: MethodNum, + params: Option, + ) -> fvm::kernel::Result<()> { + match method { + method_num if method_num == *crate::utils::WARP_NUM => { + let new_timestamp: u64 = from_slice( + params + .ok_or(ExecutionError::Fatal(anyhow!( + "No parameters provided for Warp cheatcode" + )))? + .data(), + ) + .map_err(|err| { + ExecutionError::Fatal(anyhow!(format!( + "Could not deserialize parameters for Warp cheatcode: {}", + err + ))) + })?; + self.machine_mut().override_context.timestamp = Some(new_timestamp); + } + method_num if method_num == *crate::utils::EPOCH_NUM => { + let new_epoch: i64 = from_slice( + params + .ok_or(ExecutionError::Fatal(anyhow!( + "No parameters provided for Epoch cheatcode" + )))? + .data(), + ) + .map_err(|err| { + ExecutionError::Fatal(anyhow!(format!( + "Could not deserialize parameters for Epoch cheatcode: {}", + err + ))) + })?; + self.machine_mut().override_context.epoch = Some(new_epoch); + } + method_num if method_num == *crate::utils::FEE_NUM => { + let (lo, hi): (u64, u64) = from_slice( + params + .ok_or(ExecutionError::Fatal(anyhow!( + "No parameters provided for Fee cheatcode" + )))? + .data(), + ) + .map_err(|err| { + ExecutionError::Fatal(anyhow!(format!( + "Could not deserialize parameters for Fee cheatcode: {}", + err + ))) + })?; + + self.machine_mut().override_context.base_fee = + Some(fvm_shared::sys::TokenAmount { lo, hi }); + } + method_num if method_num == *crate::utils::CHAIN_ID_NUM => { + let chain_id: u64 = from_slice( + params + .ok_or(ExecutionError::Fatal(anyhow!( + "No parameters provided for ChainId cheatcode" + )))? + .data(), + ) + .map_err(|err| { + ExecutionError::Fatal(anyhow!(format!( + "Could not deserialize parameters for ChainId cheatcode: {}", + err + ))) + })?; + + self.machine_mut().override_context.chain_id = Some(chain_id); + } + method_num if method_num == *crate::utils::PRANK_NUM => { + let new_caller: Address = from_slice( + params + .ok_or(ExecutionError::Fatal(anyhow!( + "No parameters provided for Prank cheatcode" + )))? + .data(), + ) + .map_err(|err| { + ExecutionError::Fatal(anyhow!(format!( + "Could not deserialize parameters for Prank cheatcode: {}", + err + ))) + })?; + + let new_caller_id = match new_caller.id() { + Ok(id) => id, + Err(err) => { + return Err(ExecutionError::Fatal(anyhow!(format!( + "Address parameter for Prank should have a valid ActorID: {}", + err + )))) + } + }; + + self.machine_mut().override_context.caller = Some(new_caller_id); + } + method_num if method_num == *crate::utils::TRICK_NUM => { + let new_origin: Address = from_slice( + params + .ok_or(ExecutionError::Fatal(anyhow!( + "No parameters provided for Trick cheatcode" + )))? + .data(), + ) + .map_err(|err| { + ExecutionError::Fatal(anyhow!(format!( + "Could not deserialize parameters for Trick cheatcode: {}", + err + ))) + })?; + + let new_origin_id = match new_origin.id() { + Ok(id) => id, + Err(err) => { + return Err(ExecutionError::Fatal(anyhow!(format!( + "Address parameter for Trick should have a valid ActorID: {}", + err + )))) + } + }; + + self.machine_mut().override_context.origin = Some(new_origin_id); + } + _ => return Err(ExecutionError::Fatal(anyhow!("Call to unknown cheatcode"))), + } + + Ok(()) + } } -impl CallManager for KytheraCallManager { - type Machine = KytheraMachine; +impl CallManager for KytheraCallManager +where + M: Machine, + C: CallManager>, +{ + type Machine = C::Machine; fn new( machine: Self::Machine, @@ -36,20 +175,17 @@ impl CallManager for KytheraCallManager { nonce: u64, gas_premium: TokenAmount, ) -> Self { - Self { - inner: DefaultCallManager::new( - machine, - engine, - gas_limit, - origin, - origin_address, - receiver, - receiver_address, - nonce, - gas_premium, - ), - override_context: OverrideContext::default(), - } + Self(C::new( + machine, + engine, + gas_limit, + origin, + origin_address, + receiver, + receiver_address, + nonce, + gas_premium, + )) } fn send>( @@ -62,58 +198,68 @@ impl CallManager for KytheraCallManager { gas_limit: Option, read_only: bool, ) -> fvm::kernel::Result { - if &to == &Address::new_id(98) { - if method == *crate::utils::WARP_NUM { - if !params.is_none() { - let new_timestamp: u64 = from_slice(params.clone().unwrap().data()).unwrap(); - dbg!(new_timestamp); - } - } + // If cheatcode actor then we proceed as usual + if to == Address::new_id(98) { + self.handle_cheatcode(method, params.clone())?; + + self.0 + .send::>(from, to, method, params, value, gas_limit, read_only) + } + // If any other actor, check if override caller + else { + let caller = self.machine().override_context().caller.unwrap_or(from); + self.machine_mut().override_context.caller = None; + self.0 + .send::>(caller, to, method, params, value, gas_limit, read_only) } - // TODO Having call manager require the Kernel to refer to the same structure prevent us from doing this - self.inner.send::>>>( - from, to, method, params, value, gas_limit, read_only, - ) } fn with_transaction( &mut self, - _f: impl FnOnce(&mut Self) -> fvm::kernel::Result, + f: impl FnOnce(&mut Self) -> fvm::kernel::Result, ) -> fvm::kernel::Result { - // TODO having the callback function refering to this structure prevent us from passing it to the inner call manager - Err(ExecutionError::Fatal(anyhow!("aa"))) + // This transmute is _safe_ because this type is "repr transparent". + let inner_ptr = &mut self.0 as *mut C; + self.0.with_transaction(|inner: &mut C| unsafe { + // Make sure that we've got the right pointer. Otherwise, this cast definitely isn't + // safe. + assert_eq!(inner_ptr, inner as *mut C); + + // Ok, we got the pointer we expected, casting back to the interceptor is safe. + f(&mut *(inner as *mut C as *mut Self)) + }) } fn finish(self) -> (fvm::kernel::Result, Self::Machine) { - self.inner.finish() + self.0.finish() } fn machine(&self) -> &Self::Machine { - self.inner.machine() + self.0.machine() } fn machine_mut(&mut self) -> &mut Self::Machine { - self.inner.machine_mut() + self.0.machine_mut() } fn engine(&self) -> &Engine { - self.inner.engine() + self.0.engine() } fn gas_tracker(&self) -> &GasTracker { - self.inner.gas_tracker() + self.0.gas_tracker() } fn gas_premium(&self) -> &TokenAmount { - self.inner.gas_premium() + self.0.gas_premium() } fn origin(&self) -> ActorID { - self.inner.origin() + self.0.origin() } fn next_actor_address(&self) -> Address { - self.inner.next_actor_address() + self.0.next_actor_address() } fn create_actor( @@ -122,24 +268,23 @@ impl CallManager for KytheraCallManager { actor_id: ActorID, delegated_address: Option
, ) -> fvm::kernel::Result<()> { - self.inner - .create_actor(code_id, actor_id, delegated_address) + self.0.create_actor(code_id, actor_id, delegated_address) } fn resolve_address(&self, address: &Address) -> fvm::kernel::Result> { - self.inner.resolve_address(address) + self.0.resolve_address(address) } fn set_actor(&mut self, id: ActorID, state: ActorState) -> fvm::kernel::Result<()> { - self.inner.set_actor(id, state) + self.0.set_actor(id, state) } fn get_actor(&self, id: ActorID) -> fvm::kernel::Result> { - self.inner.get_actor(id) + self.0.get_actor(id) } fn delete_actor(&mut self, id: ActorID) -> fvm::kernel::Result<()> { - self.inner.delete_actor(id) + self.0.delete_actor(id) } fn transfer( @@ -148,22 +293,22 @@ impl CallManager for KytheraCallManager { to: ActorID, value: &TokenAmount, ) -> fvm::kernel::Result<()> { - self.inner.transfer(from, to, value) + self.0.transfer(from, to, value) } fn nonce(&self) -> u64 { - self.inner.nonce() + self.0.nonce() } fn invocation_count(&self) -> u64 { - self.inner.invocation_count() + self.0.invocation_count() } fn limiter_mut(&mut self) -> &mut ::Limiter { - self.inner.limiter_mut() + self.0.limiter_mut() } fn append_event(&mut self, evt: StampedEvent) { - self.inner.append_event(evt) + self.0.append_event(evt) } } diff --git a/fvm/src/context.rs b/fvm/src/context.rs index be7f518..6d9a9a2 100644 --- a/fvm/src/context.rs +++ b/fvm/src/context.rs @@ -1,7 +1,8 @@ -use fvm::machine::{MachineContext, NetworkConfig}; -use fvm_shared::chainid::ChainID; use fvm_shared::clock::ChainEpoch; -use fvm_shared::econ::TokenAmount; +use fvm_shared::sys::out::network::NetworkContext; +use fvm_shared::sys::out::vm::MessageContext; +use fvm_shared::sys::TokenAmount; +use fvm_shared::ActorID; pub trait Override { fn override_with_context(&self, context: &S) -> Self; @@ -10,7 +11,7 @@ pub trait Override { #[derive(Default, Debug, Clone)] pub struct OverrideContext { /// The Chain ID of the network. - pub chain_id: Option, + pub chain_id: Option, /// The current epoch. pub epoch: Option, @@ -20,19 +21,31 @@ pub struct OverrideContext { /// The base fee that's in effect when the Machine runs. pub base_fee: Option, + + /// The current call's origin actor ID. + pub origin: Option, + + /// The caller's actor ID. + pub caller: Option, } -impl Override for MachineContext { - fn override_with_context(&self, context: &OverrideContext) -> MachineContext { - MachineContext { - network: NetworkConfig { - chain_id: context.chain_id.unwrap_or(self.network.chain_id), - ..self.network.clone() - }, +impl Override for NetworkContext { + fn override_with_context(&self, context: &OverrideContext) -> NetworkContext { + NetworkContext { + chain_id: context.chain_id.unwrap_or(self.chain_id), epoch: context.epoch.unwrap_or(self.epoch), timestamp: context.timestamp.unwrap_or(self.timestamp), - base_fee: context.base_fee.clone().unwrap_or(self.base_fee.clone()), - ..self.clone() + base_fee: context.base_fee.unwrap_or(self.base_fee), + ..*self + } + } +} + +impl Override for MessageContext { + fn override_with_context(&self, context: &OverrideContext) -> MessageContext { + MessageContext { + origin: context.origin.unwrap_or(self.origin), + ..*self } } } diff --git a/fvm/src/executor.rs b/fvm/src/executor.rs index 0041802..a24006e 100644 --- a/fvm/src/executor.rs +++ b/fvm/src/executor.rs @@ -8,12 +8,14 @@ use fvm::engine::EnginePool; use fvm::executor::DefaultExecutor; use crate::kernel::KytheraKernel; +use crate::utils::KYTHERA_NETWORK_ID; pub use fvm::executor::Executor as _; pub use fvm::executor::{ApplyFailure, ApplyKind, ApplyRet}; -use fvm::machine::{Machine, NetworkConfig}; -use fvm_ipld_blockstore::MemoryBlockstore; +use fvm::machine::{DefaultMachine, Machine, NetworkConfig}; +use fvm_ipld_blockstore::{Buffered, MemoryBlockstore}; use fvm_ipld_encoding::RawBytes; use fvm_shared::address::Address; +use fvm_shared::chainid::ChainID; use fvm_shared::econ::TokenAmount; use fvm_shared::message::Message; use fvm_shared::version::NetworkVersion; @@ -43,6 +45,10 @@ impl KytheraExecutor { let mut nc = NetworkConfig::new(NETWORK_VERSION); nc.override_actors(builtin_actors); nc.enable_actor_debugging(); + // If chain Id is 0 (invalid value) we set our default + if nc.chain_id == ChainID::from(0) { + nc.chain_id = ChainID::from(KYTHERA_NETWORK_ID) + } let mut mc = nc.for_epoch(0, 0, state_root); mc.set_base_fee(TokenAmount::from_atto(DEFAULT_BASE_FEE)) @@ -57,8 +63,12 @@ impl KytheraExecutor { .preload(&blockstore, &code_cids) .expect("Should be able to preload Executor"); - let machine = KytheraMachine::new(&mc, blockstore, FakeExterns::new()) - .expect("Should be able to start KytheraMachine"); + let machine = KytheraMachine::>::new( + mc, + blockstore, + FakeExterns::new(), + ) + .expect("Should be able to start KytheraMachine"); Self { inner: DefaultExecutor::new(engine, machine).expect("Should be able to start Executor"), @@ -79,7 +89,7 @@ impl KytheraExecutor { to: self.test_address, gas_limit: 1000000000, method_num, - params: self.target_actor_id.clone().into(), + params: self.target_actor_id.clone(), sequence, ..Message::default() }; @@ -95,12 +105,20 @@ impl KytheraExecutor { .flush() .expect("Should be able to flush Executor"); - let blockstore = self + let mut machine: KytheraMachine = self .inner .into_machine() - .expect("Machine should exist at this point") - .into_store() - .into_inner(); - (root, blockstore) + .expect("Machine should exist at this point"); + + machine.state_tree_mut(); + + let buff_blockstore = machine.into_store(); + buff_blockstore + .flush(&root) + .expect("Should be able to flush Buffered Blockstore"); + + let memory_blockstore = buff_blockstore.into_inner(); + + (root, memory_blockstore) } } diff --git a/fvm/src/kernel.rs b/fvm/src/kernel.rs index 23f4d51..ce3e9bc 100644 --- a/fvm/src/kernel.rs +++ b/fvm/src/kernel.rs @@ -1,5 +1,5 @@ use crate::call_manager::KytheraCallManager; -use crate::externs::FakeExterns; +use crate::context::Override; use crate::machine::KytheraMachine; use cid::Cid; use fvm::call_manager::CallManager; @@ -11,7 +11,6 @@ use fvm::kernel::{ }; use fvm::machine::Machine; use fvm::{DefaultKernel, Kernel}; -use fvm_ipld_blockstore::MemoryBlockstore; use fvm_shared::address::Address; use fvm_shared::clock::ChainEpoch; use fvm_shared::consensus::ConsensusFault; @@ -30,18 +29,24 @@ use fvm_shared::sys::out::vm::MessageContext; use fvm_shared::sys::SendFlags; use fvm_shared::{ActorID, MethodNum}; -pub struct KytheraKernel { - inner: DefaultKernel, +pub struct KytheraKernel> { + inner: K, } -impl Kernel for KytheraKernel { - type CallManager = KytheraCallManager; +impl Kernel for KytheraKernel +where + M: Machine, + C: CallManager>, + K: Kernel>, +{ + type CallManager = C; fn into_inner(self) -> (Self::CallManager, BlockRegistry) where Self: Sized, { - self.inner.into_inner() + let (kythera_cm, br) = self.inner.into_inner(); + (kythera_cm.0, br) } fn new( @@ -57,8 +62,8 @@ impl Kernel for KytheraKernel { Self: Sized, { Self { - inner: DefaultKernel::new( - mgr, + inner: K::new( + KytheraCallManager(mgr), blocks, caller, actor_id, @@ -74,7 +79,12 @@ impl Kernel for KytheraKernel { } } -impl ActorOps for KytheraKernel { +impl ActorOps for KytheraKernel +where + M: Machine, + C: CallManager>, + K: Kernel>, +{ fn resolve_address(&self, address: &Address) -> fvm::kernel::Result { self.inner.resolve_address(address) } @@ -114,7 +124,12 @@ impl ActorOps for KytheraKernel { } } -impl IpldBlockOps for KytheraKernel { +impl IpldBlockOps for KytheraKernel +where + M: Machine, + C: CallManager>, + K: Kernel>, +{ fn block_open(&mut self, cid: &Cid) -> fvm::kernel::Result<(BlockId, BlockStat)> { self.inner.block_open(cid) } @@ -141,13 +156,23 @@ impl IpldBlockOps for KytheraKernel { } } -impl CircSupplyOps for KytheraKernel { +impl CircSupplyOps for KytheraKernel +where + M: Machine, + C: CallManager>, + K: Kernel>, +{ fn total_fil_circ_supply(&self) -> fvm::kernel::Result { self.inner.total_fil_circ_supply() } } -impl CryptoOps for KytheraKernel { +impl CryptoOps for KytheraKernel +where + M: Machine, + C: CallManager>, + K: Kernel>, +{ fn verify_signature( &self, sig_type: SignatureType, @@ -212,7 +237,12 @@ impl CryptoOps for KytheraKernel { } } -impl DebugOps for KytheraKernel { +impl DebugOps for KytheraKernel +where + M: Machine, + C: CallManager>, + K: Kernel>, +{ fn log(&self, msg: String) { self.inner.log(msg) } @@ -226,13 +256,23 @@ impl DebugOps for KytheraKernel { } } -impl EventOps for KytheraKernel { +impl EventOps for KytheraKernel +where + M: Machine, + C: CallManager>, + K: Kernel>, +{ fn emit_event(&mut self, raw_evt: &[u8]) -> fvm::kernel::Result<()> { self.inner.emit_event(raw_evt) } } -impl GasOps for KytheraKernel { +impl GasOps for KytheraKernel +where + M: Machine, + C: CallManager>, + K: Kernel>, +{ fn gas_used(&self) -> Gas { self.inner.gas_used() } @@ -250,15 +290,29 @@ impl GasOps for KytheraKernel { } } -impl MessageOps for KytheraKernel { +impl MessageOps for KytheraKernel +where + M: Machine, + C: CallManager>, + K: Kernel>, +{ fn msg_context(&self) -> fvm::kernel::Result { - self.inner.msg_context() + self.inner + .msg_context() + .map(|mc| mc.override_with_context(self.machine().override_context())) } } -impl NetworkOps for KytheraKernel { +impl NetworkOps for KytheraKernel +where + M: Machine, + C: CallManager>, + K: Kernel>, +{ fn network_context(&self) -> fvm::kernel::Result { - self.inner.network_context() + self.inner + .network_context() + .map(|nc| nc.override_with_context(self.machine().override_context())) } fn tipset_cid(&self, epoch: ChainEpoch) -> fvm::kernel::Result { @@ -266,7 +320,12 @@ impl NetworkOps for KytheraKernel { } } -impl RandomnessOps for KytheraKernel { +impl RandomnessOps for KytheraKernel +where + M: Machine, + C: CallManager>, + K: Kernel>, +{ fn get_randomness_from_tickets( &self, personalization: i64, @@ -288,7 +347,12 @@ impl RandomnessOps for KytheraKernel { } } -impl SelfOps for KytheraKernel { +impl SelfOps for KytheraKernel +where + M: Machine, + C: CallManager>, + K: Kernel>, +{ fn root(&self) -> fvm::kernel::Result { self.inner.root() } @@ -306,7 +370,12 @@ impl SelfOps for KytheraKernel { } } -impl SendOps for KytheraKernel { +impl SendOps for KytheraKernel +where + M: Machine, + C: CallManager>, + K: Kernel>, +{ fn send( &mut self, recipient: &Address, @@ -321,8 +390,11 @@ impl SendOps for KytheraKernel { } } -impl LimiterOps for KytheraKernel { - type Limiter = as Machine>::Limiter; +impl LimiterOps for KytheraKernel +where + K: LimiterOps, +{ + type Limiter = K::Limiter; fn limiter_mut(&mut self) -> &mut Self::Limiter { self.inner.limiter_mut() diff --git a/fvm/src/lib.rs b/fvm/src/lib.rs index ac061d7..ab77eba 100644 --- a/fvm/src/lib.rs +++ b/fvm/src/lib.rs @@ -10,10 +10,6 @@ pub mod engine { } pub mod executor; -pub mod machine { - pub use fvm::machine::{DefaultMachine as KytheraMachine, Machine, Manifest, NetworkConfig}; -} - pub mod state_tree { pub use fvm::state_tree::ActorState; pub use fvm::state_tree::StateTree; @@ -25,4 +21,5 @@ mod call_manager; mod context; pub mod externs; mod kernel; +pub mod machine; pub(crate) mod utils; diff --git a/fvm/src/machine.rs b/fvm/src/machine.rs new file mode 100644 index 0000000..d84ff6d --- /dev/null +++ b/fvm/src/machine.rs @@ -0,0 +1,77 @@ +use crate::context::OverrideContext; +use crate::externs::FakeExterns; +use fvm::machine::MachineContext; +pub use fvm::machine::{DefaultMachine, Machine, Manifest, NetworkConfig}; +use fvm::state_tree::StateTree; +use fvm_ipld_blockstore::MemoryBlockstore; + +pub struct KytheraMachine> { + inner: M, + pub(crate) override_context: OverrideContext, +} + +impl KytheraMachine +where + M: Machine, +{ + pub fn new( + context: MachineContext, + blockstore: MemoryBlockstore, + externs: FakeExterns, + ) -> anyhow::Result>> { + let machine = DefaultMachine::new(&context, blockstore, externs)?; + Ok(KytheraMachine { + inner: machine, + override_context: OverrideContext::default(), + }) + } + + pub fn override_context(&self) -> &OverrideContext { + &self.override_context + } +} + +impl Machine for KytheraMachine +where + M: Machine, +{ + type Blockstore = M::Blockstore; + type Externs = M::Externs; + type Limiter = M::Limiter; + + fn blockstore(&self) -> &Self::Blockstore { + self.inner.blockstore() + } + + fn context(&self) -> &MachineContext { + self.inner.context() + } + + fn externs(&self) -> &Self::Externs { + self.inner.externs() + } + + fn builtin_actors(&self) -> &Manifest { + self.inner.builtin_actors() + } + + fn state_tree(&self) -> &StateTree { + self.inner.state_tree() + } + + fn state_tree_mut(&mut self) -> &mut StateTree { + self.inner.state_tree_mut() + } + + fn into_store(self) -> Self::Blockstore { + self.inner.into_store() + } + + fn machine_id(&self) -> &str { + self.inner.machine_id() + } + + fn new_limiter(&self) -> Self::Limiter { + self.inner.new_limiter() + } +} diff --git a/fvm/src/utils.rs b/fvm/src/utils.rs index 1d63df3..5c52b63 100644 --- a/fvm/src/utils.rs +++ b/fvm/src/utils.rs @@ -1,7 +1,20 @@ use kythera_common::abi::derive_method_num; -pub(crate) const WARP_METHOD: &'static str = "Warp"; +pub const KYTHERA_NETWORK_ID: u64 = 1312; + +pub(crate) const WARP_METHOD: &str = "Warp"; +pub(crate) const EPOCH_METHOD: &str = "Epoch"; +pub(crate) const FEE_METHOD: &str = "Fee"; +pub(crate) const CHAIN_ID_METHOD: &str = "ChainId"; +pub(crate) const PRANK_METHOD: &str = "Prank"; +pub(crate) const TRICK_METHOD: &str = "Trick"; lazy_static::lazy_static! { pub(crate) static ref WARP_NUM: u64 = derive_method_num(WARP_METHOD).unwrap(); + pub(crate) static ref EPOCH_NUM: u64 = derive_method_num(EPOCH_METHOD).unwrap(); + pub(crate) static ref FEE_NUM: u64 = derive_method_num(FEE_METHOD).unwrap(); + pub(crate) static ref CHAIN_ID_NUM: u64 = derive_method_num(CHAIN_ID_METHOD).unwrap(); + pub(crate) static ref PRANK_NUM: u64 = derive_method_num(PRANK_METHOD).unwrap(); + pub(crate) static ref TRICK_NUM: u64 = derive_method_num(TRICK_METHOD).unwrap(); + } diff --git a/lib/src/lib.rs b/lib/src/lib.rs index 8fdfe3c..6dde085 100644 --- a/lib/src/lib.rs +++ b/lib/src/lib.rs @@ -6,6 +6,7 @@ pub use kythera_common::{ from_slice, to_vec, }; +use fvm_ipld_encoding::RawBytes; use kythera_fvm::{ executor::{ApplyRet, KytheraExecutor}, Account, @@ -160,7 +161,9 @@ impl Tester { .ok_or(Error::MissingActor)?; let target_id = match target.address.id() { - Ok(id) => id.to_ne_bytes().to_vec(), + Ok(id) => { + RawBytes::new(to_vec(&id).expect("Should be able to serialize target actor ID")) + } Err(_) => panic!("Actor Id should be valid"), }; @@ -185,7 +188,6 @@ impl Tester { }; log::info!("Testing Actor {}", target.name); - let root = self.state_tree.flush(); let blockstore = self.state_tree.store().clone(); let mut executor = KytheraExecutor::new( @@ -194,7 +196,7 @@ impl Tester { self.builtin_actors.root, self.account.1, test_address, - target_id.clone().into(), + target_id.clone(), ); // Run the constructor if it exists. @@ -269,7 +271,7 @@ impl Tester { self.builtin_actors.root, self.account.1, test_address, - target_id.clone().into(), + target_id.clone(), ); log::info!( diff --git a/lib/src/state_tree.rs b/lib/src/state_tree.rs index a36103d..dd077e6 100644 --- a/lib/src/state_tree.rs +++ b/lib/src/state_tree.rs @@ -90,6 +90,7 @@ impl StateTree { log::trace!("Setting Actor {} on the BlockStore", name); self.inner.set_actor(id, actor_state); + Ok(()) } @@ -422,11 +423,13 @@ impl StateTree { actor: &WasmActor, balance: TokenAmount, ) -> Result { - let actor_id = rand::random(); - let actor_address = Address::new_id(actor_id); - - self.deploy_actor_from_bin_at_address(&actor_address, actor, balance)?; - - Ok(actor_address) + let actor_address = Address::new_actor(actor.name.as_bytes()); + let actor_id = self + .inner + .register_new_address(&actor_address) + .expect("Should be able to register verified registry multisig root address"); + let actor_address_id = Address::new_id(actor_id); + self.deploy_actor_from_bin_at_address(&actor_address_id, actor, balance)?; + Ok(actor_address_id) } } diff --git a/lib/tests/lib.rs b/lib/tests/lib.rs index 4f3b9e8..e8b7eec 100644 --- a/lib/tests/lib.rs +++ b/lib/tests/lib.rs @@ -1,9 +1,10 @@ use fvm_shared::error::ExitCode; use kythera_actors::wasm_bin::test_actors::{ - BASIC_TEST_ACTOR_BINARY, BUILTINS_TEST_ACTOR_BINARY, CHEATCODES_TEST_ACTOR_BINARY, - CONSTRUCTOR_SETUP_TEST_ACTOR_BINARY, + BASIC_TARGET_ACTOR_BINARY, BASIC_TEST_ACTOR_BINARY, BUILTINS_TEST_ACTOR_BINARY, + CHEATCODES_TEST_ACTOR_BINARY, CONSTRUCTOR_SETUP_TEST_ACTOR_BINARY, }; use kythera_common::abi::{Abi, Method, MethodType}; +use kythera_fvm::executor::ApplyFailure::MessageBacktrace; use kythera_lib::{TestResultType, Tester, WasmActor}; const TARGET_WAT: &str = r#" @@ -192,6 +193,24 @@ fn test_constructor_and_set_up_called() { } } +macro_rules! generate_match_assert { + ($apply_failure:expr, $result:expr, $($test_name:expr => $test_message:expr),*) => {{ + match $apply_failure { + MessageBacktrace(backtrace) => { + match $result.method().name() { + $($test_name => { + assert!(backtrace.to_string().contains($test_message)); + })* + _ => {} + } + }, + _ => { + panic!("Failure should be a MessageBacktrace variant for failing tests"); + } + } + }}; +} + #[test] fn test_cheatcodes() { // Instantiate tester @@ -201,11 +220,14 @@ fn test_cheatcodes() { set_target_actor( &mut tester, String::from("Target"), - wat::parse_str(TARGET_WAT).unwrap(), + Vec::from(BASIC_TARGET_ACTOR_BINARY), Abi { constructor: None, set_up: None, - methods: vec![], + methods: vec![ + Method::new_from_name("Caller").unwrap(), + Method::new_from_name("Origin").unwrap(), + ], }, ); @@ -214,7 +236,28 @@ fn test_cheatcodes() { let test_abi = Abi { constructor: None, set_up: None, - methods: vec![Method::new_from_name("TestWarp").unwrap()], + methods: vec![ + Method::new_from_name("TestWarp").unwrap(), + Method::new_from_name("TestFailDeserializationWarp").unwrap(), + Method::new_from_name("TestFailNoParametersWarp").unwrap(), + Method::new_from_name("TestEpoch").unwrap(), + Method::new_from_name("TestFailDeserializationEpoch").unwrap(), + Method::new_from_name("TestFailNoParametersEpoch").unwrap(), + Method::new_from_name("TestFee").unwrap(), + Method::new_from_name("TestFailDeserializationFee").unwrap(), + Method::new_from_name("TestFailNoParametersFee").unwrap(), + Method::new_from_name("TestChainId").unwrap(), + Method::new_from_name("TestFailDeserializationChainId").unwrap(), + Method::new_from_name("TestFailNoParametersChainId").unwrap(), + Method::new_from_name("TestPrank").unwrap(), + Method::new_from_name("TestFailDeserializationPrank").unwrap(), + Method::new_from_name("TestFailNoParametersPrank").unwrap(), + Method::new_from_name("TestFailAddressTypePrank").unwrap(), + Method::new_from_name("TestTrick").unwrap(), + Method::new_from_name("TestFailDeserializationTrick").unwrap(), + Method::new_from_name("TestFailNoParametersTrick").unwrap(), + Method::new_from_name("TestFailAddressTypeTrick").unwrap(), + ], }; let test_actor = WasmActor::new(String::from("Cheatcodes Tests"), test_wasm_bin, test_abi); @@ -222,24 +265,44 @@ fn test_cheatcodes() { Err(_) => { panic!("Could not run test when testing Tester") } - Ok(test_res) => { - assert_eq!(test_res.len(), 1); - assert_eq!(test_res[0].results.as_ref().unwrap().len(), 1); - dbg!(&test_res[0].results); - assert_eq!(test_res[0].test_actor, &test_actor); - test_res[0] - .results - .as_ref() - .unwrap() - .iter() - .for_each(|result| match (result.method().r#type(), result.ret()) { - (MethodType::Test, TestResultType::Passed(apply_ret)) => { - assert_eq!(apply_ret.msg_receipt.exit_code, ExitCode::OK); - } - apply_ret => { - panic!("test against basic test actor should pass: {apply_ret:?}") - } - }) - } + Ok(test_res) => test_res[0] + .results + .as_ref() + .unwrap() + .iter() + .for_each(|result| match (result.method().r#type(), result.ret()) { + (MethodType::TestFail, TestResultType::Failed(apply_ret)) => { + assert_eq!( + apply_ret.msg_receipt.exit_code, + ExitCode::SYS_ASSERTION_FAILED + ); + let apply_failure = apply_ret.failure_info.clone().unwrap(); + + generate_match_assert!( + apply_failure, + result, + "TestFailDeserializationWarp" => "Could not deserialize parameters for Warp cheatcode", + "TestFailNoParametersWarp" => "No parameters provided for Warp cheatcode", + "TestFailDeserializationEpoch" => "Could not deserialize parameters for Epoch cheatcode", + "TestFailNoParametersEpoch" => "No parameters provided for Epoch cheatcode", + "TestFailDeserializationFee" => "Could not deserialize parameters for Fee cheatcode", + "TestFailNoParametersFee" => "No parameters provided for Fee cheatcode", + "TestFailDeserializationChainId" => "Could not deserialize parameters for ChainId cheatcode", + "TestFailNoParametersChainId" => "No parameters provided for ChainId cheatcode", + "TestFailDeserializationPrank" => "Could not deserialize parameters for Prank cheatcode", + "TestFailNoParametersPrank" => "No parameters provided for Prank cheatcode", + "TestFailAddressTypePrank" => "Address parameter for Prank should have a valid ActorID", + "TestFailDeserializationTrick" => "Could not deserialize parameters for Trick cheatcode", + "TestFailNoParametersTrick" => "No parameters provided for Trick cheatcode", + "TestFailAddressTypeTrick" => "Address parameter for Trick should have a valid ActorID" + ); + } + (MethodType::Test, TestResultType::Passed(apply_ret)) => { + assert_eq!(apply_ret.msg_receipt.exit_code, ExitCode::OK); + } + apply_ret => { + panic!("test against cheatcodes test actor should be valid: {apply_ret:?}") + } + }), } } From 309c0546568c975f420c43bc134a1f58c46b9dd9 Mon Sep 17 00:00:00 2001 From: tchataigner Date: Thu, 20 Apr 2023 15:33:42 +0200 Subject: [PATCH 27/38] Update lib/src/state_tree.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: João Oliveira --- lib/src/state_tree.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/state_tree.rs b/lib/src/state_tree.rs index dd077e6..7ece3eb 100644 --- a/lib/src/state_tree.rs +++ b/lib/src/state_tree.rs @@ -328,7 +328,7 @@ impl StateTree { } } - /// Load Kythera utilities' actors + /// Load Kythera utilities' actors. pub fn load_kythera_actors(&mut self) { // Deploy cheatcodes actor. let cheatcodes_actor = WasmActor::new( From 45c431a1631f1a2d0a1c24db7d6093e5ee632901 Mon Sep 17 00:00:00 2001 From: tchataigner Date: Thu, 20 Apr 2023 15:33:49 +0200 Subject: [PATCH 28/38] Update cli/src/utils/search.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: João Oliveira --- cli/src/utils/search.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/src/utils/search.rs b/cli/src/utils/search.rs index 4f5a298..f4aa1df 100644 --- a/cli/src/utils/search.rs +++ b/cli/src/utils/search.rs @@ -64,7 +64,7 @@ fn read_actor>(binary_path: P) -> anyhow::Result { /// Gather the target Actor file and its test files. /// The rules for reading Actor files and it's matching tests are: -/// - All .wasm files that are at the root of the kythera input dir are test_actors. +/// - All .wasm files that are at the root of the kythera input dir are target actors. /// - All .t.wasm files that are at the root of the kythera wasm dir are test test_actors. /// - All .wasm files that are in .t dirs are test test_actors. pub fn search_files>(path: P) -> anyhow::Result> { From e508ce82f09f03184b3132e62f8223920f1e68c3 Mon Sep 17 00:00:00 2001 From: tchataigner Date: Thu, 20 Apr 2023 18:06:03 +0200 Subject: [PATCH 29/38] Update cli/src/utils/search.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: João Oliveira --- cli/src/utils/search.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cli/src/utils/search.rs b/cli/src/utils/search.rs index f4aa1df..0c41848 100644 --- a/cli/src/utils/search.rs +++ b/cli/src/utils/search.rs @@ -65,8 +65,8 @@ fn read_actor>(binary_path: P) -> anyhow::Result { /// Gather the target Actor file and its test files. /// The rules for reading Actor files and it's matching tests are: /// - All .wasm files that are at the root of the kythera input dir are target actors. -/// - All .t.wasm files that are at the root of the kythera wasm dir are test test_actors. -/// - All .wasm files that are in .t dirs are test test_actors. +/// - All .t.wasm files that are at the root of the kythera wasm dir are test_actors. +/// - All .wasm files that are in .t dirs are test_actors. pub fn search_files>(path: P) -> anyhow::Result> { // Search the root dir and find all the .wasm files there which may be target test_actors // or its matching test dirs and files. From 92f89f8b54cd8604a3d548f827fc0ea209b9acd1 Mon Sep 17 00:00:00 2001 From: tchataigner Date: Thu, 20 Apr 2023 18:06:12 +0200 Subject: [PATCH 30/38] Update cli/src/utils/search.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: João Oliveira --- cli/src/utils/search.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/src/utils/search.rs b/cli/src/utils/search.rs index 0c41848..3229ecd 100644 --- a/cli/src/utils/search.rs +++ b/cli/src/utils/search.rs @@ -222,7 +222,7 @@ mod tests { methods: vec![Method::new_from_name("TestTransfer").unwrap()], }; - // Create target & test test_actors files. + // Create target & test_actors files. create_actors_in_dir( dir_path, vec![("token", &target_actor_abi), ("token.t", &test_actor_abi)], From f8216ceaa1aa4ace1b0b49c8d4551ee7e3eabb5d Mon Sep 17 00:00:00 2001 From: Thomas Chataigner Date: Thu, 20 Apr 2023 18:34:03 +0200 Subject: [PATCH 31/38] fix(cheatcodes): address jxs review --- Cargo.lock | 2 +- fvm/Cargo.toml | 2 +- fvm/src/machine.rs | 3 +++ fvm/src/utils.rs | 17 ++++++++--------- lib/src/lib.rs | 2 +- 5 files changed, 14 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d859b67..ef581f3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3105,8 +3105,8 @@ dependencies = [ "fvm_ipld_encoding 0.3.3", "fvm_shared 3.1.0", "kythera-common", - "lazy_static", "multihash", + "once_cell", ] [[package]] diff --git a/fvm/Cargo.toml b/fvm/Cargo.toml index e8e73cf..3f0e1d6 100644 --- a/fvm/Cargo.toml +++ b/fvm/Cargo.toml @@ -12,7 +12,7 @@ fvm = { version = "3.1.0", default-features = false, features = ["testing"] } fvm_ipld_blockstore = "0.1.1" fvm_ipld_encoding = { version = "0.3.3" } fvm_shared = { version = "3.1.0" } -lazy_static = "1.4.0" +once_cell = "1.17.1" multihash = { version = "0.16.1", default-features = false } kythera-common = { path = "../common" } diff --git a/fvm/src/machine.rs b/fvm/src/machine.rs index d84ff6d..8ff421d 100644 --- a/fvm/src/machine.rs +++ b/fvm/src/machine.rs @@ -7,6 +7,9 @@ use fvm_ipld_blockstore::MemoryBlockstore; pub struct KytheraMachine> { inner: M, + // We store OverrideContext here as the Kernel is instantiated at every new implicit message + // and the CallManager needs to have only one inner value for the unsafe code in `with_transaction()` + // to work. pub(crate) override_context: OverrideContext, } diff --git a/fvm/src/utils.rs b/fvm/src/utils.rs index 5c52b63..df191ae 100644 --- a/fvm/src/utils.rs +++ b/fvm/src/utils.rs @@ -1,4 +1,5 @@ use kythera_common::abi::derive_method_num; +use once_cell::sync::Lazy; pub const KYTHERA_NETWORK_ID: u64 = 1312; @@ -9,12 +10,10 @@ pub(crate) const CHAIN_ID_METHOD: &str = "ChainId"; pub(crate) const PRANK_METHOD: &str = "Prank"; pub(crate) const TRICK_METHOD: &str = "Trick"; -lazy_static::lazy_static! { - pub(crate) static ref WARP_NUM: u64 = derive_method_num(WARP_METHOD).unwrap(); - pub(crate) static ref EPOCH_NUM: u64 = derive_method_num(EPOCH_METHOD).unwrap(); - pub(crate) static ref FEE_NUM: u64 = derive_method_num(FEE_METHOD).unwrap(); - pub(crate) static ref CHAIN_ID_NUM: u64 = derive_method_num(CHAIN_ID_METHOD).unwrap(); - pub(crate) static ref PRANK_NUM: u64 = derive_method_num(PRANK_METHOD).unwrap(); - pub(crate) static ref TRICK_NUM: u64 = derive_method_num(TRICK_METHOD).unwrap(); - -} +pub(crate) static WARP_NUM: Lazy = Lazy::new(|| derive_method_num(WARP_METHOD).unwrap()); +pub(crate) static EPOCH_NUM: Lazy = Lazy::new(|| derive_method_num(EPOCH_METHOD).unwrap()); +pub(crate) static FEE_NUM: Lazy = Lazy::new(|| derive_method_num(FEE_METHOD).unwrap()); +pub(crate) static CHAIN_ID_NUM: Lazy = + Lazy::new(|| derive_method_num(CHAIN_ID_METHOD).unwrap()); +pub(crate) static PRANK_NUM: Lazy = Lazy::new(|| derive_method_num(PRANK_METHOD).unwrap()); +pub(crate) static TRICK_NUM: Lazy = Lazy::new(|| derive_method_num(TRICK_METHOD).unwrap()); diff --git a/lib/src/lib.rs b/lib/src/lib.rs index 8c09ffc..3c1108f 100644 --- a/lib/src/lib.rs +++ b/lib/src/lib.rs @@ -27,7 +27,7 @@ mod state_tree; /// Main interface to test `Actor`s with Kythera. pub struct Tester { - // Builtin test_actors root Cid used in the Machine + // Builtin actors root Cid used in the Machine builtin_actors: BuiltInActors, // State tree constructed before instantiating the Machine state_tree: StateTree, From 06611919eb12381fee2992091b8a4c8a35fd01d2 Mon Sep 17 00:00:00 2001 From: Thomas Chataigner Date: Fri, 21 Apr 2023 08:55:06 +0200 Subject: [PATCH 32/38] fix(cheatcodes): jxs review addressed --- Cargo.lock | 1 - fvm/Cargo.toml | 3 +-- fvm/src/call_manager.rs | 15 +++++++------- fvm/src/utils.rs | 45 ++++++++++++++++++++++++++--------------- 4 files changed, 38 insertions(+), 26 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ef581f3..a98edae 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3106,7 +3106,6 @@ dependencies = [ "fvm_shared 3.1.0", "kythera-common", "multihash", - "once_cell", ] [[package]] diff --git a/fvm/Cargo.toml b/fvm/Cargo.toml index 3f0e1d6..6f88fdd 100644 --- a/fvm/Cargo.toml +++ b/fvm/Cargo.toml @@ -11,8 +11,7 @@ cid = { version = "0.8.5", default-features = false } fvm = { version = "3.1.0", default-features = false, features = ["testing"] } fvm_ipld_blockstore = "0.1.1" fvm_ipld_encoding = { version = "0.3.3" } -fvm_shared = { version = "3.1.0" } -once_cell = "1.17.1" +fvm_shared = { version = "3.1.0", feature = ["testing"] } multihash = { version = "0.16.1", default-features = false } kythera-common = { path = "../common" } diff --git a/fvm/src/call_manager.rs b/fvm/src/call_manager.rs index 66870fe..968d21d 100644 --- a/fvm/src/call_manager.rs +++ b/fvm/src/call_manager.rs @@ -1,5 +1,6 @@ use crate::kernel::KytheraKernel; use crate::machine::KytheraMachine; +use crate::utils::{CHAIN_ID_NUM, EPOCH_NUM, FEE_NUM, PRANK_NUM, TRICK_NUM, WARP_NUM}; use anyhow::anyhow; use cid::Cid; use fvm::call_manager::{CallManager, DefaultCallManager, FinishRet, InvocationResult}; @@ -28,8 +29,8 @@ where method: MethodNum, params: Option, ) -> fvm::kernel::Result<()> { - match method { - method_num if method_num == *crate::utils::WARP_NUM => { + match method as u64 { + WARP_NUM => { let new_timestamp: u64 = from_slice( params .ok_or(ExecutionError::Fatal(anyhow!( @@ -45,7 +46,7 @@ where })?; self.machine_mut().override_context.timestamp = Some(new_timestamp); } - method_num if method_num == *crate::utils::EPOCH_NUM => { + EPOCH_NUM => { let new_epoch: i64 = from_slice( params .ok_or(ExecutionError::Fatal(anyhow!( @@ -61,7 +62,7 @@ where })?; self.machine_mut().override_context.epoch = Some(new_epoch); } - method_num if method_num == *crate::utils::FEE_NUM => { + FEE_NUM => { let (lo, hi): (u64, u64) = from_slice( params .ok_or(ExecutionError::Fatal(anyhow!( @@ -79,7 +80,7 @@ where self.machine_mut().override_context.base_fee = Some(fvm_shared::sys::TokenAmount { lo, hi }); } - method_num if method_num == *crate::utils::CHAIN_ID_NUM => { + CHAIN_ID_NUM => { let chain_id: u64 = from_slice( params .ok_or(ExecutionError::Fatal(anyhow!( @@ -96,7 +97,7 @@ where self.machine_mut().override_context.chain_id = Some(chain_id); } - method_num if method_num == *crate::utils::PRANK_NUM => { + PRANK_NUM => { let new_caller: Address = from_slice( params .ok_or(ExecutionError::Fatal(anyhow!( @@ -123,7 +124,7 @@ where self.machine_mut().override_context.caller = Some(new_caller_id); } - method_num if method_num == *crate::utils::TRICK_NUM => { + TRICK_NUM => { let new_origin: Address = from_slice( params .ok_or(ExecutionError::Fatal(anyhow!( diff --git a/fvm/src/utils.rs b/fvm/src/utils.rs index df191ae..5438934 100644 --- a/fvm/src/utils.rs +++ b/fvm/src/utils.rs @@ -1,19 +1,32 @@ -use kythera_common::abi::derive_method_num; -use once_cell::sync::Lazy; - pub const KYTHERA_NETWORK_ID: u64 = 1312; -pub(crate) const WARP_METHOD: &str = "Warp"; -pub(crate) const EPOCH_METHOD: &str = "Epoch"; -pub(crate) const FEE_METHOD: &str = "Fee"; -pub(crate) const CHAIN_ID_METHOD: &str = "ChainId"; -pub(crate) const PRANK_METHOD: &str = "Prank"; -pub(crate) const TRICK_METHOD: &str = "Trick"; +pub(crate) const WARP_NUM: u64 = 112632689; +pub(crate) const EPOCH_NUM: u64 = 1015545011; +pub(crate) const FEE_NUM: u64 = 1307676284; +pub(crate) const CHAIN_ID_NUM: u64 = 2832802136; +pub(crate) const PRANK_NUM: u64 = 3950310035; +pub(crate) const TRICK_NUM: u64 = 4270775027; + +#[cfg(test)] +mod test { + use super::*; + use kythera_common::abi::derive_method_num; + + // Cheatcodes methods names + pub(crate) const WARP_METHOD: &str = "Warp"; + pub(crate) const EPOCH_METHOD: &str = "Epoch"; + pub(crate) const FEE_METHOD: &str = "Fee"; + pub(crate) const CHAIN_ID_METHOD: &str = "ChainId"; + pub(crate) const PRANK_METHOD: &str = "Prank"; + pub(crate) const TRICK_METHOD: &str = "Trick"; -pub(crate) static WARP_NUM: Lazy = Lazy::new(|| derive_method_num(WARP_METHOD).unwrap()); -pub(crate) static EPOCH_NUM: Lazy = Lazy::new(|| derive_method_num(EPOCH_METHOD).unwrap()); -pub(crate) static FEE_NUM: Lazy = Lazy::new(|| derive_method_num(FEE_METHOD).unwrap()); -pub(crate) static CHAIN_ID_NUM: Lazy = - Lazy::new(|| derive_method_num(CHAIN_ID_METHOD).unwrap()); -pub(crate) static PRANK_NUM: Lazy = Lazy::new(|| derive_method_num(PRANK_METHOD).unwrap()); -pub(crate) static TRICK_NUM: Lazy = Lazy::new(|| derive_method_num(TRICK_METHOD).unwrap()); + #[test] + fn test_cheatcodes_number() { + assert_eq!(WARP_NUM, derive_method_num(WARP_METHOD).unwrap()); + assert_eq!(EPOCH_NUM, derive_method_num(EPOCH_METHOD).unwrap()); + assert_eq!(FEE_NUM, derive_method_num(FEE_METHOD).unwrap()); + assert_eq!(CHAIN_ID_NUM, derive_method_num(CHAIN_ID_METHOD).unwrap()); + assert_eq!(PRANK_NUM, derive_method_num(PRANK_METHOD).unwrap()); + assert_eq!(TRICK_NUM, derive_method_num(TRICK_METHOD).unwrap()); + } +} From def912ec48376814848dcf5f3b7fffa69262411c Mon Sep 17 00:00:00 2001 From: Thomas Chataigner Date: Fri, 21 Apr 2023 13:25:40 +0200 Subject: [PATCH 33/38] fix(cheatcodes): typo --- lib/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/lib.rs b/lib/src/lib.rs index 3c1108f..18e2a8a 100644 --- a/lib/src/lib.rs +++ b/lib/src/lib.rs @@ -377,7 +377,7 @@ mod tests { // Instantiate tester let tester = Tester::new(); - // Testing that we got proper CIDs for our revision for builtin test_actors and that they are + // Testing that we got proper CIDs for our revision for builtin actors and that they are // set in the state tree assert_eq!(tester.builtin_actors.root, builtins_actors.root); assert!(tester From baa541d5c0834a552ab5f5b0f740ddc051615a4c Mon Sep 17 00:00:00 2001 From: Thomas Chataigner Date: Fri, 21 Apr 2023 13:26:37 +0200 Subject: [PATCH 34/38] fix(cheatcodes): typo --- lib/src/state_tree.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/state_tree.rs b/lib/src/state_tree.rs index 7ece3eb..a2883c7 100644 --- a/lib/src/state_tree.rs +++ b/lib/src/state_tree.rs @@ -94,7 +94,7 @@ impl StateTree { Ok(()) } - /// Load the built-in test_actors into the `Blockstore`. + /// Load the built-in actors into the `Blockstore`. /// And activate them on the `StateTree`. pub fn load_builtin_actors(&mut self) -> BuiltInActors { // Load the built-in Actors From 4b2866c544755f4b6d62a6ab92aca6f38abb0950 Mon Sep 17 00:00:00 2001 From: Thomas Chataigner Date: Fri, 21 Apr 2023 13:25:40 +0200 Subject: [PATCH 35/38] fix(cheatcodes): typo fix(cheatcodes): typo fix(cheatcodes): typo --- actors/src/wasm_bin/mod.rs | 2 +- cli/src/utils/search.rs | 8 ++++---- lib/src/lib.rs | 2 +- lib/src/state_tree.rs | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/actors/src/wasm_bin/mod.rs b/actors/src/wasm_bin/mod.rs index 3ded121..6582fed 100644 --- a/actors/src/wasm_bin/mod.rs +++ b/actors/src/wasm_bin/mod.rs @@ -17,7 +17,7 @@ pub const CHEATCODES_ACTOR_BINARY: &[u8] = include_bytes!(wasm_bin!("cheatcodes_ #[cfg(feature = "testing")] pub mod test_actors { - // Integration test 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")); diff --git a/cli/src/utils/search.rs b/cli/src/utils/search.rs index 3229ecd..fb292ee 100644 --- a/cli/src/utils/search.rs +++ b/cli/src/utils/search.rs @@ -65,10 +65,10 @@ fn read_actor>(binary_path: P) -> anyhow::Result { /// Gather the target Actor file and its test files. /// The rules for reading Actor files and it's matching tests are: /// - All .wasm files that are at the root of the kythera input dir are target actors. -/// - All .t.wasm files that are at the root of the kythera wasm dir are test_actors. -/// - All .wasm files that are in .t dirs are test_actors. +/// - All .t.wasm files that are at the root of the kythera wasm dir are test actors. +/// - All .wasm files that are in .t dirs are test actors. pub fn search_files>(path: P) -> anyhow::Result> { - // Search the root dir and find all the .wasm files there which may be target test_actors + // Search the root dir and find all the .wasm files there which may be target actors // or its matching test dirs and files. // Split into two lists, the first being the target Actors and the second // their matching test files and dirs. @@ -222,7 +222,7 @@ mod tests { methods: vec![Method::new_from_name("TestTransfer").unwrap()], }; - // Create target & test_actors files. + // Create target & test actors files. create_actors_in_dir( dir_path, vec![("token", &target_actor_abi), ("token.t", &test_actor_abi)], diff --git a/lib/src/lib.rs b/lib/src/lib.rs index 3c1108f..18e2a8a 100644 --- a/lib/src/lib.rs +++ b/lib/src/lib.rs @@ -377,7 +377,7 @@ mod tests { // Instantiate tester let tester = Tester::new(); - // Testing that we got proper CIDs for our revision for builtin test_actors and that they are + // Testing that we got proper CIDs for our revision for builtin actors and that they are // set in the state tree assert_eq!(tester.builtin_actors.root, builtins_actors.root); assert!(tester diff --git a/lib/src/state_tree.rs b/lib/src/state_tree.rs index 7ece3eb..a2883c7 100644 --- a/lib/src/state_tree.rs +++ b/lib/src/state_tree.rs @@ -94,7 +94,7 @@ impl StateTree { Ok(()) } - /// Load the built-in test_actors into the `Blockstore`. + /// Load the built-in actors into the `Blockstore`. /// And activate them on the `StateTree`. pub fn load_builtin_actors(&mut self) -> BuiltInActors { // Load the built-in Actors From 00547915cef72aa0c3e4403dabccb763421130cb Mon Sep 17 00:00:00 2001 From: tchataigner Date: Fri, 21 Apr 2023 13:58:00 +0200 Subject: [PATCH 36/38] Update lib/src/state_tree.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: João Oliveira --- lib/src/state_tree.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/state_tree.rs b/lib/src/state_tree.rs index a2883c7..485196d 100644 --- a/lib/src/state_tree.rs +++ b/lib/src/state_tree.rs @@ -417,7 +417,7 @@ impl StateTree { } /// Deploy a new Actor at a given address, provided with a given token balance - /// and returns the CodeCID of the installed actor + /// and returns the CodeCID of the installed actor. pub fn deploy_actor_from_bin( &mut self, actor: &WasmActor, From 9c98ad71c447da11f9ca340787405835ae09d57d Mon Sep 17 00:00:00 2001 From: Thomas Chataigner Date: Fri, 21 Apr 2023 14:02:05 +0200 Subject: [PATCH 37/38] fix(cheatcodes): typo in comments + comment on deploy_actor_from_bin_at_address --- lib/src/state_tree.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/src/state_tree.rs b/lib/src/state_tree.rs index 485196d..68c3bca 100644 --- a/lib/src/state_tree.rs +++ b/lib/src/state_tree.rs @@ -383,6 +383,8 @@ impl StateTree { (assigned_addr, pub_key_addr) } + /// Deploy a new Actor at a given address, provided with a given token balance and returns the + /// CodeCID of the installed actor. fn deploy_actor_from_bin_at_address( &mut self, address: &Address, @@ -416,8 +418,8 @@ impl StateTree { ) } - /// Deploy a new Actor at a given address, provided with a given token balance - /// and returns the CodeCID of the installed actor. + /// Deploy a new Actor provided with a given token balance and returns the CodeCID of the + /// installed actor. pub fn deploy_actor_from_bin( &mut self, actor: &WasmActor, From 427afcd56956fe11440b985808164fad9543753c Mon Sep 17 00:00:00 2001 From: Thomas Chataigner Date: Mon, 24 Apr 2023 09:48:24 +0200 Subject: [PATCH 38/38] fix(cheatcodes): remove unused feature --- Cargo.lock | 30 ++++++++++++++++++++++++++++++ fvm/Cargo.toml | 2 +- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index a98edae..54d31b3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1133,6 +1133,36 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "demo-target-actor" +version = "0.1.0" +dependencies = [ + "cid", + "frc42_dispatch", + "fvm_ipld_blockstore", + "fvm_ipld_encoding 0.3.3", + "fvm_sdk 3.0.0", + "fvm_shared 3.1.0", + "serde", + "serde_tuple", + "thiserror", +] + +[[package]] +name = "demo-test-actor" +version = "0.1.0" +dependencies = [ + "cid", + "fil_actors_runtime_v10", + "frc42_dispatch", + "fvm_ipld_blockstore", + "fvm_ipld_encoding 0.3.3", + "fvm_sdk 3.0.0", + "fvm_shared 3.1.0", + "paste", + "serde", +] + [[package]] name = "derive-getters" version = "0.2.0" diff --git a/fvm/Cargo.toml b/fvm/Cargo.toml index 6f88fdd..715c7e6 100644 --- a/fvm/Cargo.toml +++ b/fvm/Cargo.toml @@ -11,7 +11,7 @@ cid = { version = "0.8.5", default-features = false } fvm = { version = "3.1.0", default-features = false, features = ["testing"] } fvm_ipld_blockstore = "0.1.1" fvm_ipld_encoding = { version = "0.3.3" } -fvm_shared = { version = "3.1.0", feature = ["testing"] } +fvm_shared = { version = "3.1.0" } multihash = { version = "0.16.1", default-features = false } kythera-common = { path = "../common" }