diff --git a/Cargo.lock b/Cargo.lock index 464285fd4..5b7327184 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1839,6 +1839,7 @@ dependencies = [ "fvm_actor_utils", "fvm_ipld_blockstore 0.2.0", "fvm_ipld_encoding 0.4.0", + "fvm_sdk", "fvm_shared", "num-derive", "num-traits", @@ -1976,6 +1977,7 @@ dependencies = [ "fvm_ipld_blockstore 0.2.0", "fvm_ipld_encoding 0.4.0", "fvm_ipld_hamt", + "fvm_sdk", "fvm_shared", "log", "num-derive", @@ -2542,10 +2544,8 @@ dependencies = [ [[package]] name = "fvm_ipld_bitfield" version = "0.5.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d1950291f40d2d1047eb0a4568f7ef6d5b4973452dcef012dffb1957fe483ff7" dependencies = [ - "fvm_ipld_encoding 0.3.3", + "fvm_ipld_encoding 0.4.0", "serde", "thiserror", "unsigned-varint", @@ -2565,8 +2565,6 @@ dependencies = [ [[package]] name = "fvm_ipld_blockstore" version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "417f52f6915b9f9a68de8462e1cf46f14a2c16420f484b8d2066873de2ffe420" dependencies = [ "anyhow", "cid 0.10.1", @@ -2608,8 +2606,6 @@ dependencies = [ [[package]] name = "fvm_ipld_encoding" version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90608092e31d9a06236268c58f7c36668ab4b2a48afafe3a97e08f094ad7ae50" dependencies = [ "anyhow", "cid 0.10.1", @@ -2625,8 +2621,6 @@ dependencies = [ [[package]] name = "fvm_ipld_hamt" version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f01c65915bd7ab95ff973bb0bb7e03e8d43a43642c8f4b15407e42e4ffcc0d98" dependencies = [ "anyhow", "byteorder", @@ -2663,8 +2657,6 @@ dependencies = [ [[package]] name = "fvm_sdk" version = "3.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c855aead9219cacd48450a4d9d5f57d13dbe4dbbe2d8538d350212792854f5d" dependencies = [ "cid 0.10.1", "fvm_ipld_encoding 0.4.0", @@ -2678,8 +2670,6 @@ dependencies = [ [[package]] name = "fvm_shared" version = "3.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8704b912372b9640f625fef1b8af24873e27feba66dcbae3f2a49f486a26589d" dependencies = [ "anyhow", "bitflags 2.3.3", @@ -5295,3 +5285,7 @@ name = "zeroize" version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2a0956f1ba7c7909bfb66c2e9e4124ab6f6482560f6628b5aaeba39207c9aad9" + +[[patch.unused]] +name = "fvm_ipld_amt" +version = "0.6.1" diff --git a/Cargo.toml b/Cargo.toml index 8e4af5cfe..f5d1a6641 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -86,13 +86,13 @@ members = [ ## Assumes the ref-fvm checkout is in a sibling directory with the same name. ## (Valid once FVM modules are published to crates.io) # [patch.crates-io] -# fvm_shared = { path = "../ref-fvm/shared" } -# fvm_sdk = { path = "../ref-fvm/sdk" } -# fvm_ipld_hamt = { path = "../ref-fvm/ipld/hamt" } -# fvm_ipld_amt = { path = "../ref-fvm/ipld/amt" } -# fvm_ipld_bitfield = { path = "../ref-fvm/ipld/bitfield"} -# fvm_ipld_encoding = { path = "../ref-fvm/ipld/encoding"} -# fvm_ipld_blockstore = { path = "../ref-fvm/ipld/blockstore"} +fvm_shared = { path = "../ref-fvm/shared" } +fvm_sdk = { path = "../ref-fvm/sdk" } +fvm_ipld_hamt = { path = "../ref-fvm/ipld/hamt" } +fvm_ipld_amt = { path = "../ref-fvm/ipld/amt" } +fvm_ipld_bitfield = { path = "../ref-fvm/ipld/bitfield"} +fvm_ipld_encoding = { path = "../ref-fvm/ipld/encoding"} +fvm_ipld_blockstore = { path = "../ref-fvm/ipld/blockstore"} #fvm_actor_utils = { path = "../../filecoin/fvm_actor_utils"} #frc42_dispatch = { path = "../../filecoin/frc42_dispatch"} #frc46_token = { path = "../../filecoin/frc46_token"} diff --git a/actors/account/Cargo.toml b/actors/account/Cargo.toml index 4901e18f3..c018e58e7 100644 --- a/actors/account/Cargo.toml +++ b/actors/account/Cargo.toml @@ -13,6 +13,7 @@ keywords = ["filecoin", "web3", "wasm"] crate-type = ["cdylib", "lib"] [dependencies] +fvm_sdk = { version = "3.3.0" } fil_actors_runtime = { version = "12.0.0", path = "../../runtime" } frc42_dispatch = "3.3.0" fvm_actor_utils = "7.0.0" diff --git a/actors/account/src/lib.rs b/actors/account/src/lib.rs index a83557aae..2beb724ce 100644 --- a/actors/account/src/lib.rs +++ b/actors/account/src/lib.rs @@ -6,7 +6,7 @@ use fvm_shared::address::Protocol; use fvm_shared::crypto::signature::SignatureType::{Secp256k1, BLS}; use fvm_shared::crypto::signature::{Signature, SignatureType}; use fvm_shared::error::ExitCode; -use fvm_shared::{MethodNum, METHOD_CONSTRUCTOR}; +use fvm_shared::MethodNum; use num_derive::FromPrimitive; use fil_actors_runtime::builtin::singletons::SYSTEM_ACTOR_ADDR; @@ -30,7 +30,6 @@ fil_actors_runtime::wasm_trampoline!(Actor); #[derive(FromPrimitive)] #[repr(u64)] pub enum Method { - Constructor = METHOD_CONSTRUCTOR, PubkeyAddress = 2, // Deprecated in v10 // AuthenticateMessage = 3, @@ -115,7 +114,6 @@ impl ActorCode for Actor { } actor_dispatch! { - Constructor => constructor, PubkeyAddress => pubkey_address, AuthenticateMessageExported => authenticate_message, _ => fallback [raw], diff --git a/actors/account/tests/account_actor_test.rs b/actors/account/tests/account_actor_test.rs index 486779a81..df38fbca6 100644 --- a/actors/account/tests/account_actor_test.rs +++ b/actors/account/tests/account_actor_test.rs @@ -24,11 +24,7 @@ fn construction() { rt.expect_validate_caller_addr(vec![SYSTEM_ACTOR_ADDR]); if exit_code.is_success() { - rt.call::( - Method::Constructor as MethodNum, - IpldBlock::serialize_cbor(&addr).unwrap(), - ) - .unwrap(); + rt.construct::(IpldBlock::serialize_cbor(&addr).unwrap()).unwrap(); let state: State = rt.get_state(); assert_eq!(state.address, addr); @@ -45,7 +41,7 @@ fn construction() { } else { expect_abort( exit_code, - rt.call::(1, IpldBlock::serialize_cbor(&addr).unwrap()), + rt.construct::(IpldBlock::serialize_cbor(&addr).unwrap()), ) } rt.verify(); @@ -67,11 +63,7 @@ fn token_receiver() { rt.expect_validate_caller_addr(vec![SYSTEM_ACTOR_ADDR]); let param = Address::new_secp256k1(&[2; fvm_shared::address::SECP_PUB_LEN]).unwrap(); - rt.call::( - Method::Constructor as MethodNum, - IpldBlock::serialize_cbor(¶m).unwrap(), - ) - .unwrap(); + rt.construct::(IpldBlock::serialize_cbor(¶m).unwrap()).unwrap(); rt.set_caller(*EVM_ACTOR_CODE_ID, Address::new_id(1000)); rt.expect_validate_caller_any(); @@ -95,11 +87,7 @@ fn authenticate_message() { let addr = Address::new_secp256k1(&[2; fvm_shared::address::SECP_PUB_LEN]).unwrap(); rt.expect_validate_caller_addr(vec![SYSTEM_ACTOR_ADDR]); - rt.call::( - Method::Constructor as MethodNum, - IpldBlock::serialize_cbor(&addr).unwrap(), - ) - .unwrap(); + rt.construct::(IpldBlock::serialize_cbor(&addr).unwrap()).unwrap(); let state: State = rt.get_state(); assert_eq!(state.address, addr); @@ -166,11 +154,7 @@ fn test_fallback() { let addr = Address::new_secp256k1(&[2; fvm_shared::address::SECP_PUB_LEN]).unwrap(); rt.expect_validate_caller_addr(vec![SYSTEM_ACTOR_ADDR]); - rt.call::( - Method::Constructor as MethodNum, - IpldBlock::serialize_cbor(&addr).unwrap(), - ) - .unwrap(); + rt.construct::(IpldBlock::serialize_cbor(&addr).unwrap()).unwrap(); let state: State = rt.get_state(); assert_eq!(state.address, addr); diff --git a/actors/cron/src/lib.rs b/actors/cron/src/lib.rs index f01b7a4df..8b56f66da 100644 --- a/actors/cron/src/lib.rs +++ b/actors/cron/src/lib.rs @@ -2,14 +2,11 @@ // SPDX-License-Identifier: Apache-2.0, MIT use fil_actors_runtime::runtime::{ActorCode, Runtime}; -use fil_actors_runtime::{ - actor_dispatch, actor_error, extract_send_result, ActorError, SYSTEM_ACTOR_ADDR, -}; +use fil_actors_runtime::{actor_dispatch, extract_send_result, ActorError, SYSTEM_ACTOR_ADDR}; use fvm_ipld_encoding::tuple::*; use fvm_shared::econ::TokenAmount; -use fvm_shared::METHOD_CONSTRUCTOR; use num_derive::FromPrimitive; use num_traits::Zero; @@ -27,7 +24,6 @@ fil_actors_runtime::wasm_trampoline!(Actor); #[derive(FromPrimitive)] #[repr(u64)] pub enum Method { - Constructor = METHOD_CONSTRUCTOR, EpochTick = 2, } @@ -84,7 +80,6 @@ impl ActorCode for Actor { } actor_dispatch! { - Constructor => constructor, EpochTick => epoch_tick, } } diff --git a/actors/cron/tests/cron_actor_test.rs b/actors/cron/tests/cron_actor_test.rs index 169d76530..4377e3d3d 100644 --- a/actors/cron/tests/cron_actor_test.rs +++ b/actors/cron/tests/cron_actor_test.rs @@ -120,7 +120,7 @@ fn epoch_tick_with_entries() { fn construct_and_verify(rt: &MockRuntime, params: &ConstructorParams) { rt.set_caller(*SYSTEM_ACTOR_CODE_ID, SYSTEM_ACTOR_ADDR); rt.expect_validate_caller_addr(vec![SYSTEM_ACTOR_ADDR]); - let ret = rt.call::(1, IpldBlock::serialize_cbor(¶ms).unwrap()).unwrap(); + let ret = rt.construct::(IpldBlock::serialize_cbor(¶ms).unwrap()).unwrap(); assert!(ret.is_none()); rt.verify(); } diff --git a/actors/datacap/src/lib.rs b/actors/datacap/src/lib.rs index d8713a02f..a6c2b3aac 100644 --- a/actors/datacap/src/lib.rs +++ b/actors/datacap/src/lib.rs @@ -14,7 +14,7 @@ use fvm_shared::bigint::BigInt; use fvm_shared::econ::TokenAmount; use fvm_shared::error::{ErrorNumber, ExitCode}; use fvm_shared::Response; -use fvm_shared::{ActorID, MethodNum, METHOD_CONSTRUCTOR}; +use fvm_shared::{ActorID, MethodNum}; use lazy_static::lazy_static; use log::info; use num_derive::FromPrimitive; @@ -50,7 +50,6 @@ lazy_static! { #[derive(FromPrimitive)] #[repr(u64)] pub enum Method { - Constructor = METHOD_CONSTRUCTOR, // Deprecated in v10 // Mint = 2, // Destroy = 3, @@ -505,7 +504,6 @@ impl ActorCode for Actor { } actor_dispatch! { - Constructor => constructor, MintExported => mint, DestroyExported => destroy, NameExported => name, diff --git a/actors/datacap/tests/harness/mod.rs b/actors/datacap/tests/harness/mod.rs index 48ac748ac..c6896c345 100644 --- a/actors/datacap/tests/harness/mod.rs +++ b/actors/datacap/tests/harness/mod.rs @@ -47,12 +47,8 @@ impl Harness { pub fn construct_and_verify(&self, rt: &MockRuntime, registry: &Address) { rt.set_caller(*SYSTEM_ACTOR_CODE_ID, SYSTEM_ACTOR_ADDR); rt.expect_validate_caller_addr(vec![SYSTEM_ACTOR_ADDR]); - let ret = rt - .call::( - Method::Constructor as MethodNum, - IpldBlock::serialize_cbor(registry).unwrap(), - ) - .unwrap(); + let ret = + rt.construct::(IpldBlock::serialize_cbor(registry).unwrap()).unwrap(); assert!(ret.is_none()); rt.verify(); diff --git a/actors/eam/src/lib.rs b/actors/eam/src/lib.rs index f95c85f10..86e3430d1 100644 --- a/actors/eam/src/lib.rs +++ b/actors/eam/src/lib.rs @@ -14,7 +14,7 @@ use fil_actors_runtime::{ }; use fvm_ipld_encoding::ipld_block::IpldBlock; -use fvm_shared::{error::ExitCode, sys::SendFlags, ActorID, METHOD_CONSTRUCTOR}; +use fvm_shared::{error::ExitCode, sys::SendFlags, ActorID}; use serde::{Deserialize, Serialize}; pub mod ext; @@ -33,7 +33,6 @@ fil_actors_runtime::wasm_trampoline!(EamActor); #[derive(FromPrimitive)] #[repr(u64)] pub enum Method { - Constructor = METHOD_CONSTRUCTOR, Create = 2, Create2 = 3, CreateExternal = 4, @@ -296,7 +295,6 @@ impl ActorCode for EamActor { } actor_dispatch_unrestricted! { - Constructor => constructor, Create => create, Create2 => create2, CreateExternal => create_external, diff --git a/actors/eam/tests/create.rs b/actors/eam/tests/create.rs index bc8258867..f918ddc7a 100644 --- a/actors/eam/tests/create.rs +++ b/actors/eam/tests/create.rs @@ -274,7 +274,7 @@ pub fn construct_and_verify() -> MockRuntime { rt.expect_validate_caller_addr(vec![SYSTEM_ACTOR_ADDR]); - let result = rt.call::(eam::Method::Constructor as u64, None).unwrap(); + let result = rt.construct::(None).unwrap(); expect_empty(result); rt.verify(); rt.reset(); diff --git a/actors/ethaccount/src/lib.rs b/actors/ethaccount/src/lib.rs index 81da5aabf..3da759832 100644 --- a/actors/ethaccount/src/lib.rs +++ b/actors/ethaccount/src/lib.rs @@ -2,8 +2,7 @@ pub mod types; use fvm_ipld_encoding::ipld_block::IpldBlock; use fvm_shared::address::Payload; -use fvm_shared::{MethodNum, METHOD_CONSTRUCTOR}; -use num_derive::FromPrimitive; +use fvm_shared::MethodNum; use fil_actors_runtime::runtime::{ActorCode, Runtime}; use fil_actors_runtime::{ @@ -14,13 +13,6 @@ use fil_actors_runtime::{ #[cfg(feature = "fil-actor")] fil_actors_runtime::wasm_trampoline!(EthAccountActor); -/// Ethereum Account actor methods. -#[derive(FromPrimitive)] -#[repr(u64)] -pub enum Method { - Constructor = METHOD_CONSTRUCTOR, -} - /// Ethereum Account actor. pub struct EthAccountActor; @@ -66,14 +58,13 @@ impl EthAccountActor { } impl ActorCode for EthAccountActor { - type Methods = Method; + type Methods = fvm_shared::MethodNum; fn name() -> &'static str { "EVMAccount" } actor_dispatch! { - Constructor => constructor, _ => fallback [raw], } } diff --git a/actors/ethaccount/tests/ethaccount_test.rs b/actors/ethaccount/tests/ethaccount_test.rs index f9b403788..b0ead5e4d 100644 --- a/actors/ethaccount/tests/ethaccount_test.rs +++ b/actors/ethaccount/tests/ethaccount_test.rs @@ -6,9 +6,8 @@ use fvm_ipld_encoding::ipld_block::IpldBlock; use fvm_ipld_encoding::RawBytes; use fvm_shared::address::Address; -use fil_actor_ethaccount::{EthAccountActor, Method}; +use fil_actor_ethaccount::EthAccountActor; use fvm_shared::error::ExitCode; -use fvm_shared::MethodNum; use fil_actors_runtime::test_utils::{ expect_abort_contains_message, ACCOUNT_ACTOR_CODE_ID, SYSTEM_ACTOR_CODE_ID, @@ -23,7 +22,7 @@ fn no_delegated_cant_deploy() { expect_abort_contains_message( ExitCode::USR_ILLEGAL_ARGUMENT, "receiver must have a predictable address", - rt.call::(Method::Constructor as MethodNum, None), + rt.construct::(None), ); rt.verify(); } diff --git a/actors/ethaccount/tests/util.rs b/actors/ethaccount/tests/util.rs index d275c5e16..d9c1357b2 100644 --- a/actors/ethaccount/tests/util.rs +++ b/actors/ethaccount/tests/util.rs @@ -1,11 +1,10 @@ use std::cell::RefCell; -use fil_actor_ethaccount::{EthAccountActor, Method}; +use fil_actor_ethaccount::EthAccountActor; use fil_actors_runtime::test_utils::{MockRuntime, SYSTEM_ACTOR_CODE_ID}; use fil_actors_runtime::EAM_ACTOR_ID; use fil_actors_runtime::SYSTEM_ACTOR_ADDR; use fvm_shared::address::Address; -use fvm_shared::MethodNum; pub const EOA: Address = Address::new_id(1000); @@ -31,7 +30,7 @@ pub fn setup() -> MockRuntime { ) .unwrap(), ); - rt.call::(Method::Constructor as MethodNum, None).unwrap(); + rt.construct::(None).unwrap(); rt.verify(); rt } diff --git a/actors/evm/src/lib.rs b/actors/evm/src/lib.rs index 3c1f34344..ddf4fe1a6 100644 --- a/actors/evm/src/lib.rs +++ b/actors/evm/src/lib.rs @@ -15,7 +15,6 @@ use crate::interpreter::{execute, Bytecode, ExecutionState, System}; use crate::reader::ValueReader; use cid::Cid; use fil_actors_runtime::runtime::{ActorCode, Runtime}; -use fvm_shared::METHOD_CONSTRUCTOR; use num_derive::FromPrimitive; pub use types::*; @@ -59,7 +58,6 @@ fn test_method_selector() { #[derive(FromPrimitive)] #[repr(u64)] pub enum Method { - Constructor = METHOD_CONSTRUCTOR, Resurrect = 2, GetBytecode = 3, GetBytecodeHash = 4, @@ -410,7 +408,6 @@ impl ActorCode for EvmContractActor { } actor_dispatch_unrestricted! { - Constructor => constructor, InvokeContract => invoke_contract [default_params], GetBytecode => bytecode, GetBytecodeHash => bytecode_hash, diff --git a/actors/evm/tests/call.rs b/actors/evm/tests/call.rs index c656e748d..6ce74f9b6 100644 --- a/actors/evm/tests/call.rs +++ b/actors/evm/tests/call.rs @@ -1179,10 +1179,7 @@ impl ContractTester { rt.set_delegated_address(0, Address::new_delegated(EAM_ACTOR_ID, &addr.0).unwrap()); assert!(rt - .call::( - evm::Method::Constructor as u64, - IpldBlock::serialize_cbor(¶ms).unwrap(), - ) + .construct::(IpldBlock::serialize_cbor(¶ms).unwrap(),) .unwrap() .is_none()); diff --git a/actors/evm/tests/env.rs b/actors/evm/tests/env.rs index 7eaccf905..7645c3a71 100644 --- a/actors/evm/tests/env.rs +++ b/actors/evm/tests/env.rs @@ -65,10 +65,7 @@ impl TestEnv { assert!(self .runtime - .call::( - evm::Method::Constructor as u64, - IpldBlock::serialize_cbor(¶ms).unwrap(), - ) + .construct::(IpldBlock::serialize_cbor(¶ms).unwrap(),) .unwrap() .is_none()); diff --git a/actors/evm/tests/util.rs b/actors/evm/tests/util.rs index 335612fbb..1b00c2773 100644 --- a/actors/evm/tests/util.rs +++ b/actors/evm/tests/util.rs @@ -51,10 +51,7 @@ pub fn init_construct_and_verify( }; assert!(rt - .call::( - evm::Method::Constructor as u64, - IpldBlock::serialize_cbor(¶ms).unwrap(), - ) + .construct::(IpldBlock::serialize_cbor(¶ms).unwrap(),) .unwrap() .is_none()); let evm_st: State = rt.state().unwrap(); diff --git a/actors/init/Cargo.toml b/actors/init/Cargo.toml index 378864d68..67965da30 100644 --- a/actors/init/Cargo.toml +++ b/actors/init/Cargo.toml @@ -14,6 +14,7 @@ keywords = ["filecoin", "web3", "wasm"] crate-type = ["cdylib", "lib"] [dependencies] +fvm_sdk = { version = "3.3.0" } fil_actors_runtime = { version = "12.0.0", path = "../../runtime" } frc42_dispatch = "3.3.0" fvm_shared = { version = "3.4.0", default-features = false } diff --git a/actors/init/src/lib.rs b/actors/init/src/lib.rs index 5f1f0fb89..2abdf5443 100644 --- a/actors/init/src/lib.rs +++ b/actors/init/src/lib.rs @@ -11,7 +11,7 @@ use fil_actors_runtime::{ }; use fvm_shared::address::Address; use fvm_shared::error::ExitCode; -use fvm_shared::{ActorID, METHOD_CONSTRUCTOR}; +use fvm_shared::ActorID; use num_derive::FromPrimitive; pub use self::state::State; @@ -28,7 +28,6 @@ fil_actors_runtime::wasm_trampoline!(Actor); #[derive(FromPrimitive)] #[repr(u64)] pub enum Method { - Constructor = METHOD_CONSTRUCTOR, Exec = 2, Exec4 = 3, } @@ -92,17 +91,15 @@ impl Actor { )); } - // Create an empty actor - rt.create_actor(params.code_cid, id_address, None)?; - - // Invoke constructor - extract_send_result(rt.send_simple( - &Address::new_id(id_address), - METHOD_CONSTRUCTOR, + // Create the actor. + extract_send_result(rt.create_actor( + params.code_cid, + id_address, + None, params.constructor_params.into(), rt.message().value_received(), - )) - .context("constructor failed")?; + None, + ))?; Ok(ExecReturn { id_address: Address::new_id(id_address), robust_address }) } @@ -148,17 +145,15 @@ impl Actor { } } - // Create an empty actor - rt.create_actor(params.code_cid, id_address, Some(delegated_address))?; - - // Invoke constructor - extract_send_result(rt.send_simple( - &Address::new_id(id_address), - METHOD_CONSTRUCTOR, + // Create the actor. + extract_send_result(rt.create_actor( + params.code_cid, + id_address, + Some(delegated_address), params.constructor_params.into(), rt.message().value_received(), - )) - .context("constructor failed")?; + None, + ))?; Ok(Exec4Return { id_address: Address::new_id(id_address), robust_address }) } @@ -172,7 +167,6 @@ impl ActorCode for Actor { } actor_dispatch! { - Constructor => constructor, Exec => exec, Exec4 => exec4, } diff --git a/actors/init/tests/init_actor_test.rs b/actors/init/tests/init_actor_test.rs index c6d123101..6316122d7 100644 --- a/actors/init/tests/init_actor_test.rs +++ b/actors/init/tests/init_actor_test.rs @@ -19,7 +19,7 @@ use fvm_ipld_encoding::RawBytes; use fvm_shared::address::Address; use fvm_shared::econ::TokenAmount; use fvm_shared::error::ExitCode; -use fvm_shared::{ActorID, HAMT_BIT_WIDTH, METHOD_CONSTRUCTOR}; +use fvm_shared::{ActorID, HAMT_BIT_WIDTH}; use num_traits::Zero; use serde::Serialize; @@ -69,12 +69,10 @@ fn repeated_robust_address() { // Next id let expected_id = 100; let expected_id_addr = Address::new_id(expected_id); - rt.expect_create_actor(*MULTISIG_ACTOR_CODE_ID, expected_id, None); - - // Expect a send to the multisig actor constructor - rt.expect_send_simple( - expected_id_addr, - METHOD_CONSTRUCTOR, + rt.expect_create_actor( + *MULTISIG_ACTOR_CODE_ID, + expected_id, + None, IpldBlock::serialize_cbor(&fake_params).unwrap(), TokenAmount::zero(), None, @@ -83,7 +81,7 @@ fn repeated_robust_address() { // Return should have been successful. Check the returned addresses let exec_ret = exec_and_verify(&rt, *MULTISIG_ACTOR_CODE_ID, &fake_params).unwrap(); - assert_eq!(unique_address, exec_ret.robust_address, "Robust address does not macth"); + assert_eq!(unique_address, exec_ret.robust_address, "Robust address does not match"); assert_eq!(expected_id_addr, exec_ret.id_address, "Id address does not match"); check_state(&rt); } @@ -129,16 +127,13 @@ fn create_2_payment_channels() { let expected_id = 100 + n; let expected_id_addr = Address::new_id(expected_id); - rt.expect_create_actor(*PAYCH_ACTOR_CODE_ID, expected_id, None); - let fake_params = ConstructorParams { network_name: String::from("fake_param") }; - // expect anne creating a payment channel to trigger a send to the payment channels constructor let balance = TokenAmount::from_atto(100); - - rt.expect_send_simple( - expected_id_addr, - METHOD_CONSTRUCTOR, + rt.expect_create_actor( + *PAYCH_ACTOR_CODE_ID, + expected_id, + None, IpldBlock::serialize_cbor(&fake_params).unwrap(), balance, None, @@ -173,13 +168,11 @@ fn create_storage_miner() { let expected_id = 100; let expected_id_addr = Address::new_id(expected_id); - rt.expect_create_actor(*MINER_ACTOR_CODE_ID, expected_id, None); - let fake_params = ConstructorParams { network_name: String::from("fake_param") }; - - rt.expect_send_simple( - expected_id_addr, - METHOD_CONSTRUCTOR, + rt.expect_create_actor( + *MINER_ACTOR_CODE_ID, + expected_id, + None, IpldBlock::serialize_cbor(&fake_params).unwrap(), TokenAmount::zero(), None, @@ -222,13 +215,11 @@ fn create_multisig_actor() { // Next id let expected_id = 100; let expected_id_addr = Address::new_id(expected_id); - rt.expect_create_actor(*MULTISIG_ACTOR_CODE_ID, expected_id, None); - let fake_params = ConstructorParams { network_name: String::from("fake_param") }; - // Expect a send to the multisig actor constructor - rt.expect_send_simple( - expected_id_addr, - METHOD_CONSTRUCTOR, + rt.expect_create_actor( + *MULTISIG_ACTOR_CODE_ID, + expected_id, + None, IpldBlock::serialize_cbor(&fake_params).unwrap(), TokenAmount::zero(), None, @@ -256,13 +247,11 @@ fn sending_constructor_failure() { // Create the next id address let expected_id = 100; - let expected_id_addr = Address::new_id(expected_id); - rt.expect_create_actor(*MINER_ACTOR_CODE_ID, expected_id, None); - let fake_params = ConstructorParams { network_name: String::from("fake_param") }; - rt.expect_send_simple( - expected_id_addr, - METHOD_CONSTRUCTOR, + rt.expect_create_actor( + *MINER_ACTOR_CODE_ID, + expected_id, + None, IpldBlock::serialize_cbor(&fake_params).unwrap(), TokenAmount::zero(), None, @@ -304,13 +293,11 @@ fn call_exec4() { // Next id let expected_id = 100; let expected_id_addr = Address::new_id(expected_id); - rt.expect_create_actor(*MULTISIG_ACTOR_CODE_ID, expected_id, Some(f4_addr)); - let fake_params = ConstructorParams { network_name: String::from("fake_param") }; - // Expect a send to the multisig actor constructor - rt.expect_send_simple( - expected_id_addr, - METHOD_CONSTRUCTOR, + rt.expect_create_actor( + *MULTISIG_ACTOR_CODE_ID, + expected_id, + Some(f4_addr), IpldBlock::serialize_cbor(&fake_params).unwrap(), TokenAmount::zero(), None, @@ -379,15 +366,13 @@ fn call_exec4_placeholder() { let expected_id_addr = Address::new_id(expected_id); rt.set_address_actor_type(expected_id_addr, *PLACEHOLDER_ACTOR_CODE_ID); rt.set_delegated_address(expected_id, f4_addr); + let fake_params = ConstructorParams { network_name: String::from("fake_param") }; // Now try to create it. - rt.expect_create_actor(*MULTISIG_ACTOR_CODE_ID, expected_id, Some(f4_addr)); - - let fake_params = ConstructorParams { network_name: String::from("fake_param") }; - // Expect a send to the multisig actor constructor - rt.expect_send_simple( - expected_id_addr, - METHOD_CONSTRUCTOR, + rt.expect_create_actor( + *MULTISIG_ACTOR_CODE_ID, + expected_id, + Some(f4_addr), IpldBlock::serialize_cbor(&fake_params).unwrap(), TokenAmount::zero(), None, @@ -415,9 +400,7 @@ fn construct_and_verify(rt: &MockRuntime) { rt.set_caller(*SYSTEM_ACTOR_CODE_ID, SYSTEM_ACTOR_ADDR); rt.expect_validate_caller_addr(vec![SYSTEM_ACTOR_ADDR]); let params = ConstructorParams { network_name: "mock".to_string() }; - let ret = rt - .call::(METHOD_CONSTRUCTOR, IpldBlock::serialize_cbor(¶ms).unwrap()) - .unwrap(); + let ret = rt.construct::(IpldBlock::serialize_cbor(¶ms).unwrap()).unwrap(); assert!(ret.is_none()); diff --git a/actors/market/src/lib.rs b/actors/market/src/lib.rs index 5837cddad..b8ed2704b 100644 --- a/actors/market/src/lib.rs +++ b/actors/market/src/lib.rs @@ -20,7 +20,7 @@ use fvm_shared::error::ExitCode; use fvm_shared::piece::PieceInfo; use fvm_shared::reward::ThisEpochRewardReturn; use fvm_shared::sector::{RegisteredSealProof, SectorSize, StoragePower}; -use fvm_shared::{ActorID, METHOD_CONSTRUCTOR, METHOD_SEND}; +use fvm_shared::{ActorID, METHOD_SEND}; use integer_encoding::VarInt; use log::info; use num_derive::FromPrimitive; @@ -69,7 +69,6 @@ pub const EX_DEAL_EXPIRED: ExitCode = ExitCode::new(FIRST_ACTOR_SPECIFIC_EXIT_CO #[derive(FromPrimitive)] #[repr(u64)] pub enum Method { - Constructor = METHOD_CONSTRUCTOR, AddBalance = 2, WithdrawBalance = 3, PublishStorageDeals = 4, @@ -1450,7 +1449,6 @@ impl ActorCode for Actor { } actor_dispatch! { - Constructor => constructor, AddBalance|AddBalanceExported => add_balance, WithdrawBalance|WithdrawBalanceExported => withdraw_balance, PublishStorageDeals|PublishStorageDealsExported => publish_storage_deals, diff --git a/actors/market/tests/harness.rs b/actors/market/tests/harness.rs index c024f79d8..62faee211 100644 --- a/actors/market/tests/harness.rs +++ b/actors/market/tests/harness.rs @@ -44,9 +44,7 @@ use fvm_shared::reward::ThisEpochRewardReturn; use fvm_shared::sector::{RegisteredSealProof, StoragePower}; use fvm_shared::smooth::FilterEstimate; use fvm_shared::sys::SendFlags; -use fvm_shared::{ - address::Address, econ::TokenAmount, error::ExitCode, ActorID, METHOD_CONSTRUCTOR, METHOD_SEND, -}; +use fvm_shared::{address::Address, econ::TokenAmount, error::ExitCode, ActorID, METHOD_SEND}; // Define common set of actor ids that will be used across all tests. const OWNER_ID: u64 = 101; @@ -133,7 +131,7 @@ pub fn check_state_with_expected(rt: &MockRuntime, expected_patterns: &[Regex]) pub fn construct_and_verify(rt: &MockRuntime) { rt.set_caller(*SYSTEM_ACTOR_CODE_ID, SYSTEM_ACTOR_ADDR); rt.expect_validate_caller_addr(vec![SYSTEM_ACTOR_ADDR]); - assert!(rt.call::(METHOD_CONSTRUCTOR, None).unwrap().is_none()); + assert!(rt.construct::(None).unwrap().is_none()); rt.verify(); } diff --git a/actors/market/tests/market_actor_test.rs b/actors/market/tests/market_actor_test.rs index e4d3f4052..655c7a64f 100644 --- a/actors/market/tests/market_actor_test.rs +++ b/actors/market/tests/market_actor_test.rs @@ -30,7 +30,7 @@ use fvm_shared::econ::TokenAmount; use fvm_shared::error::ExitCode; use fvm_shared::piece::PaddedPieceSize; use fvm_shared::sector::{RegisteredSealProof, StoragePower}; -use fvm_shared::{MethodNum, HAMT_BIT_WIDTH, METHOD_CONSTRUCTOR, METHOD_SEND}; +use fvm_shared::{MethodNum, HAMT_BIT_WIDTH, METHOD_SEND}; use regex::Regex; use std::cell::RefCell; use std::ops::Add; @@ -66,7 +66,7 @@ fn simple_construction() { rt.set_caller(*SYSTEM_ACTOR_CODE_ID, SYSTEM_ACTOR_ADDR); rt.expect_validate_caller_addr(vec![SYSTEM_ACTOR_ADDR]); - assert!(rt.call::(METHOD_CONSTRUCTOR, None).unwrap().is_none()); + assert!(rt.construct::(None).unwrap().is_none()); rt.verify(); diff --git a/actors/miner/src/lib.rs b/actors/miner/src/lib.rs index d52a9c387..7a56fca3a 100644 --- a/actors/miner/src/lib.rs +++ b/actors/miner/src/lib.rs @@ -24,7 +24,7 @@ use fvm_shared::randomness::*; use fvm_shared::reward::ThisEpochRewardReturn; use fvm_shared::sector::*; use fvm_shared::smooth::FilterEstimate; -use fvm_shared::{ActorID, METHOD_CONSTRUCTOR, METHOD_SEND}; +use fvm_shared::{ActorID, METHOD_SEND}; use itertools::Itertools; use log::{error, info, warn}; use num_derive::FromPrimitive; @@ -96,7 +96,6 @@ mod vesting_state; #[derive(FromPrimitive)] #[repr(u64)] pub enum Method { - Constructor = METHOD_CONSTRUCTOR, ControlAddresses = 2, ChangeWorkerAddress = 3, ChangePeerID = 4, @@ -5094,7 +5093,6 @@ impl ActorCode for Actor { } actor_dispatch! { - Constructor => constructor, ControlAddresses => control_addresses, ChangeWorkerAddress|ChangeWorkerAddressExported => change_worker_address, ChangePeerID|ChangePeerIDExported => change_peer_id, diff --git a/actors/miner/tests/miner_actor_test_construction.rs b/actors/miner/tests/miner_actor_test_construction.rs index 332a54eca..ab18e0e88 100644 --- a/actors/miner/tests/miner_actor_test_construction.rs +++ b/actors/miner/tests/miner_actor_test_construction.rs @@ -3,7 +3,7 @@ use fil_actors_runtime::INIT_ACTOR_ADDR; use fil_actor_account::Method as AccountMethod; use fil_actor_miner::{ - Actor, Deadline, Deadlines, Method, MinerConstructorParams as ConstructorParams, State, + Actor, Deadline, Deadlines, MinerConstructorParams as ConstructorParams, State, }; use fvm_ipld_encoding::{BytesDe, CborStore}; @@ -80,10 +80,7 @@ fn simple_construction() { ExitCode::OK, ); - let result = env - .rt - .call::(Method::Constructor as u64, IpldBlock::serialize_cbor(¶ms).unwrap()) - .unwrap(); + let result = env.rt.construct::(IpldBlock::serialize_cbor(¶ms).unwrap()).unwrap(); expect_empty(result); env.rt.verify(); @@ -155,10 +152,7 @@ fn control_addresses_are_resolved_during_construction() { ExitCode::OK, ); - let result = env - .rt - .call::(Method::Constructor as u64, IpldBlock::serialize_cbor(¶ms).unwrap()) - .unwrap(); + let result = env.rt.construct::(IpldBlock::serialize_cbor(¶ms).unwrap()).unwrap(); expect_empty(result); env.rt.verify(); @@ -179,10 +173,8 @@ fn test_construct_with_invalid_peer_id() { env.rt.set_caller(*INIT_ACTOR_CODE_ID, INIT_ACTOR_ADDR); env.rt.expect_validate_caller_addr(vec![INIT_ACTOR_ADDR]); - let result = env - .rt - .call::(Method::Constructor as u64, IpldBlock::serialize_cbor(¶ms).unwrap()) - .unwrap_err(); + let result = + env.rt.construct::(IpldBlock::serialize_cbor(¶ms).unwrap()).unwrap_err(); assert_eq!(result.exit_code(), ExitCode::USR_ILLEGAL_ARGUMENT); env.rt.verify(); } @@ -199,10 +191,8 @@ fn fails_if_control_addresses_exceeds_maximum_length() { env.rt.set_caller(*INIT_ACTOR_CODE_ID, INIT_ACTOR_ADDR); env.rt.expect_validate_caller_addr(vec![INIT_ACTOR_ADDR]); - let result = env - .rt - .call::(Method::Constructor as u64, IpldBlock::serialize_cbor(¶ms).unwrap()) - .unwrap_err(); + let result = + env.rt.construct::(IpldBlock::serialize_cbor(¶ms).unwrap()).unwrap_err(); assert_eq!(result.exit_code(), ExitCode::USR_ILLEGAL_ARGUMENT); env.rt.verify(); } @@ -219,10 +209,8 @@ fn test_construct_with_large_multiaddr() { env.rt.set_caller(*INIT_ACTOR_CODE_ID, INIT_ACTOR_ADDR); env.rt.expect_validate_caller_addr(vec![INIT_ACTOR_ADDR]); - let result = env - .rt - .call::(Method::Constructor as u64, IpldBlock::serialize_cbor(¶ms).unwrap()) - .unwrap_err(); + let result = + env.rt.construct::(IpldBlock::serialize_cbor(¶ms).unwrap()).unwrap_err(); assert_eq!(result.exit_code(), ExitCode::USR_ILLEGAL_ARGUMENT); env.rt.verify(); } @@ -238,10 +226,8 @@ fn test_construct_with_empty_multiaddr() { env.rt.set_caller(*INIT_ACTOR_CODE_ID, INIT_ACTOR_ADDR); env.rt.expect_validate_caller_addr(vec![INIT_ACTOR_ADDR]); - let result = env - .rt - .call::(Method::Constructor as u64, IpldBlock::serialize_cbor(¶ms).unwrap()) - .unwrap_err(); + let result = + env.rt.construct::(IpldBlock::serialize_cbor(¶ms).unwrap()).unwrap_err(); assert_eq!(result.exit_code(), ExitCode::USR_ILLEGAL_ARGUMENT); env.rt.verify(); } diff --git a/actors/miner/tests/util.rs b/actors/miner/tests/util.rs index 5482d5dae..54abb4abc 100644 --- a/actors/miner/tests/util.rs +++ b/actors/miner/tests/util.rs @@ -270,9 +270,7 @@ impl ActorHarness { ExitCode::OK, ); - let result = rt - .call::(Method::Constructor as u64, IpldBlock::serialize_cbor(¶ms).unwrap()) - .unwrap(); + let result = rt.construct::(IpldBlock::serialize_cbor(¶ms).unwrap()).unwrap(); expect_empty(result); rt.verify(); } diff --git a/actors/multisig/src/lib.rs b/actors/multisig/src/lib.rs index 1530c038c..d4ba7c738 100644 --- a/actors/multisig/src/lib.rs +++ b/actors/multisig/src/lib.rs @@ -12,7 +12,7 @@ use fvm_shared::address::Address; use fvm_shared::econ::TokenAmount; use fvm_shared::error::ExitCode; use fvm_shared::MethodNum; -use fvm_shared::{HAMT_BIT_WIDTH, METHOD_CONSTRUCTOR}; +use fvm_shared::HAMT_BIT_WIDTH; use num_derive::FromPrimitive; use num_traits::Zero; @@ -37,7 +37,6 @@ mod types; #[derive(FromPrimitive)] #[repr(u64)] pub enum Method { - Constructor = METHOD_CONSTRUCTOR, Propose = 2, Approve = 3, Cancel = 4, @@ -568,7 +567,6 @@ impl ActorCode for Actor { } actor_dispatch! { - Constructor => constructor, Propose => propose, Approve => approve, Cancel => cancel, diff --git a/actors/multisig/tests/multisig_actor_test.rs b/actors/multisig/tests/multisig_actor_test.rs index 9d17da4b0..f0e2bcbdf 100644 --- a/actors/multisig/tests/multisig_actor_test.rs +++ b/actors/multisig/tests/multisig_actor_test.rs @@ -80,10 +80,7 @@ mod constructor_tests { rt.set_received(TokenAmount::from_atto(100u8)); rt.expect_validate_caller_addr(vec![INIT_ACTOR_ADDR]); rt.set_caller(*INIT_ACTOR_CODE_ID, INIT_ACTOR_ADDR); - let ret = rt.call::( - Method::Constructor as u64, - IpldBlock::serialize_cbor(¶ms).unwrap(), - ); + let ret = rt.construct::(IpldBlock::serialize_cbor(¶ms).unwrap()); assert!(ret.unwrap().is_none()); rt.verify(); @@ -116,12 +113,8 @@ mod constructor_tests { rt.expect_validate_caller_addr(vec![INIT_ACTOR_ADDR]); rt.set_caller(*INIT_ACTOR_CODE_ID, INIT_ACTOR_ADDR); - let ret = rt - .call::( - Method::Constructor as u64, - IpldBlock::serialize_cbor(¶ms).unwrap(), - ) - .unwrap(); + let ret = + rt.construct::(IpldBlock::serialize_cbor(¶ms).unwrap()).unwrap(); assert!(ret.is_none()); check_state(&rt); } @@ -140,10 +133,7 @@ mod constructor_tests { rt.expect_validate_caller_addr(vec![INIT_ACTOR_ADDR]); rt.set_caller(*INIT_ACTOR_CODE_ID, INIT_ACTOR_ADDR); assert!(rt - .call::( - Method::Constructor as u64, - IpldBlock::serialize_cbor(¶ms).unwrap(), - ) + .construct::(IpldBlock::serialize_cbor(¶ms).unwrap()) .unwrap() .is_none()); @@ -171,10 +161,7 @@ mod constructor_tests { expect_abort( ExitCode::USR_ILLEGAL_ARGUMENT, - rt.call::( - Method::Constructor as u64, - IpldBlock::serialize_cbor(&zero_signer_params).unwrap(), - ), + rt.construct::(IpldBlock::serialize_cbor(&zero_signer_params).unwrap()), ); rt.verify(); } @@ -198,8 +185,7 @@ mod constructor_tests { rt.set_caller(*INIT_ACTOR_CODE_ID, INIT_ACTOR_ADDR); expect_abort( ExitCode::USR_ILLEGAL_ARGUMENT, - rt.call::( - Method::Constructor as u64, + rt.construct::( IpldBlock::serialize_cbor(&over_max_signers_params).unwrap(), ), ); @@ -219,10 +205,7 @@ mod constructor_tests { rt.set_caller(*INIT_ACTOR_CODE_ID, INIT_ACTOR_ADDR); expect_abort( ExitCode::USR_ILLEGAL_ARGUMENT, - rt.call::( - Method::Constructor as u64, - IpldBlock::serialize_cbor(¶ms).unwrap(), - ), + rt.construct::(IpldBlock::serialize_cbor(¶ms).unwrap()), ); rt.verify(); } @@ -250,10 +233,7 @@ mod constructor_tests { rt.set_caller(*INIT_ACTOR_CODE_ID, INIT_ACTOR_ADDR); expect_abort( ExitCode::USR_ILLEGAL_ARGUMENT, - rt.call::( - Method::Constructor as u64, - IpldBlock::serialize_cbor(¶ms).unwrap(), - ), + rt.construct::(IpldBlock::serialize_cbor(¶ms).unwrap()), ); rt.verify(); } @@ -271,10 +251,7 @@ mod constructor_tests { rt.set_caller(*INIT_ACTOR_CODE_ID, INIT_ACTOR_ADDR); expect_abort( ExitCode::USR_ILLEGAL_ARGUMENT, - rt.call::( - Method::Constructor as u64, - IpldBlock::serialize_cbor(¶ms).unwrap(), - ), + rt.construct::(IpldBlock::serialize_cbor(¶ms).unwrap()), ); rt.verify(); } @@ -294,10 +271,7 @@ mod constructor_tests { rt.set_caller(*INIT_ACTOR_CODE_ID, INIT_ACTOR_ADDR); expect_abort( ExitCode::USR_ILLEGAL_ARGUMENT, - rt.call::( - Method::Constructor as u64, - IpldBlock::serialize_cbor(¶ms).unwrap(), - ), + rt.construct::(IpldBlock::serialize_cbor(¶ms).unwrap()), ); rt.verify(); } diff --git a/actors/multisig/tests/util.rs b/actors/multisig/tests/util.rs index 4a639e9e8..5b57cad15 100644 --- a/actors/multisig/tests/util.rs +++ b/actors/multisig/tests/util.rs @@ -41,9 +41,7 @@ impl ActorHarness { }; rt.set_caller(*INIT_ACTOR_CODE_ID, INIT_ACTOR_ADDR); rt.expect_validate_caller_addr(vec![INIT_ACTOR_ADDR]); - let result = rt - .call::(Method::Constructor as u64, IpldBlock::serialize_cbor(¶ms).unwrap()) - .unwrap(); + let result = rt.construct::(IpldBlock::serialize_cbor(¶ms).unwrap()).unwrap(); assert!(result.is_none()); rt.verify(); } diff --git a/actors/paych/src/lib.rs b/actors/paych/src/lib.rs index 1cb3c2305..32e26858f 100644 --- a/actors/paych/src/lib.rs +++ b/actors/paych/src/lib.rs @@ -15,7 +15,7 @@ use fvm_ipld_encoding::ipld_block::IpldBlock; use fvm_shared::econ::TokenAmount; use fvm_shared::error::ExitCode; use fvm_shared::sys::SendFlags; -use fvm_shared::{METHOD_CONSTRUCTOR, METHOD_SEND}; +use fvm_shared::METHOD_SEND; use num_derive::FromPrimitive; use num_traits::Zero; @@ -36,7 +36,6 @@ mod types; #[derive(FromPrimitive)] #[repr(u64)] pub enum Method { - Constructor = METHOD_CONSTRUCTOR, UpdateChannelState = 2, Settle = 3, Collect = 4, @@ -325,7 +324,6 @@ impl ActorCode for Actor { } actor_dispatch! { - Constructor => constructor, UpdateChannelState => update_channel_state, Settle => settle, Collect => collect, diff --git a/actors/paych/tests/paych_actor_test.rs b/actors/paych/tests/paych_actor_test.rs index 3b2158352..b0e976c83 100644 --- a/actors/paych/tests/paych_actor_test.rs +++ b/actors/paych/tests/paych_actor_test.rs @@ -26,7 +26,6 @@ use fvm_shared::crypto::signature::Signature; use fvm_shared::econ::TokenAmount; use fvm_shared::error::ExitCode; use fvm_shared::sys::SendFlags; -use fvm_shared::METHOD_CONSTRUCTOR; use num_traits::Zero; const PAYCH_ID: u64 = 100; @@ -51,11 +50,20 @@ fn call(rt: &MockRuntime, method_num: u64, ser: Option) -> Option(method_num, ser).unwrap() } +fn construct(rt: &MockRuntime, ser: Option) -> Option { + rt.construct::(ser).unwrap() +} + fn expect_abort(rt: &MockRuntime, method_num: u64, ser: Option, exp: ExitCode) { let err = rt.call::(method_num, ser).unwrap_err(); assert_eq!(exp, err.exit_code()); } +fn expect_constructor_abort(rt: &MockRuntime, ser: Option, exp: ExitCode) { + let err = rt.construct::(ser).unwrap_err(); + assert_eq!(exp, err.exit_code()); +} + fn construct_lane_state_amt(rt: &MockRuntime, lss: Vec) -> Cid { let mut arr = Amt::new(&rt.store); for (i, ls) in (0..).zip(lss.into_iter()) { @@ -77,7 +85,7 @@ fn check_state(rt: &MockRuntime) { mod paych_constructor { use fil_actors_runtime::runtime::builtins::Type; - use fvm_shared::{METHOD_CONSTRUCTOR, METHOD_SEND}; + use fvm_shared::METHOD_SEND; use super::*; @@ -119,9 +127,8 @@ mod paych_constructor { to: Address::new_id(TEST_PAYCH_ADDR), from: Address::new_secp256k1(&[2; fvm_shared::address::SECP_PUB_LEN]).unwrap(), }; - expect_abort( + expect_constructor_abort( &rt, - METHOD_CONSTRUCTOR, IpldBlock::serialize_cbor(¶ms).unwrap(), ExitCode::USR_NOT_FOUND, ); @@ -146,7 +153,7 @@ mod paych_constructor { } #[test] - fn sendr_addr_not_resolvable_to_id_addr() { + fn sender_addr_not_resolvable_to_id_addr() { const TO_ADDR: u64 = 101; let to_addr = Address::new_id(TO_ADDR); let paych_addr = Address::new_id(TEST_PAYCH_ADDR); @@ -176,9 +183,8 @@ mod paych_constructor { rt.set_caller(*INIT_ACTOR_CODE_ID, INIT_ACTOR_ADDR); rt.expect_validate_caller_type(vec![Type::Init]); let params = ConstructorParams { from: non_id_addr, to: to_addr }; - expect_abort( + expect_constructor_abort( &rt, - METHOD_CONSTRUCTOR, IpldBlock::serialize_cbor(¶ms).unwrap(), ExitCode::USR_ILLEGAL_ARGUMENT, ); @@ -214,9 +220,8 @@ mod paych_constructor { rt.set_caller(*INIT_ACTOR_CODE_ID, INIT_ACTOR_ADDR); rt.expect_validate_caller_type(vec![Type::Init]); let params = ConstructorParams { from: from_addr, to: non_id_addr }; - expect_abort( + expect_constructor_abort( &rt, - METHOD_CONSTRUCTOR, IpldBlock::serialize_cbor(¶ms).unwrap(), ExitCode::USR_ILLEGAL_ARGUMENT, ); @@ -1091,7 +1096,7 @@ fn construct_and_verify(rt: &MockRuntime, sender: Address, receiver: Address) { let params = ConstructorParams { from: sender, to: receiver }; rt.set_caller(*INIT_ACTOR_CODE_ID, INIT_ACTOR_ADDR); rt.expect_validate_caller_type(vec![Type::Init]); - call(rt, METHOD_CONSTRUCTOR, IpldBlock::serialize_cbor(¶ms).unwrap()); + construct(rt, IpldBlock::serialize_cbor(¶ms).unwrap()); rt.verify(); let sender_id = *rt.id_addresses.borrow().get(&sender).unwrap_or(&sender); let receiver_id = *rt.id_addresses.borrow().get(&receiver).unwrap_or(&receiver); diff --git a/actors/power/src/ext.rs b/actors/power/src/ext.rs index 81ec9f9d8..198cc0ff9 100644 --- a/actors/power/src/ext.rs +++ b/actors/power/src/ext.rs @@ -6,7 +6,6 @@ use fvm_shared::address::Address; use fvm_shared::bigint::bigint_ser; use fvm_shared::sector::{RegisteredPoStProof, SectorNumber, StoragePower}; use fvm_shared::smooth::FilterEstimate; -use fvm_shared::METHOD_CONSTRUCTOR; use num_derive::FromPrimitive; pub mod init { @@ -75,7 +74,6 @@ pub mod reward { #[derive(FromPrimitive)] #[repr(u64)] pub enum Method { - Constructor = METHOD_CONSTRUCTOR, AwardBlockReward = 2, ThisEpochReward = 3, UpdateNetworkKPI = 4, diff --git a/actors/power/src/lib.rs b/actors/power/src/lib.rs index d714ff25b..1b02efce8 100644 --- a/actors/power/src/lib.rs +++ b/actors/power/src/lib.rs @@ -21,7 +21,7 @@ use fvm_shared::econ::TokenAmount; use fvm_shared::error::ExitCode; use fvm_shared::reward::ThisEpochRewardReturn; use fvm_shared::sector::SealVerifyInfo; -use fvm_shared::{MethodNum, HAMT_BIT_WIDTH, METHOD_CONSTRUCTOR}; +use fvm_shared::{MethodNum, HAMT_BIT_WIDTH}; use log::{debug, error}; use num_derive::FromPrimitive; use num_traits::Zero; @@ -53,7 +53,6 @@ pub mod detail { #[repr(u64)] pub enum Method { /// Constructor for Storage Power Actor - Constructor = METHOD_CONSTRUCTOR, CreateMiner = 2, UpdateClaimedPower = 3, EnrollCronEvent = 4, @@ -683,7 +682,6 @@ impl ActorCode for Actor { } actor_dispatch! { - Constructor => constructor, CreateMiner|CreateMinerExported => create_miner, UpdateClaimedPower => update_claimed_power , EnrollCronEvent => enroll_cron_event, diff --git a/actors/power/tests/harness/mod.rs b/actors/power/tests/harness/mod.rs index 7d747e844..bbdcfe718 100644 --- a/actors/power/tests/harness/mod.rs +++ b/actors/power/tests/harness/mod.rs @@ -105,7 +105,7 @@ impl Harness { pub fn construct(&self, rt: &MockRuntime) { rt.set_caller(*SYSTEM_ACTOR_CODE_ID, SYSTEM_ACTOR_ADDR); rt.expect_validate_caller_addr(vec![SYSTEM_ACTOR_ADDR]); - rt.call::(Method::Constructor as MethodNum, None).unwrap(); + rt.construct::(None).unwrap(); rt.verify() } diff --git a/actors/reward/src/lib.rs b/actors/reward/src/lib.rs index 1815e7333..e2914a238 100644 --- a/actors/reward/src/lib.rs +++ b/actors/reward/src/lib.rs @@ -10,7 +10,7 @@ use fil_actors_runtime::{ use fvm_ipld_encoding::ipld_block::IpldBlock; use fvm_shared::address::Address; use fvm_shared::econ::TokenAmount; -use fvm_shared::{METHOD_CONSTRUCTOR, METHOD_SEND}; +use fvm_shared::METHOD_SEND; use log::{error, warn}; use num_derive::FromPrimitive; @@ -40,7 +40,6 @@ pub const PENALTY_MULTIPLIER: u64 = 3; #[derive(FromPrimitive)] #[repr(u64)] pub enum Method { - Constructor = METHOD_CONSTRUCTOR, AwardBlockReward = 2, ThisEpochReward = 3, UpdateNetworkKPI = 4, @@ -223,7 +222,6 @@ impl ActorCode for Actor { } actor_dispatch! { - Constructor => constructor, AwardBlockReward => award_block_reward, ThisEpochReward => this_epoch_reward, UpdateNetworkKPI => update_network_kpi, diff --git a/actors/reward/tests/reward_actor_test.rs b/actors/reward/tests/reward_actor_test.rs index 9bb4e3b21..5f97d19e6 100644 --- a/actors/reward/tests/reward_actor_test.rs +++ b/actors/reward/tests/reward_actor_test.rs @@ -20,7 +20,7 @@ use fvm_shared::clock::ChainEpoch; use fvm_shared::econ::TokenAmount; use fvm_shared::error::ExitCode; use fvm_shared::sector::StoragePower; -use fvm_shared::{METHOD_CONSTRUCTOR, METHOD_SEND}; +use fvm_shared::METHOD_SEND; use lazy_static::lazy_static; use num_traits::FromPrimitive; @@ -335,10 +335,7 @@ fn construct_and_verify(curr_power: &StoragePower) -> MockRuntime { rt.set_caller(*SYSTEM_ACTOR_CODE_ID, SYSTEM_ACTOR_ADDR); rt.expect_validate_caller_addr(vec![SYSTEM_ACTOR_ADDR]); let ret = rt - .call::( - METHOD_CONSTRUCTOR, - IpldBlock::serialize_cbor(&(BigIntSer(curr_power))).unwrap(), - ) + .construct::(IpldBlock::serialize_cbor(&(BigIntSer(curr_power))).unwrap()) .unwrap(); assert!(ret.is_none()); diff --git a/actors/system/src/lib.rs b/actors/system/src/lib.rs index 8d6cc487a..8c112e4bd 100644 --- a/actors/system/src/lib.rs +++ b/actors/system/src/lib.rs @@ -1,28 +1,20 @@ // Copyright 2019-2022 ChainSafe Systems // SPDX-License-Identifier: Apache-2.0, MIT use cid::{multihash, Cid}; +use fil_actors_runtime::Never; use fvm_ipld_blockstore::Blockstore; use fvm_ipld_encoding::tuple::*; use fvm_ipld_encoding::CborStore; use fvm_shared::error::ExitCode; -use fvm_shared::METHOD_CONSTRUCTOR; -use num_derive::FromPrimitive; use fil_actors_runtime::runtime::{ActorCode, Runtime}; use fil_actors_runtime::{ - actor_dispatch, actor_error, ActorContext, ActorError, AsActorError, SYSTEM_ACTOR_ADDR, + actor_dispatch, ActorContext, ActorError, AsActorError, SYSTEM_ACTOR_ADDR, }; #[cfg(feature = "fil-actor")] fil_actors_runtime::wasm_trampoline!(Actor); -/// System actor methods. -#[derive(FromPrimitive)] -#[repr(u64)] -pub enum Method { - Constructor = METHOD_CONSTRUCTOR, -} - /// System actor state. #[derive(Default, Deserialize_tuple, Serialize_tuple, Debug, Clone)] pub struct State { @@ -65,27 +57,23 @@ impl Actor { } impl ActorCode for Actor { - type Methods = Method; + type Methods = Never; fn name() -> &'static str { "System" } - actor_dispatch! { - Constructor => constructor, - } + actor_dispatch! {} } #[cfg(test)] mod tests { use std::cell::RefCell; - use fvm_shared::MethodNum; - use fil_actors_runtime::test_utils::{MockRuntime, SYSTEM_ACTOR_CODE_ID}; use fil_actors_runtime::SYSTEM_ACTOR_ADDR; - use crate::{Actor, Method, State}; + use crate::{Actor, State}; pub fn new_runtime() -> MockRuntime { MockRuntime { @@ -101,7 +89,7 @@ mod tests { let rt = new_runtime(); rt.expect_validate_caller_addr(vec![SYSTEM_ACTOR_ADDR]); rt.set_caller(*SYSTEM_ACTOR_CODE_ID, SYSTEM_ACTOR_ADDR); - rt.call::(Method::Constructor as MethodNum, None).unwrap(); + rt.construct::(None).unwrap(); let state: State = rt.get_state(); let builtin_actors = state.get_builtin_actors(&rt.store).unwrap(); diff --git a/actors/verifreg/src/lib.rs b/actors/verifreg/src/lib.rs index c79c96f17..2aeb3ffda 100644 --- a/actors/verifreg/src/lib.rs +++ b/actors/verifreg/src/lib.rs @@ -14,7 +14,7 @@ use fvm_shared::bigint::BigInt; use fvm_shared::clock::ChainEpoch; use fvm_shared::econ::TokenAmount; use fvm_shared::error::ExitCode; -use fvm_shared::{ActorID, HAMT_BIT_WIDTH, METHOD_CONSTRUCTOR}; +use fvm_shared::{ActorID, HAMT_BIT_WIDTH}; use log::info; use num_derive::FromPrimitive; use num_traits::{Signed, Zero}; @@ -52,7 +52,6 @@ pub mod types; #[derive(FromPrimitive)] #[repr(u64)] pub enum Method { - Constructor = METHOD_CONSTRUCTOR, AddVerifier = 2, RemoveVerifier = 3, AddVerifiedClient = 4, @@ -1084,7 +1083,6 @@ impl ActorCode for Actor { } actor_dispatch! { - Constructor => constructor, AddVerifier => add_verifier, RemoveVerifier => remove_verifier, AddVerifiedClient|AddVerifiedClientExported => add_verified_client, diff --git a/actors/verifreg/tests/harness/mod.rs b/actors/verifreg/tests/harness/mod.rs index 61b49e902..4f2a87217 100644 --- a/actors/verifreg/tests/harness/mod.rs +++ b/actors/verifreg/tests/harness/mod.rs @@ -88,12 +88,8 @@ impl Harness { pub fn construct_and_verify(&self, rt: &MockRuntime, root_param: &Address) { rt.set_caller(*SYSTEM_ACTOR_CODE_ID, SYSTEM_ACTOR_ADDR); rt.expect_validate_caller_addr(vec![SYSTEM_ACTOR_ADDR]); - let ret = rt - .call::( - Method::Constructor as MethodNum, - IpldBlock::serialize_cbor(root_param).unwrap(), - ) - .unwrap(); + let ret = + rt.construct::(IpldBlock::serialize_cbor(root_param).unwrap()).unwrap(); assert!(ret.is_none()); rt.verify(); diff --git a/actors/verifreg/tests/verifreg_actor_test.rs b/actors/verifreg/tests/verifreg_actor_test.rs index c2e8df8ef..fef6c4c28 100644 --- a/actors/verifreg/tests/verifreg_actor_test.rs +++ b/actors/verifreg/tests/verifreg_actor_test.rs @@ -40,9 +40,8 @@ mod util { mod construction { use fvm_shared::address::{Address, BLS_PUB_LEN}; use fvm_shared::error::ExitCode; - use fvm_shared::MethodNum; - use fil_actor_verifreg::{Actor as VerifregActor, Method}; + use fil_actor_verifreg::Actor as VerifregActor; use fil_actors_runtime::test_utils::*; use fil_actors_runtime::SYSTEM_ACTOR_ADDR; use fvm_ipld_encoding::ipld_block::IpldBlock; @@ -77,10 +76,7 @@ mod construction { rt.expect_validate_caller_addr(vec![SYSTEM_ACTOR_ADDR]); expect_abort( ExitCode::USR_ILLEGAL_ARGUMENT, - rt.call::( - Method::Constructor as MethodNum, - IpldBlock::serialize_cbor(&root_pubkey).unwrap(), - ), + rt.construct::(IpldBlock::serialize_cbor(&root_pubkey).unwrap()), ); } } diff --git a/runtime/src/builtin/shared.rs b/runtime/src/builtin/shared.rs index 6d7ecd7d1..629d634a8 100644 --- a/runtime/src/builtin/shared.rs +++ b/runtime/src/builtin/shared.rs @@ -141,9 +141,12 @@ impl Display for SendError { } } -pub fn extract_send_result( - res: Result, -) -> Result, ActorError> { +pub fn extract_send_result( + res: Result, +) -> Result, ActorError> +where + ActorError: From, +{ let ret = res?; if ret.exit_code.is_success() { Ok(ret.return_data) diff --git a/runtime/src/dispatch.rs b/runtime/src/dispatch.rs index d0fd345d7..2c0285214 100644 --- a/runtime/src/dispatch.rs +++ b/runtime/src/dispatch.rs @@ -13,19 +13,85 @@ use crate::ActorError; /// #[derive(FromPrimitive)] /// #[repr(u64)] /// enum Method { -/// Constructor = 1, +/// SomeMethod = 2, /// } /// impl ActorCode for Actor { /// type Methods = Method; /// actor_dispatch! { -/// Constructor => constructor, +/// SomeMethod => some_method, /// } /// } /// ``` #[macro_export] macro_rules! actor_dispatch { + () => { + fn create( + rt: &RT, + args: Option, + ) -> Result, $crate::ActorError> + where + RT: $crate::runtime::Runtime, + RT::Blockstore: Clone, + { + $crate::dispatch(rt, Self::constructor, &args) + } + + fn invoke( + rt: &RT, + method: fvm_shared::MethodNum, + args: Option, + ) -> Result, $crate::ActorError> + where + RT: $crate::runtime::Runtime, + RT::Blockstore: Clone, + { + $crate::builtin::shared::restrict_internal_api(rt, method)?; + Err($crate::actor_error!(unhandled_message; "invalid method: {}", method)) + } + }; + ($(#[$m:meta])* _ => $func:ident $([$tag:ident])?,) => { + fn create( + rt: &RT, + args: Option, + ) -> Result, $crate::ActorError> + where + RT: $crate::runtime::Runtime, + RT::Blockstore: Clone, + { + $crate::dispatch(rt, Self::constructor, &args) + } + + fn invoke( + rt: &RT, + method: fvm_shared::MethodNum, + args: Option, + ) -> Result, $crate::ActorError> + where + RT: $crate::runtime::Runtime, + RT::Blockstore: Clone, + { + $crate::builtin::shared::restrict_internal_api(rt, method)?; + match ::from_u64(method) { + $(#[$m])* + Some(_) => + $crate::actor_dispatch!(@target rt args method $func $($tag)?), + None => Err($crate::actor_error!(unhandled_message; "invalid method: {}", method)), + } + } + }; ($($(#[$m:meta])* $(_)? $($method:ident)|* => $func:ident $([$tag:ident])?,)*) => { - fn invoke_method( + fn create( + rt: &RT, + args: Option, + ) -> Result, $crate::ActorError> + where + RT: $crate::runtime::Runtime, + RT::Blockstore: Clone, + { + $crate::dispatch(rt, Self::constructor, &args) + } + + fn invoke( rt: &RT, method: fvm_shared::MethodNum, args: Option, @@ -39,7 +105,7 @@ macro_rules! actor_dispatch { $($(#[$m])* $crate::actor_dispatch!(@pattern $($method)|*) => $crate::actor_dispatch!(@target rt args method $func $($tag)?),)* - None => Err(actor_error!(unhandled_message; "invalid method: {}", method)), + None => Err($crate::actor_error!(unhandled_message; "invalid method: {}", method)), } } }; @@ -63,7 +129,18 @@ macro_rules! actor_dispatch { #[macro_export] macro_rules! actor_dispatch_unrestricted { ($($(#[$m:meta])* $(_)? $($method:ident)|* => $func:ident $([$tag:ident])?,)*) => { - fn invoke_method( + fn create( + rt: &RT, + args: Option, + ) -> Result, $crate::ActorError> + where + RT: $crate::runtime::Runtime, + RT::Blockstore: Clone, + { + $crate::dispatch(rt, Self::constructor, &args) + } + + fn invoke( rt: &RT, method: fvm_shared::MethodNum, args: Option, diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 82565f170..09166fbce 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -38,9 +38,20 @@ pub mod test_utils; #[macro_export] macro_rules! wasm_trampoline { ($target:ty) => { + #[no_mangle] + pub extern "C" fn create(param: u32) -> u32 { + $crate::runtime::fvm::trampoline::<$target>( + param, + $crate::runtime::fvm::Entrypoint::Create, + ) + } + #[no_mangle] pub extern "C" fn invoke(param: u32) -> u32 { - $crate::runtime::fvm::trampoline::<$target>(param) + $crate::runtime::fvm::trampoline::<$target>( + param, + $crate::runtime::fvm::Entrypoint::Invoke, + ) } }; } @@ -135,3 +146,6 @@ impl Keyer for &str { BytesKey(self.as_bytes().to_owned()) } } + +/// A type which can never be constructed. +pub enum Never {} diff --git a/runtime/src/runtime/actor_code.rs b/runtime/src/runtime/actor_code.rs index 353982bdb..fa706b487 100644 --- a/runtime/src/runtime/actor_code.rs +++ b/runtime/src/runtime/actor_code.rs @@ -10,11 +10,22 @@ use crate::{ActorError, Runtime}; /// Interface for invoking methods on an Actor pub trait ActorCode { type Methods; + /// A name for the actor type, used in debugging. fn name() -> &'static str; + + /// The actor constructor. Called once, when the actor is first created. + fn create(rt: &RT, params: Option) -> Result, ActorError> + where + // TODO: remove the clone requirement on the blockstore when we fix "replica update" to not + // hold onto state between transactions. + // https://github.com/filecoin-project/builtin-actors/issues/133 + RT: Runtime, + RT::Blockstore: Blockstore + Clone; + /// Invokes method with runtime on the actor's code. Method number will match one /// defined by the Actor, and parameters will be serialized and used in execution - fn invoke_method( + fn invoke( rt: &RT, method: MethodNum, params: Option, diff --git a/runtime/src/runtime/fvm.rs b/runtime/src/runtime/fvm.rs index 37352ee45..198e35e60 100644 --- a/runtime/src/runtime/fvm.rs +++ b/runtime/src/runtime/fvm.rs @@ -320,19 +320,23 @@ where code_id: Cid, actor_id: ActorID, predictable_address: Option
, - ) -> Result<(), ActorError> { + params: Option, + value: TokenAmount, + gas_limit: Option, + ) -> Result { if *self.in_transaction.borrow() { return Err( actor_error!(assertion_failed; "create_actor is not allowed during transaction"), ); } - fvm::actor::create_actor(actor_id, &code_id, predictable_address).map_err(|e| match e { - ErrorNumber::IllegalArgument => { - ActorError::illegal_argument("failed to create actor".into()) - } - ErrorNumber::Forbidden => ActorError::forbidden("actor already exists".into()), - _ => actor_error!(assertion_failed; "create failed with unknown error: {}", e), - }) + fvm::actor::create_actor(actor_id, &code_id, predictable_address, params, value, gas_limit) + .map_err(|e| match e { + ErrorNumber::IllegalArgument => { + ActorError::illegal_argument("failed to create actor".into()) + } + ErrorNumber::Forbidden => ActorError::forbidden("actor already exists".into()), + _ => actor_error!(assertion_failed; "create failed with unknown error: {}", e), + }) } fn delete_actor(&self, beneficiary: &Address) -> Result<(), ActorError> { @@ -563,20 +567,25 @@ where /// 4. Invokes the target method. /// 5a. In case of error, aborts the execution with the emitted exit code, or /// 5b. In case of success, stores the return data as a block and returns the latter. -pub fn trampoline(params: u32) -> u32 { +pub fn trampoline(params: u32, entrypoint: Entrypoint) -> u32 { init_logging(C::name()); std::panic::set_hook(Box::new(|info| { fvm::vm::abort(ExitCode::USR_ASSERTION_FAILED.value(), Some(&format!("{}", info))) })); - let method = fvm::message::method_number(); - let params = fvm::message::params_raw(params).expect("params block invalid"); - // Construct a new runtime. let rt = FvmRuntime::default(); - // Invoke the method, aborting if the actor returns an errored exit code. - let ret = C::invoke_method(&rt, method, params).unwrap_or_else(|mut err| { + let params = fvm_sdk::message::params_raw(params).expect("params block invalid"); + // Invoke the entrypoint, aborting if the actor returns an errored exit code. + let ret = match entrypoint { + Entrypoint::Create => C::create(&rt, params), + Entrypoint::Invoke => { + let method = fvm_sdk::message::method_number(); + C::invoke(&rt, method, params) + } + } + .unwrap_or_else(|mut err| { fvm::vm::exit(err.exit_code().value(), err.take_data(), Some(err.msg())) }); @@ -595,6 +604,12 @@ pub fn trampoline(params: u32) -> u32 { } } +#[derive(Debug)] +pub enum Entrypoint { + Create, + Invoke, +} + /// If debugging is enabled in the VM, installs a logger that sends messages to the FVM log syscall. /// Messages are prefixed with "[LEVEL] ". /// If debugging is not enabled, no logger will be installed which means that log!() and diff --git a/runtime/src/runtime/mod.rs b/runtime/src/runtime/mod.rs index 8db350ce6..5439a1b99 100644 --- a/runtime/src/runtime/mod.rs +++ b/runtime/src/runtime/mod.rs @@ -209,7 +209,10 @@ pub trait Runtime: Primitives + Verifier + RuntimePolicy { code_id: Cid, actor_id: ActorID, predictable_address: Option
, - ) -> Result<(), ActorError>; + params: Option, + value: TokenAmount, + gas_limit: Option, + ) -> Result; /// Deletes the executing actor from the state tree, transferring any balance to beneficiary. /// Aborts if the beneficiary does not exist. diff --git a/runtime/src/test_utils.rs b/runtime/src/test_utils.rs index 8b5ac1cfc..293faa8a2 100644 --- a/runtime/src/test_utils.rs +++ b/runtime/src/test_utils.rs @@ -366,6 +366,10 @@ pub struct ExpectCreateActor { pub code_id: Cid, pub actor_id: ActorID, pub predictable_address: Option
, + pub params: Option, + pub value: TokenAmount, + pub gas_limit: Option, + pub exit_code: ExitCode, } #[derive(Clone, Debug)] @@ -543,6 +547,21 @@ impl MockRuntime { self.id_addresses.borrow_mut().insert(target, Address::new_id(source)); } + pub fn construct( + &self, + params: Option, + ) -> Result, ActorError> { + self.in_call.replace(true); + let prev_state = *self.state.borrow(); + let res = A::create(self, params); + + if res.is_err() { + self.state.replace(prev_state); + } + self.in_call.replace(false); + res + } + pub fn call( &self, method_num: MethodNum, @@ -550,7 +569,7 @@ impl MockRuntime { ) -> Result, ActorError> { self.in_call.replace(true); let prev_state = *self.state.borrow(); - let res = A::invoke_method(self, method_num, params); + let res = A::invoke(self, method_num, params); if res.is_err() { self.state.replace(prev_state); @@ -692,8 +711,20 @@ impl MockRuntime { code_id: Cid, actor_id: ActorID, predictable_address: Option
, + params: Option, + value: TokenAmount, + gas_limit: Option, + exit_code: ExitCode, ) { - let a = ExpectCreateActor { code_id, actor_id, predictable_address }; + let a = ExpectCreateActor { + code_id, + actor_id, + predictable_address, + params, + value, + gas_limit, + exit_code, + }; self.expectations.borrow_mut().expect_create_actor = Some(a); } @@ -1178,7 +1209,10 @@ impl Runtime for MockRuntime { code_id: Cid, actor_id: ActorID, predictable_address: Option
, - ) -> Result<(), ActorError> { + params: Option, + value: TokenAmount, + gas_limit: Option, + ) -> Result { self.require_in_call(); if *self.in_transaction.borrow() { return Err(actor_error!(assertion_failed; "side-effect within transaction")); @@ -1190,13 +1224,14 @@ impl Runtime for MockRuntime { .take() .expect("unexpected call to create actor"); - assert_eq!( - expect_create_actor, - ExpectCreateActor { code_id, actor_id, predictable_address }, - "unexpected actor being created" - ); + assert_eq!(expect_create_actor.code_id, code_id); + assert_eq!(expect_create_actor.actor_id, actor_id); + assert_eq!(expect_create_actor.predictable_address, predictable_address); + assert_eq!(expect_create_actor.params, params); + assert_eq!(expect_create_actor.value, value); + assert_eq!(expect_create_actor.gas_limit, gas_limit); self.set_address_actor_type(Address::new_id(actor_id), code_id); - Ok(()) + Ok(Response { exit_code: expect_create_actor.exit_code, return_data: None }) } fn delete_actor(&self, addr: &Address) -> Result<(), ActorError> { diff --git a/test_vm/src/lib.rs b/test_vm/src/lib.rs index 42887e669..9139d3ea5 100644 --- a/test_vm/src/lib.rs +++ b/test_vm/src/lib.rs @@ -802,24 +802,24 @@ where let params = self.msg.params.clone(); let mut res = match ACTOR_TYPES.get(&to_actor.code).expect("Target actor is not a builtin") { - Type::Account => AccountActor::invoke_method(self, self.msg.method, params), - Type::Cron => CronActor::invoke_method(self, self.msg.method, params), - Type::Init => InitActor::invoke_method(self, self.msg.method, params), - Type::Market => MarketActor::invoke_method(self, self.msg.method, params), - Type::Miner => MinerActor::invoke_method(self, self.msg.method, params), - Type::Multisig => MultisigActor::invoke_method(self, self.msg.method, params), - Type::System => SystemActor::invoke_method(self, self.msg.method, params), - Type::Reward => RewardActor::invoke_method(self, self.msg.method, params), - Type::Power => PowerActor::invoke_method(self, self.msg.method, params), - Type::PaymentChannel => PaychActor::invoke_method(self, self.msg.method, params), - Type::VerifiedRegistry => VerifregActor::invoke_method(self, self.msg.method, params), - Type::DataCap => DataCapActor::invoke_method(self, self.msg.method, params), + Type::Account => AccountActor::invoke(self, self.msg.method, params), + Type::Cron => CronActor::invoke(self, self.msg.method, params), + Type::Init => InitActor::invoke(self, self.msg.method, params), + Type::Market => MarketActor::invoke(self, self.msg.method, params), + Type::Miner => MinerActor::invoke(self, self.msg.method, params), + Type::Multisig => MultisigActor::invoke(self, self.msg.method, params), + Type::System => SystemActor::invoke(self, self.msg.method, params), + Type::Reward => RewardActor::invoke(self, self.msg.method, params), + Type::Power => PowerActor::invoke(self, self.msg.method, params), + Type::PaymentChannel => PaychActor::invoke(self, self.msg.method, params), + Type::VerifiedRegistry => VerifregActor::invoke(self, self.msg.method, params), + Type::DataCap => DataCapActor::invoke(self, self.msg.method, params), Type::Placeholder => { Err(ActorError::unhandled_message("placeholder actors only handle method 0".into())) } - Type::EVM => EvmContractActor::invoke_method(self, self.msg.method, params), - Type::EAM => EamActor::invoke_method(self, self.msg.method, params), - Type::EthAccount => EthAccountActor::invoke_method(self, self.msg.method, params), + Type::EVM => EvmContractActor::invoke(self, self.msg.method, params), + Type::EAM => EamActor::invoke(self, self.msg.method, params), + Type::EthAccount => EthAccountActor::invoke(self, self.msg.method, params), }; if res.is_ok() && !*self.caller_validated.borrow() { res = Err(actor_error!(assertion_failed, "failed to validate caller"));