Skip to content

Commit d4c7346

Browse files
authored
datacap: fix Name and Symbol methods (#794)
1 parent 931f7da commit d4c7346

File tree

2 files changed

+40
-4
lines changed

2 files changed

+40
-4
lines changed

actors/datacap/src/lib.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,19 +89,21 @@ impl Actor {
8989
Ok(())
9090
}
9191

92-
pub fn name<BS, RT>(_: &RT, _: ()) -> Result<String, ActorError>
92+
pub fn name<BS, RT>(rt: &mut RT) -> Result<String, ActorError>
9393
where
9494
BS: Blockstore,
9595
RT: Runtime<BS>,
9696
{
97+
rt.validate_immediate_caller_accept_any()?;
9798
Ok("DataCap".to_string())
9899
}
99100

100-
pub fn symbol<BS, RT>(_: &RT, _: ()) -> Result<String, ActorError>
101+
pub fn symbol<BS, RT>(rt: &mut RT) -> Result<String, ActorError>
101102
where
102103
BS: Blockstore,
103104
RT: Runtime<BS>,
104105
{
106+
rt.validate_immediate_caller_accept_any()?;
105107
Ok("DCAP".to_string())
106108
}
107109

@@ -536,11 +538,11 @@ impl ActorCode for Actor {
536538
serialize(&ret, "destroy result")
537539
}
538540
Some(Method::Name) => {
539-
let ret = Self::name(rt, cbor::deserialize_params(params)?)?;
541+
let ret = Self::name(rt)?;
540542
serialize(&ret, "name result")
541543
}
542544
Some(Method::Symbol) => {
543-
let ret = Self::symbol(rt, cbor::deserialize_params(params)?)?;
545+
let ret = Self::symbol(rt)?;
544546
serialize(&ret, "symbol result")
545547
}
546548
Some(Method::TotalSupply) => {

test_vm/tests/datacap_tests.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use test_vm::VM;
1616

1717
use fil_actor_datacap::{Method as DataCapMethod, MintParams};
1818
use frc46_token::token::types::TransferFromParams;
19+
use fvm_ipld_encoding::RawBytes;
1920

2021
/* Mint a token for client and transfer it to a receiver, exercising error cases */
2122
#[test]
@@ -186,3 +187,36 @@ fn datacap_transfer_scenario() {
186187
ExitCode::USR_INSUFFICIENT_FUNDS,
187188
);
188189
}
190+
191+
/* Call name & symbol */
192+
#[test]
193+
fn call_name_symbol() {
194+
let store = MemoryBlockstore::new();
195+
let v = VM::new_with_singletons(&store);
196+
let addrs = create_accounts(&v, 1, TokenAmount::from_whole(10_000));
197+
let sender = addrs[0];
198+
199+
let mut ret: String = apply_ok(
200+
&v,
201+
sender,
202+
DATACAP_TOKEN_ACTOR_ADDR,
203+
TokenAmount::zero(),
204+
DataCapMethod::Name as u64,
205+
RawBytes::default(),
206+
)
207+
.deserialize()
208+
.unwrap();
209+
assert_eq!("DataCap", ret, "expected name DataCap, got {}", ret);
210+
211+
ret = apply_ok(
212+
&v,
213+
sender,
214+
DATACAP_TOKEN_ACTOR_ADDR,
215+
TokenAmount::zero(),
216+
DataCapMethod::Symbol as u64,
217+
RawBytes::default(),
218+
)
219+
.deserialize()
220+
.unwrap();
221+
assert_eq!("DCAP", ret, "expected name DataCap, got {}", ret);
222+
}

0 commit comments

Comments
 (0)