forked from filecoin-project/builtin-actors
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Automatically approve built-in market as operator for all minted data…
…cap (filecoin-project#611)
- Loading branch information
Showing
8 changed files
with
224 additions
and
35 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,27 +1,113 @@ | ||
use fvm_shared::address::Address; | ||
use lazy_static::lazy_static; | ||
|
||
use fil_actors_runtime::test_utils::MockRuntime; | ||
use fil_actors_runtime::VERIFIED_REGISTRY_ACTOR_ADDR; | ||
|
||
use crate::harness::{new_runtime, Harness}; | ||
|
||
mod harness; | ||
|
||
lazy_static! { | ||
static ref VERIFIER: Address = Address::new_id(201); | ||
static ref VERIFIER2: Address = Address::new_id(202); | ||
static ref CLIENT: Address = Address::new_id(301); | ||
static ref CLIENT2: Address = Address::new_id(302); | ||
static ref CLIENT3: Address = Address::new_id(303); | ||
static ref CLIENT4: Address = Address::new_id(304); | ||
static ref ALICE: Address = Address::new_id(101); | ||
static ref BOB: Address = Address::new_id(102); | ||
static ref CARLA: Address = Address::new_id(103); | ||
} | ||
|
||
mod construction { | ||
use harness::*; | ||
|
||
use crate::*; | ||
use fil_actors_runtime::VERIFIED_REGISTRY_ACTOR_ADDR; | ||
|
||
#[test] | ||
fn construct_with_verified() { | ||
let mut rt = new_runtime(); | ||
let h = Harness { registry: *REGISTRY_ADDR }; | ||
let h = Harness { registry: *VERIFIED_REGISTRY_ACTOR_ADDR }; | ||
h.construct_and_verify(&mut rt, &h.registry); | ||
h.check_state(&rt); | ||
} | ||
} | ||
|
||
mod mint { | ||
use fvm_shared::econ::TokenAmount; | ||
use fvm_shared::error::ExitCode; | ||
use fvm_shared::MethodNum; | ||
|
||
use fil_actor_datacap::{Actor, Method, MintParams}; | ||
use fil_actors_runtime::cbor::serialize; | ||
use fil_actors_runtime::test_utils::{expect_abort_contains_message, MARKET_ACTOR_CODE_ID}; | ||
use fil_actors_runtime::{STORAGE_MARKET_ACTOR_ADDR, VERIFIED_REGISTRY_ACTOR_ADDR}; | ||
|
||
use crate::*; | ||
|
||
#[test] | ||
fn mint_balances() { | ||
// The token library has far more extensive tests, this is just a sanity check. | ||
let (mut rt, h) = make_harness(); | ||
|
||
let amt = TokenAmount::from_whole(1); | ||
h.mint(&mut rt, &*ALICE, &amt, vec![]).unwrap(); | ||
assert_eq!(amt, h.get_supply(&rt)); | ||
assert_eq!(amt, h.get_balance(&rt, &*ALICE)); | ||
|
||
h.mint(&mut rt, &*BOB, &amt, vec![]).unwrap(); | ||
assert_eq!(&amt * 2, h.get_supply(&rt)); | ||
assert_eq!(amt, h.get_balance(&rt, &*BOB)); | ||
|
||
h.check_state(&rt); | ||
} | ||
|
||
#[test] | ||
fn requires_verifreg_caller() { | ||
let (mut rt, _) = make_harness(); | ||
let amt = TokenAmount::from_whole(1); | ||
let params = MintParams { to: *ALICE, amount: amt, operators: vec![] }; | ||
|
||
rt.expect_validate_caller_addr(vec![*VERIFIED_REGISTRY_ACTOR_ADDR]); | ||
rt.set_caller(*MARKET_ACTOR_CODE_ID, *STORAGE_MARKET_ACTOR_ADDR); | ||
expect_abort_contains_message( | ||
ExitCode::USR_FORBIDDEN, | ||
"caller address", | ||
rt.call::<Actor>(Method::Mint as MethodNum, &serialize(¶ms, "params").unwrap()), | ||
); | ||
} | ||
|
||
#[test] | ||
fn requires_whole_tokens() { | ||
let (mut rt, h) = make_harness(); | ||
let amt = TokenAmount::from_atto(100); | ||
expect_abort_contains_message( | ||
ExitCode::USR_ILLEGAL_ARGUMENT, | ||
"must be a multiple of 1000000000000000000", | ||
h.mint(&mut rt, &*ALICE, &amt, vec![]), | ||
); | ||
} | ||
|
||
#[test] | ||
fn adds_allowance_for_operator() { | ||
let (mut rt, h) = make_harness(); | ||
|
||
let amt = TokenAmount::from_whole(1); | ||
let allowance = TokenAmount::from_whole(2_000_000_000); | ||
h.mint(&mut rt, &*ALICE, &amt, vec![*BOB]).unwrap(); | ||
assert_eq!(allowance, h.get_allowance(&rt, &*ALICE, &BOB)); | ||
|
||
h.mint(&mut rt, &*ALICE, &amt, vec![*BOB]).unwrap(); | ||
// Note: the doubling of allowance here is unfortunate, should be resolved when | ||
// the token library offers a set_allowance method. | ||
assert_eq!(&allowance * 2, h.get_allowance(&rt, &*ALICE, &BOB)); | ||
|
||
// Different operator | ||
h.mint(&mut rt, &*ALICE, &amt, vec![*CARLA]).unwrap(); | ||
assert_eq!(&allowance * 2, h.get_allowance(&rt, &*ALICE, &BOB)); | ||
assert_eq!(allowance, h.get_allowance(&rt, &*ALICE, &CARLA)); | ||
|
||
h.check_state(&rt); | ||
} | ||
} | ||
|
||
fn make_harness() -> (MockRuntime, Harness) { | ||
let mut rt = new_runtime(); | ||
let h = Harness { registry: *VERIFIED_REGISTRY_ACTOR_ADDR }; | ||
h.construct_and_verify(&mut rt, &h.registry); | ||
(rt, h) | ||
} |
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
Oops, something went wrong.