Skip to content

Commit 2e21be3

Browse files
authored
Merge pull request #423 from dusk-network/issue-422
callstack returns callers id list without self id
2 parents c7015f5 + a94764a commit 2e21be3

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

piecrust/CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Changed
11+
12+
- Change `callstack` to return callers' id list with no self id at the beginning [#422]
13+
1014
## [0.27.1] - 2025-01-15
1115

1216
### Added
@@ -493,6 +497,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
493497
<!-- ISSUES -->
494498

495499
[#rusk_3341]: https://github.com/dusk-network/rusk/issues/3341
500+
[#422]: https://github.com/dusk-network/piecrust/issues/422
496501
[#410]: https://github.com/dusk-network/piecrust/issues/410
497502
[#405]: https://github.com/dusk-network/piecrust/issues/405
498503
[#396]: https://github.com/dusk-network/piecrust/issues/396

piecrust/src/imports.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ fn callstack(env: Caller<Env>) -> i32 {
392392
let instance = env.self_instance();
393393

394394
let mut i = 0usize;
395-
for contract_id in env.call_ids() {
395+
for contract_id in env.call_ids().iter().skip(1) {
396396
instance.with_arg_buf_mut(|buf| {
397397
buf[i * CONTRACT_ID_BYTES..(i + 1) * CONTRACT_ID_BYTES]
398398
.copy_from_slice(contract_id.as_bytes());

piecrust/tests/callcenter.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -263,19 +263,18 @@ pub fn cc_callstack() -> Result<(), Error> {
263263
let callstack: Vec<ContractId> = session
264264
.call(center_id, "return_callstack", &(), LIMIT)?
265265
.data;
266-
assert_eq!(callstack.len(), 1);
266+
assert_eq!(callstack.len(), 0);
267267

268268
let self_id: ContractId =
269269
session.call(center_id, "return_self_id", &(), LIMIT)?.data;
270-
assert_eq!(callstack[0], self_id);
271270

272271
const N: u32 = 5;
273272
let callstack: Vec<ContractId> = session
274273
.call(center_id, "call_self_n_times", &N, LIMIT)?
275274
.data;
276-
assert_eq!(callstack.len(), N as usize + 1);
277-
for i in 1..=N as usize {
278-
assert_eq!(callstack[0], callstack[i]);
275+
assert_eq!(callstack.len(), N as usize);
276+
for i in 0..N as usize {
277+
assert_eq!(self_id, callstack[i]);
279278
}
280279

281280
let res = session
@@ -295,9 +294,8 @@ pub fn cc_callstack() -> Result<(), Error> {
295294
let callstack: Vec<ContractId> =
296295
rkyv::from_bytes(&res).expect("Deserialization to succeed");
297296

298-
assert_eq!(callstack.len(), 2);
299-
assert_eq!(callstack[0], callstack_id);
300-
assert_eq!(callstack[1], center_id);
297+
assert_eq!(callstack.len(), 1);
298+
assert_eq!(callstack[0], center_id);
301299

302300
Ok(())
303301
}

0 commit comments

Comments
 (0)