Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add log decoding capabilities to show decoded log values for forc-test #5812

Merged
merged 10 commits into from
May 15, 2024

Conversation

kayagokalp
Copy link
Member

@kayagokalp kayagokalp commented Apr 1, 2024

Description

This PR adds log decoding capabilities to forc, so that it can be used for showing actual decoded, human readable values at forc-test output.

For the following unit test:

script;

fn main() {}

#[test]
fn test_fn() {
	let a = 10;
	log(a);
	let b = 30;
	log(b);
	assert_eq(a, 10)
}

Logs are:

zbap@/Users/-/fuel/test_projects/script_main > ../../dev/sway/target/release/forc test --logs --experimental-new-encoding
  Finished debug [unoptimized + fuel] target(s) in 5.14s
      Bytecode hash: 0x562b471bae4323b806a1b2829014ef7078a5b9406a076a54cf0b2f1a61cb49f8
   Running 1 test, filtered 0 tests
      test test_fn ... ok (33.875µs, 200 gas)
Decoded log value: 10, log rb: 0
Decoded log value: 30, log rb: 1
Raw logs:
[{"LogData":{"data":"000000000000000a","digest":"8d85f8467240628a94819b26bee26e3a9b2804334c63482deacec8d64ab4e1e7","id":"0000000000000000000000000000000000000000000000000000000000000000","is":10336,"len":8,"pc":10784,"ptr":67107840,"ra":0,"rb":0}},{"LogData":{"data":"000000000000001e","digest":"48a97e421546f8d4cae1cf88c51a459a8c10a88442eed63643dd263cef880c1c","id":"0000000000000000000000000000000000000000000000000000000000000000","is":10336,"len":8,"pc":11048,"ptr":67106816,"ra":0,"rb":1}}]
   Result: OK. 1 passed. 0 failed. Finished in 33.875µs.

Also this PR fixes a bug in test suite which causes test suite to omit the encoding information passed into forc-test from unit_tests_pass tests. And adds log decode testing capabilities to the test suite.

Next up is adding actual variable names instead of log id so that decoded log values will show as, this is left to a future PR

Decoded log: ( a = 10 )
Decoded log: ( b = 30 )

@kayagokalp kayagokalp added enhancement New feature or request forc forc-test Everything related to the `forc-test` lib and `forc test` command. labels Apr 1, 2024
@kayagokalp kayagokalp self-assigned this Apr 1, 2024
@kayagokalp kayagokalp force-pushed the kayagokalp/log-decode branch from f03a1e7 to 09a6630 Compare April 29, 2024 21:31
@kayagokalp kayagokalp enabled auto-merge (squash) May 14, 2024 06:41
@kayagokalp kayagokalp requested a review from a team May 14, 2024 06:41
Copy link
Member

@JoshuaBatty JoshuaBatty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work

@kayagokalp kayagokalp merged commit cd76c64 into master May 15, 2024
41 checks passed
@kayagokalp kayagokalp deleted the kayagokalp/log-decode branch May 15, 2024 06:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request forc forc-test Everything related to the `forc-test` lib and `forc test` command.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants