Skip to content

Commit

Permalink
Merge branch 'master' into feat/fip-0084
Browse files Browse the repository at this point in the history
  • Loading branch information
ZenGround0 authored May 29, 2024
2 parents 9c12a07 + 84d40fc commit 4663904
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 2 deletions.
44 changes: 42 additions & 2 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ pretty_env_logger = "0.4.0"
serde_repr = "0.1.8"
unsigned-varint = "0.7.1"
rand_chacha = "0.3.1"
const-hex = "1.11.3"

# Crypto
libsecp256k1 = { version = "0.7.1", default-features = false }
Expand Down
14 changes: 14 additions & 0 deletions actors/miner/tests/prove_commit2_failures_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,20 @@ fn reject_mismatched_proof_len() {
h.check_state(&rt);
}

#[test]
fn reject_too_soon() {
let (h, rt, activations) = setup_precommits(&[(0, 0, 0)]);
let epoch = *rt.epoch.borrow();
rt.set_epoch(epoch - 2);
let cfg = ProveCommitSectors2Config::default();
expect_abort_contains_message(
ExitCode::USR_FORBIDDEN,
"too early to prove sector",
h.prove_commit_sectors2(&rt, &activations, false, false, false, cfg),
);
h.check_state(&rt);
}

#[test]
fn reject_expired_precommit() {
let (h, rt, activations) = setup_precommits(&[(0, 0, 0)]);
Expand Down
1 change: 1 addition & 0 deletions actors/verifreg/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ log = { workspace = true }
num-derive = { workspace = true }
num-traits = { workspace = true }
serde = { workspace = true }
const-hex = { workspace = true }

[dev-dependencies]
fil_actors_runtime = { workspace = true, features = ["test_utils", "sector-default"] }
Expand Down
68 changes: 68 additions & 0 deletions actors/verifreg/tests/verifreg_actor_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1567,3 +1567,71 @@ mod datacap {
}
}
}

// Tests to match with Go github.com/filecoin-project/go-state-types/builtin/*/verifreg
mod serialization {
use std::str::FromStr;

use cid::Cid;
use fil_actor_verifreg::{AllocationClaim, ClaimAllocationsParams, SectorAllocationClaims};
use fvm_ipld_encoding::ipld_block::IpldBlock;
use fvm_shared::piece::PaddedPieceSize;

#[test]
fn claim_allocations_params() {
let test_cases = vec![
(
ClaimAllocationsParams { sectors: vec![], all_or_nothing: false },
// [[],false]
"8280f4",
),
(
ClaimAllocationsParams {
sectors: vec![SectorAllocationClaims {
sector: 101,
expiry: 202,
claims: vec![],
}],
all_or_nothing: true,
},
// [[[101,202,[]]],true]
"828183186518ca80f5",
),
(
ClaimAllocationsParams {
sectors: vec![
SectorAllocationClaims {
sector: 101,
expiry: 202,
claims: vec![
AllocationClaim {
client: 303,
allocation_id: 404,
data: Cid::from_str("baga6ea4seaaqa").unwrap(),
size: PaddedPieceSize(505),
},
AllocationClaim {
client: 606,
allocation_id: 707,
data: Cid::from_str("baga6ea4seaaqc").unwrap(),
size: PaddedPieceSize(808),
},
],
},
SectorAllocationClaims { sector: 303, expiry: 404, claims: vec![] },
],
all_or_nothing: true,
},
// [[[101,202,[[303,404,baga6ea4seaaqa,505],[606,707,baga6ea4seaaqc,808]]],[303,404,[]]],true]
"828283186518ca828419012f190194d82a49000181e203922001001901f98419025e1902c3d82a49000181e203922001011903288319012f19019480f5",
),
];

for (params, expected_hex) in test_cases {
let encoded = IpldBlock::serialize_cbor(&params).unwrap().unwrap();
assert_eq!(const_hex::encode(&encoded.data), expected_hex);
let decoded: ClaimAllocationsParams = IpldBlock::deserialize(&encoded).unwrap();
assert_eq!(params, decoded);
}
}
}

0 comments on commit 4663904

Please sign in to comment.