Skip to content

Commit

Permalink
update async_calls contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
lilyanB committed Jul 7, 2023
1 parent 8863b9e commit 674f8d3
Show file tree
Hide file tree
Showing 25 changed files with 18,413 additions and 149 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/async-calls-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Async-calls CI

on: [push]

defaults:
run:
working-directory: ./async-calls/contracts

jobs:
unit-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- uses: actions/setup-node@v3
with:
node-version: 18

- name: Install
run: npm ci

- name: Code quality
run: npm run fmt:check

- name: Test
run: npm run test
43 changes: 43 additions & 0 deletions .github/workflows/async-calls-daily-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Async-calls Daily Deploy

on:
push:
paths:
- async-calls/**
workflow_dispatch:
schedule:
- cron: "0 7 * * *"

jobs:
deploy-age:
defaults:
run:
working-directory: ./async-calls/contracts/

runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Install node
uses: actions/setup-node@v3
with:
node-version: "18"
cache: "npm"
cache-dependency-path: ./async-calls/contracts/package-lock.json

- name: Install dependencies
run: npm install

- name: Deploy
run: |
if npm run deploy | grep -q "Contract deployed"; then
echo "Contract successfully deployed!"
else
echo "Failed to deploy contract ..."
exit 1
fi
env:
JSON_RPC_URL_PUBLIC: ${{ secrets.JSON_RPC_URL_PUBLIC }}
WALLET_PRIVATE_KEY: ${{ secrets.WALLET_PRIVATE_KEY }}
20 changes: 0 additions & 20 deletions async-calls/.eslintrc.json

This file was deleted.

5 changes: 0 additions & 5 deletions async-calls/.gitignore

This file was deleted.

6 changes: 0 additions & 6 deletions async-calls/.prettierrc

This file was deleted.

Empty file removed async-calls/asconfig.json
Empty file.
7 changes: 0 additions & 7 deletions async-calls/assembly/__test__/example.spec.ts

This file was deleted.

1 change: 0 additions & 1 deletion async-calls/assembly/__test__/tester.d.ts

This file was deleted.

72 changes: 0 additions & 72 deletions async-calls/assembly/sendHelloAsyncMessage.ts

This file was deleted.

3 changes: 3 additions & 0 deletions async-calls/contracts/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
WALLET_PRIVATE_KEY=""

JSON_RPC_URL_PUBLIC=https://buildnet.massa.net/api/v2:33035
5 changes: 5 additions & 0 deletions async-calls/contracts/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
extends: [
'@massalabs',
],
};
3 changes: 3 additions & 0 deletions async-calls/contracts/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
build
.env
File renamed without changes.
24 changes: 24 additions & 0 deletions async-calls/contracts/as-pect.asconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"targets": {
"coverage": {
"lib": ["./node_modules/@as-covers/assembly/index.ts"],
"transform": ["@as-covers/transform", "@as-pect/transform"]
},
"noCoverage": {
"transform": ["@as-pect/transform"]
}
},
"options": {
"exportMemory": true,
"outFile": "output.wasm",
"textFile": "output.wat",
"bindings": "raw",
"exportStart": "_start",
"exportRuntime": true,
"use": ["RTRACE=1"],
"debug": true,
"exportTable": true
},
"extends": "./asconfig.json",
"entries": ["./node_modules/@as-pect/assembly/assembly/index.ts"]
}
28 changes: 28 additions & 0 deletions async-calls/contracts/as-pect.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import createMockedABI from '@massalabs/massa-as-sdk/vm-mock';

export default {
/**
* A set of globs passed to the glob package that qualify typescript files for testing.
*/
entries: ['assembly/__tests__/**/*.spec.ts'],
/**
* A set of globs passed to the glob package that quality files to be added to each test.
*/
include: ['assembly/__tests__/**/*.include.ts'],
/**
* A set of regexp that will disclude source files from testing.
*/
disclude: [/node_modules/],
/**
* Add your required AssemblyScript imports here.
*/
async instantiate(memory, createImports, instantiate, binary) {
return createMockedABI(memory, createImports, instantiate, binary);
},
/** Enable code coverage. */
// coverage: ["assembly/**/*.ts"],
/**
* Specify if the binary wasm file should be written to the file system.
*/
outputBinary: false,
};
21 changes: 21 additions & 0 deletions async-calls/contracts/asconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"targets": {
"debug": {
"outFile": "build/main.wasm",
"sourceMap": true,
"debug": true
},
"release": {
"outFile": "build/main.wasm",
"sourceMap": true,
"optimizeLevel": 3,
"shrinkLevel": 0,
"converge": false,
"noAssert": false
}
},
"options": {
"exportRuntime": true,
"bindings": "esm"
}
}
1 change: 1 addition & 0 deletions async-calls/contracts/assembly/__test__/tester.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference types="@as-pect/assembly/types/as-pect" />
File renamed without changes.
72 changes: 72 additions & 0 deletions async-calls/contracts/assembly/contracts/sendHelloAsyncMessage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { Args } from '@massalabs/as-types';
/** ***********************
*
* SendHelloAsyncMessage sends an asynchronous message to a previous deployed contract containing a message handler function
**/

import {
sendMessage,
callerHasWriteAccess,
Address,
} from '@massalabs/massa-as-sdk';
import { currentPeriod } from '@massalabs/massa-as-sdk/assembly/std/context';

/**
* This function is meant to be called only one time: when the contract is deployed.
*/
export function constructor(binaryArgs: StaticArray<u8>): StaticArray<u8> {
// This line is important. It ensure that this function can't be called in the future.
// If you remove this check someone could call your constructor function and reset your SC.
if (!callerHasWriteAccess()) {
return [];
}
sendHelloAsyncMessage(binaryArgs);
return [];
}

/**
* @param binaryArgs - The address of the receive message contract encoded with `Args`
* @returns empty array
*/
export function sendHelloAsyncMessage(
binaryArgs: StaticArray<u8>,
): StaticArray<u8> {
// Setup the 'message' we will send to our deployed SC
const functionName = 'receive';
const current_period = currentPeriod();
const validityStartPeriod = current_period + 1;
const validityStartThread = 13 as u8;
const validityEndPeriod = current_period + 20;
const validityEndThread = 13 as u8;
const maxGas = 1_000_000_000; // gas for smart contract execution.
const rawFee = 0;
const coins = 100; // coins that can be used inside SC.
const msg = new Args().add('hello my good friend!').serialize();

const args = new Args(binaryArgs);

const address = new Address(
args.nextString().expect('Address argument is missing or invalid'),
);

// Send the message
sendMessage(
address,
functionName,
validityStartPeriod,
validityStartThread,
validityEndPeriod,
validityEndThread,
maxGas,
rawFee,
coins,
msg,
);

return [];
}
14 changes: 14 additions & 0 deletions async-calls/contracts/assembly/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"extends": "assemblyscript/std/assembly.json",
"include": [
"**/*.ts"
],
"typedocOptions": {
"exclude": "assembly/**/__tests__",
"excludePrivate": true,
"excludeProtected": true,
"excludeExternals": true,
"includeVersion": true,
"skipErrorChecking": true
}
}
Loading

0 comments on commit 674f8d3

Please sign in to comment.