Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
twilson63 authored May 15, 2024
0 parents commit e54d408
Show file tree
Hide file tree
Showing 11 changed files with 232 additions and 0 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Deploy AOS Process

on:
push:
branches:
- main

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: ⬇️ Checkout repo
uses: actions/checkout@v4

- name: ⎔ Setup node
uses: actions/setup-node@v4
with:
node-version: 20

- name: 📥 Download deps
working-directory: deploy
run: |
npm i
- name: Deploy AOS Process
working-directory: deploy
run: node index.js
env:
KEYFILE: ${{ secrets.KEYFILE }}
AOS: ${{ secrets.AOS }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
Binary file added AOS-SQLITE.wasm
Binary file not shown.
Binary file added AOS.wasm
Binary file not shown.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 permaweb

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
52 changes: 52 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# AOS Test Kit Template

This is a simple github template repo that can be used to build and maintain AOS processes.
It is setup to test locally out of the box, deploy when using trunk-based deployment.

## How it works?

You can create a new repo with this template and then utilize TDD to construct your AOS process,
step by step, test by test. This workflow gives you a nice developer experience and an extremely
easy way to test and publish your code.

## First Test

In test/main.test.js after the load source test, create a test that designs a prompt function.

```js
test('create a prompt', async () => {
const result = await Send({Action: 'Eval', Data: 'Prompt = function () return "hi> " end' })
assert.equal(result.prompt, 'hi> ')
})
```

Save then run `npm t`

More Examples coming soon...

## Manually Deploy

```
npm i --no-fund -g https://get_ao.g8way.io
aos --load src/main.lua
```

## Deploy Setup

In you github repo, you need to setup a few secrets:

* Your Process Identifier `AOS`
* Your Deployment Key `KEYFILE` (you want to base64 encode it)

> NOTE: Don't have a deployment key, use `~/.aos.json`
## CONTRIBUTIONS

If you like this approach to building AOS processes, and have suggestions to make improves please
submit issues or PRs. But lets keep it simple and easy to use.

### Principles

* Should be easy to use
* Should emulate typing commands in the aos console
* Should make testing fun with AOS
35 changes: 35 additions & 0 deletions deploy/publish.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Deploy to AO
import { connect, createDataItemSigner } from '@permaweb/aoconnect'
import fs from 'fs'

const AOS = process.env.AOS
const lua = fs.readFileSync('../src/main.lua', 'utf-8')
const keyfile = process.env.KEYFILE
const jwk = JSON.parse(atob(keyfile))


async function main() {
const { message, result } = connect()

const messageId = await message({
process: AOS,
signer: createDataItemSigner(jwk),
tags: [
{ name: 'Action', value: 'Eval' }
],
data: lua
})

const res = await result({
process: AOS,
message: messageId
})

if (res?.Output?.data) {
console.log('Successfully published AOS process ', messageId)
} else {
console.error(res?.Error || 'Unknown error occured deploying AOS')
}
}

main()
16 changes: 16 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "ao-test-kit",
"type": "module",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "node --test test"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@permaweb/ao-loader": "^0.0.26"
}
}
1 change: 1 addition & 0 deletions src/main.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1 + 1
64 changes: 64 additions & 0 deletions test/aos.helper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import AoLoader from '@permaweb/ao-loader'
import fs from 'fs'

const aos = fs.readFileSync(process.env.WASM || './AOS.wasm')
const format = 'wasm32-unknown-emscripten'
let memory = null

export async function Send(DataItem) {

const msg = Object.keys(DataItem).reduce(function (di, k) {
if (di[k]) {
di[k] = DataItem[k]
} else {
di.Tags = di.Tags.concat([{ name: k, value: DataItem[k] }])
}
return di
}, createMsg())

const handle = await AoLoader(aos, { format })
const env = createEnv()

const result = await handle(memory, msg, env)
if (result.Error) {
return 'ERROR: ' + JSON.stringify(result.Error)
}
memory = result.Memory

return { Messages: result.Messages, Spawns: result.Spawns, Output: result.Output, Assignments: result.Assignments }
}

function createMsg() {
return {
Id: '1234',
Target: 'AOS',
Owner: 'OWNER',
From: 'OWNER',
Data: '1984',
Tags: [],
'Block-Height': '1',
Timestamp: Date.now(),
Module: '4567'
}
}

function createEnv() {
return {
Process: {
Id: '9876',
Tags: [
{ name: 'Data-Protocol', value: 'ao' },
{ name: 'Variant', value: 'ao.TN.1' },
{ name: 'Type', value: 'Process' }
]
},
Module: {
Id: '4567',
Tags: [
{ name: 'Data-Protocol', value: 'ao' },
{ name: 'Variant', value: 'ao.TN.1' },
{ name: 'Type', value: 'Module' }
]
}
}
}
12 changes: 12 additions & 0 deletions test/main.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { test } from 'node:test'
import * as assert from 'node:assert'
import { Send } from './aos.helper.js'
import fs from 'node:fs'

test('load source', async () => {
const code = fs.readFileSync('./src/main.lua', 'utf-8')
const result = await Send({ Action: "Eval", Data: code })

assert.equal(result.Output.data.output, 2)

})

0 comments on commit e54d408

Please sign in to comment.