-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from massalabs/smart_contract
Smart contract
- Loading branch information
Showing
17 changed files
with
13,160 additions
and
0 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
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 | ||
|
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,3 @@ | ||
WALLET_SECRET_KEY="" | ||
|
||
JSON_RPC_URL_PUBLIC=https://buildnet.massa.net/api/v2:33035 |
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,3 @@ | ||
module.exports = { | ||
extends: ['@massalabs'], | ||
}; |
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,3 @@ | ||
node_modules | ||
build | ||
.env |
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,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 | ||
``` |
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,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"] | ||
} |
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,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, | ||
}; |
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,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" | ||
} | ||
} |
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 @@ | ||
/// <reference types="@as-pect/assembly/types/as-pect" /> |
Oops, something went wrong.