Skip to content

Commit

Permalink
Merge pull request #146 from tonlabs/1.5.0-rc
Browse files Browse the repository at this point in the history
Version 1.5.0
  • Loading branch information
d3p authored Dec 23, 2022
2 parents d779b05 + eede59d commit 91f66c9
Show file tree
Hide file tree
Showing 18 changed files with 239 additions and 7,876 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/npmpublish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,12 @@ jobs:
npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
send-discord-msg:
needs: [publish-npm]
runs-on: ubuntu-latest
steps:
- name: Discord notification
env:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
uses: Ilshidur/action-discord@master
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,5 @@ dist
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*
.idea
/package-lock.json
13 changes: 10 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,21 @@

All notable changes to this project will be documented in this file.

## [1.5.0] - 2022-11-16

### New

- Support for `*.tsol` extension in Solidity compiler.
- Ability to specify contract arguments from json files in form of `@file` or `@file@field`.

## [1.4.1] - 2022-11-16

### Fixed

- Versions of dependency packages have been increased: @eversdk/core and @eversdk/appkit.\
The old ones caused unclear error messages.
- Versions of dependency packages have been increased: @eversdk/core and @eversdk/appkit.\
The old ones caused unclear error messages.

- Added an error message if the `network/registry.json` configuration file is corrupted.
- Added an error message if the `network/registry.json` configuration file is corrupted.

## [1.4.0] - 2022-10-19

Expand Down
7,780 changes: 0 additions & 7,780 deletions package-lock.json

