Skip to content

Commit

Permalink
chore: added test for 2 arguments handlers add
Browse files Browse the repository at this point in the history
  • Loading branch information
twilson63 committed Aug 1, 2024
1 parent 20fd900 commit 89d4bea
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions process/test/handlers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,4 +307,50 @@ Handlers.add("timestamp",
const result = await handle(Memory, timestamp, env)
assert.equal(result.Output.data, currentTimestamp)
assert.ok(true)
})

test('test pattern, fn handler', async () => {
const handle = await AoLoader(wasm, options)
const env = {
Process: {
Id: 'AOS',
Owner: 'FOOBAR',
Tags: [
{ name: 'Name', value: 'Thomas' }
]
}
}
const msg = {
Target: 'AOS',
From: 'FOOBAR',
Owner: 'FOOBAR',
['Block-Height']: "1000",
Id: "1234xyxfoo",
Module: "WOOPAWOOPA",
Tags: [
{ name: 'Action', value: 'Eval' }
],
Data: `
Handlers.add("Balance",
function (msg)
msg.reply({Data = "1000"})
end
)
`
}
// load handler
const { Memory } = await handle(null, msg, env)
// ---
const currentTimestamp = Date.now();
const balance = {
Target: 'AOS',
From: 'FRED',
Owner: 'FRED',
Tags: [{ name: 'Action', value: 'Balance' }],
Data: 'timestamp',
Timestamp: currentTimestamp
}
const result = await handle(Memory, balance, env)
assert.equal(result.Messages[0].Data, "1000")
assert.ok(true)
})

0 comments on commit 89d4bea

Please sign in to comment.