Skip to content

Commit

Permalink
Merge branch 'develop' into PE-6910-primary-names
Browse files Browse the repository at this point in the history
  • Loading branch information
dtfiedler authored Nov 19, 2024
2 parents a99080a + d359e4a commit 688b9f9
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 95 deletions.
1 change: 0 additions & 1 deletion .luacheckrc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ globals = {
"Description",
"Keywords",
"Denomination",
"SourceCodeTxId",
"Initialized"
}
max_line_length = 185
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ 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
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ Retrieves the entire state of the ANT, which includes:
- Denomination
- TotalSupply
- Initialized
- Source-Code-TX-ID

| Tag Name | Type | Pattern | Required | Description |
| -------- | ------ | ------- | -------- | --------------------------------- |
Expand Down
42 changes: 1 addition & 41 deletions src/common/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ function ant.init()
local json = require(".common.json")
local utils = require(".common.utils")
local notices = require(".common.notices")
local camel = utils.camelCase
local createActionHandler = utils.createActionHandler

-- spec modules
Expand Down Expand Up @@ -49,9 +48,6 @@ function ant.init()
---@alias Initialized boolean
---@description Whether the ANT has been initialized with the
Initialized = Initialized or false
---@alias SourceCodeTxId string
---@description The Arweave ID of the lua source the ANT currently uses. INSERT placeholder used by build script to inject the appropriate ID
SourceCodeTxId = SourceCodeTxId or "__INSERT_SOURCE_CODE_ID__"
---@alias AntRegistryId string
---@description The Arweave ID of the ANT Registry contract that this ANT is registered with
AntRegistryId = AntRegistryId or ao.env.Process.Tags["ANT-Registry-Id"] or nil
Expand Down Expand Up @@ -139,7 +135,6 @@ function ant.init()
Denomination = tostring(Denomination),
Owner = Owner,
Handlers = utils.getHandlerNames(Handlers),
["Source-Code-TX-ID"] = SourceCodeTxId,
}
ao.send({
Target = msg.From,
Expand Down Expand Up @@ -277,7 +272,7 @@ function ant.init()
["Process-Id"] = antProcessIdToReassign,
})
end)

createActionHandler(ActionMap.ApproveName, function(msg)
--- NOTE: this could be modified to allow specific users/controllers to create claims
utils.validateOwner(msg.From)
Expand Down Expand Up @@ -317,41 +312,6 @@ function ant.init()
Names = json.encode(names),
})
end)

Handlers.prepend(
camel(ActionMap.Evolve),
Handlers.utils.continue(utils.hasMatchingTag("Action", "Eval")),
function(msg)
local srcCodeTxId = msg.Tags["Source-Code-TX-ID"]
if not srcCodeTxId then
return
end

if Owner ~= msg.From then
ao.send({
Target = msg.From,
Action = "Invalid-Evolve-Notice",
Error = "Evolve-Error",
["Message-Id"] = msg.Id,
Data = "Only the Owner [" .. Owner or "no owner set" .. "] can call Evolve",
})
return
end

local srcCodeTxIdStatus = pcall(utils.validateArweaveId, srcCodeTxId)
if not srcCodeTxIdStatus then
ao.send({
Target = msg.From,
Action = "Invalid-Evolve-Notice",
Error = "Evolve-Error",
["Message-Id"] = msg.Id,
Data = "Source-Code-TX-ID is required",
})
return
end
SourceCodeTxId = srcCodeTxId
end
)
end

return ant
1 change: 0 additions & 1 deletion src/common/notices.lua
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ function notices.notifyState(msg, target)
Denomination = Denomination,
TotalSupply = TotalSupply,
Initialized = Initialized,
["Source-Code-TX-ID"] = SourceCodeTxId,
}

