-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(power): add CurrentTotalPowerReturn serialization tests (#1580)
plus a minor naming fix
- Loading branch information
Showing
5 changed files
with
52 additions
and
2 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Tests to match with Go github.com/filecoin-project/go-state-types/builtin/*/power | ||
mod serialization { | ||
use fil_actor_power::CurrentTotalPowerReturn; | ||
use fvm_ipld_encoding::ipld_block::IpldBlock; | ||
|
||
use fil_actors_runtime::reward::FilterEstimate; | ||
use fvm_shared::bigint::BigInt; | ||
use fvm_shared::econ::TokenAmount; | ||
use fvm_shared::sector::StoragePower; | ||
|
||
#[test] | ||
fn current_total_power_return() { | ||
let test_cases = vec![ | ||
( | ||
CurrentTotalPowerReturn { | ||
raw_byte_power: Default::default(), | ||
quality_adj_power: Default::default(), | ||
pledge_collateral: Default::default(), | ||
quality_adj_power_smoothed: Default::default(), | ||
ramp_start_epoch: Default::default(), | ||
ramp_duration_epochs: Default::default(), | ||
}, | ||
// [byte[],byte[],byte[],[byte[],byte[]],0,0] | ||
"864040408240400000", | ||
), | ||
( | ||
CurrentTotalPowerReturn { | ||
raw_byte_power: StoragePower::from(1 << 20), | ||
quality_adj_power: StoragePower::from(1 << 21), | ||
pledge_collateral: TokenAmount::from_atto(1 << 22), | ||
quality_adj_power_smoothed: FilterEstimate::new(BigInt::from(1 << 23), BigInt::from(1 << 24)), | ||
ramp_start_epoch: 25, | ||
ramp_duration_epochs: 26, | ||
}, | ||
// FilterEstimate BigInts have a precision shift of 128, so they end up larger than the others. | ||
// [byte[00100000],byte[00200000],byte[00400000],[byte[0080000000000000000000000000000000000000],byte[000100000000000000000000000000000000000000]],25,26] | ||
"8644001000004400200000440040000082540080000000000000000000000000000000000000550001000000000000000000000000000000000000001819181a", | ||
), | ||
]; | ||
|
||
for (params, expected_hex) in test_cases { | ||
let encoded = IpldBlock::serialize_cbor(¶ms).unwrap().unwrap(); | ||
assert_eq!(const_hex::encode(&encoded.data), expected_hex); | ||
let decoded: CurrentTotalPowerReturn = IpldBlock::deserialize(&encoded).unwrap(); | ||
assert_eq!(params, decoded); | ||
} | ||
} | ||
} |