hirosystems / clarinet

Write, test and deploy high-quality smart contracts to the Stacks blockchain and Bitcoin.
https://hiro.so/clarinet
GNU General Public License v3.0
297 stars 130 forks source link

Include tx cost in transaction receipts #1507

Open hstove opened 1 month ago

hstove commented 1 month ago

One handy feature in Clarinet v1 was the inclusion of costs in the return type of function calls (both public and read-only). It would be great if this was included in the Clarinet v2. Specifically, I'm referring to writing unit tests and the JS return type. I wouldn't consider this a "must have", so if it's a huge effort, it's probably not worth prioritization. But if it's relatively easy to add, I'd appreciate considering it as a feature.

hugocaillard commented 1 month ago

Definitely easy to add. The interface could be

const { result, events, costs } = simnet.callReadOnlyFn(...)

console.log(costs)
/*
{
    total: {
      write_length: 19,
      write_count: 2,
      read_length: 1137,
      read_count: 8,
      runtime: 8882
    },
    limit: {
      write_length: 15000000,
      write_count: 15000,
      read_length: 100000000,
      read_count: 15000,
      runtime: 5000000000
    },
    memory: 393,
    memory_limit: 100000000
  }
*/

Is that what you have in mind?