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

[5.0 -> main] Fix non-working cleos set code and set abi commands, and add tests #1915

Merged
merged 12 commits into from
Nov 17, 2023
Merged
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
33 changes: 22 additions & 11 deletions programs/cleos/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3471,12 +3471,18 @@ int main( int argc, char** argv ) {
bytes code_bytes;
if(!contract_clear){
std::string wasm;
std::filesystem::path cpath = std::filesystem::canonical(std::filesystem::path(contractPath));

if( wasmPath.empty() ) {
wasmPath = (cpath / std::filesystem::path(cpath.filename().generic_string()+".wasm")).generic_string();
} else if ( std::filesystem::path(wasmPath).is_relative() ) {
wasmPath = (cpath / std::filesystem::path(wasmPath)).generic_string();
// contractPath (set by contract-dir argument) is only applicable
// to "set contract" command. It is empty for "set code" and can be
// empty for "set contract.
if(!contractPath.empty()) {
std::filesystem::path cpath = std::filesystem::canonical(std::filesystem::path(contractPath));

if( wasmPath.empty() ) {
wasmPath = (cpath / std::filesystem::path(cpath.filename().generic_string()+".wasm")).generic_string();
} else if ( std::filesystem::path(wasmPath).is_relative() ) {
wasmPath = (cpath / std::filesystem::path(wasmPath)).generic_string();
}
}

std::cerr << localized(("Reading WASM from " + wasmPath + "...").c_str()) << std::endl;
Expand Down Expand Up @@ -3527,12 +3533,17 @@ int main( int argc, char** argv ) {

bytes abi_bytes;
if(!contract_clear){
std::filesystem::path cpath = std::filesystem::canonical(std::filesystem::path(contractPath));

if( abiPath.empty() ) {
abiPath = (cpath / std::filesystem::path(cpath.filename().generic_string()+".abi")).generic_string();
} else if ( std::filesystem::path(abiPath).is_relative() ) {
abiPath = (cpath / std::filesystem::path(abiPath)).generic_string();
// contractPath (set by contract-dir argument) is only applicable
// to "set contract" command. It is empty for "set abi" and can be
// empty for "set contract.
if(!contractPath.empty()) {
std::filesystem::path cpath = std::filesystem::canonical(std::filesystem::path(contractPath));

if( abiPath.empty() ) {
abiPath = (cpath / std::filesystem::path(cpath.filename().generic_string()+".abi")).generic_string();
} else if ( std::filesystem::path(abiPath).is_relative() ) {
abiPath = (cpath / std::filesystem::path(abiPath)).generic_string();
}
}

EOS_ASSERT( std::filesystem::exists( abiPath ), abi_file_not_found, "no abi file found ${f}", ("f", abiPath) );
Expand Down
1 change: 0 additions & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,6 @@ set_property(TEST nodeos_high_transaction_lr_test PROPERTY LABELS long_running_t
add_test(NAME nodeos_retry_transaction_lr_test COMMAND tests/nodeos_retry_transaction_test.py -v --num-transactions 100 --max-transactions-per-second 10 --total-accounts 5 ${UNSHARE} WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
set_property(TEST nodeos_retry_transaction_lr_test PROPERTY LABELS long_running_tests)


add_test(NAME cli_test COMMAND tests/cli_test.py WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
set_property(TEST cli_test PROPERTY LABELS nonparallelizable_tests)

Expand Down
14 changes: 14 additions & 0 deletions tests/TestHarness/transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,20 @@ def publishContract(self, account, contractDir, wasmFile, abiFile, waitForTransB

return trans

# set code or abi and return True for success and False for failure
def setCodeOrAbi(self, account, setType, setFile):
cmd=f"{Utils.EosClientPath} {self.eosClientArgs()} -v set {setType} -j {account.name} {setFile} "
if Utils.Debug: Utils.Print("cmd: %s" % (cmd))
try:
trans=Utils.runCmdReturnJson(cmd, trace=False)
self.trackCmdTransaction(trans)
except subprocess.CalledProcessError as ex:
msg=ex.stderr.decode("utf-8")
Utils.Print("ERROR: Exception during set %s. stderr: %s." % (setType, msg))
return False

return True

# returns tuple with indication if transaction was successfully sent and either the transaction or else the exception output
def pushTransaction(self, trans, opts="", silentErrors=False, permissions=None):
assert(isinstance(trans, dict))
Expand Down
11 changes: 11 additions & 0 deletions tests/nodeos_run_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,17 @@
currentBlockNum=node.getHeadBlockNum()
Print("CurrentBlockNum: %d" % (currentBlockNum))

# Verify "set code" and "set abi" work
Print("Verify set code and set abi work")
setCodeAbiAccount = Account("setcodeabi")
setCodeAbiAccount.ownerPublicKey = cluster.eosioAccount.ownerPublicKey
setCodeAbiAccount.activePublicKey = cluster.eosioAccount.ownerPublicKey
cluster.createAccountAndVerify(setCodeAbiAccount, cluster.eosioAccount, buyRAM=100000)
wasmFile="unittests/test-contracts/payloadless/payloadless.wasm"
abiFile="unittests/test-contracts/payloadless/payloadless.abi"
assert(node.setCodeOrAbi(setCodeAbiAccount, "code", wasmFile))
assert(node.setCodeOrAbi(setCodeAbiAccount, "abi", abiFile))

testSuccessful=True
finally:
TestHelper.shutdown(cluster, walletMgr, testSuccessful, dumpErrorDetails)
Expand Down