Skip to content

Commit

Permalink
fix(records): remove change on records return sorted - will be furthe…
Browse files Browse the repository at this point in the history
…r considered
  • Loading branch information
atticusofsparta committed Nov 22, 2024
1 parent b2476f4 commit 74060a5
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 58 deletions.
1 change: 0 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

- Refactored handlers to use a util that codifies responses on calls.
- Added documentation with luadoc types for improved linting.
- Records are now returned as an alphabetically sorted array of [{name, transactionId, ttlSeconds}] with the '@' record being the first.
- Removed `Evolve` handler and SourceCodeTxId from state and state responses.

### Fixed
Expand Down
7 changes: 1 addition & 6 deletions spec/ant_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,13 @@ describe("Arweave Name Token", function()
end)

it("gets all records", function()
_G.Records["zed"] = {
transactionId = string.rep("1", 43),
ttlSeconds = 3600,
}
_G.Records["@"] = {
transactionId = string.rep("1", 43),
ttlSeconds = 3600,
}
local recordEntries = records.getRecords()

assert.are.same(recordEntries[1].name, "@")
assert.are.same(recordEntries[#recordEntries].name, "zed")
assert(recordEntries["@"])
end)

it("removes a record", function()
Expand Down
23 changes: 2 additions & 21 deletions src/common/records.lua
Original file line number Diff line number Diff line change
Expand Up @@ -51,34 +51,15 @@ end

--- Get all records from the ANT
---@alias RecordEntry {
--- name: string,
--- transactionId: string,
--- ttlSeconds: integer,
---}
---@return table<RecordEntry> The sorted records of the ANT
---@return table<string, RecordEntry> The sorted records of the ANT
function records.getRecords()
local antRecords = utils.deepCopy(Records)
assert(antRecords, "Failed to copy Records")

---@type table<RecordEntry>
local recordEntries = {}

for undername, record in pairs(antRecords) do
local entry = record
entry.name = undername
table.insert(recordEntries, entry)
end
table.sort(recordEntries, function(a, b)
if a.name == "@" then
return true
end
if b.name == "@" then
return false
end
return a.name < b.name
end)

return recordEntries
return antRecords
end

return records
30 changes: 0 additions & 30 deletions test/records.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,6 @@ describe('aos Records', async () => {
);
}

async function setRecord(
{ name, ttl = 3600, transactionId = STUB_ADDRESS },
mem,
) {
return handle(
{
Tags: [
{ name: 'Action', value: 'Set-Record' },
{ name: 'Sub-Domain', value: name },
{ name: 'TTL-Seconds', value: ttl },
{ name: 'Transaction-Id', value: transactionId },
],
},
mem,
);
}

async function getRecords(mem) {
const res = await handle(
{
Expand All @@ -51,21 +34,8 @@ describe('aos Records', async () => {
}

it('should get the records of the ant', async () => {
const setRecordRes = await setRecord({ name: 'test-1' });
const setRecordRes2 = await setRecord(
{ name: 'test-2' },
setRecordRes.Memory,
);
const setRecordRes3 = await setRecord(
{ name: 'test-3' },
setRecordRes2.Memory,
);

const records = await getRecords(setRecordRes3.Memory);
assert(records);

assert.strictEqual(records[0].name, '@');
assert.strictEqual(records.at(-1).name, 'test-3');
});

it('should get a singular record of the ant', async () => {
Expand Down

0 comments on commit 74060a5

Please sign in to comment.