This file was deleted.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "everdev",
"version": "1.4.1",
"version": "1.5.0",
"description": "Everscale Dev Environment",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down Expand Up @@ -45,9 +45,9 @@
"node": ">=6"
},
"dependencies": {
"@eversdk/appkit": "^0.3.3",
"@eversdk/core": "^1.38.1",
"@eversdk/lib-node": "^1.38.1",
"@eversdk/appkit": "^0.3.4",
"@eversdk/core": "^1.39.0",
"@eversdk/lib-node": "^1.39.0",
"chalk": "^2.4.2",
"dockerode": "^3.3.1",
"fs-extra": "^9.1.0",
Expand Down
6 changes: 3 additions & 3 deletions src/__tests__/addProjectId.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { transormEndpoint } from "../controllers/contract/accounts"
import { transformEndpoint } from "../controllers/contract/accounts"
import { doneTests, initTests } from "./init"

beforeAll(initTests)
Expand All @@ -12,7 +12,7 @@ test("Transform different endpoints. Add projectId", async () => {
"https://eri01.net.everos.dev/graphql/",
"eri01.net.everos.dev/graphql",
]
const result = endpoints.map(transormEndpoint("myId"))
const result = endpoints.map(transformEndpoint("myId"))
expect(result[0]).toEqual("eri01.net.everos.dev/myId")
expect(result[1]).toEqual("https://eri01.net.everos.dev/myId")
expect(result[2]).toEqual("eri01.net.everos.dev/myId")
Expand All @@ -27,7 +27,7 @@ test("Transform different endpoints. Add void projectId", async () => {
"https://eri01.net.everos.dev/graphql/",
"eri01.net.everos.dev/graphql",
]
const result = endpoints.map(transormEndpoint(undefined))
const result = endpoints.map(transformEndpoint(undefined))
expect(result[0]).toEqual("eri01.net.everos.dev")
expect(result[1]).toEqual("https://eri01.net.everos.dev")
expect(result[2]).toEqual("eri01.net.everos.dev")
Expand Down
28 changes: 28 additions & 0 deletions src/__tests__/contracts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { doneTests, initTests } from "./init"
import path from "path"
import { ParamParser } from "../controllers/contract/param-parser"

beforeAll(initTests)
afterAll(doneTests)

function dataPath(name: string): string {
return path.resolve(__dirname, "..", "..", "src", "__tests__", "data", name)
}

test("Contract alone args file", async () => {
const file = dataPath("contracts-input-alone.json")
const abi = { name: "a", type: "string[]" }
const args = ParamParser.components(abi, `@${file}`)
expect(args).toEqual([1, 2, 3])
})

test("Contract multi args file", async () => {
const file = dataPath("contracts-input.json")
const abi = { name: "a", type: "string[]" }
const args = ParamParser.components(abi, `@${file}@test1`)
expect(args).toEqual({ a: [1, 2, 3] })
const args2 = ParamParser.components(abi, `@${file}@test2`)
expect(args2).toEqual({ b: [1, 2, 3] })
const args3 = ParamParser.components(abi, `@${file}@test2.b`)
expect(args3).toEqual([1, 2, 3])
})
2 changes: 2 additions & 0 deletions src/__tests__/data/contracts-input-alone.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[1, 2, 3]

8 changes: 8 additions & 0 deletions src/__tests__/data/contracts-input.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"test1": {
"a": [1, 2, 3]
},
"test2": {
"b": [1, 2, 3]
}
}
2 changes: 1 addition & 1 deletion src/__tests__/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
beforeAll(initTests)
afterAll(doneTests)

test("Shoud throw", async () => {
test("Should throw", async () => {
const parser = new CommandLine()
try {
await parser.parse(["nono"])
Expand Down
8 changes: 4 additions & 4 deletions src/controllers/contract/accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import { NetworkRegistry } from "../network/registry"
import { TonClient } from "@eversdk/core"
import { SignerRegistry } from "../signer/registry"
import { ParamParser } from "./param-parser"
import { resolveContract } from "../../core/utils"
import { resolveContract } from "../../core/solFileResolvers"

// Remove sufix graphql if exists and add projectId
// Remove suffix graphql if exists and add projectId
// Intentionally do not use URL object or any modules,
// because url may lack `http://` prefix
export const transormEndpoint = (project?: string) => (url: string) => {
export const transformEndpoint = (project?: string) => (url: string) => {
const result = url
.trim()
.replace(/\/graphql\/?$/i, "")
Expand All @@ -32,7 +32,7 @@ export async function getAccount(
const { project, accessKey } = network.credentials || {}
const client = new TonClient({
network: {
endpoints: network.endpoints.map(transormEndpoint(project)),
endpoints: network.endpoints.map(transformEndpoint(project)),

...(accessKey ? { access_key: accessKey } : {}),
},
Expand Down
38 changes: 30 additions & 8 deletions src/controllers/contract/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { Command, CommandArg, Terminal, ToolController } from "../../core"
import { resolveContract, resolveTvcAsBase64 } from "../../core/utils"
import {
resolveContract,
resolveTvcAsBase64,
} from "../../core/solFileResolvers"
import { Account, AccountType } from "@eversdk/appkit"
import { TonClient } from "@eversdk/core"
import { getAccount } from "./accounts"
Expand Down Expand Up @@ -75,14 +78,35 @@ const functionArg: CommandArg = {
defaultValue: "",
}

const JSON_ARG_DESCR = `
Value is resolved to the JSON object. Can be provided in several variants:
- \`name:value\` pairs.
Array values must be specified as [item,...].
Spaces are not allowed. If value contains spaces or special symbols "[],:" it must be enclosed in "" or ''.
Example: \`'foo:1,bar:"2",baz:[1,2,3]'\`.
Result: \`{ foo: 1, bar: "2", baz: [1, 2, 3] }\`.
- \`{ name: value, ... }\` – JSON object.
Example: \`'{foo:1,bar:"2",baz:[1,2,3]}\`.
Result: \`{ foo: 1, bar: "2", baz: [1, 2, 3] }\`.
- \`@file\` – JSON object loaded from the specified file.
Example: \`@./args.json\`.
File args.json: \`{ foo: 1, bar: "2", baz: [1, 2, 3] }\`.
Result: \`{ foo: 1, bar: "2", baz: [1, 2, 3] }\`.
- \`@file@field\` – specified field of the JSON object loaded from the specified file.
\`field\` is a path to nested field separated by \`.\` (e.g. \`foo.bar.baz\`).
Example: \`@./args.json@f1\`.
File args.json: \`{ f1: { foo: 1, bar: "2", baz: [1, 2, 3] } }\`.
Result: \`{ foo: 1, bar: "2", baz: [1, 2, 3] }\`.
Example: \`@./[email protected]\`.
File args.json: \`{ f1: { foo: 1, bar: "2", baz: [1, 2, 3] } }\`.
Result: \`[1, 2, 3]\`.
`

const inputOpt: CommandArg = {
name: "input",
alias: "i",
title: "Function parameters as name:value,...",
description:
"Array values must be specified as [item,...]. " +
'Spaces are not allowed. If value contains spaces or special symbols "[],:" ' +
"it must be enclosed in \"\" or ''",
description: `Value for function parameters.${JSON_ARG_DESCR}`,
type: "string",
defaultValue: "",
}
Expand All @@ -93,9 +117,7 @@ const dataOpt: CommandArg = {
title: "Deploying initial data as name:value,...",
description:
"This data is required to calculate the account address and to deploy contract.\n" +
"Array values must be specified as [item,...]. " +
'Spaces are not allowed. If value contains spaces or special symbols "[],:" ' +
"it must be enclosed in \"\" or ''",
JSON_ARG_DESCR,
type: "string",
defaultValue: "",
}
Expand Down
16 changes: 16 additions & 0 deletions src/controllers/contract/param-parser.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { AbiParam } from "@eversdk/core"
import path from "path"
import process from "process"
import { loadJSON } from "../../core/utils"

export class ParamParser {
pos = 0
Expand Down Expand Up @@ -108,6 +111,19 @@ export class ParamParser {
}

parseComponents(param: AbiParam): { [name: string]: any } {
const text = this.text.trim()
if (text.startsWith("@")) {
return loadJSON(path.resolve(process.cwd(), text.substring(1)))
}

if (text.startsWith("{") && text.endsWith("}")) {
try {
return JSON.parse(text)
} catch (err: any) {
throw new Error(`Malformed JSON object has been passed`)
}
}

const isLetter = (x: string) => x.toLowerCase() !== x.toUpperCase()
const isDigit = (x: string) => x >= "0" && x <= "9"
const isIdent = (x: string) => isLetter(x) || isDigit(x) || x === "_"
Expand Down
13 changes: 1 addition & 12 deletions src/controllers/contract/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
import { Account } from "@eversdk/appkit"
import { ParamParser } from "./param-parser"
import { SignerRegistry } from "../signer/registry"
import * as process from "process"

export async function resolveFunction(
terminal: Terminal,
Expand Down Expand Up @@ -117,18 +118,6 @@ export async function resolveParams(
paramsString: string,
preventUi: boolean,
): Promise<object> {
if (paramsString.match(/{.+}/)) {
let jsonArgs: any
try {
jsonArgs = JSON.parse(paramsString)
} catch (err: any) {
throw new Error(`Malformed JSON object has been passed`)
}
terminal.log(
`Skip ABI validation step because a JSON object has been passed as an argument.`,
)
return jsonArgs
}
const values: { [name: string]: any } = ParamParser.components(
{
name: "params",
Expand Down
3 changes: 2 additions & 1 deletion src/controllers/js/wrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import path from "path"
import { TonClient } from "@eversdk/core"
import { libNode } from "@eversdk/lib-node"

import { resolveContract, writeTextFile } from "../../core/utils"
import { writeTextFile } from "../../core/utils"
import { resolveContract } from "../../core/solFileResolvers"
import { Command, CommandArgVariant, Terminal } from "../../core"

TonClient.useBinaryLibrary(libNode)
Expand Down
23 changes: 18 additions & 5 deletions src/controllers/solidity/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
import { Command, Component, Terminal, ToolController } from "../../core"
import path from "path"
import { changeExt, uniqueFilePath, writeTextFile } from "../../core/utils"
import {
changeExt,
defineFileType,
uniqueFilePath,
writeTextFile,
} from "../../core/utils"
import fs from "fs"
import mv from "mv"
import { BasicContract } from "./snippets"
import { components } from "./components"

export const SOLIDITY_FILE = defineFileType("Solidity", /\.t?sol$/i, [
".sol",
".tsol",
])

export const solidityVersionCommand: Command = {
name: "version",
title: "Show Solidity Version",
Expand All @@ -32,7 +42,10 @@ export const solidityCreateCommand: Command = {
},
],
async run(terminal: Terminal, args: { name: string; folder: string }) {
const filePath = uniqueFilePath(args.folder, `${args.name}{}.sol`)
const filePath = uniqueFilePath(
args.folder,
`${args.name}{}${SOLIDITY_FILE.defaultExt}`,
)
const text = BasicContract.split("{name}").join(args.name)
writeTextFile(filePath, text)
terminal.log(`Solidity contract ${path.basename(filePath)} created.`)
Expand All @@ -48,7 +61,7 @@ export const solidityCompileCommand: Command = {
name: "file",
type: "file",
title: "Source file",
nameRegExp: /\.sol$/i,
nameRegExp: SOLIDITY_FILE.nameRegEx,
greedy: true,
},
{
Expand Down Expand Up @@ -178,7 +191,7 @@ export const solidityAstCommand: Command = {
name: "file",
type: "file",
title: "Source file",
nameRegExp: /\.sol$/i,
nameRegExp: SOLIDITY_FILE.nameRegEx,
greedy: true,
},
{
Expand Down Expand Up @@ -214,7 +227,7 @@ export const solidityAstCommand: Command = {
): Promise<void> {
for (const file of args.file.split(" ")) {
const ext = path.extname(file)
if (ext !== ".sol") {
if (SOLIDITY_FILE.extensions.includes(ext) === false) {
terminal.log(`Choose solidity source file.`)
return
}
Expand Down
Loading

0 comments on commit 91f66c9

Please sign in to comment.