From ff62b3b35d0f83fefa81d5a90ea772c16907bb2a Mon Sep 17 00:00:00 2001 From: Stephen Chen <20940639+stephenctw@users.noreply.github.com> Date: Mon, 14 Oct 2024 13:02:46 +0800 Subject: [PATCH] chore(client-lua): improve code quality --- prt/client-lua/computation/commitment.lua | 4 +--- prt/tests/compute/prt_compute.lua | 9 +++------ prt/tests/compute/runners/helpers/fake_commitment.lua | 4 +--- prt/tests/compute/runners/rust_hero_runner.lua | 6 +++--- 4 files changed, 8 insertions(+), 15 deletions(-) diff --git a/prt/client-lua/computation/commitment.lua b/prt/client-lua/computation/commitment.lua index 5155a86d..da322ed6 100644 --- a/prt/client-lua/computation/commitment.lua +++ b/prt/client-lua/computation/commitment.lua @@ -109,9 +109,7 @@ CommitmentBuilder.__index = CommitmentBuilder function CommitmentBuilder:new(machine_path, snapshot_dir, root_commitment) -- receive honest root commitment from main process - local commitments = {} - commitments[0] = {} - commitments[0][0] = root_commitment + local commitments = { [0] = { [0] = root_commitment } } local c = { commitments = commitments, diff --git a/prt/tests/compute/prt_compute.lua b/prt/tests/compute/prt_compute.lua index e42b589f..94bd9b61 100755 --- a/prt/tests/compute/prt_compute.lua +++ b/prt/tests/compute/prt_compute.lua @@ -37,12 +37,9 @@ local function write_json_file(leafs, root_tournament) local flat = require "utils.flat" local json = require "utils.json" local file_path = string.format("/dispute_data/%s/inputs_and_leafs.json", root_tournament) - local file = io.open(file_path, "w") - - if file then - file:write(json.encode(flat.flatten(inputs_and_leafs).flat_object)) - file:close() - end + local file = assert(io.open(file_path, "w")) + file:write(json.encode(flat.flatten(inputs_and_leafs).flat_object)) + assert(file:close()) end -- Function to setup players diff --git a/prt/tests/compute/runners/helpers/fake_commitment.lua b/prt/tests/compute/runners/helpers/fake_commitment.lua index 5d3877da..24b583a0 100644 --- a/prt/tests/compute/runners/helpers/fake_commitment.lua +++ b/prt/tests/compute/runners/helpers/fake_commitment.lua @@ -111,9 +111,7 @@ end function FakeCommitmentBuilder:new(machine_path, root_commitment, snapshot_dir) -- receive honest root commitment from main process - local commitments = {} - commitments[0] = {} - commitments[0][0] = root_commitment + local commitments = { [0] = { [0] = root_commitment } } local c = { fake_index = false, diff --git a/prt/tests/compute/runners/rust_hero_runner.lua b/prt/tests/compute/runners/rust_hero_runner.lua index 6ec1fc0f..43ff5207 100644 --- a/prt/tests/compute/runners/rust_hero_runner.lua +++ b/prt/tests/compute/runners/rust_hero_runner.lua @@ -38,10 +38,10 @@ local function create_react_once_runner(player_id, machine_path) assert(reader, "Failed to open process for Rust compute: " .. rust_compute_cmd) local hero_pid = tonumber(reader:read()) - local output = reader:read() - while output do + while true do + local output = reader:read() + if not output then break end helper.log_color(player_id, output) - output = reader:read() end local success, _, code = reader:close()