Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
105 changes: 57 additions & 48 deletions src/lotus_json/actors/params/cron_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use pastey::paste;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

#[derive(Debug, Serialize, Deserialize, JsonSchema, Clone)]
#[derive(Debug, Serialize, Deserialize, JsonSchema, Clone, PartialEq)]
#[serde(rename_all = "PascalCase")]
pub struct CronConstructorParamsLotusJson {
#[schemars(with = "LotusJson<Vec<Entry>>")]
Expand All @@ -19,58 +19,67 @@ macro_rules! impl_lotus_json_for_cron_constructor_params {
($($version:literal),+) => {
$(
paste! {
impl HasLotusJson for fil_actor_cron_state::[<v $version>]::ConstructorParams {
type LotusJson = CronConstructorParamsLotusJson;

#[cfg(test)]
fn snapshots() -> Vec<(serde_json::Value, Self)> {
use crate::shim::address::Address;
vec![(
json!({
"Entries": [
{
"Receiver": "f01",
"MethodNum": 2
},
{
"Receiver": "f02",
"MethodNum": 3
}
]
}),
Self {
entries: vec![
fil_actor_cron_state::[<v $version>]::Entry {
receiver: Address::new_id(1).into(),
method_num: 2,
},
fil_actor_cron_state::[<v $version>]::Entry {
receiver: Address::new_id(2).into(),
method_num: 3,
},
],
},
)]
mod [<impl_lotus_json_for_cron_constructor_params_ $version>] {
use super::*;
type T = fil_actor_cron_state::[<v $version>]::ConstructorParams;
#[test]
fn snapshots() {
crate::lotus_json::assert_all_snapshots::<T>();
}

fn into_lotus_json(self) -> Self::LotusJson {
Self::LotusJson {
entries: self.entries.into_iter().map(Entry::[<V $version>]).collect(),
impl HasLotusJson for T {
type LotusJson = CronConstructorParamsLotusJson;

#[cfg(test)]
fn snapshots() -> Vec<(serde_json::Value, Self)> {
use crate::shim::address::Address;
vec![(
json!({
"Entries": [
{
"Receiver": "f01",
"MethodNum": 2
},
{
"Receiver": "f02",
"MethodNum": 3
}
]
}),
Self {
entries: vec![
fil_actor_cron_state::[<v $version>]::Entry {
receiver: Address::new_id(1).into(),
method_num: 2,
},
fil_actor_cron_state::[<v $version>]::Entry {
receiver: Address::new_id(2).into(),
method_num: 3,
},
],
},
)]
}

fn into_lotus_json(self) -> Self::LotusJson {
Self::LotusJson {
entries: self.entries.into_iter().map(Entry::[<V $version>]).collect(),
}
}
}

fn from_lotus_json(json: Self::LotusJson) -> Self {
Self {
entries: json.entries.into_iter().map(|entry| match entry {
Entry::[<V $version>](e) => e,
_ => {
let lotus_entry = entry.into_lotus_json();
fil_actor_cron_state::[<v $version>]::Entry {
receiver: lotus_entry.receiver.into(),
method_num: lotus_entry.method_num,
fn from_lotus_json(json: Self::LotusJson) -> Self {
Self {
entries: json.entries.into_iter().map(|entry| match entry {
Entry::[<V $version>](e) => e,
_ => {
let lotus_entry = entry.into_lotus_json();
fil_actor_cron_state::[<v $version>]::Entry {
receiver: lotus_entry.receiver.into(),
method_num: lotus_entry.method_num,
}
}
}
}).collect(),
}).collect(),
}
}
}
}
Expand Down
163 changes: 95 additions & 68 deletions src/lotus_json/actors/params/eam_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,36 +20,45 @@ macro_rules! impl_eam_create_params {
($($version:literal),+) => {
$(
paste! {
impl HasLotusJson for fil_actor_eam_state::[<v $version>]::CreateParams {
type LotusJson = EAMCreateParamsLotusJson;

#[cfg(test)]
fn snapshots() -> Vec<(serde_json::Value, Self)> {
vec![
(
json!({
"Initcode": "ESIzRFU=",
"Nonce": 42
}),
Self {
initcode: hex::decode("1122334455").unwrap(),
nonce: 42,
},
),
]
mod [<impl_eam_create_params_ $version>] {
use super::*;
type T = fil_actor_eam_state::[<v $version>]::CreateParams;
#[test]
fn snapshots() {
crate::lotus_json::assert_all_snapshots::<T>();
}

fn into_lotus_json(self) -> Self::LotusJson {
EAMCreateParamsLotusJson {
initcode: RawBytes::new(self.initcode),
nonce: self.nonce,
impl HasLotusJson for T {
type LotusJson = EAMCreateParamsLotusJson;

#[cfg(test)]
fn snapshots() -> Vec<(serde_json::Value, Self)> {
vec![
(
json!({
"Initcode": "ESIzRFU=",
"Nonce": 42
}),
Self {
initcode: hex::decode("1122334455").unwrap(),
nonce: 42,
},
),
]
}

fn into_lotus_json(self) -> Self::LotusJson {
EAMCreateParamsLotusJson {
initcode: RawBytes::new(self.initcode),
nonce: self.nonce,
}
}
}

fn from_lotus_json(lotus_json: Self::LotusJson) -> Self {
Self {
initcode: lotus_json.initcode.into(),
nonce: lotus_json.nonce,
fn from_lotus_json(lotus_json: Self::LotusJson) -> Self {
Self {
initcode: lotus_json.initcode.into(),
nonce: lotus_json.nonce,
}
}
}
}
Expand All @@ -71,36 +80,45 @@ macro_rules! impl_eam_create2_params {
($($version:literal),+) => {
$(
paste! {
impl HasLotusJson for fil_actor_eam_state::[<v $version>]::Create2Params {
type LotusJson = EAMCreate2ParamsLotusJson;

#[cfg(test)]
fn snapshots() -> Vec<(serde_json::Value, Self)> {
vec![
(
json!({
"Initcode": "ESIzRFU=",
"Salt": [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
}),
Self {
initcode: hex::decode("1122334455").unwrap(),
salt: [0; 32],
},
),
]
mod [<impl_eam_create2_params_ $version>] {
use super::*;
type T = fil_actor_eam_state::[<v $version>]::Create2Params;
#[test]
fn snapshots() {
crate::lotus_json::assert_all_snapshots::<T>();
}

fn into_lotus_json(self) -> Self::LotusJson {
EAMCreate2ParamsLotusJson {
initcode: self.initcode,
salt: self.salt,
impl HasLotusJson for T {
type LotusJson = EAMCreate2ParamsLotusJson;

#[cfg(test)]
fn snapshots() -> Vec<(serde_json::Value, Self)> {
vec![
(
json!({
"Initcode": "ESIzRFU=",
"Salt": [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
}),
Self {
initcode: hex::decode("1122334455").unwrap(),
salt: [0; 32],
},
),
]
}

fn into_lotus_json(self) -> Self::LotusJson {
EAMCreate2ParamsLotusJson {
initcode: self.initcode,
salt: self.salt,
}
}
}

fn from_lotus_json(lotus_json: Self::LotusJson) -> Self {
Self {
initcode: lotus_json.initcode,
salt: lotus_json.salt,
fn from_lotus_json(lotus_json: Self::LotusJson) -> Self {
Self {
initcode: lotus_json.initcode,
salt: lotus_json.salt,
}
}
}
}
Expand All @@ -121,25 +139,34 @@ macro_rules! impl_eam_create_external_params {
($($version:literal),+) => {
$(
paste! {
impl HasLotusJson for fil_actor_eam_state::[<v $version>]::CreateExternalParams {
type LotusJson = EAMCreateExternalParamsLotusJson;

#[cfg(test)]
fn snapshots() -> Vec<(serde_json::Value, Self)> {
vec![
(
json!("ESIzRFU="),
Self(hex::decode("1122334455").unwrap()),
),
]
mod [<impl_eam_create_external_params_ $version>] {
use super::*;
type T = fil_actor_eam_state::[<v $version>]::CreateExternalParams;
#[test]
fn snapshots() {
crate::lotus_json::assert_all_snapshots::<T>();
}

fn into_lotus_json(self) -> Self::LotusJson {
EAMCreateExternalParamsLotusJson(RawBytes::new(self.0))
}
impl HasLotusJson for T {
type LotusJson = EAMCreateExternalParamsLotusJson;

#[cfg(test)]
fn snapshots() -> Vec<(serde_json::Value, Self)> {
vec![
(
json!("ESIzRFU="),
Self(hex::decode("1122334455").unwrap()),
),
]
}

fn from_lotus_json(lotus_json: Self::LotusJson) -> Self {
Self(lotus_json.0.into())
fn into_lotus_json(self) -> Self::LotusJson {
EAMCreateExternalParamsLotusJson(RawBytes::new(self.0))
}

fn from_lotus_json(lotus_json: Self::LotusJson) -> Self {
Self(lotus_json.0.into())
}
}
}
}
Expand Down
Loading
Loading