Skip to content

Commit 047560d

Browse files
committed
test: correctly compute the f2 address in the test vm (#686)
Previously, we weren't taking the nonce into account which prevented us from testing multiple messages from the same account.
1 parent d5e40c0 commit 047560d

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

test_vm/src/lib.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ impl<'bs> VM<'bs> {
391391
// make top level context with internal context
392392
let top = TopCtx {
393393
originator_stable_addr: from,
394-
_originator_call_seq: call_seq,
394+
originator_call_seq: call_seq,
395395
new_actor_addr_count: RefCell::new(0),
396396
circ_supply: TokenAmount::from_whole(1_000_000_000),
397397
};
@@ -490,7 +490,7 @@ impl<'bs> VM<'bs> {
490490
#[derive(Clone)]
491491
pub struct TopCtx {
492492
originator_stable_addr: Address,
493-
_originator_call_seq: u64,
493+
originator_call_seq: u64,
494494
new_actor_addr_count: RefCell<u64>,
495495
circ_supply: TokenAmount,
496496
}
@@ -877,15 +877,12 @@ impl<'invocation, 'bs> Runtime<&'bs MemoryBlockstore> for InvocationCtx<'invocat
877877
}
878878

879879
fn new_actor_address(&mut self) -> Result<Address, ActorError> {
880-
let osa_bytes = self.top.originator_stable_addr.to_bytes();
881-
let mut seq_num_bytes = self.top.originator_stable_addr.to_bytes();
882-
let cnt = self.top.new_actor_addr_count.take();
883-
self.top.new_actor_addr_count.replace(cnt + 1);
884-
let mut cnt_bytes = serialize(&cnt, "count failed").unwrap().to_vec();
885-
let mut out = osa_bytes;
886-
out.append(&mut seq_num_bytes);
887-
out.append(&mut cnt_bytes);
888-
Ok(Address::new_actor(out.as_slice()))
880+
let mut b = self.top.originator_stable_addr.to_bytes();
881+
b.extend_from_slice(&self.top.originator_call_seq.to_be_bytes());
882+
b.extend_from_slice(
883+
&self.top.new_actor_addr_count.replace_with(|old| *old + 1).to_be_bytes(),
884+
);
885+
Ok(Address::new_actor(&b))
889886
}
890887

891888
fn delete_actor(&mut self, _beneficiary: &Address) -> Result<(), ActorError> {

0 commit comments

Comments
 (0)