Skip to content
This repository has been archived by the owner on Aug 29, 2023. It is now read-only.

Remove the need for our fork in integration tests #161

Merged
merged 5 commits into from
Jan 18, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
360 changes: 93 additions & 267 deletions testing/Cargo.lock

Large diffs are not rendered by default.

21 changes: 9 additions & 12 deletions testing/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
fvm_ipld_blockstore = { version = "0.1.1" }
fvm_shared = { version = "3.0.0-alpha.13" }
fvm = { version = "3.0.0-alpha.12", default-features = false, features = ["m2-native"] }
fvm_ipld_encoding = { version = "0.3.0" }
fvm_integration_tests = { version = "0.1.1-alpha.1", git = "https://github.com/Zondax/ref-fvm", branch = "lola/fixes" }
fvm_ipld_blockstore = { version = "0.1.1", git = "https://github.com/filecoin-project/ref-fvm", tag = "fvm@v3.0.0-alpha.19" }
fvm_shared = { version = "3.0.0-alpha.16", git = "https://github.com/filecoin-project/ref-fvm", tag = "fvm@v3.0.0-alpha.19" }
fvm = { version = "3.0.0-alpha.19", git = "https://github.com/filecoin-project/ref-fvm", tag = "fvm@v3.0.0-alpha.19", default-features = false, features = ["m2-native"] }
fvm_ipld_encoding = { version = "0.3.2", git = "https://github.com/filecoin-project/ref-fvm", tag = "fvm@v3.0.0-alpha.19" }
fvm_integration_tests = { version = "0.1.1-alpha.1", git = "https://github.com/filecoin-project/ref-fvm", tag = "fvm@v3.0.0-alpha.19" }

serde = { version = "1.0", features = ["derive"] }
serde_tuple = "0.5"
Expand All @@ -21,6 +21,7 @@ multihash = { version = "0.16.1", default-features = false }
libipld-core = { version = "0.13.1", features = ["serde-codec"] }
cid = "0.8.6"
rand_core = "0.6.4"
anyhow = "1.0.47"

