-
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.
- Loading branch information
Atticus
committed
Jun 17, 2024
1 parent
58b690e
commit bc07124
Showing
20 changed files
with
259 additions
and
121 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 |
---|---|---|
@@ -0,0 +1 @@ | ||
20.11.1 |
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,31 @@ | ||
const { createAntAosLoader } = require('./utils'); | ||
const { describe, it } = require('node:test'); | ||
const assert = require('node:assert'); | ||
|
||
describe('Should load AOS-ANT', async () => { | ||
const { handle: originalHandle, memory: startMemory } = | ||
await createAntAosLoader(); | ||
|
||
async function handle(options = {}, mem = startMemory) { | ||
return originalHandle( | ||
mem, | ||
{ | ||
...DEFAULT_HANDLE_OPTIONS, | ||
...options, | ||
}, | ||
AO_LOADER_HANDLER_ENV, | ||
); | ||
} | ||
|
||
it('Should fetch the balances of the ANT', async () => { | ||
const result = await handle({ | ||
Tags: [{ name: 'Action', value: 'Balances' }], | ||
}); | ||
const balances = JSON.parse(result.Messages[0].Data); | ||
assert(balances); | ||
const balanceEntries = Object.entries(balances); | ||
assert(balanceEntries.length === 1); | ||
assert(balanceEntries[0][0] === STUB_ADDRESS); | ||
assert(balanceEntries[0][1] === 1); | ||
}); | ||
}); |
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
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,30 @@ | ||
const AoLoader = require('@permaweb/ao-loader'); | ||
const { | ||
AOS_WASM, | ||
AO_LOADER_HANDLER_ENV, | ||
AO_LOADER_OPTIONS, | ||
BUNDLED_AOS_ANT_LUA, | ||
DEFAULT_ANT_STATE, | ||
DEFAULT_HANDLE_OPTIONS, | ||
} = require('../tools/constants'); | ||
|
||
/** | ||
* Loads the AOS-ANT wasm binary and returns the handle function with program memory | ||
* @returns {Promise<{handle: Function, memory: WebAssembly.Memory}>} | ||
*/ | ||
async function createAntAosLoader() { | ||
const handle = await AoLoader(AOS_WASM, AO_LOADER_OPTIONS); | ||
const evalRes = await handle( | ||
null, | ||
{ | ||
...DEFAULT_HANDLE_OPTIONS, | ||
Tags: [{ name: 'Action', value: 'Eval' }], | ||
Data: BUNDLED_AOS_ANT_LUA, | ||
}, | ||
AO_LOADER_HANDLER_ENV, | ||
); | ||
return { | ||
handle, | ||
memory: evalRes.Memory, | ||
}; | ||
} |
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,70 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const STUB_ADDRESS = ''.padEnd(43, '1'); | ||
/* ao READ-ONLY Env Variables */ | ||
const AO_LOADER_HANDLER_ENV = { | ||
Process: { | ||
Id: ''.padEnd(43, '1'), | ||
Owner: STUB_ADDRESS, | ||
Tags: [{ name: 'Authority', value: 'XXXXXX' }], | ||
}, | ||
Module: { | ||
Id: ''.padEnd(43, '1'), | ||
Tags: [{ name: 'Authority', value: 'YYYYYY' }], | ||
}, | ||
}; | ||
|
||
const AO_LOADER_OPTIONS = { | ||
format: 'wasm32-unknown-emscripten', | ||
inputEncoding: 'JSON-1', | ||
outputEncoding: 'JSON-1', | ||
memoryLimit: '524288000', // in bytes | ||
computeLimit: (9e12).toString(), | ||
extensions: [], | ||
}; | ||
|
||
const AOS_WASM = fs.readFileSync( | ||
path.join( | ||
__dirname, | ||
'fixtures/aos-9afQ1PLf2mrshqCTZEzzJTR2gWaC9zNPnYgYEqg1Pt4.wasm', | ||
), | ||
); | ||
|
||
const BUNDLED_AOS_ANT_LUA = fs.readFileSync( | ||
path.join(__dirname, '../dist/aos-ant-bundled.lua'), | ||
'utf-8', | ||
); | ||
|
||
const DEFAULT_ANT_STATE = JSON.stringify({ | ||
balances: { [STUB_ADDRESS]: 1 }, | ||
controllers: [STUB_ADDRESS], | ||
name: 'ANT-ARDRIVE', | ||
owner: STUB_ADDRESS, | ||
records: { | ||
'@': { | ||
transactionId: 'UyC5P5qKPZaltMmmZAWdakhlDXsBF6qmyrbWYFchRTk', | ||
ttlSeconds: 3600, | ||
}, | ||
}, | ||
ticker: 'ANT', | ||
}); | ||
|
||
const DEFAULT_HANDLE_OPTIONS = { | ||
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: STUB_ADDRESS, | ||
Module: 'ANT', | ||
Target: ''.padEnd(43, '1'), | ||
From: STUB_ADDRESS, | ||
}; | ||
|
||
module.exports = { | ||
BUNDLED_AOS_ANT_LUA, | ||
DEFAULT_ANT_STATE, | ||
AOS_WASM, | ||
AO_LOADER_OPTIONS, | ||
AO_LOADER_HANDLER_ENV, | ||
STUB_ADDRESS, | ||
DEFAULT_HANDLE_OPTIONS, | ||
}; |
This file was deleted.
Oops, something went wrong.
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,43 @@ | ||
const AoLoader = require('@permaweb/ao-loader'); | ||
const { | ||
BUNDLED_AOS_ANT_LUA, | ||
DEFAULT_ANT_STATE, | ||
AOS_WASM, | ||
AO_LOADER_OPTIONS, | ||
AO_LOADER_HANDLER_ENV, | ||
DEFAULT_HANDLE_OPTIONS, | ||
} = require('./constants'); | ||
|
||
async function main() { | ||
const testCases = [ | ||
['Eval', { Module: ''.padEnd(43, '1') }, BUNDLED_AOS_ANT_LUA], | ||
['Initialize-State', {}, DEFAULT_ANT_STATE], | ||
['Info', {}], | ||
['Get-Records', {}], | ||
['Transfer', { Recipient: 'iKryOeZQMONi2965nKz528htMMN_sBcjlhc-VncoRjA' }], | ||
]; | ||
|
||
const handle = await AoLoader(AOS_WASM, AO_LOADER_OPTIONS); | ||
// memory dump of the evaluated program | ||
let programState = undefined; | ||
|
||
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, | ||
{ | ||
...DEFAULT_HANDLE_OPTIONS, | ||
Tags: [...tags, { name: 'Action', value: method }], | ||
Data: data, | ||
}, | ||
AO_LOADER_HANDLER_ENV, | ||
); | ||
|
||
programState = result.Memory; | ||
console.dir({ method, result }, { depth: null }); | ||
} | ||
} | ||
main(); |
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,51 @@ | ||
const { describe, it } = require('node:test'); | ||
const assert = require('node:assert'); | ||
const AoLoader = require('@permaweb/ao-loader'); | ||
const { | ||
AOS_WASM, | ||
AO_LOADER_HANDLER_ENV, | ||
AO_LOADER_OPTIONS, | ||
BUNDLED_AOS_ANT_LUA, | ||
DEFAULT_ANT_STATE, | ||
DEFAULT_HANDLE_OPTIONS, | ||
} = require('./constants'); | ||
|
||
const testCases = [ | ||
['Eval', { Module: ''.padEnd(43, '1') }, BUNDLED_AOS_ANT_LUA], | ||
['Initialize-State', {}, DEFAULT_ANT_STATE], | ||
['Info', {}], | ||
['Get-Records', {}], | ||
['Transfer', { Recipient: 'iKryOeZQMONi2965nKz528htMMN_sBcjlhc-VncoRjA' }], | ||
]; | ||
|
||
describe('Should load AOS-ANT', async () => { | ||
// Mostly to ensure the aos binary fixture is present | ||
it('Should create handle function with the aos wasm binary', async () => { | ||
const handle = await AoLoader(AOS_WASM, AO_LOADER_OPTIONS); | ||
assert(handle); | ||
}); | ||
|
||
it('Should load the ANT lua into the AOS wasm process and execute test cases in order to modify the state.', async (t) => { | ||
let testProgramMemory = null; | ||
testCases.map(async ([method, args, data]) => { | ||
t.test(`Should call ${method}`, async () => { | ||
const tags = Object.entries(args).map(([name, value]) => ({ | ||
name, | ||
value, | ||
})); | ||
const handle = await AoLoader(AOS_WASM, AO_LOADER_OPTIONS); | ||
const result = await handle( | ||
testProgramMemory, | ||
{ | ||
...DEFAULT_HANDLE_OPTIONS, | ||
Tags: [...tags, { name: 'Action', value: method }], | ||
Data: data, | ||
}, | ||
AO_LOADER_HANDLER_ENV, | ||
); | ||
testProgramMemory = result.Memory; | ||
assert(result); | ||
}); | ||
}); | ||
}); | ||
}); |
File renamed without changes.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
const path = require('node:path'); | ||
const fs = require('node:fs'); | ||
const test = require('node:test'); | ||
const assert = require('node:assert'); | ||
const { bundle } = require('./lua-bundler'); | ||
|
||
test('Should bundle Lua file', () => { | ||
const bundledLua = bundle(path.join(__dirname, '../src/aos-ant.lua')); | ||
assert.strictEqual( | ||
bundledLua, | ||
fs.readFileSync( | ||
path.join(__dirname, '../dist/aos-ant-bundled.lua'), | ||
'utf-8', | ||
), | ||
); | ||
}); |
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
Oops, something went wrong.