Skip to content

Commit

Permalink
datacap: fix Name and Symbol methods (filecoin-project#794)
Browse files Browse the repository at this point in the history
  • Loading branch information
arajasek authored and shamb0 committed Jan 31, 2023
1 parent afcd255 commit 5bafeff
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
10 changes: 6 additions & 4 deletions actors/datacap/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,19 +89,21 @@ impl Actor {
Ok(())
}

pub fn name<BS, RT>(_: &RT, _: ()) -> Result<String, ActorError>
pub fn name<BS, RT>(rt: &mut RT) -> Result<String, ActorError>
where
BS: Blockstore,
RT: Runtime<BS>,
{
rt.validate_immediate_caller_accept_any()?;
Ok("DataCap".to_string())
}

pub fn symbol<BS, RT>(_: &RT, _: ()) -> Result<String, ActorError>
pub fn symbol<BS, RT>(rt: &mut RT) -> Result<String, ActorError>
where
BS: Blockstore,
RT: Runtime<BS>,
{
rt.validate_immediate_caller_accept_any()?;
Ok("DCAP".to_string())
}

Expand Down Expand Up @@ -537,11 +539,11 @@ impl ActorCode for Actor {
serialize(&ret, "destroy result")
}
Some(Method::Name) => {
let ret = Self::name(rt, cbor::deserialize_params(params)?)?;
let ret = Self::name(rt)?;
serialize(&ret, "name result")
}
Some(Method::Symbol) => {
let ret = Self::symbol(rt, cbor::deserialize_params(params)?)?;
let ret = Self::symbol(rt)?;
serialize(&ret, "symbol result")
}
Some(Method::TotalSupply) => {
Expand Down
34 changes: 34 additions & 0 deletions test_vm/tests/datacap_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use test_vm::VM;

use fil_actor_datacap::{Method as DataCapMethod, MintParams};
use frc46_token::token::types::TransferFromParams;
use fvm_ipld_encoding::RawBytes;

/* Mint a token for client and transfer it to a receiver, exercising error cases */
#[test]
Expand Down Expand Up @@ -186,3 +187,36 @@ fn datacap_transfer_scenario() {
ExitCode::USR_INSUFFICIENT_FUNDS,
);
}

/* Call name & symbol */
#[test]
fn call_name_symbol() {
let store = MemoryBlockstore::new();
let v = VM::new_with_singletons(&store);
let addrs = create_accounts(&v, 1, TokenAmount::from_whole(10_000));
let sender = addrs[0];

let mut ret: String = apply_ok(
&v,
sender,
DATACAP_TOKEN_ACTOR_ADDR,
TokenAmount::zero(),
DataCapMethod::Name as u64,
RawBytes::default(),
)
.deserialize()
.unwrap();
assert_eq!("DataCap", ret, "expected name DataCap, got {}", ret);

ret = apply_ok(
&v,
sender,
DATACAP_TOKEN_ACTOR_ADDR,
TokenAmount::zero(),
DataCapMethod::Symbol as u64,
RawBytes::default(),
)
.deserialize()
.unwrap();
assert_eq!("DCAP", ret, "expected name DataCap, got {}", ret);
}

0 comments on commit 5bafeff

Please sign in to comment.