diff --git a/src/lotus_json/actor_states/methods/datacap_actor_params.rs b/src/lotus_json/actor_states/methods/datacap_actor_params.rs new file mode 100644 index 000000000000..2f6c17f1741f --- /dev/null +++ b/src/lotus_json/actor_states/methods/datacap_actor_params.rs @@ -0,0 +1,549 @@ +// Copyright 2019-2025 ChainSafe Systems +// SPDX-License-Identifier: Apache-2.0, MIT + +use crate::lotus_json::{HasLotusJson, LotusJson}; +use crate::shim::address::Address; +use crate::shim::econ::TokenAmount; +use fil_actor_datacap_state as datacap; +use fil_actors_shared::frc46_token::token::types::{ + BurnFromParams, BurnParams, DecreaseAllowanceParams, GetAllowanceParams, + IncreaseAllowanceParams, RevokeAllowanceParams, TransferFromParams, TransferParams, +}; +use fvm_ipld_encoding::RawBytes; +use schemars::JsonSchema; +use serde::{Deserialize, Serialize}; + +#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, JsonSchema)] +#[serde(transparent)] +pub struct DatacapBalanceParamsLotusJson { + #[schemars(with = "LotusJson
")] + #[serde(with = "crate::lotus_json")] + pub address: Address, +} + +macro_rules! impl_datacap_balance_params_lotus_json { + ($($version:ident),*) => { + $( + impl HasLotusJson for datacap::$version::BalanceParams { + type LotusJson = DatacapBalanceParamsLotusJson; + + #[cfg(test)] + fn snapshots() -> Vec<(serde_json::Value, Self)> { + vec![( + serde_json::json!("f01234"), + datacap::$version::BalanceParams { + address: Address::new_id(1234).into(), + }, + )] + } + + fn into_lotus_json(self) -> Self::LotusJson { + DatacapBalanceParamsLotusJson { address: self.address.into() } + } + fn from_lotus_json(lotus_json: Self::LotusJson) -> Self { + datacap::$version::BalanceParams { address: lotus_json.address.into() } + } + } + )* + }; +} + +impl_datacap_balance_params_lotus_json!(v11, v12, v13, v14, v15, v16); + +#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, JsonSchema)] +#[serde(transparent)] +pub struct DatacapConstructorParamsLotusJson { + #[schemars(with = "LotusJson
")] + #[serde(with = "crate::lotus_json")] + pub governor: Address, +} + +macro_rules! impl_datacap_constructor_params_lotus_json { + ($($version:ident),*) => { + $( + impl HasLotusJson for datacap::$version::ConstructorParams { + type LotusJson = DatacapConstructorParamsLotusJson; + + #[cfg(test)] + fn snapshots() -> Vec<(serde_json::Value, Self)> { + vec![( + serde_json::json!("f01234"), + datacap::$version::ConstructorParams { + governor: Address::new_id(1234).into(), + }, + )] + } + + fn into_lotus_json(self) -> Self::LotusJson { + DatacapConstructorParamsLotusJson { governor: self.governor.into() } + } + fn from_lotus_json(lotus_json: Self::LotusJson) -> Self { + datacap::$version::ConstructorParams { governor: lotus_json.governor.into() } + } + } + )* + }; +} + +impl_datacap_constructor_params_lotus_json!(v11, v12, v13, v14, v15, v16); + +#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, JsonSchema)] +#[serde(rename_all = "PascalCase")] +pub struct DatacapDestroyParamsLotusJson { + #[schemars(with = "LotusJson
")] + #[serde(with = "crate::lotus_json")] + pub owner: Address, + #[schemars(with = "LotusJson")] + #[serde(with = "crate::lotus_json")] + pub amount: TokenAmount, +} + +macro_rules! impl_datacap_destroy_params_lotus_json { + ($($version:ident),*) => { + $( + impl HasLotusJson for datacap::$version::DestroyParams { + type LotusJson = DatacapDestroyParamsLotusJson; + + #[cfg(test)] + fn snapshots() -> Vec<(serde_json::Value, Self)> { + vec![( + serde_json::json!({ + "owner": "f01234", + "amount": "1000000000000000000" + }), + datacap::$version::DestroyParams { + owner: Address::new_id(1234).into(), + amount: TokenAmount::from_atto(1_000_000_000_000_000_000_i64).into(), + }, + )] + } + + fn into_lotus_json(self) -> Self::LotusJson { + DatacapDestroyParamsLotusJson { + owner: self.owner.into(), + amount: self.amount.into(), + } + } + fn from_lotus_json(lotus_json: Self::LotusJson) -> Self { + datacap::$version::DestroyParams { + owner: lotus_json.owner.into(), + amount: lotus_json.amount.into(), + } + } + } + )* + }; +} + +impl_datacap_destroy_params_lotus_json!(v9, v10, v11, v12, v13, v14, v15, v16); + +#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, JsonSchema)] +#[serde(rename_all = "PascalCase")] +pub struct DatacapMintParamsLotusJson { + #[schemars(with = "LotusJson
")] + #[serde(with = "crate::lotus_json")] + pub to: Address, + #[schemars(with = "LotusJson")] + #[serde(with = "crate::lotus_json")] + pub amount: TokenAmount, + #[schemars(with = "LotusJson>")] + #[serde(with = "crate::lotus_json")] + pub operators: Vec
, +} + +macro_rules! impl_datacap_mint_params_lotus_json { + ($($version:ident),*) => { + $( + impl HasLotusJson for datacap::$version::MintParams { + type LotusJson = DatacapMintParamsLotusJson; + + #[cfg(test)] + fn snapshots() -> Vec<(serde_json::Value, Self)> { + vec![( + serde_json::json!({ + "to": "f01234", + "amount": "1000000000000000000", + "operators": ["f01235", "f01236"] + }), + datacap::$version::MintParams { + to: Address::new_id(1234).into(), + amount: TokenAmount::from_atto(1_000_000_000_000_000_000_i64).into(), + operators: vec![ + Address::new_id(1235).into(), + Address::new_id(1236).into(), + ], + }, + )] + } + + fn into_lotus_json(self) -> Self::LotusJson { + DatacapMintParamsLotusJson { + to: self.to.into(), + amount: self.amount.into(), + operators: self.operators.into_iter().map(|a| a.into()).collect(), + } + } + fn from_lotus_json(lotus_json: Self::LotusJson) -> Self { + datacap::$version::MintParams { + to: lotus_json.to.into(), + amount: lotus_json.amount.into(), + operators: lotus_json.operators.into_iter().map(|a| a.into()).collect(), + } + } + } + )* + }; +} + +impl_datacap_mint_params_lotus_json!(v9, v10, v11, v12, v13, v14, v15, v16); + +#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, JsonSchema)] +#[serde(rename_all = "PascalCase")] +pub struct TransferParamsLotusJson { + #[schemars(with = "LotusJson
")] + #[serde(with = "crate::lotus_json")] + pub to: Address, + #[schemars(with = "LotusJson")] + #[serde(with = "crate::lotus_json")] + pub amount: TokenAmount, + #[schemars(with = "LotusJson")] + #[serde(with = "crate::lotus_json")] + pub operator_data: RawBytes, +} + +impl HasLotusJson for TransferParams { + type LotusJson = TransferParamsLotusJson; + + #[cfg(test)] + fn snapshots() -> Vec<(serde_json::Value, Self)> { + vec![( + serde_json::json!({ + "to": "f01234", + "amount": "1000000000000000000", + "operator_data": "dGVzdCBkYXRh" + }), + TransferParams { + to: Address::new_id(1234).into(), + amount: TokenAmount::from_atto(1_000_000_000_000_000_000_i64).into(), + operator_data: RawBytes::new(b"test data".to_vec()), + }, + )] + } + + fn into_lotus_json(self) -> Self::LotusJson { + TransferParamsLotusJson { + to: self.to.into(), + amount: self.amount.into(), + operator_data: self.operator_data, + } + } + + fn from_lotus_json(lotus_json: Self::LotusJson) -> Self { + TransferParams { + to: lotus_json.to.into(), + amount: lotus_json.amount.into(), + operator_data: lotus_json.operator_data, + } + } +} + +#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, JsonSchema)] +#[serde(rename_all = "PascalCase")] +pub struct TransferFromParamsLotusJson { + #[schemars(with = "LotusJson
")] + #[serde(with = "crate::lotus_json")] + pub from: Address, + #[schemars(with = "LotusJson
")] + #[serde(with = "crate::lotus_json")] + pub to: Address, + #[schemars(with = "LotusJson")] + #[serde(with = "crate::lotus_json")] + pub amount: TokenAmount, + #[schemars(with = "LotusJson")] + #[serde(with = "crate::lotus_json")] + pub operator_data: RawBytes, +} + +impl HasLotusJson for TransferFromParams { + type LotusJson = TransferFromParamsLotusJson; + + #[cfg(test)] + fn snapshots() -> Vec<(serde_json::Value, Self)> { + vec![( + serde_json::json!({ + "from": "f01234", + "to": "f01235", + "amount": "1000000000000000000", + "operator_data": "dGVzdCBkYXRh" + }), + TransferFromParams { + from: Address::new_id(1234).into(), + to: Address::new_id(1235).into(), + amount: TokenAmount::from_atto(1_000_000_000_000_000_000_i64).into(), + operator_data: RawBytes::new(b"test data".to_vec()), + }, + )] + } + + fn into_lotus_json(self) -> Self::LotusJson { + TransferFromParamsLotusJson { + from: self.from.into(), + to: self.to.into(), + amount: self.amount.into(), + operator_data: self.operator_data, + } + } + + fn from_lotus_json(lotus_json: Self::LotusJson) -> Self { + TransferFromParams { + from: lotus_json.from.into(), + to: lotus_json.to.into(), + amount: lotus_json.amount.into(), + operator_data: lotus_json.operator_data, + } + } +} + +#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, JsonSchema)] +#[serde(rename_all = "PascalCase")] +pub struct IncreaseAllowanceParamsLotusJson { + #[schemars(with = "LotusJson
")] + #[serde(with = "crate::lotus_json")] + pub operator: Address, + #[schemars(with = "LotusJson")] + #[serde(with = "crate::lotus_json")] + pub increase: TokenAmount, +} + +impl HasLotusJson for IncreaseAllowanceParams { + type LotusJson = IncreaseAllowanceParamsLotusJson; + + #[cfg(test)] + fn snapshots() -> Vec<(serde_json::Value, Self)> { + vec![( + serde_json::json!({ + "operator": "f01234", + "increase": "1000000000000000000" + }), + IncreaseAllowanceParams { + operator: Address::new_id(1234).into(), + increase: TokenAmount::from_atto(1_000_000_000_000_000_000_i64).into(), + }, + )] + } + + fn into_lotus_json(self) -> Self::LotusJson { + IncreaseAllowanceParamsLotusJson { + operator: self.operator.into(), + increase: self.increase.into(), + } + } + + fn from_lotus_json(lotus_json: Self::LotusJson) -> Self { + IncreaseAllowanceParams { + operator: lotus_json.operator.into(), + increase: lotus_json.increase.into(), + } + } +} + +#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, JsonSchema)] +#[serde(rename_all = "PascalCase")] +pub struct DecreaseAllowanceParamsLotusJson { + #[schemars(with = "LotusJson
")] + #[serde(with = "crate::lotus_json")] + pub operator: Address, + #[schemars(with = "LotusJson")] + #[serde(with = "crate::lotus_json")] + pub decrease: TokenAmount, +} + +impl HasLotusJson for DecreaseAllowanceParams { + type LotusJson = DecreaseAllowanceParamsLotusJson; + + #[cfg(test)] + fn snapshots() -> Vec<(serde_json::Value, Self)> { + vec![( + serde_json::json!({ + "operator": "f01234", + "decrease": "1000000000000000000" + }), + DecreaseAllowanceParams { + operator: Address::new_id(1234).into(), + decrease: TokenAmount::from_atto(1_000_000_000_000_000_000_i64).into(), + }, + )] + } + + fn into_lotus_json(self) -> Self::LotusJson { + DecreaseAllowanceParamsLotusJson { + operator: self.operator.into(), + decrease: self.decrease.into(), + } + } + + fn from_lotus_json(lotus_json: Self::LotusJson) -> Self { + DecreaseAllowanceParams { + operator: lotus_json.operator.into(), + decrease: lotus_json.decrease.into(), + } + } +} + +#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, JsonSchema)] +#[serde(rename_all = "PascalCase")] +pub struct RevokeAllowanceParamsLotusJson { + #[schemars(with = "LotusJson
")] + #[serde(with = "crate::lotus_json")] + pub operator: Address, +} + +impl HasLotusJson for RevokeAllowanceParams { + type LotusJson = RevokeAllowanceParamsLotusJson; + + #[cfg(test)] + fn snapshots() -> Vec<(serde_json::Value, Self)> { + vec![( + serde_json::json!({ + "operator": "f01234" + }), + RevokeAllowanceParams { + operator: Address::new_id(1234).into(), + }, + )] + } + + fn into_lotus_json(self) -> Self::LotusJson { + RevokeAllowanceParamsLotusJson { + operator: self.operator.into(), + } + } + + fn from_lotus_json(lotus_json: Self::LotusJson) -> Self { + RevokeAllowanceParams { + operator: lotus_json.operator.into(), + } + } +} + +#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, JsonSchema)] +#[serde(rename_all = "PascalCase")] +pub struct BurnParamsLotusJson { + #[schemars(with = "LotusJson")] + #[serde(with = "crate::lotus_json")] + pub amount: TokenAmount, +} + +impl HasLotusJson for BurnParams { + type LotusJson = BurnParamsLotusJson; + + #[cfg(test)] + fn snapshots() -> Vec<(serde_json::Value, Self)> { + vec![( + serde_json::json!({ + "amount": "1000000000000000000" + }), + BurnParams { + amount: TokenAmount::from_atto(1_000_000_000_000_000_000_i64).into(), + }, + )] + } + + fn into_lotus_json(self) -> Self::LotusJson { + BurnParamsLotusJson { + amount: self.amount.into(), + } + } + + fn from_lotus_json(lotus_json: Self::LotusJson) -> Self { + BurnParams { + amount: lotus_json.amount.into(), + } + } +} + +#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, JsonSchema)] +#[serde(rename_all = "PascalCase")] +pub struct BurnFromParamsLotusJson { + #[schemars(with = "LotusJson
")] + #[serde(with = "crate::lotus_json")] + pub owner: Address, + #[schemars(with = "LotusJson")] + #[serde(with = "crate::lotus_json")] + pub amount: TokenAmount, +} + +impl HasLotusJson for BurnFromParams { + type LotusJson = BurnFromParamsLotusJson; + + #[cfg(test)] + fn snapshots() -> Vec<(serde_json::Value, Self)> { + vec![( + serde_json::json!({ + "owner": "f01234", + "amount": "1000000000000000000" + }), + BurnFromParams { + owner: Address::new_id(1234).into(), + amount: TokenAmount::from_atto(1_000_000_000_000_000_000_i64).into(), + }, + )] + } + + fn into_lotus_json(self) -> Self::LotusJson { + BurnFromParamsLotusJson { + owner: self.owner.into(), + amount: self.amount.into(), + } + } + + fn from_lotus_json(lotus_json: Self::LotusJson) -> Self { + BurnFromParams { + owner: lotus_json.owner.into(), + amount: lotus_json.amount.into(), + } + } +} + +#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, JsonSchema)] +#[serde(rename_all = "PascalCase")] +pub struct GetAllowanceParamsLotusJson { + #[schemars(with = "LotusJson
")] + #[serde(with = "crate::lotus_json")] + pub owner: Address, + #[schemars(with = "LotusJson
")] + #[serde(with = "crate::lotus_json")] + pub operator: Address, +} + +impl HasLotusJson for GetAllowanceParams { + type LotusJson = GetAllowanceParamsLotusJson; + + #[cfg(test)] + fn snapshots() -> Vec<(serde_json::Value, Self)> { + vec![( + serde_json::json!({ + "owner": "f01234", + "operator": "f01235" + }), + GetAllowanceParams { + owner: Address::new_id(1234).into(), + operator: Address::new_id(1235).into(), + }, + )] + } + + fn into_lotus_json(self) -> Self::LotusJson { + GetAllowanceParamsLotusJson { + owner: self.owner.into(), + operator: self.operator.into(), + } + } + + fn from_lotus_json(lotus_json: Self::LotusJson) -> Self { + GetAllowanceParams { + owner: lotus_json.owner.into(), + operator: lotus_json.operator.into(), + } + } +} diff --git a/src/lotus_json/actor_states/methods/mod.rs b/src/lotus_json/actor_states/methods/mod.rs index 49d8ecd20ab0..f475f0147628 100644 --- a/src/lotus_json/actor_states/methods/mod.rs +++ b/src/lotus_json/actor_states/methods/mod.rs @@ -3,6 +3,7 @@ use super::*; mod account_authenticate_params; mod account_constructor_params; +mod datacap_actor_params; mod evm_constructor_params; mod init_constructor_params; mod init_exec4_params; diff --git a/src/rpc/registry/actors/datacap.rs b/src/rpc/registry/actors/datacap.rs new file mode 100644 index 000000000000..df13780b9948 --- /dev/null +++ b/src/rpc/registry/actors/datacap.rs @@ -0,0 +1,142 @@ +// Copyright 2019-2025 ChainSafe Systems +// SPDX-License-Identifier: Apache-2.0, MIT + +use crate::rpc::registry::methods_reg::{MethodRegistry, register_actor_methods}; +use crate::shim::address::Address; +use crate::shim::message::MethodNum; +use anyhow::Result; +use cid::Cid; + +macro_rules! register_datacap_v9 { + ($registry:expr, $code_cid:expr) => {{ + use fil_actor_datacap_state::v9::{DestroyParams, Method, MintParams}; + use fil_actors_shared::frc46_token::token::types::{ + BurnFromParams, BurnParams, DecreaseAllowanceParams, GetAllowanceParams, + IncreaseAllowanceParams, RevokeAllowanceParams, TransferFromParams, TransferParams, + }; + register_actor_methods!( + $registry, + $code_cid, + [ + (Method::Constructor, Address), + (Method::BalanceOf, Address), + (Method::Mint, MintParams), + (Method::Destroy, DestroyParams), + (Method::Transfer, TransferParams), + (Method::TransferFrom, TransferFromParams), + (Method::IncreaseAllowance, IncreaseAllowanceParams), + (Method::DecreaseAllowance, DecreaseAllowanceParams), + (Method::RevokeAllowance, RevokeAllowanceParams), + (Method::Burn, BurnParams), + (Method::BurnFrom, BurnFromParams), + (Method::Allowance, GetAllowanceParams), + ] + ); + + register_actor_methods!( + $registry, + $code_cid, + [ + (Method::Name, empty), + (Method::Symbol, empty), + (Method::TotalSupply, empty), + ] + ); + }}; +} + +macro_rules! register_datacap_v10 { + ($registry:expr, $code_cid:expr) => {{ + use fil_actor_datacap_state::v10::{DestroyParams, Method, MintParams}; + use fil_actors_shared::frc46_token::token::types::{ + BurnFromParams, BurnParams, DecreaseAllowanceParams, GetAllowanceParams, + IncreaseAllowanceParams, RevokeAllowanceParams, TransferFromParams, TransferParams, + }; + register_actor_methods!( + $registry, + $code_cid, + [ + (Method::Constructor, Address), + (Method::BalanceExported, Address), + (Method::MintExported, MintParams), + (Method::DestroyExported, DestroyParams), + (Method::TransferExported, TransferParams), + (Method::TransferFromExported, TransferFromParams), + (Method::IncreaseAllowanceExported, IncreaseAllowanceParams), + (Method::DecreaseAllowanceExported, DecreaseAllowanceParams), + (Method::RevokeAllowanceExported, RevokeAllowanceParams), + (Method::BurnExported, BurnParams), + (Method::BurnFromExported, BurnFromParams), + (Method::AllowanceExported, GetAllowanceParams), + ] + ); + + register_actor_methods!( + $registry, + $code_cid, + [ + (Method::NameExported, empty), + (Method::SymbolExported, empty), + (Method::TotalSupplyExported, empty), + (Method::GranularityExported, empty) + ] + ); + }}; +} + +macro_rules! register_datacap_version { + ($registry:expr, $code_cid:expr, $state_version:path) => {{ + use fil_actors_shared::frc46_token::token::types::{ + BurnFromParams, BurnParams, DecreaseAllowanceParams, GetAllowanceParams, + IncreaseAllowanceParams, RevokeAllowanceParams, TransferFromParams, TransferParams, + }; + use $state_version::{BalanceParams, ConstructorParams, DestroyParams, Method, MintParams}; + register_actor_methods!( + $registry, + $code_cid, + [ + (Method::Constructor, ConstructorParams), + (Method::MintExported, MintParams), + (Method::DestroyExported, DestroyParams), + (Method::BalanceExported, BalanceParams), + (Method::TransferExported, TransferParams), + (Method::TransferFromExported, TransferFromParams), + (Method::IncreaseAllowanceExported, IncreaseAllowanceParams), + (Method::DecreaseAllowanceExported, DecreaseAllowanceParams), + (Method::RevokeAllowanceExported, RevokeAllowanceParams), + (Method::BurnExported, BurnParams), + (Method::BurnFromExported, BurnFromParams), + (Method::AllowanceExported, GetAllowanceParams), + ] + ); + + register_actor_methods!( + $registry, + $code_cid, + [ + (Method::NameExported, empty), + (Method::SymbolExported, empty), + (Method::TotalSupplyExported, empty), + (Method::GranularityExported, empty) + ] + ); + }}; +} + +pub(crate) fn register_datacap_actor_methods( + registry: &mut MethodRegistry, + cid: Cid, + version: u64, +) { + match version { + 9 => register_datacap_v9!(registry, cid), + 10 => register_datacap_v10!(registry, cid), + 11 => register_datacap_version!(registry, cid, fil_actor_datacap_state::v11), + 12 => register_datacap_version!(registry, cid, fil_actor_datacap_state::v12), + 13 => register_datacap_version!(registry, cid, fil_actor_datacap_state::v13), + 14 => register_datacap_version!(registry, cid, fil_actor_datacap_state::v14), + 15 => register_datacap_version!(registry, cid, fil_actor_datacap_state::v15), + 16 => register_datacap_version!(registry, cid, fil_actor_datacap_state::v16), + _ => {} + } +} diff --git a/src/rpc/registry/actors/mod.rs b/src/rpc/registry/actors/mod.rs index 7d995f8e3658..da5178093ad9 100644 --- a/src/rpc/registry/actors/mod.rs +++ b/src/rpc/registry/actors/mod.rs @@ -2,6 +2,7 @@ // SPDX-License-Identifier: Apache-2.0, MIT pub(crate) mod account; +pub(crate) mod datacap; pub(crate) mod evm; pub(crate) mod init; pub(crate) mod miner; diff --git a/src/rpc/registry/methods_reg.rs b/src/rpc/registry/methods_reg.rs index cb9a05bf3e8c..c8fc478514df 100644 --- a/src/rpc/registry/methods_reg.rs +++ b/src/rpc/registry/methods_reg.rs @@ -74,7 +74,7 @@ impl MethodRegistry { fn register_known_methods(&mut self) { use crate::rpc::registry::actors::{ - account, evm, init, miner, multisig, power, reward, system, + account, datacap, evm, init, miner, multisig, power, reward, system, }; for (&cid, &(actor_type, version)) in ACTOR_REGISTRY.iter() { @@ -86,6 +86,9 @@ impl MethodRegistry { BuiltinActor::EVM => evm::register_evm_actor_methods(self, cid, version), BuiltinActor::Init => init::register_actor_methods(self, cid, version), BuiltinActor::System => system::register_actor_methods(self, cid, version), + BuiltinActor::DataCap => { + datacap::register_datacap_actor_methods(self, cid, version) + } BuiltinActor::Power => power::register_actor_methods(self, cid, version), BuiltinActor::Reward => reward::register_actor_methods(self, cid, version), BuiltinActor::Multisig => multisig::register_actor_methods(self, cid, version), @@ -258,6 +261,7 @@ mod test { BuiltinActor::Account, BuiltinActor::Miner, BuiltinActor::EVM, + BuiltinActor::DataCap, ]; for actor_type in supported_actors { diff --git a/src/tool/subcommands/api_cmd/api_compare_tests.rs b/src/tool/subcommands/api_cmd/api_compare_tests.rs index 393b4291ec0c..542abb71e73f 100644 --- a/src/tool/subcommands/api_cmd/api_compare_tests.rs +++ b/src/tool/subcommands/api_cmd/api_compare_tests.rs @@ -1940,7 +1940,7 @@ fn state_decode_params_api_tests(tipset: &Tipset) -> anyhow::Result amount: Default::default(), }; - let tests = vec![ + let mut tests = vec![ RpcTest::identity(StateDecodeParams::request(( MINER_ADDRESS, 1, @@ -2167,6 +2167,176 @@ fn state_decode_params_api_tests(tipset: &Tipset) -> anyhow::Result ))?), ]; + tests.extend(datacap_actor_state_decode_params_tests(tipset)?); + + Ok(tests) +} + +fn datacap_actor_state_decode_params_tests(tipset: &Tipset) -> anyhow::Result> { + let datacap_constructor_params = fil_actor_datacap_state::v16::ConstructorParams { + governor: Address::new_id(3000).into(), + }; + + let datacap_mint_params = fil_actor_datacap_state::v16::MintParams { + to: Address::new_id(3001).into(), + amount: TokenAmount::default().into(), + operators: vec![Address::new_id(3002).into(), Address::new_id(3003).into()], + }; + + let datacap_destroy_params = fil_actor_datacap_state::v16::DestroyParams { + owner: Address::new_id(3004).into(), + amount: TokenAmount::default().into(), + }; + + let datacap_balance_params = fil_actor_datacap_state::v16::BalanceParams { + address: Address::new_id(3005).into(), + }; + + let datacap_transfer_params = fil_actors_shared::frc46_token::token::types::TransferParams { + to: Address::new_id(3006).into(), + amount: TokenAmount::default().into(), + operator_data: fvm_ipld_encoding::RawBytes::new(b"transfer test data".to_vec()), + }; + + let datacap_transfer_from_params = + fil_actors_shared::frc46_token::token::types::TransferFromParams { + from: Address::new_id(3007).into(), + to: Address::new_id(3008).into(), + amount: TokenAmount::default().into(), + operator_data: fvm_ipld_encoding::RawBytes::new(b"transfer_from test data".to_vec()), + }; + + let datacap_increase_allowance_params = + fil_actors_shared::frc46_token::token::types::IncreaseAllowanceParams { + operator: Address::new_id(3009).into(), + increase: TokenAmount::default().into(), + }; + + let datacap_decrease_allowance_params = + fil_actors_shared::frc46_token::token::types::DecreaseAllowanceParams { + operator: Address::new_id(3010).into(), + decrease: TokenAmount::default().into(), + }; + + let datacap_revoke_allowance_params = + fil_actors_shared::frc46_token::token::types::RevokeAllowanceParams { + operator: Address::new_id(3011).into(), + }; + + let datacap_burn_params = fil_actors_shared::frc46_token::token::types::BurnParams { + amount: TokenAmount::default().into(), + }; + + let datacap_burn_from_params = fil_actors_shared::frc46_token::token::types::BurnFromParams { + owner: Address::new_id(3012).into(), + amount: TokenAmount::default().into(), + }; + + let datacap_get_allowance_params = + fil_actors_shared::frc46_token::token::types::GetAllowanceParams { + owner: Address::new_id(3013).into(), + operator: Address::new_id(3014).into(), + }; + + let tests = vec![ + RpcTest::identity(StateDecodeParams::request(( + Address::DATACAP_TOKEN_ACTOR, + fil_actor_datacap_state::v16::Method::Constructor as u64, + to_vec(&datacap_constructor_params)?, + tipset.key().into(), + ))?), + RpcTest::identity(StateDecodeParams::request(( + Address::DATACAP_TOKEN_ACTOR, + fil_actor_datacap_state::v16::Method::MintExported as u64, + to_vec(&datacap_mint_params)?, + tipset.key().into(), + ))?), + RpcTest::identity(StateDecodeParams::request(( + Address::DATACAP_TOKEN_ACTOR, + fil_actor_datacap_state::v16::Method::DestroyExported as u64, + to_vec(&datacap_destroy_params)?, + tipset.key().into(), + ))?), + RpcTest::identity(StateDecodeParams::request(( + Address::DATACAP_TOKEN_ACTOR, + fil_actor_datacap_state::v16::Method::NameExported as u64, + vec![], + tipset.key().into(), + ))?), + RpcTest::identity(StateDecodeParams::request(( + Address::DATACAP_TOKEN_ACTOR, + fil_actor_datacap_state::v16::Method::SymbolExported as u64, + vec![], + tipset.key().into(), + ))?), + RpcTest::identity(StateDecodeParams::request(( + Address::DATACAP_TOKEN_ACTOR, + fil_actor_datacap_state::v16::Method::TotalSupplyExported as u64, + vec![], + tipset.key().into(), + ))?), + RpcTest::identity(StateDecodeParams::request(( + Address::DATACAP_TOKEN_ACTOR, + fil_actor_datacap_state::v16::Method::BalanceExported as u64, + to_vec(&datacap_balance_params)?, + tipset.key().into(), + ))?), + RpcTest::identity(StateDecodeParams::request(( + Address::DATACAP_TOKEN_ACTOR, + fil_actor_datacap_state::v16::Method::GranularityExported as u64, + vec![], + tipset.key().into(), + ))?), + RpcTest::identity(StateDecodeParams::request(( + Address::DATACAP_TOKEN_ACTOR, + fil_actor_datacap_state::v16::Method::TransferExported as u64, + to_vec(&datacap_transfer_params)?, + tipset.key().into(), + ))?), + RpcTest::identity(StateDecodeParams::request(( + Address::DATACAP_TOKEN_ACTOR, + fil_actor_datacap_state::v16::Method::TransferFromExported as u64, + to_vec(&datacap_transfer_from_params)?, + tipset.key().into(), + ))?), + RpcTest::identity(StateDecodeParams::request(( + Address::DATACAP_TOKEN_ACTOR, + fil_actor_datacap_state::v16::Method::IncreaseAllowanceExported as u64, + to_vec(&datacap_increase_allowance_params)?, + tipset.key().into(), + ))?), + RpcTest::identity(StateDecodeParams::request(( + Address::DATACAP_TOKEN_ACTOR, + fil_actor_datacap_state::v16::Method::DecreaseAllowanceExported as u64, + to_vec(&datacap_decrease_allowance_params)?, + tipset.key().into(), + ))?), + RpcTest::identity(StateDecodeParams::request(( + Address::DATACAP_TOKEN_ACTOR, + fil_actor_datacap_state::v16::Method::RevokeAllowanceExported as u64, + to_vec(&datacap_revoke_allowance_params)?, + tipset.key().into(), + ))?), + RpcTest::identity(StateDecodeParams::request(( + Address::DATACAP_TOKEN_ACTOR, + fil_actor_datacap_state::v16::Method::BurnExported as u64, + to_vec(&datacap_burn_params)?, + tipset.key().into(), + ))?), + RpcTest::identity(StateDecodeParams::request(( + Address::DATACAP_TOKEN_ACTOR, + fil_actor_datacap_state::v16::Method::BurnFromExported as u64, + to_vec(&datacap_burn_from_params)?, + tipset.key().into(), + ))?), + RpcTest::identity(StateDecodeParams::request(( + Address::DATACAP_TOKEN_ACTOR, + fil_actor_datacap_state::v16::Method::AllowanceExported as u64, + to_vec(&datacap_get_allowance_params)?, + tipset.key().into(), + ))?), + ]; + Ok(tests) } diff --git a/src/tool/subcommands/api_cmd/test_snapshots.txt b/src/tool/subcommands/api_cmd/test_snapshots.txt index 7999437a279b..1f8120b9b01d 100644 --- a/src/tool/subcommands/api_cmd/test_snapshots.txt +++ b/src/tool/subcommands/api_cmd/test_snapshots.txt @@ -134,6 +134,22 @@ filecoin_statedecodeparams_1749826976836194.rpcsnap.json.zst filecoin_statedecodeparams_1749826976835026.rpcsnap.json.zst filecoin_statedecodeparams_1749826976835457.rpcsnap.json.zst filecoin_statedecodeparams_1750858921185411.rpcsnap.json.zst +filecoin_datacap_allowance_statedecodeparams_1754915081822379.rpcsnap.json.zst +filecoin_datacap_balance_statedecodeparams_1754907971558328.rpcsnap.json.zst +filecoin_datacap_burn_statedecodeparams_1754915081822140.rpcsnap.json.zst +filecoin_datacap_burnfrom_statedecodeparams_1754915081822428.rpcsnap.json.zst +filecoin_datacap_constructor_statedecodeparams_1754907971554508.rpcsnap.json.zst +filecoin_datacap_decreaseallowance_statedecodeparams_1754915081822632.rpcsnap.json.zst +filecoin_datacap_destroy_statedecodeparams_1754907971558376.rpcsnap.json.zst +filecoin_datacap_granularity_statedecodeparams_1754907971554148.rpcsnap.json.zst +filecoin_datacap_increaseallowance_statedecodeparams_1754915081822588.rpcsnap.json.zst +filecoin_datacap_mint_statedecodeparams_1754907971554434.rpcsnap.json.zst +filecoin_datacap_name_statedecodeparams_1754907971558192.rpcsnap.json.zst +filecoin_datacap_revokeallowance_statedecodeparams_1754915081822483.rpcsnap.json.zst +filecoin_datacap_symbol_statedecodeparams_1754907971554570.rpcsnap.json.zst +filecoin_datacap_totalsupply_statedecodeparams_1754907971558270.rpcsnap.json.zst +filecoin_datacap_transfer_statedecodeparams_1754915081822541.rpcsnap.json.zst +filecoin_datacap_transferfrom_statedecodeparams_1754915081822316.rpcsnap.json.zst filecoin_statedecodeparams_1754059748144675.rpcsnap.json.zst filecoin_statedecodeparams_1754059748147929.rpcsnap.json.zst filecoin_statedecodeparams_1754059748148210.rpcsnap.json.zst