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

Add test runner python module #318

Merged
merged 41 commits into from
Dec 7, 2021
Merged

Add test runner python module #318

merged 41 commits into from
Dec 7, 2021

Conversation

anvacaru
Copy link
Contributor

Writing tests

  • First, the module pyiele needs to be imported.
  • The default values for the client port, passphrase, spending-key, gas-limit and other parameters are defined in the config.py file.
  • A contract can be deployed using deploy_contract(walletId, sender, bytecode).
  • A contract function can be called using run_function(f_name, f_args, walletId, sender, to).
  • Any rpc call can be made using send(rpc).
  • RPC calls are defined in rpc.py.

Running tests

>$ python3 test_erc20.sol

@gtrepta gtrepta force-pushed the midnight-test-runner branch from a18fee3 to a7f7977 Compare October 18, 2021 22:04
@anvacaru anvacaru force-pushed the midnight-test-runner branch from 810fa1b to 1444d0d Compare October 19, 2021 04:33
Makefile Outdated Show resolved Hide resolved
pyiele/config.py Outdated Show resolved Hide resolved
@ehildenb
Copy link
Member

ehildenb commented Nov 2, 2021

@anvacaru and @gtrepta can we add some tests of this functionality as well? Just a single Solidity file -> generated report files, and diff the files should be enough.

Or we can just make sure the tool runs smoothly, and not record the output, as an initial test. But it probably would be better to start with too strong of testing (with the output files) and weaken it as it gets annoying.

@ehildenb ehildenb force-pushed the midnight-test-runner branch from 88b5dff to d49097f Compare December 1, 2021 19:22
@ehildenb ehildenb marked this pull request as ready for review December 1, 2021 19:22
kiele Outdated
Comment on lines 51 to 53
run_pyiele() {
python3 -m pyiele "$@"
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
run_pyiele() {
python3 -m pyiele "$@"
}
run_pyiele() {
python3 -m pyiele --host "${host}" --port "${port}" --output "${output_path}" "$@"
}

Copy link
Contributor

Choose a reason for hiding this comment

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

This will have to be

python3 -m pyiele "$@" --host "${host}" --port "${port}" --output "${output_path}"

Because the command {blackbox,test,compile,coverage} is a positional parameter.

Copy link
Contributor

@gtrepta gtrepta Dec 6, 2021

Choose a reason for hiding this comment

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

On second look, this might not work at all. None of these parameters are included in all of the commands.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was able to set the run_pyiele() function to Everett's suggestion by moving the port,host, and output parameters to the main parser (initially, they were subparser parameters).

kiele Outdated Show resolved Hide resolved
kiele Outdated
Comment on lines 155 to 178
run_testrunner() {
local run_file
if [[ $# -gt 0 ]] && [ "$1" == "--help" ]; then
run_pyiele test --help
exit
fi
if ! nc -z "$kiele_host" "$kiele_port"; then
fatal "No listener found on port $kiele_port"
fi
if [[ $# -gt 0 ]]; then
if [[ -f "$1" ]] || [[ -d "$1" ]]; then
run_file="$1"; shift
if [[ "$run_file" == *.py ]]; then
python3 "$run_file"
else
run_pyiele test --file "$run_file" --port "$kiele_port" "$@"
fi
else
run_pyiele test --port "$kiele_port" "$@"
fi
else
run_pyiele test --port "$kiele_port" "$@"
fi
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
run_testrunner() {
local run_file
if [[ $# -gt 0 ]] && [ "$1" == "--help" ]; then
run_pyiele test --help
exit
fi
if ! nc -z "$kiele_host" "$kiele_port"; then
fatal "No listener found on port $kiele_port"
fi
if [[ $# -gt 0 ]]; then
if [[ -f "$1" ]] || [[ -d "$1" ]]; then
run_file="$1"; shift
if [[ "$run_file" == *.py ]]; then
python3 "$run_file"
else
run_pyiele test --file "$run_file" --port "$kiele_port" "$@"
fi
else
run_pyiele test --port "$kiele_port" "$@"
fi
else
run_pyiele test --port "$kiele_port" "$@"
fi
}
run_testrunner() {
! nc -z "$kiele_host" "$kiele_port" || fatal "No listener found on port $kiele_port"
run_pyiele test "$@"
}

Copy link
Contributor

Choose a reason for hiding this comment

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

My suggestion:

Suggested change
run_testrunner() {
local run_file
if [[ $# -gt 0 ]] && [ "$1" == "--help" ]; then
run_pyiele test --help
exit
fi
if ! nc -z "$kiele_host" "$kiele_port"; then
fatal "No listener found on port $kiele_port"
fi
if [[ $# -gt 0 ]]; then
if [[ -f "$1" ]] || [[ -d "$1" ]]; then
run_file="$1"; shift
if [[ "$run_file" == *.py ]]; then
python3 "$run_file"
else
run_pyiele test --file "$run_file" --port "$kiele_port" "$@"
fi
else
run_pyiele test --port "$kiele_port" "$@"
fi
else
run_pyiele test --port "$kiele_port" "$@"
fi
}
run_testrunner() {
local run_file cmd
if [[ $# -gt 0 ]] && [ "$1" == "--help" ]; then
run_pyiele test --help
exit
fi
if ! nc -z "$kiele_host" "$kiele_port"; then
fatal "No listener found on port $kiele_port"
fi
cmd=(run_pyiele test --port "$kiele_port" --host "$kiele_host")
if [[ $# -gt 0 ]] && ([[ -f "$1" ]] || [[ -d "$1" ]]); then
run_file="$1"; shift
if [[ "$run_file" == *.py ]]; then
cmd=( python3 "$run_file" )
else
cmd+=( --file "$run_file" )
fi
fi
"${cmd[@]}" "$@"
}

Copy link
Member

Choose a reason for hiding this comment

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

The --help option should be handled once globally at the top, and if we want it to call the pyiele help there as well, then it should do that.

But we shouldn't duplicate all this stuff about calling help everywhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree with @ehildenb. Initially, I added explicit help calls because the check_listener would prevent the help message from being displayed if the midnight client wasn't active. For now I just removed all explicit calls.

kiele Outdated Show resolved Hide resolved
kiele Outdated
Comment on lines 185 to 187
if ! nc -z "$kiele_host" "$kiele_port"; then
fatal "No listener found on port $kiele_port"
fi
Copy link
Member

Choose a reason for hiding this comment

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

Factor out a check_listener function in the Utilities section at the top, and use that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@anvacaru anvacaru requested review from ehildenb and gtrepta December 7, 2021 12:52
kiele Outdated Show resolved Hide resolved
Co-authored-by: gtrepta <50716988+gtrepta@users.noreply.github.com>
@rv-jenkins rv-jenkins merged commit bf2707e into master Dec 7, 2021
@rv-jenkins rv-jenkins deleted the midnight-test-runner branch December 7, 2021 19:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants