Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Init test porting #394

Merged
merged 22 commits into from
May 8, 2020
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
83ebe74
Adding skeleton code and some functionality
RajarupanSampanthan Apr 22, 2020
612d126
Changing from private to public.
RajarupanSampanthan Apr 23, 2020
291d545
Added the construct and verification function. Tried to make a test f…
RajarupanSampanthan Apr 24, 2020
2c67947
Some more changes.
RajarupanSampanthan Apr 25, 2020
3c09aa4
Some more changes.
RajarupanSampanthan Apr 25, 2020
450ff50
More test changes
RajarupanSampanthan Apr 25, 2020
2cb23be
4 Tests are still failing
RajarupanSampanthan Apr 28, 2020
a66432d
Fix in_transaction mock runtime field
austinabell Apr 28, 2020
9d2178e
Clean up test file
austinabell Apr 28, 2020
f421bd7
Fix storage miner test
austinabell Apr 28, 2020
c3034d5
Fix payment channel tests
austinabell Apr 28, 2020
5378d43
Fix abort test
austinabell Apr 28, 2020
c878465
Init actor tests are passing
RajarupanSampanthan May 4, 2020
9beb783
FIxed Cron actor test error
RajarupanSampanthan May 5, 2020
9a8806d
Merge branch 'master' into init_test_porting
RajarupanSampanthan May 5, 2020
8e4f52d
Addding some changes suggets by AUstin
RajarupanSampanthan May 6, 2020
fd7280c
FOrgot to add lint chnages
RajarupanSampanthan May 6, 2020
f6a74bd
Adding minor code changes and removed caller and reciever members to …
RajarupanSampanthan May 7, 2020
130153d
Adding some final touches
RajarupanSampanthan May 7, 2020
dfcd35e
Adding more cosmetic changes
RajarupanSampanthan May 7, 2020
12d8192
Adding minor changes
RajarupanSampanthan May 7, 2020
b3c9d33
Merge branch 'master' into init_test_porting
RajarupanSampanthan May 8, 2020
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
4 changes: 2 additions & 2 deletions vm/actor/src/builtin/cron/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ impl Actor {

let st: State = rt.state()?;
for entry in st.entries {
rt.send(
let _v = rt.send(
&entry.receiver,
entry.method_num,
&Serialized::default(),
&TokenAmount::from(0u8),
)?;
);
Comment on lines +77 to +82
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

revert back to what it was, this is ignoring that error

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I was confused by this too. In the spec-actors repo they ignore any error or return values. I wasn't sure about why they did it but I just mimicked what they had. Are they doing something wrong?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ohh, you're right. Interesting why that error is ignored, but I guess it makes sense. Possibly add a comment here to indicate that this is intentional?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would do let _ = instead of let _v = but yeah, so weird they dont use the error...

}
Ok(())
}
Expand Down
1 change: 1 addition & 0 deletions vm/actor/src/builtin/init/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ impl Actor {
rt.create_actor(&params.code_cid, &id_address)?;

// Invoke constructor

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit

Suggested change

rt.send(
&id_address,
METHOD_CONSTRUCTOR,
Expand Down
3 changes: 2 additions & 1 deletion vm/actor/tests/account_actor_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use actor::{account::State, ACCOUNT_ACTOR_CODE_ID, SYSTEM_ACTOR_ADDR, SYSTEM_ACT
use address::Address;
use common::*;
use db::MemoryDB;
use message::UnsignedMessage;
use vm::{ExitCode, Serialized};

macro_rules! account_tests {
Expand All @@ -19,7 +20,7 @@ macro_rules! account_tests {
let bs = MemoryDB::default();
let receiver = Address::new_id(100);
let mut rt = MockRuntime::new(&bs, receiver.clone());
rt.caller = *SYSTEM_ACTOR_ADDR;
rt.message = UnsignedMessage::builder().to(receiver.clone()).from(SYSTEM_ACTOR_ADDR.clone()).build().unwrap();
rt.caller_type = SYSTEM_ACTOR_CODE_ID.clone();
rt.expect_validate_caller_addr(&[*SYSTEM_ACTOR_ADDR]);

Expand Down
47 changes: 37 additions & 10 deletions vm/actor/tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,21 @@ use clock::ChainEpoch;
use crypto::DomainSeparationTag;
use encoding::{de::DeserializeOwned, Cbor};
use ipld_blockstore::BlockStore;
use message::UnsignedMessage;
use message::{Message, UnsignedMessage};
use runtime::{ActorCode, Runtime, Syscalls};
use std::cell::{Cell, RefCell};
use std::collections::{HashMap, VecDeque};
use vm::{ActorError, ExitCode, MethodNum, Randomness, Serialized, TokenAmount};

pub struct MockRuntime<'a, BS: BlockStore> {
pub epoch: ChainEpoch,
pub receiver: Address,
pub caller: Address,
pub caller_type: Cid,
pub miner: Address,
pub value_received: TokenAmount,
pub id_addresses: HashMap<Address, Address>,
pub actor_code_cids: HashMap<Address, Cid>,
pub new_actor_addr: Option<Address>,
pub message: UnsignedMessage,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So about this, since all you need from this is caller, receiver, value_received and is currently storing that data twice (see above) you either need to remove the three fields above and handle those through the message type or update the runtime interface to not be hard coded UnsignedMessage and instead be an interface which returns those fields.

I think it makes sense to just do the former and add a TODO since that change is a bit more involved (cc: @ec2)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah it makes sense. I was thinking we need to make a Message trait. In this case, I think this is the only way to make it work. The message() function returns a reference to a UnsignedMessage, so its not like we can construct the message using the caller, receiever, value_received inside of that function

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to be clear about that, it is a bit awkward to use, but only for the mock runtime. I'm not convinced that making it generic is objectively better, can just handle those things through an unsigned message in the mock rt since it's only used for testing, but maybe yeah a bit clunky still.

Having the message trait makes the mockrt impl more straightforward, at the cost of the actual runtime being unnecessarily complicated

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. I was thinking about it from the perspective of the MockRt. I dont expect us to be building any more runtimes anyways.


// TODO: syscalls: syscaller

Expand Down Expand Up @@ -69,8 +68,6 @@ impl<'a, BS: BlockStore> MockRuntime<'a, BS> {
pub fn new(bs: &'a BS, receiver: Address) -> Self {
austinabell marked this conversation as resolved.
Show resolved Hide resolved
Self {
epoch: 0,
receiver: receiver,
caller: Address::default(),
caller_type: Cid::default(),

miner: Address::default(),
Expand All @@ -80,6 +77,12 @@ impl<'a, BS: BlockStore> MockRuntime<'a, BS> {
actor_code_cids: HashMap::new(),
new_actor_addr: None,

message: UnsignedMessage::builder()
.to(receiver.clone())
.from(Address::default())
.build()
.unwrap(),

state: None,
balance: 0u8.into(),

Expand Down Expand Up @@ -231,12 +234,29 @@ impl<'a, BS: BlockStore> MockRuntime<'a, BS> {
exit_code,
})
}

#[allow(dead_code)]
pub fn expect_create_actor(&mut self, code_id: Cid, address: Address) {
let a = ExpectCreateActor { code_id, address };
self.expect_create_actor = Some(a);
}

#[allow(dead_code)]
pub fn set_caller(&mut self, code_id: Cid, address: Address) {
self.message = UnsignedMessage::builder()
.to(self.message.to().clone())
.from(address.clone())
.build()
.unwrap();
austinabell marked this conversation as resolved.
Show resolved Hide resolved
self.caller_type = code_id.clone();
self.actor_code_cids.insert(address, code_id);
}
}

impl<BS: BlockStore> Runtime<BS> for MockRuntime<'_, BS> {
fn message(&self) -> &UnsignedMessage {
self.require_in_call();
todo!();
&self.message
}

fn curr_epoch(&self) -> ChainEpoch {
Expand Down Expand Up @@ -275,7 +295,7 @@ impl<BS: BlockStore> Runtime<BS> for MockRuntime<'_, BS> {
);

for expected in &addrs {
if &self.caller == expected {
if self.message().from() == expected {
*self.expect_validate_caller_addr.borrow_mut() = None;
return Ok(());
}
Expand All @@ -285,7 +305,8 @@ impl<BS: BlockStore> Runtime<BS> for MockRuntime<'_, BS> {
ExitCode::ErrForbidden,
format!(
"caller address {:?} forbidden, allowed: {:?}",
self.caller, &addrs
self.message().from(),
&addrs
),
));
}
Expand Down Expand Up @@ -385,6 +406,7 @@ impl<BS: BlockStore> Runtime<BS> for MockRuntime<'_, BS> {
self.in_transaction = true;
let ret = f(&mut read_only, &self);
self.state = Some(self.put(&read_only).unwrap());
self.in_transaction = false;
Ok(ret)
}

Expand Down Expand Up @@ -418,7 +440,7 @@ impl<BS: BlockStore> Runtime<BS> for MockRuntime<'_, BS> {

let expected_msg = self.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, &self.expect_sends[0]);
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, self.expect_sends[0]);

if value > &self.balance {
return Err(self.abort(
Expand All @@ -431,7 +453,12 @@ impl<BS: BlockStore> Runtime<BS> for MockRuntime<'_, BS> {
}
self.balance -= value;

return Ok(expected_msg.send_return);
match expected_msg.exit_code {
ExitCode::Ok => return Ok(expected_msg.send_return),
x => {
return Err(ActorError::new(x, "Expected message Fail".to_string()));
}
}
}

fn abort<S: AsRef<str>>(&self, exit_code: ExitCode, msg: S) -> ActorError {
Expand Down
10 changes: 7 additions & 3 deletions vm/actor/tests/cron_actor_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,17 @@ use address::Address;
use common::*;
use db::MemoryDB;
use ipld_blockstore::BlockStore;
use vm::ExitCode;
use vm::Serialized;
use message::UnsignedMessage;
use vm::{ExitCode, Serialized};

fn construct_runtime<BS: BlockStore>(bs: &BS) -> MockRuntime<'_, BS> {
let receiver = Address::new_id(100);
let mut rt = MockRuntime::new(bs, receiver);
rt.caller = *SYSTEM_ACTOR_ADDR;
rt.message = UnsignedMessage::builder()
.from(SYSTEM_ACTOR_ADDR.clone())
.to(receiver.clone())
.build()
.unwrap();
rt.caller_type = SYSTEM_ACTOR_CODE_ID.clone();
return rt;
}
Expand Down
Loading