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

Optimize tests and GitHub Workflows #453

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/build-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ jobs:
shell: bash
run: |
python3 -m multiversx_sdk_cli.cli deps install testwallets
python3 -m multiversx_sdk_cli.cli deps install rust
- name: Run unit tests
shell: bash
run: |
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,15 @@ jobs:
- name: Setup test dependencies
run: |
python3 -m multiversx_sdk_cli.cli deps install testwallets
python3 -m multiversx_sdk_cli.cli deps install rust
- name: Run unit tests
run: |
export PYTHONPATH=.
pytest .
- name: Run CLI tests
run: |
export PROXY=https://testnet-gateway.multiversx.com
export CHAIN_ID=T
cd ./multiversx_sdk_cli/tests
source ./test_cli_contracts.sh && testAll || return 1
source ./test_cli_tx.sh && testAll || return 1
source ./test_cli_dns.sh && testOffline || return 1
source ./test_cli_validators.sh && testAll || return 1
4 changes: 2 additions & 2 deletions .github/workflows/test-localnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:

python3 -m multiversx_sdk_cli.cli localnet clean --configfile=./multiversx_sdk_cli/tests/testdata/localnet_with_resolution_remote.toml
python3 -m multiversx_sdk_cli.cli localnet config --configfile=./multiversx_sdk_cli/tests/testdata/localnet_with_resolution_remote.toml
python3 -m multiversx_sdk_cli.cli localnet start --configfile=./multiversx_sdk_cli/tests/testdata/localnet_with_resolution_remote.toml --stop-after-seconds=120
python3 -m multiversx_sdk_cli.cli localnet start --configfile=./multiversx_sdk_cli/tests/testdata/localnet_with_resolution_remote.toml --stop-after-seconds=90

if grep -r --include=\*.log "started committing block" ./localnet; then
echo "The localnet processed blocks successfully."
Expand All @@ -71,7 +71,7 @@ jobs:

python3 -m multiversx_sdk_cli.cli localnet clean --configfile=./multiversx_sdk_cli/tests/testdata/localnet_with_resolution_local.toml
python3 -m multiversx_sdk_cli.cli localnet config --configfile=./multiversx_sdk_cli/tests/testdata/localnet_with_resolution_local.toml
python3 -m multiversx_sdk_cli.cli localnet start --configfile=./multiversx_sdk_cli/tests/testdata/localnet_with_resolution_local.toml --stop-after-seconds=120
python3 -m multiversx_sdk_cli.cli localnet start --configfile=./multiversx_sdk_cli/tests/testdata/localnet_with_resolution_local.toml --stop-after-seconds=90

if grep -r --include=\*.log "started committing block" ./localnet; then
echo "The localnet processed blocks successfully."
Expand Down
144 changes: 72 additions & 72 deletions multiversx_sdk_cli/tests/test_cli_contracts.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,78 +9,78 @@
parent = Path(__file__).parent


def test_contract_new():
main([
"contract",
"new",
"--template",
"adder",
"--path",
f"{parent}/testdata-out/SANDBOX"
])
assert Path.is_dir(parent / "testdata-out" / "SANDBOX" / "adder")


def test_contract_new_with_bad_code():
# we change the contract code so the build would fail so we can catch the error
main([
"contract",
"new",
"--template",
"adder",
"--path",
f"{parent}/testdata-out/SANDBOX",
"--name",
"adder-bad-src"
])

assert Path.is_dir(parent / "testdata-out" / "SANDBOX" / "adder-bad-src")
replace_variable_with_unknown_variable_for_adder()


def replace_variable_with_unknown_variable_for_adder():
# this is done in order to replace the value added in the adder contract with a unknown variable
with open(parent / "testdata-out" / "SANDBOX" / "adder-bad-src" / "src" / "adder_bad_src.rs", "r") as f:
contract_lines = f.readlines()

for index, line in reversed(list(enumerate(contract_lines))):
if "value" in line:
contract_lines[index] = line.replace("value", "unknown_variable")
break

with open(parent / "testdata-out" / "SANDBOX" / "adder-bad-src" / "src" / "adder_bad_src.rs", "w") as f:
f.writelines(contract_lines)


@pytest.mark.skip_on_windows
def test_contract_build():
main([
"contract",
"build",
"--path",
f"{parent}/testdata-out/SANDBOX/adder"
])

assert Path.is_file(parent / "testdata-out" / "SANDBOX" / "adder" / "output" / "adder.wasm")


@pytest.mark.skip_on_windows
def test_bad_contract_build(capsys: Any):
ERROR = "Build error: error code = 101, see output."

main([
"contract",
"build",
"--path",
f"{parent}/testdata-out/SANDBOX/adder-bad-src"
])

out, _ = capsys.readouterr()

if ERROR in out:
assert True
else:
assert False
# def test_contract_new():
# main([
# "contract",
# "new",
# "--template",
# "adder",
# "--path",
# f"{parent}/testdata-out/SANDBOX"
# ])
# assert Path.is_dir(parent / "testdata-out" / "SANDBOX" / "adder")


# def test_contract_new_with_bad_code():
# # we change the contract code so the build would fail so we can catch the error
# main([
# "contract",
# "new",
# "--template",
# "adder",
# "--path",
# f"{parent}/testdata-out/SANDBOX",
# "--name",
# "adder-bad-src"
# ])

