Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the builtin actors to expose create entrypoints #1339

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 7 additions & 13 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Expand Down
1 change: 1 addition & 0 deletions actors/account/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 1 addition & 3 deletions actors/account/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand Down Expand Up @@ -115,7 +114,6 @@ impl ActorCode for Actor {
}

actor_dispatch! {
Constructor => constructor,
PubkeyAddress => pubkey_address,
AuthenticateMessageExported => authenticate_message,
_ => fallback [raw],
Expand Down
26 changes: 5 additions & 21 deletions actors/account/tests/account_actor_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,7 @@ fn construction() {
rt.expect_validate_caller_addr(vec![SYSTEM_ACTOR_ADDR]);

if exit_code.is_success() {
rt.call::<AccountActor>(
Method::Constructor as MethodNum,
IpldBlock::serialize_cbor(&addr).unwrap(),
)
.unwrap();
rt.construct::<AccountActor>(IpldBlock::serialize_cbor(&addr).unwrap()).unwrap();

let state: State = rt.get_state();
assert_eq!(state.address, addr);
Expand All @@ -45,7 +41,7 @@ fn construction() {
} else {
expect_abort(
exit_code,
rt.call::<AccountActor>(1, IpldBlock::serialize_cbor(&addr).unwrap()),
rt.construct::<AccountActor>(IpldBlock::serialize_cbor(&addr).unwrap()),
)
}
rt.verify();
Expand All @@ -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::<AccountActor>(
Method::Constructor as MethodNum,
IpldBlock::serialize_cbor(&param).unwrap(),
)
.unwrap();
rt.construct::<AccountActor>(IpldBlock::serialize_cbor(&param).unwrap()).unwrap();

rt.set_caller(*EVM_ACTOR_CODE_ID, Address::new_id(1000));
rt.expect_validate_caller_any();
Expand All @@ -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::<AccountActor>(
Method::Constructor as MethodNum,
IpldBlock::serialize_cbor(&addr).unwrap(),
)
.unwrap();
rt.construct::<AccountActor>(IpldBlock::serialize_cbor(&addr).unwrap()).unwrap();

let state: State = rt.get_state();
assert_eq!(state.address, addr);
Expand Down Expand Up @@ -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::<AccountActor>(
Method::Constructor as MethodNum,
IpldBlock::serialize_cbor(&addr).unwrap(),
)
.unwrap();
rt.construct::<AccountActor>(IpldBlock::serialize_cbor(&addr).unwrap()).unwrap();

let state: State = rt.get_state();
assert_eq!(state.address, addr);
Expand Down
7 changes: 1 addition & 6 deletions actors/cron/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -27,7 +24,6 @@ fil_actors_runtime::wasm_trampoline!(Actor);
#[derive(FromPrimitive)]
#[repr(u64)]
pub enum Method {
Constructor = METHOD_CONSTRUCTOR,
EpochTick = 2,
}

Expand Down Expand Up @@ -84,7 +80,6 @@ impl ActorCode for Actor {
}

actor_dispatch! {
Constructor => constructor,
EpochTick => epoch_tick,
}
}
2 changes: 1 addition & 1 deletion actors/cron/tests/cron_actor_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<CronActor>(1, IpldBlock::serialize_cbor(&params).unwrap()).unwrap();
let ret = rt.construct::<CronActor>(IpldBlock::serialize_cbor(&params).unwrap()).unwrap();
assert!(ret.is_none());
rt.verify();
}
Expand Down
4 changes: 1 addition & 3 deletions actors/datacap/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -50,7 +50,6 @@ lazy_static! {
#[derive(FromPrimitive)]
#[repr(u64)]
pub enum Method {
Constructor = METHOD_CONSTRUCTOR,
// Deprecated in v10
// Mint = 2,
// Destroy = 3,
Expand Down Expand Up @@ -505,7 +504,6 @@ impl ActorCode for Actor {
}

actor_dispatch! {
Constructor => constructor,
MintExported => mint,
DestroyExported => destroy,
NameExported => name,
Expand Down
8 changes: 2 additions & 6 deletions actors/datacap/tests/harness/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<DataCapActor>(
Method::Constructor as MethodNum,
IpldBlock::serialize_cbor(registry).unwrap(),
)
.unwrap();
let ret =
rt.construct::<DataCapActor>(IpldBlock::serialize_cbor(registry).unwrap()).unwrap();

assert!(ret.is_none());
rt.verify();
Expand Down
4 changes: 1 addition & 3 deletions actors/eam/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand Down Expand Up @@ -296,7 +295,6 @@ impl ActorCode for EamActor {
}

actor_dispatch_unrestricted! {
Constructor => constructor,
Create => create,
Create2 => create2,
CreateExternal => create_external,
Expand Down
2 changes: 1 addition & 1 deletion actors/eam/tests/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ pub fn construct_and_verify() -> MockRuntime {

rt.expect_validate_caller_addr(vec![SYSTEM_ACTOR_ADDR]);

let result = rt.call::<eam::EamActor>(eam::Method::Constructor as u64, None).unwrap();
let result = rt.construct::<eam::EamActor>(None).unwrap();
expect_empty(result);
rt.verify();
rt.reset();
Expand Down
13 changes: 2 additions & 11 deletions actors/ethaccount/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand All @@ -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;

Expand Down Expand Up @@ -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],
}
}
5 changes: 2 additions & 3 deletions actors/ethaccount/tests/ethaccount_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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::<EthAccountActor>(Method::Constructor as MethodNum, None),
rt.construct::<EthAccountActor>(None),
);
rt.verify();
}
Expand Down
5 changes: 2 additions & 3 deletions actors/ethaccount/tests/util.rs
Original file line number Diff line number Diff line change
@@ -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);

Expand All @@ -31,7 +30,7 @@ pub fn setup() -> MockRuntime {
)
.unwrap(),
);
rt.call::<EthAccountActor>(Method::Constructor as MethodNum, None).unwrap();
rt.construct::<EthAccountActor>(None).unwrap();
rt.verify();
rt
}
Loading