Hi guys, how can I know the amount of gas spent on my smart contract. Is there a way to log that with blueprint?

Aug 19, 2023, 10:34 AM
+
I also wanted to know.
The only way I do know for now is to limit gas consumption for blueprint, that way you can guarantee that testcase consumes no more than a certain amount
Aug 19, 2023, 10:40 AM
It is almost certainly possible. Check how to turn on blockchain logs.
Aug 19, 2023, 11:15 AM
Following this suggestion, I found that we can specify to log information about gas on the tests like this:

await blockchain.setVerbosityForAddress(task5.address, {
print: true,
blockchainLogs: true,
vmLogs: 'vm_logs_gas',
debugLogs: false,
})

Now the doubt that I have, is that I received logs like this one:

code cell hash: 5663FF9219FDD6BDE13F1580C711426F51548B4409DCA47F085BF13A3A940CB9 offset: 0
execute SETCP 0
gas remaining: 9999974
code cell hash: 5663FF9219FDD6BDE13F1580C711426F51548B4409DCA47F085BF13A3A940CB9 offset: 16
execute DICTPUSHCONST 19 (xC_,1)
gas remaining: 9999940

Which I assume is the gas remaining after each instruction. My question is, if I'm right, remaining from how much? I don't see information in the logs about it. My intuition tells me that maybe is from the limit, that appears in this log:

[ 4][t 0][2023-08-19 15:09:18.254000][transaction.cpp:1093] starting VM
[ 4][t 0][2023-08-19 15:09:18.255000][transaction.cpp:1098] VM terminated with exit code 0
[ 3][t 0][2023-08-19 15:09:18.255000][transaction.cpp:1111] steps: 4 gas: used=291, max=50000, limit=50000, credit=0
[ 3][t 0][2023-08-19 15:09:18.255000][transaction.cpp:1113] out_of_gas=false, accepted=true, success=true, time=0.000365s
[ 4][t 0][2023-08-19 15:09:18.255000][transaction.cpp:1145] gas fees: 291000 = 65536000 * 291 /2^16 ; price=65536000; flat rate=[100000 for 100]; rem
aining balance=49709000ng
[ 4][t 0][2023-08-19 15:09:18.256000][transaction.cpp:2470] setting address rewriting info for newly-activated account F7B44BE93AC2861E1860C51FFDF3A7
AB1553A50CC3ACE572D7DA909A08F16139 with split_depth=0, orig_addr_rewrite=

But this doesn't seems to be true, otherwise I would be spending: 50000 - 9955191 = -9905191, negative gas😅 obviously this assumption it's wrong. If anyone knows, from which quantity is this "reamining gas", let me know.
@hitasp I don't know how to do that but I tried this. The issue is that I cannot know from which quantity this is the "remaining gas". Read it, maybe helps you in some way
Aug 20, 2023, 4:31 PM
this method is not easy to read.
Nov 7, 2023, 4:45 PM

© 2024 Draquery.com All rights reserved.