# assert Path.is_dir(parent / "testdata-out" / "SANDBOX" / "adder-bad-src")
# replace_variable_with_unknown_variable_for_adder()


# def replace_variable_with_unknown_variable_for_adder():
# # this is done in order to replace the value added in the adder contract with a unknown variable
# with open(parent / "testdata-out" / "SANDBOX" / "adder-bad-src" / "src" / "adder_bad_src.rs", "r") as f:
# contract_lines = f.readlines()

# for index, line in reversed(list(enumerate(contract_lines))):
# if "value" in line:
# contract_lines[index] = line.replace("value", "unknown_variable")
# break

# with open(parent / "testdata-out" / "SANDBOX" / "adder-bad-src" / "src" / "adder_bad_src.rs", "w") as f:
# f.writelines(contract_lines)


# @pytest.mark.skip_on_windows
# def test_contract_build():
# main([
# "contract",
# "build",
# "--path",
# f"{parent}/testdata-out/SANDBOX/adder"
# ])

# assert Path.is_file(parent / "testdata-out" / "SANDBOX" / "adder" / "output" / "adder.wasm")


# @pytest.mark.skip_on_windows
# def test_bad_contract_build(capsys: Any):
# ERROR = "Build error: error code = 101, see output."

# main([
# "contract",
# "build",
# "--path",
# f"{parent}/testdata-out/SANDBOX/adder-bad-src"
# ])

# out, _ = capsys.readouterr()

# if ERROR in out:
# assert True
# else:
# assert False


def test_contract_deploy():
Expand Down
40 changes: 0 additions & 40 deletions multiversx_sdk_cli/tests/test_cli_contracts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ testTrivialCommands() {
testCreateContracts() {
echo "testCreateContracts"
${CLI} contract new --template adder --path ${SANDBOX} || return 1
${CLI} contract new --template crypto-zombies --path ${SANDBOX} || return 1
${CLI} contract new --template empty --path ${SANDBOX} || return 1
}

testBuildContracts() {
Expand All @@ -24,30 +22,6 @@ testBuildContracts() {
${CLI} contract build --path=${SANDBOX}/adder --target-dir=${TARGET_DIR} || return 1
assertFileExists ${SANDBOX}/adder/output/adder.wasm || return 1
assertFileExists ${SANDBOX}/adder/output/adder.abi.json || return 1

${CLI} contract build --path=${SANDBOX}/crypto-zombies --target-dir=${TARGET_DIR} || return 1
assertFileExists ${SANDBOX}/crypto-zombies/output/crypto-zombies.wasm || return 1
assertFileExists ${SANDBOX}/crypto-zombies/output/crypto-zombies.abi.json || return 1

${CLI} contract build --path=${SANDBOX}/empty --target-dir=${TARGET_DIR} || return 1
assertFileExists ${SANDBOX}/empty/output/empty.wasm || return 1
assertFileExists ${SANDBOX}/empty/output/empty.abi.json || return 1
}

testRunScenarios() {
echo "testRunScenarios"
${CLI} --verbose contract test --path=${SANDBOX}/adder || return 1
${CLI} --verbose contract test --path=${SANDBOX}/empty || return 1
}

testWasmName() {
echo "testWasmName"

${CLI} contract clean --path ${SANDBOX}/adder
assertFileDoesNotExist ${SANDBOX}/adder/output/adder-2.wasm || return 1
${CLI} contract build --path=${SANDBOX}/adder --target-dir=${TARGET_DIR} --wasm-name adder-2 || return 1
assertFileExists ${SANDBOX}/adder/output/adder-2.wasm || return 1
assertFileExists ${SANDBOX}/adder/output/adder.abi.json || return 1
}

testCleanContracts() {
Expand All @@ -58,18 +32,6 @@ testCleanContracts() {
${CLI} contract clean --path ${SANDBOX}/adder || return 1
assertFileDoesNotExist ${SANDBOX}/adder/output/adder.wasm || return 1
assertFileDoesNotExist ${SANDBOX}/adder/output/adder.abi.json || return 1

assertFileExists ${SANDBOX}/crypto-zombies/output/crypto-zombies.wasm || return 1
assertFileExists ${SANDBOX}/crypto-zombies/output/crypto-zombies.abi.json || return 1
${CLI} contract clean --path ${SANDBOX}/crypto-zombies || return 1
assertFileDoesNotExist ${SANDBOX}/crypto-zombies/output/crypto-zombies.wasm || return 1
assertFileDoesNotExist ${SANDBOX}/crypto-zombies/output/crypto-zombies.abi.json || return 1

assertFileExists ${SANDBOX}/empty/output/empty.wasm || return 1
assertFileExists ${SANDBOX}/empty/output/empty.abi.json || return 1
${CLI} contract clean --path ${SANDBOX}/empty || return 1
assertFileDoesNotExist ${SANDBOX}/empty/output/empty.wasm || return 1
assertFileDoesNotExist ${SANDBOX}/empty/output/empty.abi.json || return 1
}

testVerifyContract(){
Expand Down Expand Up @@ -113,7 +75,5 @@ testAll() {
testTrivialCommands || return 1
testCreateContracts || return 1
testBuildContracts || return 1
testRunScenarios || return 1
testCleanContracts || return 1
testWasmName || return 1
}
Loading