diem / diem/move

[Bug]unexpected error message "Unable to find script in file sources/xxx.move" when execute command "move sandbox run sources/xxx.move"

Open
#35 1 comment 0 reactions 0 assignees View on GitHub
bug
Dominant language
Rust
Stars
378
Forks
137
PR merge metrics
No merged PRs in 30d

Description

# 🐛 Bug

Incorrect processing logic when execute command "move sandbox run". Current move-package implementation using the "main" function name as the file name (may add a suffix if there are more than one scripts using the same main function name) when saving the compiled script to dist other than the original script file name. and when using command "move sandbox run" it will compare the file name of saved compiled script and the file name user input, and may output error such as Error: Unable to find script in file "sources/xx.move" if the "main" function name in the script is not the same as the script file name

## To reproduce
create package test
```sh
move package new test
```
create test script named test_script.move under directory sources/
and add the following content to test_script.move
```rust
// sources/test__script.move
script {
use Std::Debug;

fun test() {
let num: u64 = 100;
Debug::print(&num);
}
}
```
# run script using
```sh
move sandbox run souces/test_script.move
```
and you will see the following error

**Stack trace/error message**
```
Error: Unable to find script in file "sources/test_script.move"
```

## Expected Behavior
Expected output should be
[debug] 100

Although we can change the function name of test to test_script (same as the script file name) to get the expected behavior, but it's just a suggested coding convention of using the same name of the script file name as the "main" function name in the script, it is not a must. Not event to say if there are more than one script using the same main function name, the move-compiler will append a suffix to the function name and move-package will use that name when save the compiled packages to disk.
Just using the file name to determine to compiled script is not enough, it would be better to use the FileHash to determine the compiled script to use when execute "move sandbox run"
## System information
move-cli 0.1.
rustc 1.58.1 (db9d1b20b 2022-01-20)
CentOS Linux release 7.9.2009 (Core)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.