-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(validate): draw out initial validate function
- Loading branch information
1 parent
05f3fef
commit f5e6b37
Showing
5 changed files
with
100 additions
and
6 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
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,29 @@ | ||
local utils = require(".common.utils") | ||
local json = require(".common.json") | ||
local validate = {} | ||
|
||
---@param msg AoMessage AO messages to evaluate | ||
---@param env table the AO env object | ||
function validate.validateHandlers(msg, env) | ||
local messages = json.decode(msg.Data) | ||
|
||
local results = {} | ||
|
||
local stateBackup = json.encode(utils.getState()) | ||
|
||
for name, message in pairs(messages) do | ||
local process = package.loaded[".process"] | ||
local _, res = pcall(process.handle, message, env) | ||
ao.clearOutbox() | ||
results[name] = { message = message, result = res } | ||
|
||
--- reset state | ||
for k, v in pairs(json.decode(stateBackup)) do | ||
_G[k] = v | ||
end | ||
end | ||
|
||
return results | ||
end | ||
|
||
return validate |
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,50 @@ | ||
import { createAntAosLoader } from './utils.mjs'; | ||
import { describe, it } from 'node:test'; | ||
import assert from 'node:assert'; | ||
import { | ||
AO_LOADER_HANDLER_ENV, | ||
DEFAULT_HANDLE_OPTIONS, | ||
STUB_ADDRESS, | ||
} from '../tools/constants.mjs'; | ||
|
||
describe('aos Validate', 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 validate Transfer', async () => { | ||
const messages = { | ||
Transfer: { | ||
...DEFAULT_HANDLE_OPTIONS, | ||
Tags: [ | ||
{ name: 'Action', value: 'Transfer' }, | ||
{ name: 'Recipient', value: 'STUB_ADDRESS'.padEnd(43, '1') }, | ||
], | ||
}, | ||
Transfer2: { | ||
...DEFAULT_HANDLE_OPTIONS, | ||
Tags: [ | ||
{ name: 'Action', value: 'Transfer' }, | ||
{ name: 'Recipient', value: 'STUB_ADDRESS'.padEnd(43, '1') }, | ||
], | ||
}, | ||
}; | ||
|
||
const res = await handle({ | ||
Tags: [{ name: 'Action', value: 'Validate-Handlers' }], | ||
Data: JSON.stringify(messages), | ||
}); | ||
|
||
console.dir(JSON.parse(res.Messages[0].Data), { depth: null }); | ||
}); | ||
}); |