Skip to content

Commit

Permalink
Merge pull request #1 from massalabs/smart_contract
Browse files Browse the repository at this point in the history
Smart contract
  • Loading branch information
AurelienFT authored May 13, 2024
2 parents 0f20859 + 4e5f688 commit 4283176
Show file tree
Hide file tree
Showing 17 changed files with 13,160 additions and 0 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/ci-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: massa sc ci tests
on: [push]
jobs:
sc-tests:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./smart-contract
steps:
- uses: actions/checkout@v3

- uses: actions/setup-node@v3
with:
node-version: '18'
cache: 'npm'
cache-dependency-path: ./smart-contract/package-lock.json

- name: Install
run: npm ci

- name: Format
run: npm run fmt:check

- name: Test
run: npm run test

3 changes: 3 additions & 0 deletions smart-contract/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
WALLET_SECRET_KEY=""

JSON_RPC_URL_PUBLIC=https://buildnet.massa.net/api/v2:33035
3 changes: 3 additions & 0 deletions smart-contract/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
extends: ['@massalabs'],
};
3 changes: 3 additions & 0 deletions smart-contract/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
build
.env
60 changes: 60 additions & 0 deletions smart-contract/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Massa Name service

## Build

By default this will build all files in `assembly/contracts` directory.

```shell
npm run build
```

## Deploy a smart contract

Prerequisites :

- You must add a `.env` file at the root of the repository with the following keys set to valid values :
- WALLET_SECRET_KEY="wallet_secret_key"
- JSON_RPC_URL_PUBLIC=<https://test.massa.net/api/v2:33035>

These keys will be the ones used by the deployer script to interact with the blockchain.

The following command will build contracts in `assembly/contracts` directory and execute the deployment script
`src/deploy.ts`. This script will deploy on the node specified in the `.env` file.

```shell
npm run deploy
```

You can modify `src/deploy.ts` to change the smart contract being deployed, and to pass arguments to the constructor
function:

- line 31: specify what contract you want to deploy
- line 33: create the `Args` object to pass to the constructor of the contract you want to deploy

When the deployment operation is executed on-chain, the
[constructor](https://github.com/massalabs/massa-sc-toolkit/blob/main/packages/sc-project-initializer/commands/init/assembly/contracts/main.ts#L10)
function of the smart contract being deployed will
be called with the arguments provided in the deployment script.

The deployment script uses [massa-sc-deployer library](https://www.npmjs.com/package/@massalabs/massa-sc-deployer)
to deploy smart contracts.

You can edit this script and use [massa-web3 library](https://www.npmjs.com/package/@massalabs/massa-web3)
to create advanced deployment procedure.

For more information, please visit our ReadTheDocs about
[Massa smart-contract development](https://docs.massa.net/en/latest/web3-dev/smart-contracts.html).

## Unit tests

The test framework documentation is available here: [as-pect docs](https://as-pect.gitbook.io/as-pect)

```shell
npm run test
```

## Format code

```shell
npm run fmt
```
24 changes: 24 additions & 0 deletions smart-contract/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 smart-contract/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 smart-contract/asconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"targets": {
"debug": {
"sourceMap": true,
"debug": true,
"transform": ["@massalabs/as-transformer"]
},
"release": {
"sourceMap": true,
"optimizeLevel": 3,
"shrinkLevel": 0,
"converge": false,
"noAssert": false,
"transform": ["@massalabs/as-transformer"]
}
},
"options": {
"exportRuntime": true,
"bindings": "esm"
}
}
1 change: 1 addition & 0 deletions smart-contract/assembly/__tests__/as-pect.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference types="@as-pect/assembly/types/as-pect" />
Loading

0 comments on commit 4283176

Please sign in to comment.