diff --git a/xsuite-fullsimulnet-darwin-amd64/package.json b/xsuite-fullsimulnet-darwin-amd64/package.json index 30145e55..17f52645 100644 --- a/xsuite-fullsimulnet-darwin-amd64/package.json +++ b/xsuite-fullsimulnet-darwin-amd64/package.json @@ -1,6 +1,6 @@ { "name": "@xsuite/full-simulnet-darwin-amd64", - "version": "0.0.7", + "version": "0.0.10", "os": [ "darwin" ], diff --git a/xsuite-fullsimulnet-linux-amd64/package.json b/xsuite-fullsimulnet-linux-amd64/package.json index 9dc54a36..488f0d48 100644 --- a/xsuite-fullsimulnet-linux-amd64/package.json +++ b/xsuite-fullsimulnet-linux-amd64/package.json @@ -1,6 +1,6 @@ { "name": "@xsuite/full-simulnet-linux-amd64", - "version": "0.0.7", + "version": "0.0.10", "os": [ "linux" ], diff --git a/xsuite-fullsimulnet/build-binary.mjs b/xsuite-fullsimulnet/build-binary.mjs index a4d73f5b..c0704759 100644 --- a/xsuite-fullsimulnet/build-binary.mjs +++ b/xsuite-fullsimulnet/build-binary.mjs @@ -1,6 +1,14 @@ +import assert from "node:assert"; import { $, minimist } from "zx"; const argv = minimist(process.argv.slice(2)); -await $`GOBIN="$(pwd)" GOOS=${argv.os} GOARCH=${argv.arch} go install -ldflags ${argv.ldflags} github.com/multiversx/mx-chain-simulator-go/cmd/chainsimulator@v1.7.12-rc1`; +if (process.env.CI) { + assert.deepStrictEqual(await $`go env GOOS GOARCH`.lines(), [ + argv.os, + argv.arch, + ]); +} + +await $`GOBIN="$(pwd)" go install -ldflags ${argv.ldflags} github.com/multiversx/mx-chain-simulator-go/cmd/chainsimulator@v1.7.13-fix2`; await $`mv ./chainsimulator ../xsuite-fullsimulnet-${argv.os}-${argv.arch}/bin/fsproxy`; diff --git a/xsuite-fullsimulnet/config/config.toml b/xsuite-fullsimulnet/config/config.toml index 6e179b1f..55a8a9a2 100644 --- a/xsuite-fullsimulnet/config/config.toml +++ b/xsuite-fullsimulnet/config/config.toml @@ -21,8 +21,8 @@ [config.logs] log-file-life-span-in-mb = 1024 # 1GB log-file-life-span-in-sec = 432000 # 5 days - log-file-prefix = "chain-simulator" - logs-path = "logs" + log-file-prefix = "fsproxy" + logs-path = "" [config.blocks-generator] # auto-generate-blocks specifies if the chain simulator should auto generate blocks auto-generate-blocks = false diff --git a/xsuite-fullsimulnet/index.d.ts b/xsuite-fullsimulnet/index.d.ts index 1a412084..4f5d1e34 100644 --- a/xsuite-fullsimulnet/index.d.ts +++ b/xsuite-fullsimulnet/index.d.ts @@ -1 +1,3 @@ -export declare function getFsproxyBinPath(): string; +export declare const fsproxyBinaryPath: string; + +export declare const fsproxyConfigsPath: string; diff --git a/xsuite-fullsimulnet/index.js b/xsuite-fullsimulnet/index.js index 3126eccf..12fce4cd 100644 --- a/xsuite-fullsimulnet/index.js +++ b/xsuite-fullsimulnet/index.js @@ -1,4 +1,6 @@ -function getFsproxyBinPath() { +const path = require("node:path"); + +const fsproxyBinaryPath = (() => { if (process.arch === "x64" || process.arch === "arm64") { if (process.platform === "linux") { return require.resolve("@xsuite/full-simulnet-linux-amd64/bin/fsproxy"); @@ -7,6 +9,8 @@ function getFsproxyBinPath() { } } throw new Error(`Unsupported config: ${process.platform} ${process.arch}`); -} +})(); + +const fsproxyConfigsPath = path.join(__dirname, "config"); -module.exports = { getFsproxyBinPath }; +module.exports = { fsproxyBinaryPath, fsproxyConfigsPath }; diff --git a/xsuite-fullsimulnet/index.test.js b/xsuite-fullsimulnet/index.test.js index b827e4fa..c8b13d6b 100644 --- a/xsuite-fullsimulnet/index.test.js +++ b/xsuite-fullsimulnet/index.test.js @@ -1,9 +1,9 @@ const { spawn } = require("child_process"); const { test } = require("node:test"); -const { getFsproxyBinPath } = require("."); +const { fsproxyBinaryPath } = require("."); test("binary starts", { timeout: 2000 }, async () => { - const server = spawn(getFsproxyBinPath()); + const server = spawn(fsproxyBinaryPath); await new Promise((resolve) => { server.stdout.on("data", (data) => { if ( diff --git a/xsuite-fullsimulnet/package.json b/xsuite-fullsimulnet/package.json index 05c02b0f..2080a5f2 100644 --- a/xsuite-fullsimulnet/package.json +++ b/xsuite-fullsimulnet/package.json @@ -1,6 +1,6 @@ { "name": "@xsuite/full-simulnet", - "version": "0.0.7", + "version": "0.0.10", "license": "MIT", "scripts": { "build": "run-script-os", diff --git a/xsuite-lightsimulnet-darwin-amd64/package.json b/xsuite-lightsimulnet-darwin-amd64/package.json index e66386fe..e1f1deed 100644 --- a/xsuite-lightsimulnet-darwin-amd64/package.json +++ b/xsuite-lightsimulnet-darwin-amd64/package.json @@ -1,6 +1,6 @@ { "name": "@xsuite/light-simulnet-darwin-amd64", - "version": "0.0.26", + "version": "0.0.29", "os": [ "darwin" ], diff --git a/xsuite-lightsimulnet-linux-amd64/package.json b/xsuite-lightsimulnet-linux-amd64/package.json index a1d1980d..4f22a427 100644 --- a/xsuite-lightsimulnet-linux-amd64/package.json +++ b/xsuite-lightsimulnet-linux-amd64/package.json @@ -1,6 +1,6 @@ { "name": "@xsuite/light-simulnet-linux-amd64", - "version": "0.0.26", + "version": "0.0.29", "os": [ "linux" ], diff --git a/xsuite-lightsimulnet/build-binary.mjs b/xsuite-lightsimulnet/build-binary.mjs index 6878b754..31e2bbe7 100644 --- a/xsuite-lightsimulnet/build-binary.mjs +++ b/xsuite-lightsimulnet/build-binary.mjs @@ -1,6 +1,14 @@ +import assert from "node:assert"; import { $, cd, minimist } from "zx"; const argv = minimist(process.argv.slice(2)); +if (process.env.CI) { + assert.deepStrictEqual(await $`go env GOOS GOARCH`.lines(), [ + argv.os, + argv.arch, + ]); +} + cd("src"); -await $`GOOS=${argv.os} GOARCH=${argv.arch} go build -o ../../xsuite-lightsimulnet-${argv.os}-${argv.arch}/bin/lsproxy -ldflags ${argv.ldflags}`; +await $`go build -o ../../xsuite-lightsimulnet-${argv.os}-${argv.arch}/bin/lsproxy -ldflags ${argv.ldflags}`; diff --git a/xsuite-lightsimulnet/index.d.ts b/xsuite-lightsimulnet/index.d.ts index 873e7ece..4ae65e6b 100644 --- a/xsuite-lightsimulnet/index.d.ts +++ b/xsuite-lightsimulnet/index.d.ts @@ -1 +1 @@ -export declare function getLsproxyBinPath(): string; +export declare const lsproxyBinaryPath: string; diff --git a/xsuite-lightsimulnet/index.js b/xsuite-lightsimulnet/index.js index 76e4e286..89136460 100644 --- a/xsuite-lightsimulnet/index.js +++ b/xsuite-lightsimulnet/index.js @@ -1,4 +1,4 @@ -function getLsproxyBinPath() { +const lsproxyBinaryPath = (() => { if (process.arch === "x64" || process.arch === "arm64") { if (process.platform === "linux") { return require.resolve("@xsuite/light-simulnet-linux-amd64/bin/lsproxy"); @@ -7,6 +7,6 @@ function getLsproxyBinPath() { } } throw new Error(`Unsupported config: ${process.platform} ${process.arch}`); -} +})(); -module.exports = { getLsproxyBinPath }; +module.exports = { lsproxyBinaryPath }; diff --git a/xsuite-lightsimulnet/index.test.js b/xsuite-lightsimulnet/index.test.js index e877010c..be8493bd 100644 --- a/xsuite-lightsimulnet/index.test.js +++ b/xsuite-lightsimulnet/index.test.js @@ -1,9 +1,9 @@ const { spawn } = require("child_process"); const { test } = require("node:test"); -const { getLsproxyBinPath } = require("."); +const { lsproxyBinaryPath } = require("."); test("binary starts", { timeout: 1000 }, async () => { - const server = spawn(getLsproxyBinPath()); + const server = spawn(lsproxyBinaryPath); await new Promise((resolve) => { server.stdout.on("data", (data) => { if (/Server running on (http:\/\/[\w\d.:]+)/.test(data.toString())) { diff --git a/xsuite-lightsimulnet/package.json b/xsuite-lightsimulnet/package.json index 12ab77cd..1af368c7 100644 --- a/xsuite-lightsimulnet/package.json +++ b/xsuite-lightsimulnet/package.json @@ -1,6 +1,6 @@ { "name": "@xsuite/light-simulnet", - "version": "0.0.26", + "version": "0.0.29", "license": "MIT", "scripts": { "build": "run-script-os", diff --git a/xsuite-lightsimulnet/src/go.mod b/xsuite-lightsimulnet/src/go.mod index f67b3211..a3a5a25a 100644 --- a/xsuite-lightsimulnet/src/go.mod +++ b/xsuite-lightsimulnet/src/go.mod @@ -1,14 +1,14 @@ module lsproxy -go 1.17 +go 1.20 require ( github.com/go-chi/chi v1.5.4 - github.com/multiversx/mx-chain-core-go v1.2.18 - github.com/multiversx/mx-chain-logger-go v1.0.13 - github.com/multiversx/mx-chain-scenario-go v1.4.3-0.20240413152730-7374ba129c4f - github.com/multiversx/mx-chain-vm-common-go v1.5.11 - github.com/multiversx/mx-chain-vm-go v1.5.28-0.20240428121053-a93ccf9aadf8 + github.com/multiversx/mx-chain-core-go v1.2.20 + github.com/multiversx/mx-chain-logger-go v1.0.14 + github.com/multiversx/mx-chain-scenario-go v1.4.4-0.20240708183543-61f6e1880d1d + github.com/multiversx/mx-chain-vm-common-go v1.5.12 + github.com/multiversx/mx-chain-vm-go v1.5.30-0.20240713084912-93532045748c ) require ( @@ -24,7 +24,8 @@ require ( github.com/herumi/bls-go-binary v1.28.2 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/mr-tron/base58 v1.2.0 // indirect - github.com/multiversx/mx-chain-crypto-go v1.2.9 // indirect + github.com/multiversx/mx-chain-crypto-go v1.2.11 // indirect + github.com/multiversx/mx-chain-storage-go v1.0.15 // indirect github.com/multiversx/mx-components-big-int v1.0.0 // indirect github.com/pelletier/go-toml v1.9.3 // indirect golang.org/x/crypto v0.3.0 // indirect diff --git a/xsuite-lightsimulnet/src/go.sum b/xsuite-lightsimulnet/src/go.sum index 476c4047..9611a762 100644 --- a/xsuite-lightsimulnet/src/go.sum +++ b/xsuite-lightsimulnet/src/go.sum @@ -1,12 +1,8 @@ -filippo.io/edwards25519 v1.0.0/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns= -github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= github.com/TwiN/go-color v1.1.0 h1:yhLAHgjp2iAxmNjDiVb6Z073NE65yoaPlcki1Q22yyQ= github.com/TwiN/go-color v1.1.0/go.mod h1:aKVf4e1mD4ai2FtPifkDPP5iyoCwiK08YGzGwerjKo0= github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII= -github.com/awalterschulze/gographviz v2.0.3+incompatible/go.mod h1:GEV5wmg4YquNw7v1kkyoX9etIk8yVmXj+AkDHuuETHs= github.com/btcsuite/btcd v0.20.1-beta/go.mod h1:wVuoA8VJLEcwgqHBwHmzLRazpKxTv13Px/pDuV7OomQ= github.com/btcsuite/btcd v0.22.0-beta.0.20220111032746-97732e52810c/go.mod h1:tjmYdS6MLJ5/s0Fj4DbLgSbDHbEqLJrtnHecBFkdz5M= -github.com/btcsuite/btcd v0.23.0 h1:V2/ZgjfDFIygAX3ZapeigkVBoVUtOJKSwrhZdlpSvaA= github.com/btcsuite/btcd v0.23.0/go.mod h1:0QJIIN1wwIXF/3G/m87gIwGniDMDQqjVn4SZgnFpsYY= github.com/btcsuite/btcd/btcec/v2 v2.1.0/go.mod h1:2VzYrv4Gm4apmbVVsSq5bqf1Ec8v56E48Vt0Y/umPgA= github.com/btcsuite/btcd/btcec/v2 v2.1.3/go.mod h1:ctjw4H1kknNJmRN4iP1R7bTQ+v3GJkZBd6mui8ZsAZE= @@ -28,8 +24,6 @@ github.com/btcsuite/snappy-go v0.0.0-20151229074030-0bdef8d06723/go.mod h1:8woku github.com/btcsuite/snappy-go v1.0.0/go.mod h1:8woku9dyThutzjeg+3xrA5iCpBRH8XEEg3lh6TiUghc= github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792/go.mod h1:ghJtEyQwv5/p4Mg4C0fgbePVuGr935/5ddU9Z3TmDRY= github.com/btcsuite/winsvc v1.0.0/go.mod h1:jsenWakMcC0zFBFurPLEAyrnc/teJEM1O46fmI40EZs= -github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= -github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v0.0.0-20171005155431-ecdeabc65495/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= @@ -63,7 +57,6 @@ github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4= github.com/hashicorp/golang-lru v0.6.0 h1:uL2shRDx7RTrOrTCUZEGP/wJUFiUI8QT6E7z5o8jga4= github.com/hashicorp/golang-lru v0.6.0/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4= github.com/herumi/bls-go-binary v1.28.2 h1:F0AezsC0M1a9aZjk7g0l2hMb1F56Xtpfku97pDndNZE= @@ -75,36 +68,28 @@ github.com/jrick/logrotate v1.0.0/go.mod h1:LNinyqDIJnpAur+b8yyulnQw/wDuN1+BYKlT github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/kkdai/bstream v0.0.0-20161212061736-f391b8402d23/go.mod h1:J+Gs4SYgM6CZQHDETBtE9HaSEkGmuNXF86RwHhHUvq4= -github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= -github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= -github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= -github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= -github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= -github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= -github.com/mitchellh/mapstructure v1.4.1/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/mr-tron/base58 v1.2.0 h1:T/HDJBh4ZCPbU39/+c3rRvE0uKBQlU27+QI8LJ4t64o= github.com/mr-tron/base58 v1.2.0/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc= -github.com/multiversx/mx-chain-core-go v1.2.13/go.mod h1:BILOGHUOIG5dNNX8cgkzCNfDaVtoYrJRYcPnpxRMH84= -github.com/multiversx/mx-chain-core-go v1.2.18 h1:fnub2eFL7XYOLrKKVZAPPsaM1TWEnaK5qqY3FLUv168= -github.com/multiversx/mx-chain-core-go v1.2.18/go.mod h1:BILOGHUOIG5dNNX8cgkzCNfDaVtoYrJRYcPnpxRMH84= -github.com/multiversx/mx-chain-crypto-go v1.2.9 h1:OEfF2kOQrtzUl273Z3DEcshjlTVUfPpJMd0R0SvTrlU= -github.com/multiversx/mx-chain-crypto-go v1.2.9/go.mod h1:fkaWKp1rbQN9wPKya5jeoRyC+c/SyN/NfggreyeBw+8= -github.com/multiversx/mx-chain-logger-go v1.0.13 h1:eru/TETo0MkO4ZTnXsQDKf4PBRpAXmqjT02klNT/JnY= -github.com/multiversx/mx-chain-logger-go v1.0.13/go.mod h1:MZJhTAtZTJxT+yK2EHc4ZW3YOHUc1UdjCD0iahRNBZk= -github.com/multiversx/mx-chain-scenario-go v1.4.1/go.mod h1:Sdgz8nzA9Ki/pdY/e2a4k90LALBKQB1Eo8HeCV3Bkzo= -github.com/multiversx/mx-chain-scenario-go v1.4.3-0.20240413152730-7374ba129c4f h1:4vKDKnuh/mrfTxckac7yVcR86R4ZQcdjl1YG/tWT/lw= -github.com/multiversx/mx-chain-scenario-go v1.4.3-0.20240413152730-7374ba129c4f/go.mod h1:Sdgz8nzA9Ki/pdY/e2a4k90LALBKQB1Eo8HeCV3Bkzo= -github.com/multiversx/mx-chain-vm-common-go v1.5.9/go.mod h1:sqkKMCnwkWl8DURdb9q7pctK8IANghdHY1KJLE0ox2c= -github.com/multiversx/mx-chain-vm-common-go v1.5.11 h1:rAQR00ALKOmWAuNA8XW8hR02M9gmrAE4WZwyJH4dMMU= -github.com/multiversx/mx-chain-vm-common-go v1.5.11/go.mod h1:T04rZt/VdwjPXcXVxltMmDmrhxNXsqlByYbWNWcNLYA= -github.com/multiversx/mx-chain-vm-go v1.5.27 h1:80AdXyjAnN5w4hucPMtpsXnoWtcV47ZLcjECsTTccsA= -github.com/multiversx/mx-chain-vm-go v1.5.27/go.mod h1:Y1O50Z7+suo4D1hnSBA7n34KvgKs5W9jzoEGwpfAjks= -github.com/multiversx/mx-chain-vm-go v1.5.28-0.20240428114511-e64da3ef0999 h1:wqWPtyIOCNfin9wamlcXKOFY6SZHWEOxkRjuWtLp37o= -github.com/multiversx/mx-chain-vm-go v1.5.28-0.20240428114511-e64da3ef0999/go.mod h1:Y1O50Z7+suo4D1hnSBA7n34KvgKs5W9jzoEGwpfAjks= -github.com/multiversx/mx-chain-vm-go v1.5.28-0.20240428121053-a93ccf9aadf8 h1:GN1xYRb3nV6+cRPLkv7xdEY+4HzZfPsQMoNaIi718Ko= -github.com/multiversx/mx-chain-vm-go v1.5.28-0.20240428121053-a93ccf9aadf8/go.mod h1:Y1O50Z7+suo4D1hnSBA7n34KvgKs5W9jzoEGwpfAjks= +github.com/multiversx/mx-chain-core-go v1.2.20 h1:jOQ10LxxUqECnuqUYeBBT6VoZcpJDdYgOvsSGtifDdI= +github.com/multiversx/mx-chain-core-go v1.2.20/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= +github.com/multiversx/mx-chain-crypto-go v1.2.11 h1:MNPJoiTJA5/tedYrI0N22OorbsKDESWG0SF8MCJwcJI= +github.com/multiversx/mx-chain-crypto-go v1.2.11/go.mod h1:pcZutPdfLiAFytzCU3LxU3s8cXkvpNqquyitFSfoF3o= +github.com/multiversx/mx-chain-logger-go v1.0.14 h1:PRMpAvXE7Nec2d//QNmbYfKVHMomOKmcN4UXurQWX9o= +github.com/multiversx/mx-chain-logger-go v1.0.14/go.mod h1:bDfHSdwqIimn7Gp8w+SH5KlDuGzJ//nlyEANAaTSc3o= +github.com/multiversx/mx-chain-scenario-go v1.4.3 h1:9xeVB8TOsolXS4YEr1CZ/VZr5Qk0X+nde8nRGnxJICo= +github.com/multiversx/mx-chain-scenario-go v1.4.3/go.mod h1:Bd7/Xs3mWM6pX/REHK5dfpf3MUfjMZ7li09cfCxg2ac= +github.com/multiversx/mx-chain-scenario-go v1.4.4-0.20240708183543-61f6e1880d1d h1:N7OWMPevqD2E2O4cnOKe0N+Qs3BPfSLHdxhY0E14/lU= +github.com/multiversx/mx-chain-scenario-go v1.4.4-0.20240708183543-61f6e1880d1d/go.mod h1:Bd7/Xs3mWM6pX/REHK5dfpf3MUfjMZ7li09cfCxg2ac= +github.com/multiversx/mx-chain-storage-go v1.0.15 h1:PDyP1uouAVjR32dFgM+7iaQBdReD/tKBJj10JbxXvaE= +github.com/multiversx/mx-chain-storage-go v1.0.15/go.mod h1:GZUK3sqf5onsWS/0ZPWjDCBjAL22FigQPUh252PAVk0= +github.com/multiversx/mx-chain-vm-common-go v1.5.12 h1:Q8F6DE7XhgHtWgg2rozSv4Tv5fE3ENkJz6mjRoAfht8= +github.com/multiversx/mx-chain-vm-common-go v1.5.12/go.mod h1:Sv6iS1okB6gy3HAsW6KHYtAxShNAfepKLtu//AURI8c= +github.com/multiversx/mx-chain-vm-go v1.5.29 h1:Ovz5/WM9KbD3YKRafdKI4RwtsNN36AGeNw81LZAhE70= +github.com/multiversx/mx-chain-vm-go v1.5.29/go.mod h1:n0SbVEAhIflreAGi7BnfWg4p4VHh4G8ArbvYQZsZsKQ= +github.com/multiversx/mx-chain-vm-go v1.5.30-0.20240713084912-93532045748c h1:Cj4smHBKeHB346IeRFcEVIMsoxeT80HEn3zIMruEY+I= +github.com/multiversx/mx-chain-vm-go v1.5.30-0.20240713084912-93532045748c/go.mod h1:n0SbVEAhIflreAGi7BnfWg4p4VHh4G8ArbvYQZsZsKQ= github.com/multiversx/mx-components-big-int v1.0.0 h1:Wkr8lSzK2nDqixOrrBa47VNuqdhV1m/aJhaP1EMaiS8= github.com/multiversx/mx-components-big-int v1.0.0/go.mod h1:maIEMgHlNE2u78JaDD0oLzri+ShgU4okHfzP3LWGdQM= github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= @@ -118,37 +103,22 @@ github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7J github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= github.com/pelletier/go-toml v1.9.3 h1:zeC5b1GviRUyKYd6OJPvBU/mcVDVoL1OhT17FCt5dSQ= github.com/pelletier/go-toml v1.9.3/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c= -github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= -github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= -github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE= -github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= -github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= -github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7/go.mod h1:q4W45IWZaF22tdD+VEXcAWRA037jwmWEB5VWYORlTpc= -github.com/urfave/cli/v2 v2.27.1/go.mod h1:8qnjx1vcq5s2/wpsqoZFndg2CE5tNFyrTvS6SinrnYQ= -github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= -github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= golang.org/x/crypto v0.0.0-20170930174604-9419663f5a44/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.3.0 h1:a06MkbcxBrEFc0w0QIZWXrH/9cCX6KJyWbBOIwAn+7A= golang.org/x/crypto v0.3.0/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4= golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/net v0.0.0-20180719180050-a680a1efc54d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= @@ -157,14 +127,10 @@ golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLL golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= golang.org/x/net v0.0.0-20200813134508-3edf25e44fcc/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= -golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= -golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= -golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -175,25 +141,15 @@ golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20200519105757-fe76b779f299/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200814200057-3d37ad5750ed/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.2.0 h1:ljd4t30dBnAvMZaQCevtY0xLLD0A+bRZXbgLMLU1F/A= golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= -golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= -golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= @@ -210,9 +166,6 @@ google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQ google.golang.org/protobuf v1.28.0 h1:w43yiav+6bVFTBQFZX0r7ipe9JQ1QsbMgHwbBziscLw= google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= -gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= @@ -220,4 +173,3 @@ gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= -gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/xsuite-lightsimulnet/src/handleTransaction.go b/xsuite-lightsimulnet/src/handleTransaction.go index 1cdc190c..ab86bf9d 100644 --- a/xsuite-lightsimulnet/src/handleTransaction.go +++ b/xsuite-lightsimulnet/src/handleTransaction.go @@ -17,6 +17,28 @@ import ( worldmock "github.com/multiversx/mx-chain-scenario-go/worldmock" ) +func (e *Executor) HandleTransactionSend(r *http.Request) (interface{}, error) { + reqBody, _ := io.ReadAll(r.Body) + var rawTx RawTx + err := json.Unmarshal(reqBody, &rawTx) + if err != nil { + return nil, err + } + e.txCounter += 1 + txHash := uint64ToString(e.txCounter) + err = e.executeTx(txHash, rawTx) + if err != nil { + return nil, err + } + jOutput := map[string]interface{}{ + "data": map[string]interface{}{ + "txHash": txHash, + }, + "code": "successful", + } + return jOutput, nil +} + func (e *Executor) HandleTransactionSendMultiple(r *http.Request) (interface{}, error) { reqBody, _ := io.ReadAll(r.Body) var rawTxs []RawTx @@ -28,8 +50,10 @@ func (e *Executor) HandleTransactionSendMultiple(r *http.Request) (interface{}, for i, rawTx := range rawTxs { e.txCounter += 1 txHash := uint64ToString(e.txCounter) - txsHashes[strconv.Itoa(i)] = txHash - e.executeTx(txHash, rawTx) + err := e.executeTx(txHash, rawTx) + if err == nil { + txsHashes[strconv.Itoa(i)] = txHash + } } jOutput := map[string]interface{}{ "data": map[string]interface{}{ @@ -77,6 +101,9 @@ func (e *Executor) executeTx(txHash string, rawTx RawTx) (error) { if rawTx.Version != 1 { return errors.New("invalid version") } + if rawTx.GasLimit < 50_000 { + return errors.New("insufficient gas limit") + } tx := &model.TxStep{ Tx: &model.Transaction{ Nonce: model.JSONUint64{Value: rawTx.Nonce}, diff --git a/xsuite-lightsimulnet/src/main.go b/xsuite-lightsimulnet/src/main.go index 357ecc0a..806f7299 100644 --- a/xsuite-lightsimulnet/src/main.go +++ b/xsuite-lightsimulnet/src/main.go @@ -2,6 +2,7 @@ package main import ( "encoding/json" + "flag" "fmt" "net" "net/http" @@ -10,7 +11,10 @@ import ( ) func main() { - listener, err := net.Listen("tcp", "localhost:0") + port := flag.Int("server-port", 8085, "Port to start the server on (default: 8085)") + flag.Parse() + + listener, err := net.Listen("tcp", fmt.Sprintf("localhost:%d", *port)) if err != nil { panic(err) } @@ -43,6 +47,11 @@ func main() { respond(w, resBody, err) }) + router.Post("/transaction/send", func(w http.ResponseWriter, r *http.Request) { + resBody, err := executor.HandleTransactionSend(r) + respond(w, resBody, err) + }) + router.Post("/transaction/send-multiple", func(w http.ResponseWriter, r *http.Request) { resBody, err := executor.HandleTransactionSendMultiple(r) respond(w, resBody, err) diff --git a/xsuite/package.json b/xsuite/package.json index ec68ff1f..8d55984a 100644 --- a/xsuite/package.json +++ b/xsuite/package.json @@ -1,6 +1,6 @@ { "name": "xsuite", - "version": "0.0.67", + "version": "0.0.71", "license": "MIT", "bin": { "xsuite": "cli.js" diff --git a/xsuite/src/cli/buildCmd.ts b/xsuite/src/cli/buildCmd.ts index f239b00f..3cf89966 100644 --- a/xsuite/src/cli/buildCmd.ts +++ b/xsuite/src/cli/buildCmd.ts @@ -2,12 +2,16 @@ import fs from "node:fs"; import path from "node:path"; import { Command } from "commander"; import { cwd, log } from "../context"; -import { logTitle, logAndRunCommand, logError } from "./helpers"; +import { logTitle, logAndRunCommand, logError, logWarning } from "./helpers"; export const addBuildCmd = (cmd: Command) => { cmd .command("build") .description("Build contract.") + .argument( + "[DIR]", + "Directory in which the command is executed (default: $(PWD))", + ) .option( "--ignore ", `Ignore all directories matching the RegExp (default: ${defaultIgnore})`, @@ -18,7 +22,7 @@ export const addBuildCmd = (cmd: Command) => { ) .option( "--dir ", - "Directory in which the command is executed (default: $(PWD))", + "[DEPRECATED] Directory in which the command is executed (default: $(PWD))", ) .option("-r, --recursive", "Build all contracts under the directory") .option( @@ -28,20 +32,39 @@ export const addBuildCmd = (cmd: Command) => { .action(action); }; -const action = ({ - ignore, - locked, - dir, - recursive, - targetDir, -}: { - ignore?: string; - locked?: boolean; - dir?: string; - recursive?: boolean; - targetDir?: string; -}) => { - dir = dir ?? cwd(); +const action = ( + dirArgument: string | undefined, + { + ignore, + locked, + dir: dirOption, + recursive, + targetDir, + }: { + ignore?: string; + locked?: boolean; + dir?: string; + recursive?: boolean; + targetDir?: string; + }, +) => { + let dir: string; + if (dirArgument !== undefined) { + if (dirOption !== undefined) { + logError( + "Cannot use both the DIR argument and the --dir option. You should use only the DIR argument as the --dir option is deprecated.", + ); + return; + } + dir = dirArgument; + } else if (dirOption !== undefined) { + logWarning( + "The --dir option is deprecated, you should use the DIR argument instead.", + ); + dir = dirOption; + } else { + dir = cwd(); + } targetDir = targetDir ?? path.resolve(cwd(), "target"); const dirs: string[] = []; if (recursive) { diff --git a/xsuite/src/cli/cli.test.ts b/xsuite/src/cli/cli.test.ts index 2d235d70..59f3c295 100644 --- a/xsuite/src/cli/cli.test.ts +++ b/xsuite/src/cli/cli.test.ts @@ -343,12 +343,12 @@ test.concurrent("install-rust", async () => { }); test.concurrent( - "new --dir contract && build --locked && build -r && test-rust && test-scen", + "new contract && build --locked && build -r && test-rust && test-scen", async () => { using c = newContext(); const dir = "contract"; - await c.cmd(`new --dir ${dir}`); + await c.cmd(`new ${dir}`); expect(fs.readdirSync(c.cwd()).length).toEqual(1); const starterChalk = chalk.magenta("blank"); const absDirPath = path.resolve(c.cwd(), dir); @@ -431,12 +431,12 @@ test.concurrent( ); test.concurrent( - "new --starter vested-transfers --dir contract --no-git --no-install", + "new contract --starter vested-transfers --no-git --no-install", async () => { using c = newContext(); const starter = "vested-transfers"; const dir = "contract"; - await c.cmd(`new --starter ${starter} --dir ${dir} --no-git --no-install`); + await c.cmd(`new ${dir} --starter ${starter} --no-git --no-install`); expect(fs.readdirSync(c.cwd()).length).toEqual(1); const starterChalk = chalk.magenta(starter); const absDirPath = path.resolve(c.cwd(), dir); @@ -466,11 +466,11 @@ test.concurrent( 100_000, ); -test.concurrent("new --dir contract | error: already exists", async () => { +test.concurrent("new contract | error: already exists", async () => { using c = newContext(); const absDirPath = path.resolve(c.cwd(), "contract"); fs.mkdirSync(absDirPath); - await c.cmd("new --dir contract"); + await c.cmd("new contract"); expect(c.flushStdout()).toEqual( chalk.red(`Directory already exists at "${absDirPath}".`) + "\n", ); diff --git a/xsuite/src/cli/helpers.ts b/xsuite/src/cli/helpers.ts index 4c7c8917..e5157d13 100644 --- a/xsuite/src/cli/helpers.ts +++ b/xsuite/src/cli/helpers.ts @@ -18,6 +18,8 @@ export const logSuccess = (text: string) => log(chalk.green(text)); export const logError = (text: string) => log(chalk.red(text)); +export const logWarning = (text: string) => log(chalk.yellow(text)); + export const logAndRunCommand = ( command: string, args: string[], diff --git a/xsuite/src/cli/newCmd.ts b/xsuite/src/cli/newCmd.ts index 6aed9f44..e528c3a5 100644 --- a/xsuite/src/cli/newCmd.ts +++ b/xsuite/src/cli/newCmd.ts @@ -11,30 +11,53 @@ import { logCommand, logError, downloadArchive, + logWarning, } from "./helpers"; export const addNewCmd = (cmd: Command) => { cmd .command("new") .description("Create a new blank contract.") - .requiredOption("--dir ", "Contract dir") + .argument("[DIR]", "Contract dir") + .option("--dir ", "[DEPRECATED] Contract dir") .option("--starter ", "Contract to start from") .option("--no-install", "Skip package installation") .option("--no-git", "Skip git initialization") .action(action); }; -const action = async ({ - dir: dirPath, - starter = "blank", - install, - git, -}: { - dir: string; - starter?: string; - install?: boolean; - git?: boolean; -}) => { +const action = async ( + dirArgument: string | undefined, + { + dir: dirOption, + starter = "blank", + install, + git, + }: { + dir?: string; + starter?: string; + install?: boolean; + git?: boolean; + }, +) => { + let dirPath: string; + if (dirArgument !== undefined) { + if (dirOption !== undefined) { + logError( + "Cannot use both the DIR argument and the --dir option. You should use only the DIR argument as the --dir option is deprecated.", + ); + return; + } + dirPath = dirArgument; + } else if (dirOption !== undefined) { + logWarning( + "The --dir option is deprecated, you should use the DIR argument instead.", + ); + dirPath = dirOption; + } else { + logError("The DIR argument is required."); + return; + } const absDirPath = path.resolve(cwd(), dirPath); if (fs.existsSync(absDirPath)) { logError(`Directory already exists at "${absDirPath}".`); diff --git a/xsuite/src/data/encoding.ts b/xsuite/src/data/encoding.ts index ad0d3f01..ff62d936 100644 --- a/xsuite/src/data/encoding.ts +++ b/xsuite/src/data/encoding.ts @@ -238,7 +238,7 @@ export const e = { account.code = encodableAccount.code; } if (encodableAccount.codeHash !== undefined) { - account.codeHash = eCodeMetadata(encodableAccount.codeHash); + account.codeHash = encodableAccount.codeHash; } if (encodableAccount.codeMetadata !== undefined) { account.codeMetadata = eCodeMetadata(encodableAccount.codeMetadata); @@ -521,8 +521,8 @@ const eKvsEsdt = ({ id, roles, lastNonce, ...rest }: EncodableEsdt): Kvs => { } if (metadata.length > 0) { metadata.push(["Nonce", nonce.toString()]); - message["Properties"] = new Uint8Array([1]); message["Metadata"] = Object.fromEntries(metadata); + message["Reserved"] = new Uint8Array([1]); } } else { for (const [k, v] of Object.entries(rest)) { diff --git a/xsuite/src/data/index.test.ts b/xsuite/src/data/index.test.ts index 5781a19a..9741b66c 100644 --- a/xsuite/src/data/index.test.ts +++ b/xsuite/src/data/index.test.ts @@ -717,6 +717,7 @@ test("e.kvs - complex kvs", () => { id: sft1Id, variants: range(1, 11).map((i) => ({ nonce: i, + amount: i, name: `SFT1 ${i}`, royalties: i, hash: e.U(i), @@ -729,6 +730,7 @@ test("e.kvs - complex kvs", () => { id: sft2Id, variants: range(1, 11).map((i) => ({ nonce: i, + amount: i, attrs: e.Tuple(e.Str(`${i}`), e.U(i)), creator: contract, })), @@ -736,6 +738,7 @@ test("e.kvs - complex kvs", () => { { id: sft3Id, nonce: 1, + amount: 1, creator: contract, }, ], @@ -1307,6 +1310,7 @@ test("d.kvs", async () => { id: sft1Id, variants: range(1, 11).map((i) => ({ nonce: i, + amount: BigInt(i), name: `SFT1 ${i}`, royalties: i, hash: e.U(i).toTopHex(), @@ -1319,11 +1323,12 @@ test("d.kvs", async () => { id: sft2Id, variants: range(1, 11).map((i) => ({ nonce: i, + amount: BigInt(i), attrs: [`${i}`, BigInt(i)], creator: contract, })), }, - { id: sft3Id, variants: [{ nonce: 1, creator: contract }] }, + { id: sft3Id, variants: [{ nonce: 1, amount: 1n, creator: contract }] }, ], }); }); diff --git a/xsuite/src/proxy/fsproxy.ts b/xsuite/src/proxy/fsproxy.ts index a08dc5e2..f83315ac 100644 --- a/xsuite/src/proxy/fsproxy.ts +++ b/xsuite/src/proxy/fsproxy.ts @@ -3,6 +3,18 @@ import { hexToBase64 } from "../data/utils"; import { getValuesInOrder, Proxy } from "./proxy"; export class FSProxy extends Proxy { + async sendTxs(...[txs]: Parameters) { + const r = await super.sendTxs(txs); + await new Promise((r) => setTimeout(r, 250)); // TODO-MvX: to be removed once they fix this + return r; + } + + async sendTx(...[tx]: Parameters) { + const r = await super.sendTx(tx); + await new Promise((r) => setTimeout(r, 250)); // TODO-MvX: to be removed once they fix this + return r; + } + async getInitialAddresses() { const res = await this.fetch("/simulator/initial-wallets"); return { diff --git a/xsuite/src/proxy/proxy.ts b/xsuite/src/proxy/proxy.ts index 997dd37c..163c5920 100644 --- a/xsuite/src/proxy/proxy.ts +++ b/xsuite/src/proxy/proxy.ts @@ -53,12 +53,18 @@ export class Proxy { rawTxs.push(await broadTxToRawTx(tx)); } const res = await this.fetch("/transaction/send-multiple", rawTxs); - await new Promise((r) => setTimeout(r, 250)); // TODO-MvX: to be removed once they fix this - return getValuesInOrder(res.txsHashes) as string[]; + const txsHashesSent = getValuesInOrder(res.txsHashes) as string[]; + if (txsHashesSent.length !== rawTxs.length) { + throw new Error( + `Only ${txsHashesSent.length} of ${rawTxs.length} transactions were sent. The other ones were invalid.`, + ); + } + return txsHashesSent; } - sendTx(tx: BroadTx) { - return this.sendTxs([tx]).then((r) => r[0]); + async sendTx(tx: BroadTx) { + const res = await this.fetch("/transaction/send", await broadTxToRawTx(tx)); + return res.txHash as string; } sendTransfers(txs: TransferTx[]) { @@ -66,7 +72,7 @@ export class Proxy { } sendTransfer(tx: TransferTx) { - return this.sendTransfers([tx]).then((r) => r[0]); + return this.sendTx(transferTxToTx(tx)); } sendDeployContracts(txs: DeployContractTx[]) { @@ -74,7 +80,7 @@ export class Proxy { } sendDeployContract(tx: DeployContractTx) { - return this.sendDeployContracts([tx]).then((r) => r[0]); + return this.sendTx(deployContractTxToTx(tx)); } sendCallContracts(txs: CallContractTx[]) { @@ -82,7 +88,7 @@ export class Proxy { } sendCallContract(tx: CallContractTx) { - return this.sendCallContracts([tx]).then((r) => r[0]); + return this.sendTx(callContractTxToTx(tx)); } sendUpgradeContracts(txs: UpgradeContractTx[]) { @@ -90,7 +96,7 @@ export class Proxy { } sendUpgradeContract(tx: UpgradeContractTx) { - return this.sendUpgradeContracts([tx]).then((r) => r[0]); + return this.sendTx(upgradeContractTxToTx(tx)); } async awaitTx(txHash: string) { @@ -183,8 +189,10 @@ export class Proxy { return this.resolveTxs(txHashes); } - executeTx(tx: BroadTx) { - return this.executeTxs([tx]).then((r) => r[0]); + async executeTx(tx: BroadTx) { + const txHash = await this.sendTx(tx); + await this.awaitTx(txHash); + return this.resolveTx(txHash); } async doTransfers(txs: TransferTx[]) { @@ -193,8 +201,10 @@ export class Proxy { return this.resolveTransfers(txHashs); } - transfer(tx: TransferTx) { - return this.doTransfers([tx]).then((r) => r[0]); + async transfer(tx: TransferTx) { + const txHash = await this.sendTransfer(tx); + await this.awaitTx(txHash); + return this.resolveTransfer(txHash); } async deployContracts(txs: DeployContractTx[]) { @@ -203,8 +213,10 @@ export class Proxy { return this.resolveDeployContracts(txHashes); } - deployContract(tx: DeployContractTx) { - return this.deployContracts([tx]).then((r) => r[0]); + async deployContract(tx: DeployContractTx) { + const txHash = await this.sendDeployContract(tx); + await this.awaitTx(txHash); + return this.resolveDeployContract(txHash); } async callContracts(txs: CallContractTx[]) { @@ -213,8 +225,10 @@ export class Proxy { return this.resolveCallContracts(txHashes); } - callContract(tx: CallContractTx) { - return this.callContracts([tx]).then((r) => r[0]); + async callContract(tx: CallContractTx) { + const txHash = await this.sendCallContract(tx); + await this.awaitTx(txHash); + return this.resolveCallContract(txHash); } async upgradeContracts(txs: UpgradeContractTx[]) { @@ -223,8 +237,10 @@ export class Proxy { return this.resolveUpgradeContracts(txHashes); } - upgradeContract(tx: UpgradeContractTx) { - return this.upgradeContracts([tx]).then((r) => r[0]); + async upgradeContract(tx: UpgradeContractTx) { + const txHash = await this.sendUpgradeContract(tx); + await this.awaitTx(txHash); + return this.resolveUpgradeContract(txHash); } async query(query: BroadQuery): Promise { diff --git a/xsuite/src/world/childProcesses.ts b/xsuite/src/world/childProcesses.ts deleted file mode 100644 index 05147db5..00000000 --- a/xsuite/src/world/childProcesses.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { ChildProcess, spawn } from "child_process"; - -export const childProcesses: Set = new Set(); - -export const spawnChildProcess: typeof spawn = (...args: any) => { - const childProcess = (spawn as any)(...args); - childProcesses.add(childProcess); - return childProcess; -}; - -export const killChildProcess = (childProcess: ChildProcess) => { - childProcess.kill(); - childProcesses.delete(childProcess); -}; - -process.on("SIGTERM", () => { - for (const childProcess of childProcesses) { - killChildProcess(childProcess); - } -}); diff --git a/xsuite/src/world/fsproxyBin.ts b/xsuite/src/world/fsproxyBin.ts deleted file mode 100644 index 03c1f91b..00000000 --- a/xsuite/src/world/fsproxyBin.ts +++ /dev/null @@ -1,51 +0,0 @@ -import { ChildProcess } from "node:child_process"; -import path from "node:path"; -import { getFsproxyBinPath } from "@xsuite/full-simulnet"; -import { spawnChildProcess } from "./childProcesses"; - -export const startFsproxyBin = async (): Promise<{ - server: ChildProcess; - proxyUrl: string; -}> => { - const fsproxyBinPath = getFsproxyBinPath(); - - const fsproxyPkgPath = path.dirname( - require.resolve("@xsuite/full-simulnet/package.json"), - ); - const fsproxyConfigPath = `${fsproxyPkgPath}/config`; - - const server = spawnChildProcess(`${fsproxyBinPath}`, [ - "--server-port", - "0", - "--config", - `${fsproxyConfigPath}/config.toml`, - "--node-configs", - `${fsproxyConfigPath}/node/config`, - "--proxy-configs", - `${fsproxyConfigPath}/proxy/config`, - "--node-override-config", - `${fsproxyConfigPath}/nodeOverrideDefault.toml,${fsproxyConfigPath}/nodeOverride.toml`, - "--skip-configs-download", - ]); - - server.stderr.on("data", (data: Buffer) => { - throw new Error(data.toString()); - }); - - server.on("error", (error) => { - throw error; - }); - - const proxyUrl = await new Promise((resolve) => { - server.stdout.on("data", (data: Buffer) => { - const addressRegex = - /chain simulator's is accessible through the URL ([\w\d.:]+)/; - const match = data.toString().match(addressRegex); - if (match) { - resolve(`http://${match[1]}`); - } - }); - }); - - return { server, proxyUrl }; -}; diff --git a/xsuite/src/world/fsworld.test.ts b/xsuite/src/world/fsworld.test.ts index d8fa4674..70b37874 100644 --- a/xsuite/src/world/fsworld.test.ts +++ b/xsuite/src/world/fsworld.test.ts @@ -25,6 +25,23 @@ const emptyAccount = { }; const baseExplorerUrl = "http://explorer.local"; +test.concurrent("FSWorld.start - port 3000", async () => { + using world = await FSWorld.start({ binaryPort: 3000 }); + expect(world.proxy.proxyUrl).toEqual("http://localhost:3000"); +}); + +test.concurrent("FSWorld.start - epoch, round, blockNonce", async () => { + const epoch = 12; + const round = 34; + const blockNonce = 56; + using world = await FSWorld.start({ epoch, round, blockNonce }); + expect(await world.proxy.getNetworkStatus(0)).toMatchObject({ + epoch, + round, + nonce: blockNonce, + }); +}); + test.concurrent( "FSWorld.proxy.getAccountNonce on empty bech address", async () => { @@ -436,6 +453,44 @@ test.concurrent("FSWorld.transfer", async () => { }); }); +test.concurrent( + "FSWorld.transfer - invalid tx - gasLimit too low", + async () => { + using world = await FSWorld.start(); + const { wallet } = await createAccounts(world); + await expect( + world.transfer({ + sender: wallet, + receiver: wallet, + value: 0, + gasLimit: 0, + }), + ).rejects.toThrow( + "transaction generation failed: insufficient gas limit in tx", + ); + }, +); + +test.concurrent( + "FSWorld.doTransfers - invalid tx - gasLimit too low", + async () => { + using world = await FSWorld.start(); + const { wallet } = await createAccounts(world); + await expect( + world.doTransfers([ + { + sender: wallet, + receiver: wallet, + value: 0, + gasLimit: 0, + }, + ]), + ).rejects.toThrow( + "Only 0 of 1 transactions were sent. The other ones were invalid.", + ); + }, +); + test.concurrent("FSWorld.deployContract", async () => { using world = await FSWorld.start({ explorerUrl: baseExplorerUrl }); const { wallet } = await createAccounts(world); diff --git a/xsuite/src/world/fsworld.ts b/xsuite/src/world/fsworld.ts index 77edc831..751ddbb6 100644 --- a/xsuite/src/world/fsworld.ts +++ b/xsuite/src/world/fsworld.ts @@ -1,10 +1,9 @@ -import { ChildProcess } from "node:child_process"; +import { ChildProcess, spawn } from "node:child_process"; +import { fsproxyBinaryPath, fsproxyConfigsPath } from "@xsuite/full-simulnet"; import { AddressLike, isAddressLike } from "../data/addressLike"; import { EncodableAccount } from "../data/encoding"; import { Prettify, Replace } from "../helpers"; import { FSProxy } from "../proxy"; -import { killChildProcess } from "./childProcesses"; -import { startFsproxyBin } from "./fsproxyBin"; import { DummySigner, Signer } from "./signer"; import { AddressLikeParams, createAddressLike } from "./utils"; import { @@ -65,8 +64,108 @@ export class FSWorld extends World { static async start({ gasPrice, explorerUrl, - }: { gasPrice?: number; explorerUrl?: string } = {}): Promise { - const { server, proxyUrl } = await startFsproxyBin(); + binaryPath, + binaryPort, + binaryConfigPath, + proxyConfigsPath, + nodeConfigsPath, + nodeOverrideConfigPath, + nodeOverrideConfigPaths, + downloadConfigs, + epoch, + round, + blockNonce, + saveLogs, + logsLevel, + logsPath, + }: { + gasPrice?: number; + explorerUrl?: string; + binaryPath?: string; + binaryPort?: number; + binaryConfigPath?: string; + proxyConfigsPath?: string; + nodeConfigsPath?: string; + nodeOverrideConfigPath?: string; + nodeOverrideConfigPaths?: string[]; + downloadConfigs?: boolean; + epoch?: number; + round?: number; + blockNonce?: number; + saveLogs?: boolean; + logsLevel?: string; + logsPath?: string; + } = {}): Promise { + binaryPath ??= fsproxyBinaryPath; + binaryPort ??= 0; + binaryConfigPath ??= `${fsproxyConfigsPath}/config.toml`; + proxyConfigsPath ??= `${fsproxyConfigsPath}/proxy/config`; + nodeConfigsPath ??= `${fsproxyConfigsPath}/node/config`; + nodeOverrideConfigPaths ??= [ + `${fsproxyConfigsPath}/nodeOverrideDefault.toml`, + `${fsproxyConfigsPath}/nodeOverride.toml`, + ]; + if (nodeOverrideConfigPath !== undefined) { + nodeOverrideConfigPaths.push(nodeOverrideConfigPath); + } + logsLevel ??= "*:INFO,vm:TRACE"; + logsPath ??= "fsproxy-logs"; + + const args: string[] = [ + "--server-port", + `${binaryPort}`, + "--config", + binaryConfigPath, + "--proxy-configs", + proxyConfigsPath, + "--node-configs", + nodeConfigsPath, + ]; + if (nodeOverrideConfigPaths.length > 0) { + args.push("--node-override-config", nodeOverrideConfigPaths.join(",")); + } + if (!downloadConfigs) { + args.push("--skip-configs-download"); + } + if (epoch !== undefined) { + args.push("--initial-epoch", `${epoch}`); + } + if (round !== undefined) { + args.push("--initial-round", `${round - 1}`); + } + if (blockNonce !== undefined) { + args.push("--initial-nonce", `${blockNonce - 1}`); + } + if (saveLogs) { + args.push( + "-log-save", + "-log-level", + logsLevel, + "--path-log-save", + logsPath, + ); + } + const server = spawn(binaryPath, args); + + server.stderr.on("data", (data: Buffer) => { + throw new Error(data.toString()); + }); + + server.on("error", (error) => { + throw error; + }); + + const proxyUrl = await new Promise((resolve) => { + server.stdout.on("data", (data: Buffer) => { + const addressRegex = + /chain simulator's is accessible through the URL ([\w\d.:]+)/; + const match = data.toString().match(addressRegex); + if (match) { + resolve(`http://${match[1]}`); + } + }); + }); + return FSWorld.new({ proxyUrl, gasPrice, explorerUrl, server }); } @@ -177,7 +276,7 @@ export class FSWorld extends World { terminate() { if (!this.server) throw new Error("No server defined."); - killChildProcess(this.server); + this.server.kill(); } [Symbol.dispose]() { diff --git a/xsuite/src/world/lsproxyBin.ts b/xsuite/src/world/lsproxyBin.ts deleted file mode 100644 index 55a1292a..00000000 --- a/xsuite/src/world/lsproxyBin.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { ChildProcess } from "node:child_process"; -import { getLsproxyBinPath } from "@xsuite/light-simulnet"; -import { spawnChildProcess } from "./childProcesses"; - -export const startLsproxyBin = async (): Promise<{ - server: ChildProcess; - proxyUrl: string; -}> => { - const server = spawnChildProcess(getLsproxyBinPath()); - - server.stderr.on("data", (data: Buffer) => { - throw new Error(data.toString()); - }); - - server.on("error", (error) => { - throw error; - }); - - const proxyUrl = await new Promise((resolve) => { - server.stdout.on("data", (data: Buffer) => { - const addressRegex = /Server running on (http:\/\/[\w\d.:]+)/; - const match = data.toString().match(addressRegex); - if (match) { - resolve(match[1]); - } - }); - }); - - return { server, proxyUrl }; -}; diff --git a/xsuite/src/world/lsworld.test.ts b/xsuite/src/world/lsworld.test.ts index 8f823d94..59bb985a 100644 --- a/xsuite/src/world/lsworld.test.ts +++ b/xsuite/src/world/lsworld.test.ts @@ -25,6 +25,11 @@ const emptyAccount = { }; const baseExplorerUrl = "http://explorer.local"; +test.concurrent("LSWorld.start - port 3000", async () => { + using world = await LSWorld.start({ binaryPort: 3000 }); + expect(world.proxy.proxyUrl).toEqual("http://127.0.0.1:3000"); +}); + test.concurrent( "LSWorld.proxy.getAccountNonce on empty bech address", async () => { @@ -487,6 +492,42 @@ test.concurrent("LSWorld.transfer", async () => { }); }); +test.concurrent( + "LSWorld.transfer - invalid tx - gasLimit too low", + async () => { + using world = await LSWorld.start(); + const { wallet } = await createAccounts(world); + await expect( + world.transfer({ + sender: wallet, + receiver: wallet, + value: 0, + gasLimit: 0, + }), + ).rejects.toThrow("insufficient gas limit"); + }, +); + +test.concurrent( + "LSWorld.doTransfers - invalid tx - gasLimit too low", + async () => { + using world = await LSWorld.start(); + const { wallet } = await createAccounts(world); + await expect( + world.doTransfers([ + { + sender: wallet, + receiver: wallet, + value: 0, + gasLimit: 0, + }, + ]), + ).rejects.toThrow( + "Only 0 of 1 transactions were sent. The other ones were invalid.", + ); + }, +); + test.concurrent("LSWorld.deployContract", async () => { using world = await LSWorld.start({ explorerUrl: baseExplorerUrl }); const { wallet } = await createAccounts(world); diff --git a/xsuite/src/world/lsworld.ts b/xsuite/src/world/lsworld.ts index 291fddb2..3ba1cea4 100644 --- a/xsuite/src/world/lsworld.ts +++ b/xsuite/src/world/lsworld.ts @@ -1,12 +1,11 @@ -import { ChildProcess } from "node:child_process"; +import { ChildProcess, spawn } from "node:child_process"; +import { lsproxyBinaryPath } from "@xsuite/light-simulnet"; import { fullU8AAddress } from "../data/address"; import { AddressLike, isAddressLike } from "../data/addressLike"; import { EncodableAccount } from "../data/encoding"; import { Prettify, Replace } from "../helpers"; import { LSProxy } from "../proxy"; import { Block } from "../proxy/lsproxy"; -import { killChildProcess } from "./childProcesses"; -import { startLsproxyBin } from "./lsproxyBin"; import { DummySigner, Signer } from "./signer"; import { AddressLikeParams, createAddressLike } from "./utils"; import { @@ -69,8 +68,37 @@ export class LSWorld extends World { static async start({ gasPrice, explorerUrl, - }: { gasPrice?: number; explorerUrl?: string } = {}): Promise { - const { server, proxyUrl } = await startLsproxyBin(); + binaryPath, + binaryPort, + }: { + gasPrice?: number; + explorerUrl?: string; + binaryPath?: string; + binaryPort?: number; + } = {}): Promise { + binaryPath ??= lsproxyBinaryPath; + binaryPort ??= 0; + + const server = spawn(binaryPath, ["--server-port", `${binaryPort}`]); + + server.stderr.on("data", (data: Buffer) => { + throw new Error(data.toString()); + }); + + server.on("error", (error) => { + throw error; + }); + + const proxyUrl = await new Promise((resolve) => { + server.stdout.on("data", (data: Buffer) => { + const addressRegex = /Server running on (http:\/\/[\w\d.:]+)/; + const match = data.toString().match(addressRegex); + if (match) { + resolve(match[1]); + } + }); + }); + return LSWorld.new({ proxyUrl, gasPrice, explorerUrl, server }); } @@ -172,7 +200,7 @@ export class LSWorld extends World { terminate() { if (!this.server) throw new Error("No server defined."); - killChildProcess(this.server); + this.server.kill(); } [Symbol.dispose]() { diff --git a/xsuite/vitest.config.mts b/xsuite/vitest.config.mts index 70f8e272..c1932e98 100644 --- a/xsuite/vitest.config.mts +++ b/xsuite/vitest.config.mts @@ -6,6 +6,7 @@ export default defineConfig({ target: "es2022", }, test: { + maxConcurrency: 10, typecheck: { enabled: true, },