-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(tools): update tooling for aos-ant
- Loading branch information
Atticus
committed
Jun 14, 2024
1 parent
d775991
commit d4dc843
Showing
14 changed files
with
313 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,3 +15,4 @@ luacov-html | |
*.gz | ||
luacov.stats.out | ||
process.wasm | ||
dist |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,21 @@ | ||
{ | ||
"type": "module", | ||
"scripts": { | ||
"build:module": "cd src && ao build && cd .. && yarn load-process", | ||
"publish:module": "cd src && ao publish process.wasm -w ../tools/key.json --tag=\"Memory-Limit\" --value=\"1-gb\" --tag=\"Compute-Limit\" --value=\"9000000000000\" && cd ..", | ||
"load:module": "node tools/load-module.cjs", | ||
"spawn:module": "node tools/spawn-module.cjs", | ||
"build:aos-ant": "node tools/bundle-aos-ant.cjs", | ||
"publish:aos-ant": "node tools/bundle-aos-ant.cjs && node tools/publish-aos-ant.cjs", | ||
"load:aos-ant": "node tools/bundle-aos-ant.cjs && node tools/load-aos-ant.cjs", | ||
"spawn:aos-ant": "node tools/spawn-aos-ant.cjs" | ||
}, | ||
"dependencies": { | ||
"@permaweb/ao-loader": "^0.0.35", | ||
"@permaweb/aoconnect": "^0.0.55", | ||
"arweave": "^1.15.1" | ||
}, | ||
"type": "module", | ||
"scripts": { | ||
"build": "cd src && ao build && cd .. && yarn load-process", | ||
"deploy": "cd src && ao publish process.wasm -w ../tools/key.json --tag=\"Memory-Limit\" --value=\"1-gb\" --tag=\"Compute-Limit\" --value=\"9000000000000\" && cd ..", | ||
"load-process": "node tools/load-process.cjs", | ||
"spawn": "node tools/spawn-ant.cjs", | ||
"publish:aos-ant": "node tools/bundle-aos-lua.cjs" | ||
"devDependencies": { | ||
"prettier": "^3.3.2" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
const path = require('path'); | ||
const fs = require('fs'); | ||
const { bundle } = require('./lua-bundler.cjs'); | ||
|
||
async function main() { | ||
console.log('Bundling Lua...'); | ||
|
||
const bundledLua = bundle(path.join(__dirname, '../src/aos-ant.lua')); | ||
|
||
if (!fs.existsSync(path.join(__dirname, '../dist'))) { | ||
fs.mkdirSync(path.join(__dirname, '../dist')); | ||
} | ||
|
||
fs.writeFileSync( | ||
path.join(__dirname, '../dist/aos-ant-bundled.lua'), | ||
bundledLua, | ||
); | ||
console.log( | ||
'Bundled Lua written to:', | ||
path.join(__dirname, '../dist/aos-ant-bundled.lua'), | ||
); | ||
} | ||
|
||
main(); |
Binary file added
BIN
+373 KB
ant/tools/fixtures/aos-9afQ1PLf2mrshqCTZEzzJTR2gWaC9zNPnYgYEqg1Pt4.wasm
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
const AoLoader = require('@permaweb/ao-loader'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
const address = ''.padEnd(43, 'a'); | ||
/* ao READ-ONLY Env Variables */ | ||
const env = { | ||
Process: { | ||
Id: ''.padEnd(43, '1'), | ||
Owner: address, | ||
Tags: [{ name: 'Authority', value: 'XXXXXX' }], | ||
}, | ||
Module: { | ||
Id: ''.padEnd(43, '1'), | ||
Tags: [{ name: 'Authority', value: 'YYYYYY' }], | ||
}, | ||
}; | ||
|
||
async function main() { | ||
const wasmBinary = fs.readFileSync( | ||
path.join( | ||
__dirname, | ||
'fixtures/aos-9afQ1PLf2mrshqCTZEzzJTR2gWaC9zNPnYgYEqg1Pt4.wasm', | ||
), | ||
); | ||
// read the lua code from the dist | ||
const luaCode = fs.readFileSync( | ||
path.join(__dirname, '../dist/aos-ant-bundled.lua'), | ||
'utf-8', | ||
); | ||
// for initializing ant state | ||
const initState = JSON.stringify({ | ||
balances: { [address]: 1 }, | ||
controllers: [address], | ||
name: 'ANT-ARDRIVE', | ||
owner: address, | ||
records: { | ||
'@': { | ||
transactionId: 'UyC5P5qKPZaltMmmZAWdakhlDXsBF6qmyrbWYFchRTk', | ||
ttlSeconds: 3600, | ||
}, | ||
}, | ||
ticker: 'ANT', | ||
}); | ||
// Create the handle function that executes the Wasm | ||
const options = { | ||
format: 'wasm32-unknown-emscripten', | ||
inputEncoding: 'JSON-1', | ||
outputEncoding: 'JSON-1', | ||
memoryLimit: '524288000', // in bytes | ||
computeLimit: (9e12).toString(), | ||
extensions: [], | ||
}; | ||
|
||
const testCases = [ | ||
['Eval', { Module: ''.padEnd(43, '1') }, luaCode], | ||
['Initialize-State', {}, initState], | ||
['Info', {}], | ||
['Get-Records', {}], | ||
['Transfer', { Recipient: 'iKryOeZQMONi2965nKz528htMMN_sBcjlhc-VncoRjA' }], | ||
]; | ||
|
||
const handle = await AoLoader(wasmBinary, options); | ||
// memory dump of the evaluated program | ||
let programState = undefined; | ||
const defaultHandleOptions = { | ||
Id: ''.padEnd(43, '1'), | ||
['Block-Height']: '1', | ||
// important to set the address so that that `Authority` check passes. Else the `isTrusted` with throw an error. | ||
Owner: address, | ||
Module: 'ANT', | ||
Target: ''.padEnd(43, '1'), | ||
From: address, | ||
}; | ||
|
||
for (const [method, args, data] of testCases) { | ||
const tags = args | ||
? Object.entries(args).map(([key, value]) => ({ name: key, value })) | ||
: []; | ||
// To spawn a process, pass null as the buffer | ||
const result = await handle( | ||
programState, | ||
{ | ||
...defaultHandleOptions, | ||
Tags: [...tags, { name: 'Action', value: method }], | ||
Data: data, | ||
}, | ||
env, | ||
); | ||
|
||
programState = result.Memory; | ||
console.log(method); | ||
console.dir(result.Messages[0]?.Data, { depth: null }); | ||
} | ||
} | ||
main(); |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
const { connect, createDataItemSigner } = require('@permaweb/aoconnect'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const Arweave = require('arweave'); | ||
|
||
const arweave = Arweave.init({ | ||
host: 'arweave.net', | ||
port: 443, | ||
protocol: 'https', | ||
}); | ||
|
||
const ao = connect({ | ||
GATEWAY_URL: 'https://arweave.net', | ||
}); | ||
const moduleId = '9afQ1PLf2mrshqCTZEzzJTR2gWaC9zNPnYgYEqg1Pt4'; | ||
const scheduler = '_GQ33BkPtZrqxA84vM8Zk-N2aO0toNNu_C-l-rawrBA'; | ||
|
||
async function main() { | ||
const luaCode = fs.readFileSync( | ||
path.join(__dirname, '../dist/aos-ant-bundled.lua'), | ||
'utf-8', | ||
); | ||
|
||
const wallet = fs.readFileSync(path.join(__dirname, 'key.json'), 'utf-8'); | ||
const address = await arweave.wallets.jwkToAddress(JSON.parse(wallet)); | ||
const signer = createDataItemSigner(JSON.parse(wallet)); | ||
|
||
const initState = JSON.stringify({ | ||
balances: { [address]: 1 }, | ||
controllers: [address], | ||
name: 'ANT-ARDRIVE', | ||
owner: address, | ||
records: { | ||
'@': { | ||
transactionId: 'UyC5P5qKPZaltMmmZAWdakhlDXsBF6qmyrbWYFchRTk', | ||
ttlSeconds: 3600, | ||
}, | ||
}, | ||
ticker: 'ANT', | ||
}); | ||
|
||
// const processId = await ao.spawn({ | ||
// module: moduleId, | ||
// scheduler, | ||
// signer, | ||
// }); | ||
const processId = '-IUtRutnBYxqjcHsgmBQUWeRHYV5knX8Zjgoq3EuEY0'; | ||
|
||
console.log('Process ID:', processId); | ||
console.log('Waiting 20 seconds to ensure process is readied.'); | ||
await new Promise((resolve) => setTimeout(resolve, 20_000)); | ||
console.log('Loading ANT Lua code...'); | ||
|
||
// const messageId = await ao.message({ | ||
// process: processId, | ||
// data: luaCode, | ||
// tags: [{ name: 'Action', value: 'Eval' }], | ||
// signer, | ||
// }); | ||
|
||
// console.log('Eval called. Message ID:', messageId); | ||
// console.log('Running test cases via dryrun'); | ||
|
||
const testCases = [ | ||
['Info', {}], | ||
['Set-Controller', { Controller: ''.padEnd(43, '1') }], | ||
['Remove-Controller', { Controller: ''.padEnd(43, '1') }], | ||
['Set-Name', { Name: 'Test Name' }], | ||
['Set-Ticker', { Ticker: 'TEST' }], | ||
[ | ||
'Set-Record', | ||
{ | ||
'Transaction-Id': ''.padEnd(43, '1'), | ||
'TTL-Seconds': '1000', | ||
'Sub-Domain': '@', | ||
}, | ||
], | ||
[ | ||
'Set-Record', | ||
{ | ||
'Transaction-Id': ''.padEnd(43, '1'), | ||
'TTL-Seconds': '1000', | ||
'Sub-Domain': 'bob', | ||
}, | ||
], | ||
['Remove-Record', { 'Sub-Domain': 'bob' }], | ||
['Balance', {}], | ||
['Balance', { Recipient: address }], | ||
['Balances', {}], | ||
['Get-Controllers', {}], | ||
['Get-Records', {}], | ||
['Get-Record', { 'Sub-Domain': '@' }], | ||
['Initialize-State', {}, initState], | ||
['Transfer', { Recipient: 'ZjmB2vEUlHlJ7-rgJkYP09N5IzLPhJyStVrK5u9dDEo' }], | ||
]; | ||
|
||
for (const [method, args, data] of testCases) { | ||
const tags = args | ||
? Object.entries(args).map(([key, value]) => ({ name: key, value })) | ||
: []; | ||
const result = await ao.message({ | ||
process: processId, | ||
tags: [...tags, { name: 'Action', value: method }], | ||
data, | ||
signer, | ||
// Owner: address, | ||
// From: address, | ||
}); | ||
|
||
console.dir({ method, result }, { depth: null }); | ||
} | ||
} | ||
|
||
main(); |
File renamed without changes.
Oops, something went wrong.