Skip to content

Commit

Permalink
chore: resolve PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenctw committed Sep 19, 2024
1 parent 005b041 commit 73e9f46
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 16 deletions.
5 changes: 4 additions & 1 deletion prt/tests/compute/blockchain/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ end
local deploy_cmd = [[sh -c "cd ../../contracts && ./deploy_anvil.sh"]]
local function deploy_contracts()
local reader = io.popen(deploy_cmd)
return assert(reader):read()
assert(reader, "Failed to open process for deploy command: " .. deploy_cmd)
local output = reader:read("*a")
local success = reader:close()
assert(success, string.format("Deploy command failed:\n%s", output))
end

return { advance_time = advance_time, deploy_contracts = deploy_contracts }
31 changes: 17 additions & 14 deletions prt/tests/compute/prt_compute.lua
Original file line number Diff line number Diff line change
Expand Up @@ -74,27 +74,30 @@ local player_coroutines = setup_players(use_lua_node, extra_data, contract_addre
local blockchain_node = Blockchain:new()
time.sleep(NODE_DELAY)

local pid = blockchain_utils.deploy_contracts()
blockchain_utils.deploy_contracts()
time.sleep(NODE_DELAY)

while true do
local idle = true
for i = #player_coroutines, 1, -1 do
local c = player_coroutines[i]
local success, ret = coroutine.resume(c)
local status = coroutine.status(c)

if status == "dead" then
table.remove(player_coroutines, i)
end
if not success then
print(string.format("coroutine %d fail to resume with error: %s", i, ret))
elseif ret then
idle = idle and ret.idle
local has_live_coroutine = false
for i, c in ipairs(player_coroutines) do
if c then
local success, ret = coroutine.resume(c)
local status = coroutine.status(c)

if status == "dead" then
player_coroutines[i] = nil
end
if not success then
print(string.format("coroutine %d fail to resume with error: %s", i, ret))
elseif ret then
has_live_coroutine = true
idle = idle and ret.idle
end
end
end

if #player_coroutines == 0 then
if not has_live_coroutine then
print("No active players, ending program...")
break
end
Expand Down
2 changes: 1 addition & 1 deletion prt/tests/compute/utils/scoped_require.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ local function new_scoped_require(env)

local chunk, err, result
if module_type == "lua" then
chunk, err = loadfile(path, "t", new_env)
chunk, err = loadfile(path, "bt", new_env)
elseif module_type == "clib" then
chunk, err = custom_require_c(path, name)
end
Expand Down

0 comments on commit 73e9f46

Please sign in to comment.