Skip to content

Commit

Permalink
fix(gh): rename workflows and set working directory
Browse files Browse the repository at this point in the history
  • Loading branch information
Atticus committed Jun 10, 2024
1 parent 7e996c7 commit b1d30c4
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ant.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Test / Deploy
name: Arweave Name Token

on: [push, workflow_dispatch]

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/registry.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Test / Deploy
name: ArNS Registry

on: [push, workflow_dispatch]

Expand Down
6 changes: 3 additions & 3 deletions ant/spec/ant_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
7 changes: 3 additions & 4 deletions ant/src/constants.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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}$
]]
Expand Down
4 changes: 2 additions & 2 deletions ant/src/controllers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions ant/src/initialize.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions ant/src/process.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
8 changes: 4 additions & 4 deletions ant/src/records.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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

Expand Down
7 changes: 3 additions & 4 deletions ant/src/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit b1d30c4

Please sign in to comment.