fil_actors_runtime = { version = "10.0.0-alpha.1", git = "https://github.com/filecoin-project/builtin-actors", tag = "dev/20230114-pre-rc.3", features = ["m2-native"] }
fil_actor_eam = { version = "10.0.0-alpha.1", git = "https://github.com/filecoin-project/builtin-actors", tag = "dev/20230114-pre-rc.3" }
Expand All @@ -31,13 +32,9 @@ fil_actor_miner = { version = "10.0.0-alpha.1", git = "https://github.com/fileco
fil_actor_evm = { version = "10.0.0-alpha.1", git = "https://github.com/filecoin-project/builtin-actors", tag = "dev/20230114-pre-rc.3" }

[patch.crates-io]
fvm_shared = { version = "3.0.0-alpha.14", git = "https://github.com/Zondax/ref-fvm", branch = "lola/fixes" }
fvm_ipld_encoding = { version = "0.3.0", git = "https://github.com/Zondax/ref-fvm", branch = "lola/fixes" }
fvm_ipld_hamt = { version = "0.6.1", git = "https://github.com/Zondax/ref-fvm", branch = "lola/fixes" }
fvm_ipld_amt = { version = "0.5.0", git = "https://github.com/Zondax/ref-fvm", branch = "lola/fixes" }
fvm_ipld_blockstore = { version = "0.1.1", git = "https://github.com/Zondax/ref-fvm", branch = "lola/fixes" }
fvm = { version = "3.0.0-alpha.14", git = "https://github.com/Zondax/ref-fvm", branch = "lola/fixes", default-features = false, features = ["m2-native"] }
fvm_sdk = { version = "3.0.0-alpha.17", git = "https://github.com/Zondax/ref-fvm", branch = "lola/fixes" }
fvm_shared = { version = "3.0.0-alpha.16", git = "https://github.com/filecoin-project/ref-fvm", tag = "fvm@v3.0.0-alpha.19" }
fvm_ipld_encoding = { version = "0.3.2", git = "https://github.com/filecoin-project/ref-fvm", tag = "fvm@v3.0.0-alpha.19" }
fvm_ipld_blockstore = { version = "0.1.1", git = "https://github.com/filecoin-project/ref-fvm", tag = "fvm@v3.0.0-alpha.19" }

fvm_actor_utils = { version = "3.0.0", git = "https://github.com/filecoin-project/filecoin-actor-utils", branch = "feat/fvm-m2" }
frc46_token = { version = "3.0.0", git = "https://github.com/filecoin-project/filecoin-actor-utils", branch = "feat/fvm-m2" }
Expand Down
119 changes: 119 additions & 0 deletions testing/src/helpers.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
use cid::Cid;
use multihash::Code;
use fvm_shared::ActorID;
use fvm::state_tree::{ActorState, StateTree};
use fvm_ipld_blockstore::Blockstore;
use anyhow::{Context, Result};
use fvm_ipld_encoding::CborStore;

pub const DATA_CAP_ACTOR : ActorID = 7;
pub const STORAGE_POWER_ACTOR: ActorID = 4;
pub const STORAGE_MARKET_ACTOR: ActorID = 5;
pub const VERIFIED_REGISTRY_ACTOR : ActorID = 6;


pub fn set_datacap_actor(state_tree: &mut StateTree<impl Blockstore>, datacap_code_cid: Cid,) -> Result<()> {
let datacap_state_cid = state_tree
.store()
.put_cbor(&[(); 0], Code::Blake2b256)
.context("datacap actor")?;

let datacap_actor_state = ActorState {
code: datacap_code_cid,
state: datacap_state_cid,
sequence: 0,
balance: Default::default(),
delegated_address: None,
};

state_tree
.set_actor(DATA_CAP_ACTOR, datacap_actor_state)
.map_err(anyhow::Error::from)
.context("datacap actor".to_owned())
}

pub fn set_storagepower_actor(
state_tree: &mut StateTree<impl Blockstore>,
storagepower_code_cid: Cid,
) -> Result<()> {

let storagepower_state_cid = state_tree
.store()
.put_cbor(&[(); 0], Code::Blake2b256)
.context("storagepower actor".to_owned())?;

let storagepower_actor_state = ActorState {
code: storagepower_code_cid,
state: storagepower_state_cid,
sequence: 0,
balance: Default::default(),
delegated_address: None,
};

state_tree
.set_actor(STORAGE_POWER_ACTOR, storagepower_actor_state)
.map_err(anyhow::Error::from)
.context("storagepower actor".to_owned())
}

pub fn set_storagemarket_actor(state_tree: &mut StateTree<impl Blockstore>, storagemarket_code_cid: Cid,) -> Result<()> {
let storagemarket_state_cid = state_tree
.store()
.put_cbor(&[(); 0], Code::Blake2b256)
.context("storagemarket actor".to_owned())?;

let storagemarket_actor_state = ActorState {
code: storagemarket_code_cid,
state: storagemarket_state_cid,
sequence: 0,
balance: Default::default(),
delegated_address: None,
};

state_tree
.set_actor(STORAGE_MARKET_ACTOR, storagemarket_actor_state)
.map_err(anyhow::Error::from)
.context("storagemarket actor".to_owned())
}

pub fn set_verifiedregistry_actor(state_tree: &mut StateTree<impl Blockstore>, verifiedregistry_code_cid: Cid,) -> Result<()> {
let verifiedregistry_state_cid = state_tree
.store()
.put_cbor(&[(); 0], Code::Blake2b256)
.context("verifiedregistry actor".to_owned())?;

let verifiedregistry_actor_state = ActorState {
code: verifiedregistry_code_cid,
state: verifiedregistry_state_cid,
sequence: 0,
balance: Default::default(),
delegated_address: None,
};

state_tree
.set_actor(VERIFIED_REGISTRY_ACTOR, verifiedregistry_actor_state)
.map_err(anyhow::Error::from)
.context("verifiedregistry actor".to_owned())
}

pub fn set_reward_actor(state_tree: &mut StateTree<impl Blockstore>, reward_code_cid: Cid,) -> Result<()> {
const REWARD_ACTOR_ID: ActorID = 2;

let reward_state_cid = state_tree
.store()
.put_cbor(&[(); 0], Code::Blake2b256)
.context("reward actor".to_owned())?;

let reward_actor_state = ActorState {
code: reward_code_cid,
state: reward_state_cid,
sequence: 0,
balance: Default::default(),
delegated_address: None,
};

state_tree
.set_actor(REWARD_ACTOR_ID, reward_actor_state)
.map_err(anyhow::Error::from)
.context("reward actor".to_owned())
}
1 change: 1 addition & 0 deletions testing/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod helpers;
4 changes: 0 additions & 4 deletions testing/src/main.rs

This file was deleted.

11 changes: 7 additions & 4 deletions testing/tests/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,17 @@ mod tests {
use fvm_ipld_encoding::strict_bytes;
use fvm_ipld_encoding::tuple::*;
use fvm_ipld_encoding::RawBytes;
use fvm_ipld_encoding::{serde_bytes, CborStore};
use fvm_ipld_encoding::serde_bytes;
use fvm_shared::address::Address;
use fvm_shared::econ::TokenAmount;
use fvm_shared::message::Message;
use fvm_shared::state::StateTreeVersion;
use fvm_shared::version::NetworkVersion;
use fvm_ipld_encoding::CborStore;
use multihash::Code;
use std::env;
use std::str::FromStr;
use fvm::machine::Manifest;
use serde::{Deserialize as SerdeDeserialize, Serialize as SerdeSerialize};

const WASM_COMPILED_PATH: &str = "../build/v0.8/tests/AccountApiTest.bin";
Expand Down Expand Up @@ -56,6 +58,9 @@ mod tests {
.expect("Unable to read actor devnet file");
let bundle_root = bundle::import_bundle(&bs, &actors).unwrap();

let (manifest_version, manifest_data_cid): (u32, Cid) = bs.get_cbor(&bundle_root).unwrap().unwrap();
let manifest = Manifest::load(&bs, &manifest_data_cid, manifest_version).unwrap();

let mut tester =
Tester::new(NetworkVersion::V18, StateTreeVersion::V5, bundle_root, bs).unwrap();

Expand All @@ -75,9 +80,7 @@ mod tests {
.unwrap();

let actor_state = ActorState {
// CID of Accounts actor. You get this as output from builtin-actors compiling process
code: Cid::from_str("bafk2bzaceddb65xkjgqgtcsbl2b3istnprim6j3lbf3ywyggxizb6ayzffbqe").unwrap(),
//code: Cid::from_str("bafk2bzaceanfxc6rtvtyjv2wk3ud4cx7qb6iwgif55sq43htuea2gtgfcbd22").unwrap(),
code: *manifest.get_account_code(),
state: cid,
sequence: 0,
balance: TokenAmount::from_whole(1_000_000),
Expand Down
40 changes: 34 additions & 6 deletions testing/tests/datacap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@ mod tests {
use fil_actor_evm::{Method as EvmMethods};
use fvm_ipld_encoding::RawBytes;
use fil_actors_runtime::{EAM_ACTOR_ADDR, DATACAP_TOKEN_ACTOR_ADDR};
use fvm_shared::ActorID;
use fvm_shared::econ::TokenAmount;
use serde::{Deserialize as SerdeDeserialize, Serialize as SerdeSerialize};
use fvm::machine::Manifest;
use cid::Cid;
use fvm_ipld_encoding::CborStore;

use testing::helpers::{set_datacap_actor, DATA_CAP_ACTOR};

const WASM_COMPILED_PATH: &str =
"../build/v0.8/tests/DataCapApiTest.bin";
Expand All @@ -34,24 +38,32 @@ mod tests {
let actors = std::fs::read("./builtin-actors/output/builtin-actors-devnet-wasm.car").expect("Unable to read actor devnet file");
let bundle_root = bundle::import_bundle(&bs, &actors).unwrap();

let (manifest_version, manifest_data_cid): (u32, Cid) = bs.get_cbor(&bundle_root).unwrap().unwrap();
let manifest = Manifest::load(&bs, &manifest_data_cid, manifest_version).unwrap();

let mut tester =
Tester::new(NetworkVersion::V18, StateTreeVersion::V5, bundle_root, bs).unwrap();

// As the governor address for datacap is 200, we create many many address in order to initialize the ID 200 with some tokens
// and make it a valid address to use.
let sender: [Account; 300] = tester.create_accounts().unwrap();

// Set datacap actor
const DATA_CAP_IP: u32 = 12;
let state_tree = tester.state_tree.as_mut().unwrap();
set_datacap_actor(state_tree, *manifest.code_by_id(DATA_CAP_IP).unwrap()).unwrap();

// Create embryo address to deploy the contract on it (assign some FILs to it)
let tmp = hex::decode("DAFEA492D9c6733ae3d56b7Ed1ADB60692c98Bc5").unwrap();
let embryo_eth_address = tmp.as_slice();
let embryo_delegated_address = Address::new_delegated(10, embryo_eth_address).unwrap();
let embryo_actor_id: ActorID = tester.create_placeholder(&embryo_delegated_address,TokenAmount::from_whole(100)).unwrap();
tester.create_placeholder(&embryo_delegated_address,TokenAmount::from_whole(100)).unwrap();


println!("Embryo address delegated type [{}]", embryo_delegated_address);
println!("Embryo address delegated type on hex [{}]",hex::encode(embryo_delegated_address.to_bytes()));
println!("Embryo address ID type on decimal [{}]",embryo_actor_id);
println!("Embryo address ID type on hex [{}]",hex::encode(Address::new_id(embryo_actor_id).to_bytes()));
// println!("Embryo address ID type on decimal [{}]",embryo_actor_id);
// println!("Embryo address ID type on hex [{}]",hex::encode(Address::new_id(embryo_actor_id).to_bytes()));

println!("{}", format!("Sender address id [{}] and bytes [{}]", &sender[0].0, hex::encode(&sender[0].1.to_bytes())));
println!("{}", format!("Sender address id [{}] and bytes [{}]", &sender[1].0, hex::encode(&sender[1].1.to_bytes())));
Expand All @@ -67,6 +79,22 @@ mod tests {

let executor = tester.executor.as_mut().unwrap();

// Try to call "constructor"
println!("Try to call constructor on datacap actor");

let message = Message {
from: Address::new_id(0),
to: Address::new_id(DATA_CAP_ACTOR),
gas_limit: 1000000000,
method_num: 2,
..Message::default()
};

let res = executor
.execute_message(message, ApplyKind::Implicit, 100)
.unwrap();

assert_eq!(res.msg_receipt.exit_code.value(), 0);

// First we deploy the contract in order to actually have an actor running on the embryo address
println!("Calling init actor (EVM)");
Expand All @@ -82,7 +110,7 @@ mod tests {
let constructor_params = CreateExternalParams(evm_bin);

let message = Message {
from: Address::new_id(embryo_actor_id),
from: embryo_delegated_address,
to: EAM_ACTOR_ADDR,
gas_limit: 1000000000,
method_num: 4,
Expand Down Expand Up @@ -418,4 +446,4 @@ mod tests {
assert_eq!(res.msg_receipt.exit_code.value(), 0);
assert_eq!(hex::encode(res.msg_receipt.return_data.bytes()), "58a0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001102f050fe938943acc45f65568000000000000000000000000000000000000000");
}
}
}
39 changes: 31 additions & 8 deletions testing/tests/market.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ mod tests {
use std::env;
use std::str::FromStr;
use serde::{Deserialize as SerdeDeserialize, Serialize as SerdeSerialize};
use fvm::machine::Manifest;

use testing::helpers::{set_storagemarket_actor, STORAGE_MARKET_ACTOR};

const WASM_COMPILED_PATH: &str = "../build/v0.8/tests/MarketApiTest.bin";

Expand Down Expand Up @@ -138,12 +141,21 @@ mod tests {
.expect("Unable to read actor devnet file file");
let bundle_root = bundle::import_bundle(&bs, &actors).unwrap();

let (manifest_version, manifest_data_cid): (u32, Cid) = bs.get_cbor(&bundle_root).unwrap().unwrap();
let manifest = Manifest::load(&bs, &manifest_data_cid, manifest_version).unwrap();

let mut tester =
Tester::new(NetworkVersion::V18, StateTreeVersion::V5, bundle_root, bs).unwrap();

let sender: [Account; 1] = tester.create_accounts().unwrap();
//let client: [Account; 1] = tester.create_accounts().unwrap();

// Set powermarket actor
const STORAGE_MARKET_ID: u32 = 7;
let state_tree = tester.state_tree.as_mut().unwrap();
set_storagemarket_actor(state_tree, *manifest.code_by_id(STORAGE_MARKET_ID).unwrap()).unwrap();


/***********************************************
*
* Instantiate Account Actor with a BLS address
Expand All @@ -162,10 +174,7 @@ mod tests {
.unwrap();

let actor_state = ActorState {
// CID of Accounts actor. You get this as output from builtin-actors compiling process
code: Cid::from_str("bafk2bzaceddb65xkjgqgtcsbl2b3istnprim6j3lbf3ywyggxizb6ayzffbqe")
.unwrap(),
//code: Cid::from_str("bafk2bzaceddmas33nnn2izdexi5xjzuahzezl62aa5ah5bqwzzjceusskr6ty").unwrap(),
code: *manifest.get_account_code(),
state: cid,
sequence: 0,
balance: TokenAmount::from_whole(1_000_000),
Expand All @@ -187,10 +196,7 @@ mod tests {
.unwrap();

let actor_state = ActorState {
// CID of Accounts actor. You get this as output from builtin-actors compiling process
code: Cid::from_str("bafk2bzaceddb65xkjgqgtcsbl2b3istnprim6j3lbf3ywyggxizb6ayzffbqe")
.unwrap(),
//code: Cid::from_str("bafk2bzaceanfxc6rtvtyjv2wk3ud4cx7qb6iwgif55sq43htuea2gtgfcbd22").unwrap(),
code: *manifest.get_account_code(),
state: cid,
sequence: 0,
balance: TokenAmount::from_whole(1_000_000),
Expand All @@ -204,6 +210,23 @@ mod tests {

let executor = tester.executor.as_mut().unwrap();

// Try to call "constructor"
println!("Try to call constructor on storage market actor");

let message = Message {
from: Address::new_id(0),
to: Address::new_id(STORAGE_MARKET_ACTOR),
gas_limit: 1000000000,
method_num: 2,
..Message::default()
};

let res = executor
.execute_message(message, ApplyKind::Implicit, 100)
.unwrap();

assert_eq!(res.msg_receipt.exit_code.value(), 0);

println!("Create Miner actor to be able to publish deal");

let constructor_params = CreateMinerParams {
Expand Down
Loading