Skip to content

Commit

Permalink
Merge pull request #1909 from AntelopeIO/merge_setcode_fix_to_5_0
Browse files Browse the repository at this point in the history
[4.0 -> 5.0] Fix non-working cleos set code and set abi commands, and add tests
  • Loading branch information
linh2931 authored Nov 17, 2023
2 parents c7e7b9f + 490fdf7 commit 1dba643
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 12 deletions.
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

0 comments on commit 1dba643

Please sign in to comment.