Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Remove WAST support from cleos set code/contract #5160

Merged
merged 6 commits into from
Aug 12, 2018
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
40 changes: 13 additions & 27 deletions programs/cleos/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ Usage: ./cleos create account [OPTIONS] creator name OwnerKey ActiveKey
#include <Inline/BasicTypes.h>
#include <IR/Module.h>
#include <IR/Validate.h>
#include <WAST/WAST.h>
#include <WASM/WASM.h>
#include <Runtime/Runtime.h>

Expand Down Expand Up @@ -2133,55 +2132,42 @@ int main( int argc, char** argv ) {
// set contract subcommand
string account;
string contractPath;
string wastPath;
string wasmPath;
string abiPath;
bool shouldSend = true;
auto codeSubcommand = setSubcommand->add_subcommand("code", localized("Create or update the code on an account"));
codeSubcommand->add_option("account", account, localized("The account to set code for"))->required();
codeSubcommand->add_option("code-file", wastPath, localized("The fullpath containing the contract WAST or WASM"))->required();
codeSubcommand->add_option("code-file", wasmPath, localized("The fullpath containing the contract WASM"))->required();

auto abiSubcommand = setSubcommand->add_subcommand("abi", localized("Create or update the abi on an account"));
abiSubcommand->add_option("account", account, localized("The account to set the ABI for"))->required();
abiSubcommand->add_option("abi-file", abiPath, localized("The fullpath containing the contract WAST or WASM"))->required();
abiSubcommand->add_option("abi-file", abiPath, localized("The fullpath containing the contract ABI"))->required();

auto contractSubcommand = setSubcommand->add_subcommand("contract", localized("Create or update the contract on an account"));
contractSubcommand->add_option("account", account, localized("The account to publish a contract for"))
->required();
contractSubcommand->add_option("contract-dir", contractPath, localized("The path containing the .wast and .abi"))
contractSubcommand->add_option("contract-dir", contractPath, localized("The path containing the .wasm and .abi"))
->required();
contractSubcommand->add_option("wast-file", wastPath, localized("The file containing the contract WAST or WASM relative to contract-dir"));
contractSubcommand->add_option("wasm-file", wasmPath, localized("The file containing the contract WASM relative to contract-dir"));
// ->check(CLI::ExistingFile);
auto abi = contractSubcommand->add_option("abi-file,-a,--abi", abiPath, localized("The ABI for the contract relative to contract-dir"));
// ->check(CLI::ExistingFile);

std::vector<chain::action> actions;
auto set_code_callback = [&]() {
std::string wast;
std::string wasm;
fc::path cpath(contractPath);

if( cpath.filename().generic_string() == "." ) cpath = cpath.parent_path();

if( wastPath.empty() ) {
wastPath = (cpath / (cpath.filename().generic_string()+".wasm")).generic_string();
if (!fc::exists(wastPath))
wastPath = (cpath / (cpath.filename().generic_string()+".wast")).generic_string();
} else {
wastPath = (cpath / wastPath).generic_string();
}
if( wasmPath.empty() )
wasmPath = (cpath / (cpath.filename().generic_string()+".wasm")).generic_string();
else
wasmPath = (cpath / wasmPath).generic_string();

std::cerr << localized(("Reading WAST/WASM from " + wastPath + "...").c_str()) << std::endl;
fc::read_file_contents(wastPath, wast);
EOS_ASSERT( !wast.empty(), wast_file_not_found, "no wast file found ${f}", ("f", wastPath) );
vector<uint8_t> wasm;
const string binary_wasm_header("\x00\x61\x73\x6d", 4);
if(wast.compare(0, 4, binary_wasm_header) == 0) {
std::cerr << localized("Using already assembled WASM...") << std::endl;
wasm = vector<uint8_t>(wast.begin(), wast.end());
}
else {
std::cerr << localized("Assembling WASM...") << std::endl;
wasm = wast_to_wasm(wast);
}
std::cerr << localized(("Reading WASM from " + wasmPath + "...").c_str()) << std::endl;
fc::read_file_contents(wasmPath, wasm);
EOS_ASSERT( !wasm.empty(), wast_file_not_found, "no wasm file found ${f}", ("f", wasmPath) );

actions.emplace_back( create_setcode(account, bytes(wasm.begin(), wasm.end()) ) );
if ( shouldSend ) {
Expand Down
2 changes: 1 addition & 1 deletion testnet.template
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ wcmd create -n ignition
# ------ DO NOT ALTER THE NEXT LINE -------
###INSERT prodkeys

ecmd set contract eosio contracts/eosio.bios eosio.bios.wast eosio.bios.abi
ecmd set contract eosio contracts/eosio.bios eosio.bios.wasm eosio.bios.abi

# Create required system accounts
ecmd create key
Expand Down
12 changes: 6 additions & 6 deletions tests/Cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -726,10 +726,10 @@ def bootstrap(totalNodes, prodCount, biosHost, biosPort, dontKill=False, onlyBio

contract="eosio.bios"
contractDir="contracts/%s" % (contract)
wastFile="%s.wast" % (contract)
wasmFile="%s.wasm" % (contract)
abiFile="%s.abi" % (contract)
Utils.Print("Publish %s contract" % (contract))
trans=biosNode.publishContract(eosioAccount.name, contractDir, wastFile, abiFile, waitForTransBlock=True)
trans=biosNode.publishContract(eosioAccount.name, contractDir, wasmFile, abiFile, waitForTransBlock=True)
if trans is None:
Utils.Print("ERROR: Failed to publish contract %s." % (contract))
return None
Expand Down Expand Up @@ -850,10 +850,10 @@ def bootstrap(totalNodes, prodCount, biosHost, biosPort, dontKill=False, onlyBio

contract="eosio.token"
contractDir="contracts/%s" % (contract)
wastFile="%s.wast" % (contract)
wasmFile="%s.wasm" % (contract)
abiFile="%s.abi" % (contract)
Utils.Print("Publish %s contract" % (contract))
trans=biosNode.publishContract(eosioTokenAccount.name, contractDir, wastFile, abiFile, waitForTransBlock=True)
trans=biosNode.publishContract(eosioTokenAccount.name, contractDir, wasmFile, abiFile, waitForTransBlock=True)
if trans is None:
Utils.Print("ERROR: Failed to publish contract %s." % (contract))
return None
Expand Down Expand Up @@ -905,10 +905,10 @@ def bootstrap(totalNodes, prodCount, biosHost, biosPort, dontKill=False, onlyBio

contract="eosio.system"
contractDir="contracts/%s" % (contract)
wastFile="%s.wast" % (contract)
wasmFile="%s.wasm" % (contract)
abiFile="%s.abi" % (contract)
Utils.Print("Publish %s contract" % (contract))
trans=biosNode.publishContract(eosioAccount.name, contractDir, wastFile, abiFile, waitForTransBlock=True)
trans=biosNode.publishContract(eosioAccount.name, contractDir, wasmFile, abiFile, waitForTransBlock=True)
if trans is None:
Utils.Print("ERROR: Failed to publish contract %s." % (contract))
return None
Expand Down
4 changes: 2 additions & 2 deletions tests/Node.py
Original file line number Diff line number Diff line change
Expand Up @@ -757,9 +757,9 @@ def getAccountCodeHash(self, account):
return None

# publish contract and return transaction as json object
def publishContract(self, account, contractDir, wastFile, abiFile, waitForTransBlock=False, shouldFail=False):
def publishContract(self, account, contractDir, wasmFile, abiFile, waitForTransBlock=False, shouldFail=False):
cmd="%s %s -v set contract -j %s %s" % (Utils.EosClientPath, self.endpointArgs, account, contractDir)
cmd += "" if wastFile is None else (" "+ wastFile)
cmd += "" if wasmFile is None else (" "+ wasmFile)
cmd += "" if abiFile is None else (" " + abiFile)
if Utils.Debug: Utils.Print("cmd: %s" % (cmd))
trans=None
Expand Down
4 changes: 2 additions & 2 deletions tests/consensus-validation-malicious-producers.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,10 +288,10 @@ def myTest(transWillEnterBlock):
error("Failed to create account %s" % (currencyAccount.name))
return False

wastFile="currency.wast"
wasmFile="currency.wasm"
abiFile="currency.abi"
Print("Publish contract")
trans=node.publishContract(currencyAccount.name, wastFile, abiFile, waitForTransBlock=True)
trans=node.publishContract(currencyAccount.name, wasmFile, abiFile, waitForTransBlock=True)
if trans is None:
error("Failed to publish contract.")
return False
Expand Down
12 changes: 6 additions & 6 deletions tests/nodeos_run_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,10 +319,10 @@
errorExit("FAILURE - get code currency1111 failed", raw=True)

contractDir="contracts/eosio.token"
wastFile="eosio.token.wast"
wasmFile="eosio.token.wasm"
abiFile="eosio.token.abi"
Print("Publish contract")
trans=node.publishContract(currencyAccount.name, contractDir, wastFile, abiFile, waitForTransBlock=True)
trans=node.publishContract(currencyAccount.name, contractDir, wasmFile, abiFile, waitForTransBlock=True)
if trans is None:
cmdError("%s set contract currency1111" % (ClientName))
errorExit("Failed to publish contract.")
Expand Down Expand Up @@ -605,20 +605,20 @@
Print("upload exchange contract")

contractDir="contracts/exchange"
wastFile="exchange.wast"
wasmFile="exchange.wasm"
abiFile="exchange.abi"
Print("Publish exchange contract")
trans=node.publishContract(exchangeAccount.name, contractDir, wastFile, abiFile, waitForTransBlock=True)
trans=node.publishContract(exchangeAccount.name, contractDir, wasmFile, abiFile, waitForTransBlock=True)
if trans is None:
cmdError("%s set contract exchange" % (ClientName))
errorExit("Failed to publish contract.")

contractDir="contracts/simpledb"
wastFile="simpledb.wast"
wasmFile="simpledb.wasm"
abiFile="simpledb.abi"
Print("Setting simpledb contract without simpledb account was causing core dump in %s." % (ClientName))
Print("Verify %s generates an error, but does not core dump." % (ClientName))
retMap=node.publishContract("simpledb", contractDir, wastFile, abiFile, shouldFail=True)
retMap=node.publishContract("simpledb", contractDir, wasmFile, abiFile, shouldFail=True)
if retMap is None:
errorExit("Failed to publish, but should have returned a details map")
if retMap["returncode"] == 0 or retMap["returncode"] == 139: # 139 SIGSEGV
Expand Down
4 changes: 2 additions & 2 deletions tests/nodeos_under_min_avail_ram.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,10 @@ def setName(self, num):
trans=nodes[0].delegatebw(contractAccount, 1000000.0000, 88000000.0000, exitOnError=True)

contractDir="contracts/integration_test"
wastFile="integration_test.wast"
wasmFile="integration_test.wasm"
abiFile="integration_test.abi"
Print("Publish contract")
trans=nodes[0].publishContract(contractAccount.name, contractDir, wastFile, abiFile, waitForTransBlock=True)
trans=nodes[0].publishContract(contractAccount.name, contractDir, wasmFile, abiFile, waitForTransBlock=True)
if trans is None:
cmdError("%s set contract %s" % (ClientName, contractAccount.name))
errorExit("Failed to publish contract.")
Expand Down
6 changes: 3 additions & 3 deletions tests/p2p_network_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,10 @@
Print("host %s: %s" % (hosts[i], trans))


wastFile="eosio.system.wast"
wasmFile="eosio.system.wasm"
abiFile="eosio.system.abi"
Print("\nPush system contract %s %s" % (wastFile, abiFile))
trans=node0.publishContract(eosio.name, wastFile, abiFile, waitForTransBlock=True)
Print("\nPush system contract %s %s" % (wasmFile, abiFile))
trans=node0.publishContract(eosio.name, wasmFile, abiFile, waitForTransBlock=True)
if trans is None:
Utils.errorExit("Failed to publish eosio.system.")
else:
Expand Down