Console Logging
Console logging in medusa is similar to the functionality found in Foundry or Hardhat (except for string formatting,
see below). Note that if you are not using
Foundry or Hardhat as your compilation platform, you can retrieve the necessary console.sol
library
here.
For more information on the available function signatures and general tips on console logging, please review Foundry's documentation.
Differences in console.log(format[,...args])
The core functionality of string formatting is the same. If you want to string format an int256
, the only supported function signature is:
function log(string memory, int256) external;
. Otherwise, the supported argument types are string
, bool
, address
,
and uint256
. This capability is the same as in Foundry.
The core difference in medusa's string formatting is the specifiers that are allowed for the formatted string. The supported specifiers are as follows:
%v
: The value will be printed in its default format. This will work foruint256
,int256
,address
,bool
, andstring
. Using%v
is the recommended specifier for all argument types.%s
: The values will be converted into a human-readable string. This will work foruint256
,int256
,address
, andstring
. Contrary to Foundry or Hardhat,%s
will not work forbool
. Additionally,uint256
andint256
will not be provided in their hex-encoded format. This is the recommended specifier for projects that wish to maintain compatibility with an existing fuzz test suite from Foundry. Special exceptions will need to be made forbool
arguments. For example, you could use theconsole.logBool(bool)
function to separately log thebool
.%d
: This can be used foruint256
andint256
.%i
: This specifier is not supported by medusa forint256
anduint256
%e
: This specifier is not supported by medusa forint256
anduint256
.%x
: This provides the hexadecimal representation ofint256
anduint256
.%o
: This specifier is not supported by medusa.%o
in medusa will provide the base-8 representation ofint256
anduint256
.%t
: This can be used forbool
.%%
: This will print out "%" and not consume an argument.
If a specifier does not have a corresponding argument, the following is returned:
console.log("My name is %s %s", "medusa");
// Returns: "My name is medusa %!s(MISSING)"
If there are more arguments than specifiers, the following is returned:
console.log("My name is %s", "medusa", "fuzzer");
// Returns: "My name is medusa%!(EXTRA string=fuzzer)"
If only a format string with no arguments is provided, the string is returned with no formatting:
console.log("%% %s");
// Returns: "%% %s"