Can't test simple Truffle project - solidity

I'm trying to create a simple solidity project using truffle but I'm having problems :(
Projects $ nvm current
v16.16.0
Projects $ mkdir SimpleProject
Projects $ cd SimpleProject
SimpleProject $ truffle init
Starting init...
================
> Copying project files to /home/personal/Projects/SimpleProject
Init successful, sweet!
Try our scaffold commands to get started:
$ truffle create contract YourContractName # scaffold a contract
$ truffle create test YourTestName # scaffold a test
http://trufflesuite.com/docs
SimpleProject $
SimpleProject $ truffle create contract SimpleProject
SimpleProject $ truffle create test TestSimpleProject
SimpleProject $
SimpleProject $ truffle test
Compiling your contracts...
===========================
> Compiling ./contracts/Migrations.sol
> Compiling ./contracts/SimpleProject.sol
> Compilation warnings encountered:
Warning: Visibility for constructor is ignored. If you want the contract to be non-deployable, making it "abstract" is sufficient.
--> project:/contracts/SimpleProject.sol:5:3:
|
5 | constructor() public {
| ^ (Relevant source part starts here and spans across multiple lines).
> Artifacts written to /tmp/test--16503-cBYOoJTkVAN1
> Compiled successfully using:
- solc: 0.8.15+commit.e14f2714.Emscripten.clang
Error: Could not find artifacts for TestSimpleProject from any sources
at Resolver.require (/home/personal/.nvm/versions/node/v16.16.0/lib/node_modules/truffle/build/webpack:/packages/resolver/dist/lib/resolver.js:60:1)
at Object.require (/home/personal/.nvm/versions/node/v16.16.0/lib/node_modules/truffle/build/webpack:/packages/core/lib/testing/Test.js:280:1)
at Object.<anonymous> (/home/personal/Projects/SimpleProject/test/test_simple_project.js:1:37)
at Module._compile (node:internal/modules/cjs/loader:1105:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at /home/personal/.nvm/versions/node/v16.16.0/lib/node_modules/truffle/node_modules/mocha/lib/mocha.js:417:36
at Array.forEach (<anonymous>)
at Mocha.loadFiles (/home/personal/.nvm/versions/node/v16.16.0/lib/node_modules/truffle/node_modules/mocha/lib/mocha.js:414:14)
at Mocha.run (/home/personal/.nvm/versions/node/v16.16.0/lib/node_modules/truffle/node_modules/mocha/lib/mocha.js:1015:10)
at /home/personal/.nvm/versions/node/v16.16.0/lib/node_modules/truffle/build/webpack:/packages/core/lib/testing/Test.js:156:1
at new Promise (<anonymous>)
at Object.run (/home/personal/.nvm/versions/node/v16.16.0/lib/node_modules/truffle/build/webpack:/packages/core/lib/testing/Test.js:155:1)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at startGanacheAndRunTests (/home/personal/.nvm/versions/node/v16.16.0/lib/node_modules/truffle/build/webpack:/packages/core/lib/commands/test/run.js:49:1)
at Object.module.exports [as run] (/home/personal/.nvm/versions/node/v16.16.0/lib/node_modules/truffle/build/webpack:/packages/core/lib/commands/test/run.js:106:1)
at runCommand (/home/personal/.nvm/versions/node/v16.16.0/lib/node_modules/truffle/build/webpack:/packages/core/lib/command-utils.js:184:1)
Truffle v5.5.22 (core: 5.5.22)
Node v16.16.0
SimpleProject $

truffle create test TestSimpleProject command creates a file test/test_simple_project.js with the following contents:
const TestSimpleProject = artifacts.require("TestSimpleProject");
/*
* uncomment accounts to access the test accounts made available by the
* Ethereum client
* See docs: https://www.trufflesuite.com/docs/truffle/testing/writing-tests-in-javascript
*/
contract("TestSimpleProject", function (/* accounts */) {
it("should assert true", async function () {
await TestSimpleProject.deployed();
return assert.isTrue(true);
});
});
On the first line, you can see that it's trying to load a contract named TestSimpleProject - the same contract name as you specified the test name. But there's no contract with this name in your project.
A simple fix is to change the name of the contract required for the test.
test/test_simple_project.js
const TestSimpleProject = artifacts.require("SimpleProject");
Or you can pass an existing contract name when you're creating the test.
truffle create test SimpleProject
Either way, don't forget to create a migration file for this contract.
migrations/2_simple_project.js
const SimpleProject = artifacts.require("SimpleProject");
module.exports = function (deployer) {
deployer.deploy(SimpleProject);
};

Related

Error: Cannot find module 'symbol-observable' in Angular

I'm getting the below error while running ng new. Tried with cmd opening as Administrator, but not helping.
D:\Training\Angular>ng new test
internal/modules/cjs/loader.js:797
throw err;
^
Error: Cannot find module 'symbol-observable'
Require stack:
- C:\Users\mubarakm\AppData\Roaming\npm\node_modules\#angular\cli\lib\init.js
- C:\Users\mubarakm\AppData\Roaming\npm\node_modules\#angular\cli\bin\ng
←[90m at Function.Module._resolveFilename (internal/modules/cjs/loader.js:794:15)←[39m
←[90m at Function.Module._load (internal/modules/cjs/loader.js:687:27)←[39m
←[90m at Module.require (internal/modules/cjs/loader.js:849:19)←[39m
←[90m at require (internal/modules/cjs/helpers.js:74:18)←[39m
at Object.<anonymous> (C:\Users\mubarakm\AppData\Roaming\npm\node_modules\←[4m#angular←[24m\cli\lib\init.js:10:1)
←[90m at Module._compile (internal/modules/cjs/loader.js:956:30)←[39m
←[90m at Object.Module._extensions..js (internal/modules/cjs/loader.js:973:10)←[39m
←[90m at Module.load (internal/modules/cjs/loader.js:812:32)←[39m
←[90m at Function.Module._load (internal/modules/cjs/loader.js:724:14)←[39m
←[90m at Module.require (internal/modules/cjs/loader.js:849:19)←[39m {
code: ←[32m'MODULE_NOT_FOUND'←[39m,
requireStack: [
←[32m'C:\\Users\\mubarakm\\AppData\\Roaming\\npm\\node_modules\\#angular\\cli\\lib\\init.js'←[39m,
←[32m'C:\\Users\\mubarakm\\AppData\\Roaming\\npm\\node_modules\\#angular\\cli\\bin\\ng'←[39m
]
}
npm i --save symbol-observable (or Yarn, then, Yarn add symbol-observable)
npm install (or Yarn)
npm outdated (or yarn outdated) to check for outdated dependencies(symbol-observable) then upgrading it to the corresonding version if needed by entering yarn upgrade symbol-observable #[version]
Else,
check if you import it correctly from
import { Observable } from 'rxjs/Observable';
to
import { Observable } from 'rxjs';
otherwise,you may have Rxjs issues as mentionned here https://github.com/angular/angular-cli/issues/4756
Simply check for any outdated dependencies using "npm outdated", and if there are any update the angular cli using command "npm update -g #angular/cli", should be good to go.

Cannot find module "postgraphile plugin upload field "

i installed postgraphile-plugin-upload-field
npm i graphile-contrib/postgraphile-plugin-upload-field
then
postgraphile -c 'postgres://postgres:mysecretpass#192.168.38.4:5432/gimapp' --cors -p 5001 --enhance-graphiql --host "0.0.0.0" -s messages,basic_auth,user --append-plugins #graphile/postgis,#graphile-contrib/pg-simplify-inflector,postgraphile-plugin-connection-filter,#graphile-contrib/postgraphile-plugin-upload-field --watch --no-ignore-indexes --jwt-token-identifier basic_auth.jwt_token --jwt-secret mysecretpass
throws exception like this.
Failed to load plugin '#graphile-contrib/postgraphile-plugin-upload-field'
/usr/lib/node_modules/postgraphile/build/postgraphile/cli.js:268
throw e;
^
Error: Cannot find module '#graphile-contrib/postgraphile-plugin-upload-field'
Require stack:
- /usr/lib/node_modules/postgraphile/build/postgraphile/cli.js
- /usr/lib/node_modules/postgraphile/cli.js
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:925:15)
at Function.Module._load (node:internal/modules/cjs/loader:769:27)
at Module.require (node:internal/modules/cjs/loader:997:19)
at require (node:internal/modules/cjs/helpers:92:18)
at /usr/lib/node_modules/postgraphile/build/postgraphile/cli.js:263:20
at Array.map (<anonymous>)
at loadPlugins (/usr/lib/node_modules/postgraphile/build/postgraphile/cli.js:255:18)
at Object.<anonymous> (/usr/lib/node_modules/postgraphile/build/postgraphile/cli.js:323:23)
at Module._compile (node:internal/modules/cjs/loader:1108:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1137:10) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/usr/lib/node_modules/postgraphile/build/postgraphile/cli.js',
'/usr/lib/node_modules/postgraphile/cli.js'
]
}
and here is another situation if i remove #graphile-contrib
postgraphile -c 'postgres://postgres:mysecretpass#192.168.38.4:5432/gimapp' --cors -p 5001 --enhance-graphiql --host "0.0.0.0" -s messages,basic_auth,user --append-plugins #graphile/postgis,#graphile-contrib/pg-simplify-inflector,postgraphile-plugin-connection-filter,postgraphile-plugin-upload-field --watch --no-ignore-indexes --jwt-token-identifier basic_auth.jwt_token --jwt-secret mysecretpass
here is the error:
PostGraphile v4.10.0 server listening on port 5001 🚀
Recoverable error occurred; use envvar 'DEBUG="graphile-build:warn"' for full error (see: https://graphile.org/postgraphile/debugging )
> TypeError: Cannot read property 'filter' of undefined…
Recoverable error occurred; use envvar 'DEBUG="graphile-build:warn"' for full error (see: https://graphile.org/postgraphile/debugging )

Error in React Native with RealmJS- Command PhaseScriptExecution failed with a nonzero exit code

Using Node.js v12.13.0 internal/modules/cjs/loader.js:797
throw err;
^
Error: Cannot find module '/Users/ABC/Projects/ReactNative/Project ABCD'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:794:15)
at Function.Module._load (internal/modules/cjs/loader.js:687:27)
at Function.Module.runMain (internal/modules/cjs/loader.js:1025:10)
at internal/main/run_main_module.js:17:11 { code: 'MODULE_NOT_FOUND', requireStack: [] }
Command PhaseScriptExecution failed with a nonzero exit code
It seems like you are trying to reference a module that lives somewhere else. Can we see project code and file structure?
I resolved this issue by just removing a space from project folder name.
'Project ABCD' -> 'Project_ABCD'

Webpack migration 3 -> 4: Error: Cannot find module 'webpack/lib/optimize/CommonsChunkPlugin'

I'm trying to migrate from webpack 3 to webpack 4.
The issue I have is with CommonsChunkPlugin, when I try to run webpack (npm run webpack-dev-server -- --config config/webpack.dev.js), I have the following error:
module.js:529
throw err;
^
Error: Cannot find module 'webpack/lib/optimize/CommonsChunkPlugin'
at Function.Module._resolveFilename (module.js:527:15)
at Function.Module._load (module.js:476:23)
at Module.require (module.js:568:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/Users/antoinepissot/DEV/Reports/config/webpack.common.js:17:28)
at Module._compile (module.js:624:30)
at Object.Module._extensions..js (module.js:635:10)
at Module.load (module.js:545:32)
at tryModuleLoad (module.js:508:12)
at Function.Module._load (module.js:500:3)
What is causing this issue ?
I looked at the change log on webpack github and found that CommonsChunkPlugin has been removed
But when I look at the webpack documentation, I can find CommonsChunkPlugin for version 4.1.1
My gut feeling is telling me that CommonsChunkPlugin is deprecated and we should use optimization.splitChunks.
Did anyone experienced the issue and found a good tutorial to migrate from version 3 to 4 ?
As Vardius pointed out in his comment, CommonsChunkPlugin was removed.
In webpack 4, this behaviour is done using "optimization" field at the root of webpack config.
For instance, this is how my webpack.config.js looks like now:
module.exports = function () {
return {
resolve: ...
module: ...
plugins: ...
optimization: {
namedModules: true, // old NamedModulesPlugin()
splitChunks: { // old CommonsChunkPlugin
chunks: "all"
},
runtimeChunk: true,
concatenateModules: true // old ModuleConcatenationPlugin
}
}

How do I specify the path from which my Sublime Text Build will run?

I am trying to run mocha tests from my Sublime Text 3 build module. My mocha build is:
/* Mocha.sublime-build */
{
"shell_cmd": "mocha -c --opts test/mocha.opts $file",
"shell": true,
"working_dir": "${project_path}",
"target": "ansi_color_build",
"syntax": "Packages/ANSIescape/ANSI.tmLanguage"
}
When I use Cmd+B to run my mocha build it responds with an error because my Node version doesn't support "import" statements. I have a mocha.opts file:
--require babel-register
--recursive
When running Mocha from the command line in the root project directory it works fine. How do I get the Mocha Build system to run from the root directory and receive instructions from mocha.opts?
This is the error that gets reported. It doesnt appear to be running babel.
(function (exports, require, module, __filename, __dirname) { import { expect } from 'chai'
^^^^^^
SyntaxError: Unexpected token import
at Object.exports.runInThisContext (vm.js:76:16)
at Module._compile (module.js:528:28)
at Object.Module._extensions..js (module.js:565:10)
at Module.load (module.js:473:32)
at tryModuleLoad (module.js:432:12)
at Function.Module._load (module.js:424:3)
at Module.require (module.js:483:17)
at require (internal/module.js:20:19)
at /usr/local/lib/node_modules/mocha/lib/mocha.js:220:27
Here is what is in my .babelrc:
{
"presets": ["stage-0", "es2015"]
}
My file structure is:
/Project
->public
->tests
->mocha.opts
->fooTests
->individualFooTest.js