From b1d30c4712e847b35d0a94a4c6fdf29b4f41596b Mon Sep 17 00:00:00 2001 From: Atticus Date: Mon, 10 Jun 2024 10:16:20 -0600 Subject: [PATCH] fix(gh): rename workflows and set working directory --- .github/workflows/ant.yaml | 2 +- .github/workflows/registry.yaml | 2 +- ant/spec/ant_spec.lua | 6 +++--- ant/src/constants.lua | 7 +++---- ant/src/controllers.lua | 4 ++-- ant/src/initialize.lua | 12 ++++++------ ant/src/process.lua | 2 -- ant/src/records.lua | 8 ++++---- ant/src/utils.lua | 7 +++---- 9 files changed, 23 insertions(+), 27 deletions(-) diff --git a/.github/workflows/ant.yaml b/.github/workflows/ant.yaml index f1e33ec5..b676f31a 100644 --- a/.github/workflows/ant.yaml +++ b/.github/workflows/ant.yaml @@ -1,4 +1,4 @@ -name: Test / Deploy +name: Arweave Name Token on: [push, workflow_dispatch] diff --git a/.github/workflows/registry.yaml b/.github/workflows/registry.yaml index 14da5ba4..e70f892d 100644 --- a/.github/workflows/registry.yaml +++ b/.github/workflows/registry.yaml @@ -1,4 +1,4 @@ -name: Test / Deploy +name: ArNS Registry on: [push, workflow_dispatch] diff --git a/ant/spec/ant_spec.lua b/ant/spec/ant_spec.lua index cdf0bb1c..4f0883ea 100644 --- a/ant/spec/ant_spec.lua +++ b/ant/spec/ant_spec.lua @@ -79,10 +79,10 @@ describe("Arweave Name Token", function() local controllerToRemove = fake_address controllers.removeController(fake_address) -- happy path - local hasController = nil + local hasController = false for _, controller in ipairs(_G.Controllers) do if controller == controllerToRemove then - hasController = false + hasController = true end end assert.is_false(hasController) @@ -91,7 +91,7 @@ describe("Arweave Name Token", function() it("sets a record", function() local name, transactionId, ttlSeconds = "@", fake_address, 900 records.setRecord(name, transactionId, ttlSeconds) -- happy path - + print("Records", _G.Records) assert.are.same(_G.Records["@"].transactionId, fake_address) assert.are.same(_G.Records["@"].ttlSeconds, 900) end) diff --git a/ant/src/constants.lua b/ant/src/constants.lua index 8512e84d..43591c45 100644 --- a/ant/src/constants.lua +++ b/ant/src/constants.lua @@ -2,10 +2,9 @@ local constants = {} constants.MAX_UNDERNAME_LENGTH = 61 constants.UNDERNAME_DOES_NOT_EXIST_MESSAGE = "Name does not exist in the ANT!" -constants.UNDERNAME_REGEXP = [[ - ^[a-zA-Z0-9][a-zA-Z0-9-_]{0, - ]] .. constants.MAX_UNDERNAME_LENGTH - 2 .. [[}[a-zA-Z0-9]|[a-zA-Z0-9]{1}? -]] +constants.UNDERNAME_REGEXP = "^(?:@|[a-zA-Z0-9][a-zA-Z0-9-_]{0," + .. (constants.MAX_UNDERNAME_LENGTH - 2) + .. "}[a-zA-Z0-9])$" constants.ARWEAVE_ID_REGEXP = [[ ^[a-zA-Z0-9-_]{43}$ ]] diff --git a/ant/src/controllers.lua b/ant/src/controllers.lua index df42fa65..e7341531 100644 --- a/ant/src/controllers.lua +++ b/ant/src/controllers.lua @@ -9,7 +9,7 @@ function controllers.setController(controller) utils.validateArweaveId(controller) for _, c in ipairs(Controllers) do - assert(c == controller, "Controller already exists") + assert(c ~= controller, "Controller already exists") end table.insert(Controllers, controller) @@ -27,7 +27,7 @@ function controllers.removeController(controller) end end - assert(controllerExists == nil, "Controller does not exist") + assert(controllerExists ~= nil, "Controller does not exist") end function controllers.getControllers(msg) diff --git a/ant/src/initialize.lua b/ant/src/initialize.lua index 6744a345..6efa2280 100644 --- a/ant/src/initialize.lua +++ b/ant/src/initialize.lua @@ -9,24 +9,24 @@ function initialize.initialize(state) assert(type(ticker) == "string", "ticker must be a string") assert(type(balances) == "table", "balances must be a table") for k, v in pairs(balances) do - local idValidity, _ = pcall(utils.validateArweaveId, k) - assert(idValidity == false, "balances keys must be strings") + local idValidity, idRes = pcall(utils.validateArweaveId, k) + assert(idValidity ~= false, idRes) assert(type(v) == "number", "balances values must be numbers") end assert(type(controllers) == "table", "controllers must be a table") for _, v in ipairs(controllers) do local controllerValidity, _ = pcall(utils.validateArweaveId, v) - assert(controllerValidity == false, "controllers must be a list of arweave id's") + assert(controllerValidity ~= false, "controllers must be a list of arweave id's") end assert(type(records) == "table", "records must be a table") for k, v in pairs(records) do local nameValidity, _ = pcall(utils.validateUndername, k) - assert(nameValidity == false, "records keys must be strings") + assert(nameValidity ~= false, "records keys must be strings") assert(type(v) == "table", "records values must be tables") local idValidity, _ = pcall(utils.validateArweaveId, k) - assert(idValidity == false, "records transactionId must be a string") + assert(idValidity ~= false, "records transactionId must be a string") local ttlValidity, _ = pcall(utils.validateTTLSeconds, v.ttlSeconds) - assert(ttlValidity == false, "Invalid ttlSeconds on records") + assert(ttlValidity ~= false, "Invalid ttlSeconds on records") end Name = name diff --git a/ant/src/process.lua b/ant/src/process.lua index b9a4d3cc..c3144434 100644 --- a/ant/src/process.lua +++ b/ant/src/process.lua @@ -2,8 +2,6 @@ -- utils local json = require(".json") local utils = require(".utils") -local errors = require(".errors") -local constants = require(".constants") -- core modules local balances = require(".balances") diff --git a/ant/src/records.lua b/ant/src/records.lua index a7b99628..0eddd2c6 100644 --- a/ant/src/records.lua +++ b/ant/src/records.lua @@ -6,11 +6,11 @@ Records = Records or {} function records.setRecord(name, transactionId, ttlSeconds) local nameValidity, nameValidityError = pcall(utils.validateUndername, name) - assert(nameValidity == false, nameValidityError) + assert(nameValidity ~= false, nameValidityError) local targetIdValidity, targetValidityError = pcall(utils.validateArweaveId, transactionId) - assert(targetIdValidity == false, targetValidityError) + assert(targetIdValidity ~= false, targetValidityError) local ttlSecondsValidity, ttlValidityError = pcall(utils.validateTTLSeconds, ttlSeconds) - assert(ttlSecondsValidity == false, ttlValidityError) + assert(ttlSecondsValidity ~= false, ttlValidityError) Records[name] = { transactionId = transactionId, @@ -20,7 +20,7 @@ end function records.removeRecord(name) local nameValidity, nameValidityError = pcall(utils.validateUndername, name) - assert(nameValidity == false, nameValidityError) + assert(nameValidity ~= false, nameValidityError) Records[name] = nil end diff --git a/ant/src/utils.lua b/ant/src/utils.lua index f592593e..390fc979 100644 --- a/ant/src/utils.lua +++ b/ant/src/utils.lua @@ -11,19 +11,18 @@ end function utils.validateUndername(name) local valid = string.match(name, constants.UNDERNAME_REGEXP) == nil - - assert(valid == false, constants.UNDERNAME_DOES_NOT_EXIST_MESSAGE) + assert(valid ~= false, constants.UNDERNAME_DOES_NOT_EXIST_MESSAGE) end function utils.validateArweaveId(id) local valid = string.match(id, constants.ARWEAVE_ID_REGEXP) == nil - assert(valid == false, constants.INVALID_ARWEAVE_ID_MESSAGE) + assert(valid ~= false, constants.INVALID_ARWEAVE_ID_MESSAGE) end function utils.validateTTLSeconds(ttl) local valid = type(ttl) == "number" and ttl >= constants.MIN_TTL_SECONDS and ttl <= constants.MAX_TTL_SECONDS - return assert(valid == false, constants.INVALID_TTL_MESSAGE) + return assert(valid ~= false, constants.INVALID_TTL_MESSAGE) end function utils.validateOwner(caller)