Skip to content

Commit 48eca5e

Browse files
authored
chore(power): add CurrentTotalPowerReturn serialization tests (#1580)
plus a minor naming fix
1 parent 01a05fc commit 48eca5e

File tree

5 files changed

+52
-2
lines changed

5 files changed

+52
-2
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

actors/market/src/ext.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ pub mod power {
155155
pub const CURRENT_TOTAL_POWER_METHOD: u64 = 9;
156156

157157
#[derive(Serialize_tuple, Deserialize_tuple)]
158-
pub struct CurrentTotalPowerReturnParams {
158+
pub struct CurrentTotalPowerReturn {
159159
#[serde(with = "bigint_ser")]
160160
pub raw_byte_power: StoragePower,
161161
#[serde(with = "bigint_ser")]

actors/market/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1775,7 +1775,7 @@ fn request_current_baseline_power(rt: &impl Runtime) -> Result<StoragePower, Act
17751775
fn request_current_network_power(
17761776
rt: &impl Runtime,
17771777
) -> Result<(StoragePower, StoragePower), ActorError> {
1778-
let ret: ext::power::CurrentTotalPowerReturnParams =
1778+
let ret: ext::power::CurrentTotalPowerReturn =
17791779
deserialize_block(extract_send_result(rt.send_simple(
17801780
&STORAGE_POWER_ACTOR_ADDR,
17811781
ext::power::CURRENT_TOTAL_POWER_METHOD,

actors/power/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ fvm_ipld_encoding = { workspace = true }
3333
[dev-dependencies]
3434
fil_actors_runtime = { workspace = true, features = ["test_utils", "sector-default"] }
3535
fil_actor_reward = { workspace = true }
36+
const-hex = { workspace = true }
3637

3738
[features]
3839
fil-actor = ["fil_actors_runtime/fil-actor"]

actors/power/tests/types_test.rs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Tests to match with Go github.com/filecoin-project/go-state-types/builtin/*/power
2+
mod serialization {
3+
use fil_actor_power::CurrentTotalPowerReturn;
4+
use fvm_ipld_encoding::ipld_block::IpldBlock;
5+
6+
use fil_actors_runtime::reward::FilterEstimate;
7+
use fvm_shared::bigint::BigInt;
8+
use fvm_shared::econ::TokenAmount;
9+
use fvm_shared::sector::StoragePower;
10+
11+
#[test]
12+
fn current_total_power_return() {
13+
let test_cases = vec![
14+
(
15+
CurrentTotalPowerReturn {
16+
raw_byte_power: Default::default(),
17+
quality_adj_power: Default::default(),
18+
pledge_collateral: Default::default(),
19+
quality_adj_power_smoothed: Default::default(),
20+
ramp_start_epoch: Default::default(),
21+
ramp_duration_epochs: Default::default(),
22+
},
23+
// [byte[],byte[],byte[],[byte[],byte[]],0,0]
24+
"864040408240400000",
25+
),
26+
(
27+
CurrentTotalPowerReturn {
28+
raw_byte_power: StoragePower::from(1 << 20),
29+
quality_adj_power: StoragePower::from(1 << 21),
30+
pledge_collateral: TokenAmount::from_atto(1 << 22),
31+
quality_adj_power_smoothed: FilterEstimate::new(BigInt::from(1 << 23), BigInt::from(1 << 24)),
32+
ramp_start_epoch: 25,
33+
ramp_duration_epochs: 26,
34+
},
35+
// FilterEstimate BigInts have a precision shift of 128, so they end up larger than the others.
36+
// [byte[00100000],byte[00200000],byte[00400000],[byte[0080000000000000000000000000000000000000],byte[000100000000000000000000000000000000000000]],25,26]
37+
"8644001000004400200000440040000082540080000000000000000000000000000000000000550001000000000000000000000000000000000000001819181a",
38+
),
39+
];
40+
41+
for (params, expected_hex) in test_cases {
42+
let encoded = IpldBlock::serialize_cbor(&params).unwrap().unwrap();
43+
assert_eq!(const_hex::encode(&encoded.data), expected_hex);
44+
let decoded: CurrentTotalPowerReturn = IpldBlock::deserialize(&encoded).unwrap();
45+
assert_eq!(params, decoded);
46+
}
47+
}
48+
}

0 commit comments

Comments
 (0)