ao.send(notices.addForwardedTags(msg, {
Expand Down
1 change: 0 additions & 1 deletion src/common/types.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,5 @@
--- Denomination: integer,
--- TotalSupply: integer,
--- Initialized: boolean,
--- ["Source-Code-TX-ID"|SourceCodeTxId]: string,
--- Records: table<string, Record>,
---}
2 changes: 1 addition & 1 deletion src/common/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ function utils.getState()
Denomination = Denomination,
TotalSupply = TotalSupply,
Initialized = Initialized,
["Source-Code-TX-ID"] = SourceCodeTxId,
}
end

Expand All @@ -169,6 +168,7 @@ end
--- @return string[]
function utils.getHandlerNames(handlers)
local names = {}

for _, handler in ipairs(handlers.list) do
table.insert(names, handler.name)
end
Expand Down
52 changes: 35 additions & 17 deletions test/evolve.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,8 @@ describe('aos Evolve', async () => {
}

it('should evolve the ant and retain eval ability', async () => {
const srcCodeTxIdStub = 'new-source-code-tx-id-'.padEnd(43, '-1');
const evolveResult = await handle({
Tags: [
{ name: 'Action', value: 'Eval' },
{ name: 'Source-Code-TX-ID', value: srcCodeTxIdStub },
],
Tags: [{ name: 'Action', value: 'Eval' }],
Data: BUNDLED_AOS_ANT_LUA,
});

Expand All @@ -40,7 +36,6 @@ describe('aos Evolve', async () => {
);
const state = JSON.parse(result.Messages[0].Data);
assert(state);
assert(state['Source-Code-TX-ID'] === srcCodeTxIdStub);

const evalResult = await handle(
{
Expand All @@ -49,9 +44,8 @@ describe('aos Evolve', async () => {
},
evolveResult.Memory,
);

assert(evalResult.Output.data.output);
assert(evalResult.Output.data.output.includes('evolve'));
assert(evalResult.Output.data.output.includes('info'));
});

it('should not evolve the ant', async () => {
Expand All @@ -60,7 +54,7 @@ describe('aos Evolve', async () => {
{ name: 'Action', value: 'Eval' },
// omit src code id
],
Data: BUNDLED_AOS_ANT_LUA,
Data: "Foo = 'bar'",
});

const result = await handle(
Expand All @@ -72,17 +66,27 @@ describe('aos Evolve', async () => {

const state = JSON.parse(result.Messages[0].Data);
assert(state);
assert(state['Source-Code-TX-ID'] === '__INSERT_SOURCE_CODE_ID__');

const fooRes = await handle(
{
Tags: [
{
name: 'Action',
value: 'Eval',
},
],
Data: 'print(Foo)',
},
result.Memory,
);

assert(!fooRes.Output.output?.includes('bar'));
});

it('should not evolve the ant with correct tags called by a non owner', async () => {
const srcCodeTxIdStub = ''.padEnd(43, '123-test');
const evolveResult = await handle({
Tags: [
{ name: 'Action', value: 'Eval' },
{ name: 'Source-Code-TX-ID', value: srcCodeTxIdStub },
],
Data: BUNDLED_AOS_ANT_LUA,
Tags: [{ name: 'Action', value: 'Eval' }],
Data: "Foo = 'bar'",
Owner: 'im-not-the-owner-'.padEnd(43, 'a'),
});

Expand All @@ -95,6 +99,20 @@ describe('aos Evolve', async () => {

const state = JSON.parse(result.Messages[0].Data);
assert(state);
assert(state['Source-Code-TX-ID'] === '__INSERT_SOURCE_CODE_ID__');

const fooRes = await handle(
{
Tags: [
{
name: 'Action',
value: 'Eval',
},
],
Data: 'print(Foo)',
},
result.Memory,
);

assert(!fooRes.Output?.output?.includes('bar'));
});
});
3 changes: 1 addition & 2 deletions test/info.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@ describe('aos Info', async () => {
assert(processInfo.Owner);
assert(processInfo.Handlers);
assert.deepStrictEqual(processInfo.Handlers, [
'evolve',
'_eval',
'_default',
'_default',
'transfer',
'balance',
'balances',
Expand Down
41 changes: 11 additions & 30 deletions tools/publish-aos.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,22 @@ import version from '../version.mjs';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

const srcCodeTxIdPlaceholder = '__INSERT_SOURCE_CODE_ID__';

const bundledLua = fs.readFileSync(
path.join(__dirname, '../dist/aos-bundled.lua'),
'utf-8',
);

const dryRun =
process.argv.includes('--dry-run') || process.env.DRY_RUN === 'true';

const walletPath = process.argv.includes('--wallet-file')
? process.argv[process.argv.indexOf('--wallet-file') + 1]
: process.env.WALLET_PATH || path.join(__dirname, 'key.json');

const jwk = process.env.WALLET
? JSON.parse(process.env.WALLET)
: JSON.parse(fs.readFileSync(walletPath, 'utf-8'));

const signer = new ArweaveSigner(jwk);
const turbo = TurboFactory.authenticated({ signer });
const publishingTags = Object.entries({
Expand All @@ -36,38 +37,18 @@ const publishingTags = Object.entries({
.filter(([_, value]) => value !== undefined)
.map(([name, value]) => ({ name, value }));

/**
* NOTE: with the current use of SOURCE-CODE-TX-ID, we have to publish the generate the source code twice
* to get the tx id into the bundled file. In the future, we should move to using incremental
* bundle versions to avoid this issue.
*/
const data1 = createData(bundledLua, signer, {
const data = createData(bundledLua, signer, {
tags: publishingTags,
});
await data1.sign(signer);

console.log('Generated source code data item with id: ' + data1.id);
// replace placeholder with actual tx id
const bundledLuaWithTxId = bundledLua.replace(srcCodeTxIdPlaceholder, data1.id);

const data2 = createData(bundledLuaWithTxId, signer, {
tags: [...publishingTags, { name: 'Original-Tx-Id', value: data1.id }],
});
await data2.sign(signer);
await data.sign(signer);

console.log('Generated bundled data item with id: ' + data2.id);
console.log('Generated source code data item with id: ' + data.id);

if (!dryRun) {
console.log('Publishing ANT Source code to Arweave...');
await Promise.all([
turbo.uploadSignedDataItem({
dataItemSizeFactory: () => data1.getRaw().byteLength,
dataItemStreamFactory: () => data1.getRaw(),
}),
turbo.uploadSignedDataItem({
dataItemSizeFactory: () => data2.getRaw().byteLength,
dataItemStreamFactory: () => data2.getRaw(),
}),
]);
await turbo.uploadSignedDataItem({
dataItemSizeFactory: () => data.getRaw().byteLength,
dataItemStreamFactory: () => data.getRaw(),
});
}
console.log('Tagged source code tx id: ' + data1.id);
console.log('Tagged source code tx id: ' + data.id);

0 comments on commit 688b9f9

Please sign in to comment.