Skip to content

Commit

Permalink
fix(PE-6981): disallow names that look like wallet addresses (#155)
Browse files Browse the repository at this point in the history
  • Loading branch information
dtfiedler authored Oct 30, 2024
2 parents 87f5bc2 + ea0532b commit 65c97f5
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 12 deletions.
36 changes: 27 additions & 9 deletions spec/arns_spec.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
local testProcessId = "NdZ3YRwMB2AMwwFYjKn1g88Y9nRybTo0qhS1ORq_E7g"
local constants = require("constants")
local arns = require("arns")
local balances = require("balances")
local demand = require("demand")
local utils = require("utils")
local Auction = require("auctions")
Expand Down Expand Up @@ -58,9 +57,9 @@ describe("arns", function()
startTimestamp = 0,
endTimestamp = timestamp + constants.oneYearMs * 1,
},
}, arns.getRecords())
assert.are.equal(_G.Balances[testAddress], startBalance - 600000000)
assert.are.equal(balances.getBalance(_G.ao.id), 600000000)
}, _G.NameRegistry.records)
assert.are.equal(startBalance - 600000000, _G.Balances[testAddress])
assert.are.equal(600000000, _G.Balances[_G.ao.id])
assert.are.equal(demandBefore + 600000000, demand.getCurrentPeriodRevenue())
assert.are.equal(purchasesBefore + 1, demand.getCurrentPeriodPurchases())
end
Expand Down Expand Up @@ -147,7 +146,7 @@ describe("arns", function()
pcall(arns.buyRecord, "test-name", "lease", 1, testAddress, timestamp, testProcessId)
assert.is_false(status)
assert.match("Name is reserved", result)
assert.are.same({}, arns.getRecords())
assert.are.same({}, _G.NameRegistry.records)
assert.are.same(reservedName, _G.NameRegistry.reserved["test-name"])
end)

Expand All @@ -170,7 +169,7 @@ describe("arns", function()
}
assert.is_true(status)
assert.are.same(expectation, result.record)
assert.are.same({ ["test-name"] = expectation }, arns.getRecords())
assert.are.same({ ["test-name"] = expectation }, _G.NameRegistry.records)

assert.is.equal(
_G.Balances[testAddress],
Expand All @@ -194,7 +193,26 @@ describe("arns", function()
pcall(arns.buyRecord, "test-name", "lease", 1, testAddress, timestamp, testProcessId)
assert.is_false(status)
assert.match("Insufficient balance", result)
assert.are.same({}, arns.getRecords())
assert.are.same({}, _G.NameRegistry.records)
end)

it("should throw an error if the name is in auction [" .. addressType .. "]", function()
_G.NameRegistry.auctions["test-name"] = {
endTimestamp = timestamp + constants.oneYearMs,
}
local status, result =
pcall(arns.buyRecord, "test-name", "lease", 1, testAddress, timestamp, testProcessId)
assert.is_false(status)
assert.match("Name is in auction", result)
assert.are.same({}, _G.NameRegistry.records)
end)

it("should throw an error if the name looks like a wallet address [" .. addressType .. "]", function()
local status, result =
pcall(arns.buyRecord, testAddress, "lease", 1, testAddress, timestamp, testProcessId)
assert.is_false(status)
assert.match("Name cannot be a wallet address", result)
assert.are.same({}, _G.NameRegistry.records)
end)
end)

Expand Down Expand Up @@ -258,7 +276,7 @@ describe("arns", function()
}
assert.is_true(status)
assert.are.same(expectation, result.record)
assert.are.same({ ["test-name"] = expectation }, arns.getRecords())
assert.are.same({ ["test-name"] = expectation }, _G.NameRegistry.records)

assert.is.equal(
_G.Balances[testAddress],
Expand Down Expand Up @@ -368,7 +386,7 @@ describe("arns", function()
type = "lease",
undernameLimit = 10,
},
}, arns.getRecords())
}, _G.NameRegistry.records)

assert.is.equal(
_G.Balances[testAddress],
Expand Down
4 changes: 4 additions & 0 deletions src/arns.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ function arns.buyRecord(name, purchaseType, years, from, timestamp, processId)
error("Name is reserved")
end

if arns.getAuction(name) then
error("Name is in auction")
end

local newRecord = {
processId = processId,
startTimestamp = timestamp,
Expand Down
9 changes: 6 additions & 3 deletions src/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,10 @@ addEventingHandler(ActionMap.Transfer, utils.hasMatchingTag("Action", ActionMap.
local shouldContinue = eventingPcall(msg.ioEvent, function(error)
ao.send({
Target = msg.From,
Tags = { Action = ActionMap.Transfer .. "-Notice", Error = "Transfer-Error" },
Tags = {
Action = "Invalid-" .. ActionMap.Transfer .. "-Notice",
Error = "Bad-Input",
},
Data = tostring(error),
})
end, checkAssertions)
Expand All @@ -378,7 +381,7 @@ addEventingHandler(ActionMap.Transfer, utils.hasMatchingTag("Action", ActionMap.
local shouldContinue2, result = eventingPcall(msg.ioEvent, function(error)
ao.send({
Target = msg.From,
Tags = { Action = ActionMap.Transfer .. "-Notice", Error = "Transfer-Error" },
Tags = { Action = "Invalid-" .. ActionMap.Transfer .. "-Notice", Error = "Transfer-Error" },
Data = tostring(error),
})
end, balances.transfer, recipient, from, quantity)
Expand Down Expand Up @@ -735,7 +738,7 @@ addEventingHandler(ActionMap.BuyRecord, utils.hasMatchingTag("Action", ActionMap
ao.send({
Target = msg.From,
Tags = {
Action = ActionMap.BuyRecord .. "-Notice",
Action = "Invalid-" .. ActionMap.BuyRecord .. "-Notice",
Error = "Invalid-" .. ActionMap.BuyRecord,
},
Data = tostring(error),
Expand Down

0 comments on commit 65c97f5

Please sign in to comment.