diff --git a/CHANGELOG.md b/CHANGELOG.md index 609eea5..941f68c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/spec/ant_spec.lua b/spec/ant_spec.lua index 7ca7b00..8eb7eac 100644 --- a/spec/ant_spec.lua +++ b/spec/ant_spec.lua @@ -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() diff --git a/src/common/records.lua b/src/common/records.lua index 08e519b..2e1ff3d 100644 --- a/src/common/records.lua +++ b/src/common/records.lua @@ -51,34 +51,15 @@ end --- Get all records from the ANT ---@alias RecordEntry { ---- name: string, --- transactionId: string, --- ttlSeconds: integer, ---} ----@return table The sorted records of the ANT +---@return table The sorted records of the ANT function records.getRecords() local antRecords = utils.deepCopy(Records) assert(antRecords, "Failed to copy Records") - ---@type table - 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 diff --git a/test/records.test.mjs b/test/records.test.mjs index d34cb39..a73d90b 100644 --- a/test/records.test.mjs +++ b/test/records.test.mjs @@ -52,20 +52,9 @@ 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); + const records = await getRecords(setRecordRes); 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 () => { @@ -100,7 +89,7 @@ describe('aos Records', async () => { ); const records = JSON.parse(recordsResult.Messages[0].Data); - const record = records[0]; + const record = records['@']; assert(record.transactionId === ''.padEnd(43, '3')); assert(record.ttlSeconds === 3600); }); @@ -154,7 +143,7 @@ describe('aos Records', async () => { ); const records = JSON.parse(recordsResult.Messages[0].Data); - const record = records.find((r) => r.name == 'timmy'); + const record = records['timmy']; assert(record.transactionId === ''.padEnd(43, '3')); assert(record.ttlSeconds === 3600); });