Skip to content

Commit

Permalink
Fix bug in paych actor and implement last tests in the UpdateChannelS…
Browse files Browse the repository at this point in the history
…tateExtra category. (#220)
  • Loading branch information
lemmih authored May 3, 2022
1 parent 231a868 commit 716f054
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 21 deletions.
9 changes: 2 additions & 7 deletions actors/paych/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,8 @@ impl Actor {
}

if let Some(extra) = &sv.extra {
rt.send(
extra.actor,
extra.method,
RawBytes::serialize(&extra.data)?,
TokenAmount::from(0u8),
)
.map_err(|e| e.wrap("spend voucher verification failed"))?;
rt.send(extra.actor, extra.method, extra.data.clone(), TokenAmount::from(0u8))
.map_err(|e| e.wrap("spend voucher verification failed"))?;
}

rt.transaction(|st: &mut State, rt| {
Expand Down
15 changes: 4 additions & 11 deletions actors/paych/tests/paych_actor_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ use cid::Cid;
use derive_builder::Builder;
use fil_actor_paych::{
Actor as PaychActor, ConstructorParams, LaneState, Merge, Method, ModVerifyParams,
PaymentVerifyParams, SignedVoucher, State as PState, UpdateChannelStateParams, MAX_LANE,
SETTLE_DELAY,
SignedVoucher, State as PState, UpdateChannelStateParams, MAX_LANE, SETTLE_DELAY,
};
use fil_actors_runtime::test_utils::*;
use fil_actors_runtime::INIT_ACTOR_ADDR;
Expand Down Expand Up @@ -750,38 +749,33 @@ mod update_channel_state_extra {
let (mut rt, mut sv) = require_create_channel_with_lanes(1);
let state: PState = rt.get_state();
let other_addr = Address::new_id(OTHER_ADDR);
let fake_params = [1, 2, 3, 4];
let fake_params = RawBytes::new(vec![1, 2, 3, 4]);
rt.set_caller(*ACCOUNT_ACTOR_CODE_ID, state.from);
rt.expect_validate_caller_addr(vec![state.from, state.to]);

sv.extra = Some(ModVerifyParams {
actor: other_addr,
method: Method::UpdateChannelState as u64,
data: RawBytes::serialize(fake_params).unwrap(),
data: fake_params.clone(),
});
rt.expect_verify_signature(ExpectedVerifySig {
sig: sv.clone().signature.unwrap(),
signer: state.to,
plaintext: sv.signing_bytes().unwrap(),
result: Ok(()),
});
let exp_send_params = PaymentVerifyParams {
extra: RawBytes::serialize(fake_params.to_vec()).unwrap(),
proof: vec![],
};

rt.expect_send(
other_addr,
Method::UpdateChannelState as u64,
RawBytes::serialize(exp_send_params).unwrap(),
fake_params,
TokenAmount::from(0u8),
RawBytes::default(),
exit_code,
);
(rt, sv)
}
#[test]
#[ignore = "old functionality -- test framework needs to be updated"]
fn extra_call_succeed() {
let (mut rt, sv) = construct_runtime(ExitCode::OK);
call(
Expand All @@ -793,7 +787,6 @@ mod update_channel_state_extra {
}

#[test]
#[ignore = "old functionality -- test framework needs to be updated"]
fn extra_call_fail() {
let (mut rt, sv) = construct_runtime(ExitCode::USR_UNSPECIFIED);
expect_abort(
Expand Down
20 changes: 17 additions & 3 deletions actors/runtime/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -879,9 +879,23 @@ impl Runtime<MemoryBlockstore> for MockRuntime {

let expected_msg = self.expectations.borrow_mut().expect_sends.pop_front().unwrap();

assert!(expected_msg.to == to && expected_msg.method == method && expected_msg.params == params && expected_msg.value == value,
"expectedMessage being sent does not match expectation.\nMessage -\t to: {:?} method: {:?} value: {:?} params: {:?}\nExpected -\t {:?}",
to, method, value, params, expected_msg);
assert!(
expected_msg.to == to
&& expected_msg.method == method
&& expected_msg.params == params
&& expected_msg.value == value,
"expectedMessage being sent does not match expectation.\n\
Message - to: {:?}, method: {:?}, value: {:?}, params: {:?}\n\
Expected - to: {:?}, method: {:?}, value: {:?}, params: {:?}",
to,
method,
value,
params,
expected_msg.to,
expected_msg.method,
expected_msg.value,
expected_msg.params,
);

{
let mut balance = self.balance.borrow_mut();
Expand Down

0 comments on commit 716f054

Please sign in to comment.